mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-05 14:57:46 -04:00
more input wip
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@624 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
34581c95f8
commit
595491c499
5 changed files with 258 additions and 84 deletions
120
common/input.c
120
common/input.c
|
@ -23,8 +23,11 @@ static int in_dev_count = 0;
|
|||
static int in_bind_count(int drv_id)
|
||||
{
|
||||
int count = 0;
|
||||
if (drv_id == IN_DRVID_EVDEV)
|
||||
switch (drv_id) {
|
||||
case IN_DRVID_EVDEV:
|
||||
count = in_evdev_bind_count();
|
||||
break;
|
||||
}
|
||||
if (count <= 0)
|
||||
printf("input: failed to get bind count for drv %d\n", drv_id);
|
||||
|
||||
|
@ -48,8 +51,11 @@ static int *in_alloc_binds(int drv_id)
|
|||
static void in_free(in_dev_t *dev)
|
||||
{
|
||||
if (dev->probed) {
|
||||
if (dev->drv_id == IN_DRVID_EVDEV)
|
||||
switch (dev->drv_id) {
|
||||
case IN_DRVID_EVDEV:
|
||||
in_evdev_free(dev->drv_data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
dev->probed = 0;
|
||||
dev->drv_data = NULL;
|
||||
|
@ -157,37 +163,73 @@ int in_update(void)
|
|||
|
||||
for (i = 0; i < in_dev_count; i++) {
|
||||
if (in_devices[i].probed && in_devices[i].binds != NULL) {
|
||||
if (in_devices[i].drv_id == IN_DRVID_EVDEV)
|
||||
switch (in_devices[i].drv_id) {
|
||||
case IN_DRVID_EVDEV:
|
||||
result |= in_evdev_update(in_devices[i].drv_data, in_devices[i].binds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void **in_collect_drvdata(int drv_id, int *count)
|
||||
{
|
||||
static void *data[IN_MAX_DEVS];
|
||||
int i;
|
||||
|
||||
for (*count = i = 0; i < in_dev_count; i++) {
|
||||
if (in_devices[i].drv_id == drv_id && in_devices[i].probed)
|
||||
data[(*count)++] = in_devices[i].drv_data;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void in_set_blocking(int is_blocking)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < in_dev_count; i++) {
|
||||
if (in_devices[i].probed) {
|
||||
switch (in_devices[i].drv_id) {
|
||||
case IN_DRVID_EVDEV:
|
||||
in_evdev_set_blocking(in_devices[i].drv_data, is_blocking);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* update with wait for a press, return bitfield of BTN_*
|
||||
* update with wait for a press, return keycode
|
||||
* only can use 1 drv here..
|
||||
*/
|
||||
int in_update_menu(void)
|
||||
int in_update_keycode(int *dev_id, int *is_down)
|
||||
{
|
||||
int result = 0;
|
||||
#ifdef IN_EVDEV
|
||||
void *data[IN_MAX_DEVS];
|
||||
int i, count = 0;
|
||||
|
||||
for (i = 0; i < in_dev_count; i++) {
|
||||
if (in_devices[i].probed)
|
||||
data[count++] = in_devices[i].drv_data;
|
||||
}
|
||||
void **data;
|
||||
int i, id = 0, count = 0;
|
||||
|
||||
data = in_collect_drvdata(IN_DRVID_EVDEV, &count);
|
||||
if (count == 0) {
|
||||
/* don't deadlock, fail */
|
||||
printf("input: failed to find devices to read\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
result = in_evdev_update_menu(data, count);
|
||||
result = in_evdev_update_keycode(data, count, &id, is_down);
|
||||
|
||||
if (dev_id != NULL) {
|
||||
for (i = id; i < in_dev_count; i++) {
|
||||
if (in_devices[i].drv_data == data[id]) {
|
||||
*dev_id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error no menu read handlers
|
||||
#endif
|
||||
|
@ -195,6 +237,47 @@ int in_update_menu(void)
|
|||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* same as above, only return bitfield of BTN_*
|
||||
*/
|
||||
int in_update_menu(void)
|
||||
{
|
||||
static int keys_active = 0;
|
||||
int keys_old = keys_active;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int code, is_down = 0;
|
||||
code = in_update_keycode(NULL, &is_down);
|
||||
#ifdef IN_EVDEV
|
||||
code = in_evdev_menu_translate(code);
|
||||
#endif
|
||||
if (code == 0) continue;
|
||||
|
||||
if (is_down)
|
||||
keys_active |= code;
|
||||
else
|
||||
keys_active &= ~code;
|
||||
|
||||
if (keys_old != keys_active)
|
||||
break;
|
||||
}
|
||||
|
||||
return keys_active;
|
||||
}
|
||||
|
||||
const char *in_get_key_name(int dev_id, int keycode)
|
||||
{
|
||||
if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
|
||||
return "Unkn0";
|
||||
switch (in_devices[dev_id].drv_id) {
|
||||
case IN_DRVID_EVDEV:
|
||||
return in_evdev_get_key_name(keycode);
|
||||
}
|
||||
|
||||
return "Unkn1";
|
||||
}
|
||||
|
||||
void in_init(void)
|
||||
{
|
||||
memset(in_devices, 0, sizeof(in_devices));
|
||||
|
@ -208,11 +291,20 @@ int main(void)
|
|||
in_init();
|
||||
in_probe();
|
||||
|
||||
in_set_blocking(1);
|
||||
|
||||
#if 1
|
||||
while (1) {
|
||||
int dev = 0, down;
|
||||
ret = in_update_keycode(&dev, &down);
|
||||
printf("#%i: %i %i (%s)\n", dev, down, ret, in_get_key_name(dev, ret));
|
||||
}
|
||||
#else
|
||||
while (1) {
|
||||
ret = in_update_menu();
|
||||
printf("%08x\n", ret);
|
||||
sleep(1);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -8,3 +8,7 @@ void in_register(const char *nname, int drv_id, void *drv_data);
|
|||
void in_init(void);
|
||||
void in_probe(void);
|
||||
int in_update(void);
|
||||
void in_set_blocking(int is_blocking);
|
||||
int in_update_keycode(int *dev_id, int *is_down);
|
||||
int in_update_menu(void);
|
||||
const char *in_get_key_name(int dev_id, int keycode);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue