コード例 #1
0
ファイル: SDL_pspevents.c プロジェクト: Helios-vmg/CopperRat
void PSP_PumpEvents(_THIS)
{
    int i;
    enum PspHprmKeys keys;
    enum PspHprmKeys changed;
    static enum PspHprmKeys old_keys = 0;
    SDL_Keysym sym;

    SDL_SemWait(event_sem);
    keys = hprm;
    SDL_SemPost(event_sem);

    /* HPRM Keyboard */
    changed = old_keys ^ keys;
    old_keys = keys;
    if(changed) {
        for(i=0; i<sizeof(keymap_psp)/sizeof(keymap_psp[0]); i++) {
            if(changed & keymap_psp[i].id) {
                sym.scancode = keymap_psp[i].id;
                sym.sym = keymap_psp[i].sym;

                /* out of date
                SDL_PrivateKeyboard((keys & keymap_psp[i].id) ?
                            SDL_PRESSED : SDL_RELEASED,
                            &sym);
        */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap_psp[i].sym));
            }
        }
    }

#ifdef PSPIRKEYB
    if (irkbd_ready) {
            unsigned char buffer[255];
        int i, length, count;
        SIrKeybScanCodeData *scanData;

            if(pspIrKeybReadinput(buffer, &length) >= 0) {
                if((length % sizeof(SIrKeybScanCodeData)) == 0){
                    count = length / sizeof(SIrKeybScanCodeData);
                    for( i=0; i < count; i++ ) {
                unsigned char raw, pressed;
                        scanData=(SIrKeybScanCodeData*) buffer+i;
                        raw = scanData->raw;
                        pressed = scanData->pressed;
                sym.scancode = raw;
                sym.sym = keymap[raw];
                /* not tested */
                /* SDL_PrivateKeyboard(pressed?SDL_PRESSED:SDL_RELEASED, &sym); */
                SDL_SendKeyboardKey((keys & keymap_psp[i].id) ?
                                    SDL_PRESSED : SDL_RELEASED, SDL_GetScancodeFromKey(keymap[raw]);

                }
            }
        }
    }
コード例 #2
0
ファイル: main.c プロジェクト: Bracket-/psp-ports
/*
 *  this will get raw chars from the keyboard
 */
void outputScanCodeTest()
{
    unsigned char shift, ctrl, alt, pressed, raw, termchar = KEY_X;
    unsigned char buffer[255];
    SIrKeybScanCodeData * scanData;
    int i, length, count;

    printf( "outputScanCodeTest\n" );
    printf("\npress %s on keyboard to exit\n", pspIrKeybRawkeyName( termchar ) );

    while(1) {
        if( pspIrKeybReadinput(buffer, &length) >= 0 )
        {
            if( ( length % sizeof(SIrKeybScanCodeData) ) > 0 ) {
                printf( "error: read length is %d\n", length );
                break;
            }
            count = length / sizeof(SIrKeybScanCodeData);
            for( i=0; i < count; i++ )
            {
                scanData=(SIrKeybScanCodeData*) buffer+i;

                raw = scanData->raw;
                shift = scanData->shift;
                ctrl = scanData->ctrl;
                alt = scanData->alt;
                pressed = scanData->pressed;
                
                if( raw == KEY_RESERVED )
                {
                    printf( "DEAD KEY - please check driver\n" );
                }
                else if( raw >= (unsigned char)KEY_MAX )
                {
                    printf( "!illegal KEY - please check driver\n" );
                }
                else
                {
                    printf( "scan: %3d - '%18s' (%8s) %s %s %s\n", raw, 
                             pspIrKeybRawkeyName( raw ), pressed ? "pressed" : "released",
                             shift ? "shift" : "", alt ? "alt" : "", ctrl ? "ctrl" : "" );
                    if( raw == termchar )
                        return;
                }
            }
        } 
        else 
        {
            // tick(); do what you want here... keyboard is not blocking
        }
    }
}
コード例 #3
0
ファイル: main.c プロジェクト: Bracket-/psp-ports
/*
 *  this will get raw chars from the keyboard
 */
void outputRawTest()
{
    unsigned char pressed, raw, termchar = KEY_X;
    unsigned char buffer[255];
    SIrKeybRawCodeData * rawData;
    int i, count, length;

    printf( "outputRawTest\n" );
    printf("\npress %s on keyboard to exit\n", pspIrKeybRawkeyName( termchar ) );

    while(1) {
        if( pspIrKeybReadinput(buffer, &length) >= 0 )
        {
            if( ( length % sizeof(SIrKeybRawCodeData) ) > 0 ) {
                printf( "error: read length is %d\n", length );
                break;
            }
            count = length / sizeof(SIrKeybRawCodeData);
            for( i=0; i < count; i++ )
            {
                rawData = (SIrKeybRawCodeData*)buffer+i;
                pressed = rawData->pressed;
                raw = rawData->raw;

                if( raw == KEY_RESERVED )
                {
                    printf( "DEAD KEY - please check driver\n" );
                }
                else if( raw >= (unsigned char)KEY_MAX )
                {
                    printf( "!illegal KEY - please check driver\n" );
                }
                else
                {
                    printf( "raw: %3d - '%18s' (%8s)\n", raw, 
                             pspIrKeybRawkeyName( raw ), pressed ? "pressed" : "released" );
                    if( raw == termchar )
                        return;
                }
            }
        } 
        else 
        {
            // tick(); do what you want here... keyboard is not blocking
        }
    }
}
コード例 #4
0
ファイル: main.c プロジェクト: Bracket-/psp-ports
/*
 *  this will get ascii chars from the keyboard
 */
void outputAsciiTest()
{
    unsigned char termchar = 'X';
    unsigned char buffer[255];
    int i, length=0;
    
    printf( "outputAsciiTest\n" );
    printf("\npress %c on keyboard to exit\n", termchar );

    while(1) {
        if( pspIrKeybReadinput(buffer, &length) >= 0 )
        {
            for( i=0; i < length; i++ )
                printf( "%c", buffer[i] ); 
            if( length == 1 && buffer[0] == termchar )
                break;
        } 
        else 
        {
            // tick(); do what you want here... keyboard is not blocking
        }
    }
}
コード例 #5
0
ファイル: psp_irkeyb.c プロジェクト: kerheol/dingux-atari
static int
psp_irkeyb_check_key()
{
  int key = PSP_IRKEYB_EMPTY;
  loc_irkbd_inc_step = 0;
  if (loc_psp_irkeyb_mode) {
    if (loc_irkbd_current >= loc_irkbd_length) {
      loc_irkbd_current = 0;
      loc_irkbd_length  = 0;
      pspIrKeybReadinput(loc_irkbd_buffer, &loc_irkbd_length);
    }
    int delta = loc_irkbd_length - loc_irkbd_current;
    if (delta >= 5) {
      u8* scan_buffer = &loc_irkbd_buffer[loc_irkbd_current];
      if (!strncmp(scan_buffer, "\033[[3~", 5)) {
        key = PSP_IRKEYB_SUPPR;
        loc_irkbd_inc_step = 5;
      } else
      if (!strncmp(scan_buffer, "\033[[2~", 5)) {
        key = PSP_IRKEYB_INSERT;
        loc_irkbd_inc_step = 5;
      } else
      if (!strncmp(scan_buffer, "\033[OH~", 5)) {
        key = PSP_IRKEYB_HOME;
        loc_irkbd_inc_step = 5;
      } else
      if (!strncmp(scan_buffer, "\033[[5~", 5)) {
        key = PSP_IRKEYB_PAGEUP;
        loc_irkbd_inc_step = 5;
      } else
      if (!strncmp(scan_buffer, "\033[[6~", 5)) {
        key = PSP_IRKEYB_PAGEDOWN;
        loc_irkbd_inc_step = 5;
      }
    }
    if (delta >= 4) {
      u8* scan_buffer = &loc_irkbd_buffer[loc_irkbd_current];
      if (!strncmp(scan_buffer, "\033[OF", 4)) {
        key = PSP_IRKEYB_END;
        loc_irkbd_inc_step = 4;
      } else
      if (!strncmp(scan_buffer, "\033[[Z", 4)) {
        key = PSP_IRKEYB_START;
        loc_irkbd_inc_step = 4;
      }
    }
    if (delta >= 3) {
      u8* scan_buffer = &loc_irkbd_buffer[loc_irkbd_current];
      if (!strncmp(scan_buffer, "\033[B", 3)) {
        key = PSP_IRKEYB_DOWN;
        loc_irkbd_inc_step = 3;
      } else 
      if (!strncmp(scan_buffer, "\033[A", 3)) {
        key = PSP_IRKEYB_UP;
        loc_irkbd_inc_step = 3;
      } else 
      if (!strncmp(scan_buffer, "\033[C", 3)) {
        key = PSP_IRKEYB_RIGHT;
        loc_irkbd_inc_step = 3;
      } else
      if (!strncmp(scan_buffer, "\033[D", 3)) {
        key = PSP_IRKEYB_LEFT;
        loc_irkbd_inc_step = 3;
      }
    }
    if (delta >= 1) { 
      if (key == PSP_IRKEYB_EMPTY) {

        key = loc_irkbd_buffer[loc_irkbd_current];
        if ((key == 9) || (key == 23)) key = PSP_IRKEYB_START; //W
        else
        if ((key == 0x1b) || (key == 17)) key = PSP_IRKEYB_SELECT; //Q
        else
        if (key == 5) key = PSP_IRKEYB_TRIANGLE; //E
        else
        if (key == 19) key = PSP_IRKEYB_SQUARE; //S
        else
        if (key == 24) key = PSP_IRKEYB_CROSS; //X
        else
        if (key == 6) key = PSP_IRKEYB_CIRCLE; //F
        else
        if (key == 26) key = PSP_IRKEYB_LTRIGGER; //Z
        else
        if (key == 3) key = PSP_IRKEYB_RTRIGGER; //R

        loc_irkbd_inc_step = 1;
      }
    }
  }
# if 0 //LUDO: DEBUG
  if (key != PSP_IRKEYB_EMPTY) {
    fprintf(stdout, "press %x %c\n", key, key);
  }
# endif
  return key;
}
コード例 #6
0
ファイル: main.c プロジェクト: Bracket-/psp-ports
int main(int argc, char *argv[])
{
    SceCtrlData pad;
    u32 buttonsold = 0;
    int kernelmode = 0;       /* only 0 works for now - some keyboards need baud change */
    const char *config_file = NULL; /* this will force ms0:/seplugins/pspirkeyb.ini */

	SetupCallbacks();

    pspDebugScreenInit();
    printf("PSP Irda Keyboard test - ASCii input \n");

	if (sceKernelDevkitVersion() >= 0x03080010)
	{
        /* Load irda PRX for CFW >= 3.80 - Thanks, ZX81! */
        u32 mod_id = sceKernelLoadModule("flash0:/kd/irda.prx", 0, NULL);
        sceKernelStartModule(mod_id, 0, NULL, NULL, NULL);
	}

    if( pspIrKeybInit( config_file, kernelmode ) != 0 )
    {
        printf( "error: can't inialize the keyboard\n" );
        printf( "       check keyboard type/map in ms0:/seplugins/pspirkeyb.ini\n" );
    }
    else
    {
        unsigned char termchar = 'X';
        unsigned char buffer[255];
        int i, length=0;

        printf("\npress %c on keyboard or any PSP button to exit\n", termchar );

        /* setup output method to ASCii */
        pspIrKeybOutputMode( PSP_IRKBD_OUTPUT_MODE_ASCII );

        while(1) {
            length = 0;
            /* non blocking read */
            if( pspIrKeybReadinput(buffer, &length) >= 0 )
            {
                for( i=0; i < length; i++ )
                    printf( "%c", buffer[i] );
                if( length == 1 && buffer[0] == termchar )
                    break;
            }
            else
            {
                sceKernelDelayThread(10*1000);
                sceCtrlReadBufferPositive(&pad, 1);
                if (pad.Buttons != buttonsold)
                    break;
            }
        }

        /* bye keyboard */
        pspIrKeybFinish();
    }

    printf( "\n bye... (PRESS psp button to quit)\n" );

    buttonsold = 0;
    while (1) {
        sceCtrlReadBufferPositive(&pad, 1);
        if (pad.Buttons != buttonsold) {
            /* Exit */
            sceKernelExitGame();
        }
    }

	return 0;
}