SDL_PollEvent() - question for programmers

Here for general support for B series TVs, request and problem solve area.
Post Reply

geo650
Official SamyGO Developer
Posts: 303
Joined: Wed Oct 07, 2009 12:03 pm

SDL_PollEvent() - question for programmers

Post by geo650 »

Hi!
I am working on "Game" library for Content Library that is going to use USB keyboard connected to the TV-set.
Unfortunetely, I cannot force my application to get pressed key information.
Function SDL_PollEvent(&event) always returns false (or 0).
I am doing SDL initialisation by SDL_Init(SDL_INIT_VIDEO), then setting video mode by SDL_SetVideoMode(), then loading and displaying some bitmaps (which are displayed well), then waiting for keypresses.
USB HID drivers are loaded (can be checked by lsmod command) and keyboard seems to be working (you can light NumLock etc.)
Also, SDL_EnableUNICODE(1) doesn't help.
What is going on? What mistake do I make?

Code: Select all

SDL_Event event;
SDL_Surface *screen;
int quit = 0;

SDL_Init(SDL_INIT_VIDEO);
...
screen = SDL_SetVideoMode(1920/2,1080/2,32,0)
...
SDL_EnableUNICODE(1);

while (!quit)
{
   if (SDL_PollEvent(&event)) ....never got here....;
   ...
}
arris69
Official SamyGO Developer
Posts: 1700
Joined: Fri Oct 02, 2009 8:52 am
Location: Austria/Vienna (no Kangaroos here)
Contact:

Re: SDL_PollEvent() - question for programmers

Post by arris69 »

but you get events from tv's remote?
you have also the device files?
like:

Code: Select all

    /* for keyboard and mouse */
    mode_t mode = S_IFCHR;
    mode_t perm = 0666;
    dev_t dev;
    char device[100];
    umask(0);
    mkdir("/dtv/usb", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    mkdir("/dtv/usb/dev", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    mkdir("/dtv/usb/dev/input", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    for (i = 0; i < 7; i++) {
        dev = makedev(13, 64 + i);
        sprintf(device, "/dtv/usb/dev/input/event%d", i);
        mknod(device, mode | perm , dev);
    }
    for (i = 0; i < 2; i++) {
        dev = makedev(13, 32 + i);
        sprintf(device, "/dtv/usb/dev/input/mouse%d", i);
        mknod(device, mode | perm, dev);
    }
    dev = makedev(13, 63);
    mknod("/dtv/usb/dev/input/mice", mode | perm, dev);
hth
arris
geo650
Official SamyGO Developer
Posts: 303
Joined: Wed Oct 07, 2009 12:03 pm

Re: SDL_PollEvent() - question for programmers

Post by geo650 »

arris69 wrote:but you get events from tv's remote?
you have also the device files?
like:...
Thank you for your quick answer. You're right about tv's remote: I didn't notice this before but my tv's remote produces correct events. But USB keyboard does not. I think the code you posted does the same my code does in system command called before SDL_Init():

Code: Select all

insmod usbhid.ko; insmod evdev.ko; i=0; while [ $i -le 31 ]; do mknod /dtv/event$i c 13 $(($i + 64)); i=$(( i + 1 )); done
Am I right?
It is strange but keyboard works in other applications but not in this new one.
Maybe I should post the whole (simplified) source code of my app?

EDIT:
One more information: when I link with SamyGO "libSDL.a" it seems to work well (reads keyboard events) but there is a problem after exiting Content Library because TV screen stays covered by my last SDL screen surface. Calling Content Library again and exiting to TV mode can clean this. By the way, 6KB-application grows to 200KB when linked statically(?) with libSDL.
aquadran
Posts: 264
Joined: Fri Oct 16, 2009 9:35 pm
Location: Poland

Re: SDL_PollEvent() - question for programmers

Post by aquadran »

geo650 wrote:
arris69 wrote:but you get events from tv's remote?
you have also the device files?
like:...
Thank you for your quick answer. You're right about tv's remote: I didn't notice this before but my tv's remote produces correct events. But USB keyboard does not. I think the code you posted does the same my code does in system command called before SDL_Init():

Code: Select all

insmod usbhid.ko; insmod evdev.ko; i=0; while [ $i -le 31 ]; do mknod /dtv/event$i c 13 $(($i + 64)); i=$(( i + 1 )); done
Am I right?
It is strange but keyboard works in other applications but not in this new one.
Maybe I should post the whole (simplified) source code of my app?

EDIT:
One more information: when I link with SamyGO "libSDL.a" it seems to work well (reads keyboard events) but there is a problem after exiting Content Library because TV screen stays covered by my last SDL screen surface. Calling Content Library again and exiting to TV mode can clean this. By the way, 6KB-application grows to 200KB when linked statically(?) with libSDL.
Use SamyGO SDL port, and can be only used as staticaly linked to override SDL library builded into tv.
I'm not sure right now about exiting, but you should handle SDLK_POWER key which mean you need quit your application and make SDL_Quit().
If you do any improvements into port code share with me I'll update it on site.
geo650
Official SamyGO Developer
Posts: 303
Joined: Wed Oct 07, 2009 12:03 pm

Re: SDL_PollEvent() - question for programmers

Post by geo650 »

aquadran wrote:Use SamyGO SDL port, and can be only used as staticaly linked to override SDL library builded into tv.
I'm not sure right now about exiting, but you should handle SDLK_POWER key which mean you need quit your application and make SDL_Quit().
If you do any improvements into port code share with me I'll update it on site.
I think, I use SamyGO SDL port now (by linking). I am not going to make any changes to SamyGO SDL but I am trying to understand what is going on.
I am attaching my simple application so you may check these strange effects. Instructions: please connect USB keyboard, run this app from pendrive, then hit some keys or buttons (you'll see some information on the screen), and then when you exit by F10, then hit TV on your remote control to quit Content Library menu. The screen will be dirty. But if you exit by EXIT remote's button, then TV button, the screen will be clear. :? It is strange because SDLK_POWER and SDLK_F10 are in the same place of code (switch/case). Please check my source code (only 200 lines of code with comments and spaces). As you will see, SDL_Quit() is performed after EXIT or F10 key is pressed. I don't know what to think.
Thank you.

EDIT: Forget it. I made another application and this effect does not occur anymore. Thanks for explaining linking of SDL.

Post Reply

Return to “[B] Support”