skeezix
Internal Development
libpnd is really a few parts, some parts of which most people will never concern themselves with. Other parts I think every dev for Pandora should be aware of
Aside: Let me know if theres anything you'd like in there, and if its something I can squeeze in I'll see what I can do. Otherwise, you can add it yourself I'm really hoping people will keep going with the 'this is really great bit, lets add it to libpnd so no one else has to reinvent the wheel' .. I'm hoping we won't have too many similar-but-different approaches to the same things, as that just increases the surface area for issues. Anyway..
Anyway, I've added a really basic simple way to read the nubs and d-pads, and thought I'd post it here so you know where to look for your upcoming projects; theres a couple input methods in there, but I'm referring to one I just called 'pnd evdev'.
I expect most people will use SDL for IO, and that will mostly 'just work'...
- SDL audio, works fine
- SDL keyboard will pick up d-pads (SDLK_LEFT for left on the d-pad, for instance.)
- SDL surfaces work for rendering, and it'll center if fulscreen and a funny sized window (funny compared to our 800x480 I mean
Maybe I didn't enable something in SDL in my ports, but the nubs don't show up in SDL by default, but it is absolutely trival to pick up with the libpnd stuff.
You can pick up pretty much everything with SDL. If you're not using SDL, you can pick it all up through other means, and sample code and APIs are in libpnd to do it all for you, or show you the way.
I'll have some SDL answers below, and fill in the gaps; for pure non-SDL, its just easy.
Q: When someone hits a key on the pandora..
A: You get a SDL key event, generally. dpads, bpadbuttons, shoulders, start/select/pandora buttons too.
Q: If I want to have d-pad events sent as joystick events, can I?
A: The kernel will default to sending keyb events for those buttons; there is a device-gloval setting to switch it to send joystick events for dpad buttons. (Likewise, you can switch the nubs to be a mouse, too.)
NOTE: This _shoudl not_ really be used. Its a multitasking device, and if the user fires up 5 apps in a row that all screw with global settings, its just going tyo break everything. We've wrestled over it, but it is best to just not touch the settings and leave the default.
Q: If you want to use pnd_io_evdev.[ch] libs from libpnd, it is absoltuely trivial:
pnd_evdev_open ( pnd_evdev_dpads ) -> returns 0 on fail, 1 on success
pnd_evdev_catchup ( 0 /* no block */ ) -> lib catches up on events; call this before testing values. You can have it block (Wait for inputs) if you want.
pnd_evdev_get_dpad_state, and pnd_evdev_Get_nub_state() -> return the buttons that are down, or the x/y for the nubs.
Thats it, easy as pie. 'evdevtest' sample program included in libpnd.
Its really as easy as "int state = get state; if state & pnd_evdev_left -> move guy left". I added nub control as ST mouse to hatari in 5 lines of code. Seriously.
Q: If my SDL app gets keyboard events, but I don't want to it to handle d-pads soI can have them movie Mario around..
A: Then you can 1) ignore SDLK_LEFT/etc, perhaps using a if ( dpad_is_joystick ) mode of your own, or 2) switch device global mode (bad idea), or 3) comment out or don't use SDLK processing for those events, just use libpnd as above since its so easy.
Note; we used to have the kernel return joystick+keyb events for a single dpad hit, but that caused problems for apps that read both joystick and keyboard; since d-pad as keyboard is so utterly damned useful for keyboard (ie: d-pad to move cursor arounjd in abiword, to move selection around on the xfce desktop, and the various butotns as control and shift and such), thats the default. If you want to get dpad as something else, libpnd makes it very easy to do. And if you really want SDL_joystick type code ot just work, you can switch the mode of the device for your app.. but I would seriously think you shoudl ask the user first before breaking some of his keyboard
Consider..
pnd_nubstate_t ns;
pnd_evdev_get_nub_state ( pnd_evdev_nub1, &ns )
--> now you have ns.x and ns.y (-256 <-> +256 values for those)
We've made your life easy
jeff
Once we get right to release day, maybe I'll spend a few hours filling out wiki docs for some of the general purpose APIs (ie: the pnd magic stuff most will never look at, but I imagine cpu clock setting people will all want to see; or folks will roll their own, but thats sillyness
Aside: Let me know if theres anything you'd like in there, and if its something I can squeeze in I'll see what I can do. Otherwise, you can add it yourself I'm really hoping people will keep going with the 'this is really great bit, lets add it to libpnd so no one else has to reinvent the wheel' .. I'm hoping we won't have too many similar-but-different approaches to the same things, as that just increases the surface area for issues. Anyway..
Anyway, I've added a really basic simple way to read the nubs and d-pads, and thought I'd post it here so you know where to look for your upcoming projects; theres a couple input methods in there, but I'm referring to one I just called 'pnd evdev'.
I expect most people will use SDL for IO, and that will mostly 'just work'...
- SDL audio, works fine
- SDL keyboard will pick up d-pads (SDLK_LEFT for left on the d-pad, for instance.)
- SDL surfaces work for rendering, and it'll center if fulscreen and a funny sized window (funny compared to our 800x480 I mean
Maybe I didn't enable something in SDL in my ports, but the nubs don't show up in SDL by default, but it is absolutely trival to pick up with the libpnd stuff.
You can pick up pretty much everything with SDL. If you're not using SDL, you can pick it all up through other means, and sample code and APIs are in libpnd to do it all for you, or show you the way.
I'll have some SDL answers below, and fill in the gaps; for pure non-SDL, its just easy.
Q: When someone hits a key on the pandora..
A: You get a SDL key event, generally. dpads, bpadbuttons, shoulders, start/select/pandora buttons too.
Q: If I want to have d-pad events sent as joystick events, can I?
A: The kernel will default to sending keyb events for those buttons; there is a device-gloval setting to switch it to send joystick events for dpad buttons. (Likewise, you can switch the nubs to be a mouse, too.)
NOTE: This _shoudl not_ really be used. Its a multitasking device, and if the user fires up 5 apps in a row that all screw with global settings, its just going tyo break everything. We've wrestled over it, but it is best to just not touch the settings and leave the default.
Q: If you want to use pnd_io_evdev.[ch] libs from libpnd, it is absoltuely trivial:
pnd_evdev_open ( pnd_evdev_dpads ) -> returns 0 on fail, 1 on success
pnd_evdev_catchup ( 0 /* no block */ ) -> lib catches up on events; call this before testing values. You can have it block (Wait for inputs) if you want.
pnd_evdev_get_dpad_state, and pnd_evdev_Get_nub_state() -> return the buttons that are down, or the x/y for the nubs.
Thats it, easy as pie. 'evdevtest' sample program included in libpnd.
Its really as easy as "int state = get state; if state & pnd_evdev_left -> move guy left". I added nub control as ST mouse to hatari in 5 lines of code. Seriously.
Q: If my SDL app gets keyboard events, but I don't want to it to handle d-pads soI can have them movie Mario around..
A: Then you can 1) ignore SDLK_LEFT/etc, perhaps using a if ( dpad_is_joystick ) mode of your own, or 2) switch device global mode (bad idea), or 3) comment out or don't use SDLK processing for those events, just use libpnd as above since its so easy.
Note; we used to have the kernel return joystick+keyb events for a single dpad hit, but that caused problems for apps that read both joystick and keyboard; since d-pad as keyboard is so utterly damned useful for keyboard (ie: d-pad to move cursor arounjd in abiword, to move selection around on the xfce desktop, and the various butotns as control and shift and such), thats the default. If you want to get dpad as something else, libpnd makes it very easy to do. And if you really want SDL_joystick type code ot just work, you can switch the mode of the device for your app.. but I would seriously think you shoudl ask the user first before breaking some of his keyboard
Consider..
pnd_nubstate_t ns;
pnd_evdev_get_nub_state ( pnd_evdev_nub1, &ns )
--> now you have ns.x and ns.y (-256 <-> +256 values for those)
We've made your life easy
jeff
Once we get right to release day, maybe I'll spend a few hours filling out wiki docs for some of the general purpose APIs (ie: the pnd magic stuff most will never look at, but I imagine cpu clock setting people will all want to see; or folks will roll their own, but thats sillyness