project for a (works on my devices) demo
This commit is contained in:
303
sources/input/input_events.c
Normal file
303
sources/input/input_events.c
Normal file
@@ -0,0 +1,303 @@
|
||||
#include "../../headers/input/input_events.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
/* capturing all the keys known by linux */
|
||||
unsigned char buffered_keys[KEY_CNT];
|
||||
|
||||
/*
|
||||
glut exposes
|
||||
keypress
|
||||
until a key is pressed, will keep invoking the keypress callback
|
||||
mousemoved
|
||||
absolute x and y of the mouse
|
||||
*/
|
||||
|
||||
void dispatch_input_event( device_event event){
|
||||
switch( event.type){
|
||||
case EV_SYN:
|
||||
//printf("separator for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_KEY:
|
||||
dispatch_input_key_event( event);
|
||||
break;
|
||||
case EV_REL:
|
||||
//printf("delta event %d : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_ABS:
|
||||
dispatch_input_absolute_event( event);
|
||||
break;
|
||||
case EV_MSC:
|
||||
//printf("miscellaneous event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_SW:
|
||||
//printf("binary switch event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_LED:
|
||||
//printf("led toggle event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_SND:
|
||||
//printf("sound event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_REP:
|
||||
//printf("autorepeating event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_FF:
|
||||
//printf("force-feedback event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_PWR:
|
||||
//printf("power toggle event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
case EV_FF_STATUS:
|
||||
//printf("force-feedback status event for %u : %d\n", event.code, event.value);
|
||||
break;
|
||||
default:
|
||||
printf("unknown event for %u : %d\n", event.code, event.value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dispatch_input_key_event( device_event event){
|
||||
/* goes from KEY_RESERVED = 0 to KEY_MAX = 0x2ff */
|
||||
|
||||
printf("this is dispatch_input_key_event\n");
|
||||
|
||||
/* common keyboard codes from 0 up to KEY_MACRO, before KEY_MUTE */
|
||||
if( event.code < KEY_MUTE){
|
||||
dispatch_keyboard_keys( event);
|
||||
}
|
||||
/* INTERESTING KEYS BEGIN */
|
||||
/* interesting keys from KEY_MIN_INTERESTING = KEY_MUTE up to BTN_DEAD, before BTN_GAMEPAD */
|
||||
else if( event.code >= KEY_MUTE && event.code <= BTN_DEAD){
|
||||
dispatch_interesting_keys_1( event);
|
||||
}
|
||||
/* NO GAP */
|
||||
/* joypad keys, from BTN_GAMEPAD up to BTN_THUMBR, gap of one before BTN_DIGI */
|
||||
else if( event.code >= BTN_GAMEPAD && event.code <= BTN_THUMBR){
|
||||
dispatch_interesting_keys_2( event);
|
||||
}
|
||||
/* GAP OF ONE between this and the previous.. */
|
||||
/* ignored keys */
|
||||
/* interesting keys, from BTN_DIGI up to the MAX */
|
||||
else if( event.code >= BTN_DIGI && event.code <= KEY_MAX){
|
||||
dispatch_interesting_keys_3( event);
|
||||
}
|
||||
else{
|
||||
printf("UNKNOWN KEY EVENT CODE %d with value %d\n", event.code, event.value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void dispatch_input_absolute_event( device_event event){
|
||||
if(event.code < ABS_RESERVED){
|
||||
dispatch_regular_absolute_event( event);
|
||||
}
|
||||
/* a gap for ABS_RESERVED */
|
||||
else if( event.code >= ABS_MT_SLOT && event.code <= ABS_MT_TOOL_Y){
|
||||
dispatch_multitouch_event( event);
|
||||
}
|
||||
else{
|
||||
printf("UNKNOWN ABSOLUTE EVENT CODE %d with value %d\n", event.code, event.value);
|
||||
}
|
||||
}
|
||||
|
||||
void dispatch_regular_absolute_event( device_event event){
|
||||
switch( event.code){
|
||||
case ABS_X:
|
||||
//cursor_x = event.value;
|
||||
//printf("WARN !!! ABS_X untracked %d\n", event.value);
|
||||
break;
|
||||
case ABS_Y:
|
||||
//cursor_y = event.value;
|
||||
//printf("WARN !!! ABS_Y untracked %d\n", event.value);
|
||||
break;
|
||||
default:
|
||||
printf("UNKNOWN REGULAR ABSOLUTE EVENT CODE %d with value %d\n", event.code, event.value);
|
||||
}
|
||||
}
|
||||
|
||||
void dispatch_multitouch_event( device_event event){
|
||||
switch( event.code){
|
||||
case ABS_MT_SLOT: /* MT slot being modified */
|
||||
//printf("ABS_MT_SLOT [MULTITOUCH SLOT MODIFIED] %d\n", event.value);
|
||||
TC_L1_builder_set_slot_number( event.value);
|
||||
break;
|
||||
case ABS_MT_TOUCH_MAJOR: /* Major axis of touching ellipse */
|
||||
// printf("ABS_MT_TOUCH_MAJOR [MAJOR AXIS OF TOUCH ELLIPSE] %d\n", event.value);
|
||||
TC_L1_builder_set_major_axis( event.value);
|
||||
break;
|
||||
case ABS_MT_TOUCH_MINOR: /* Minor axis (omit if circular) */
|
||||
// printf("ABS_MT_TOUCH_MINOR [MINOR AXIS OF TOUCH ELLIPSE] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_WIDTH_MAJOR: /* Major axis of approaching ellipse */
|
||||
// printf("ABS_MT_WIDTH_MAJOR [MAJOR AXIS OF APPROACHING ELLIPSE] %d\n", event.value);
|
||||
TC_L1_builder_set_approaching_major_axis( event.value);
|
||||
break;
|
||||
case ABS_MT_WIDTH_MINOR: /* Minor axis (omit if circular) */
|
||||
// printf("ABS_MT_WIDTH_MINOR [MINOR AXIS OF APPROACHING ELLIPSE] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_ORIENTATION: /* Ellipse orientation */
|
||||
// printf("ABS_MT_ORIENTATION [ELLIPSE ORIENTATION] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_POSITION_X: /* Center X touch position */
|
||||
// printf("ABS_MT_POSITION_X [CENTER X TOUCH POSITION] %d\n", event.value);
|
||||
TC_L1_builder_set_position_x( event.value);
|
||||
break;
|
||||
case ABS_MT_POSITION_Y: /* Center Y touch position */
|
||||
//printf("ABS_MT_POSITION_Y [CENTER Y TOUCH POSITION] %d\n", event.value);
|
||||
TC_L1_builder_set_position_y( event.value);
|
||||
break;
|
||||
case ABS_MT_TOOL_TYPE: /* Type of touching device */
|
||||
// printf("ABS_MT_TOOL_TYPE [TYPE OF TOUCHING DEVICE] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_BLOB_ID: /* Group a set of packets as a blob */
|
||||
// printf("ABS_MT_BLOB_ID [GROUP A SET OF PACKETS AS A BLOB] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_TRACKING_ID: /* Unique ID of initiated contact */
|
||||
//printf("ABS_MT_TRACKING_ID [UNIQUE ID OF INITIATED CONTACT] %d\n", event.value);
|
||||
TC_L1_builder_set_tracking_id( event.value);
|
||||
break;
|
||||
case ABS_MT_PRESSURE: /* Pressure on contact area */
|
||||
// printf("ABS_MT_PRESSURE [PRESSURE ON CONTACT AREA] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_DISTANCE: /* Contact hover distance */
|
||||
// printf("ABS_MT_DISTANCE [CONTACT HOVER DISTANCE] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_TOOL_X: /* Center X tool position */
|
||||
// printf("ABS_MT_TOOL_X [CENTER X TOOL POSITION] %d\n", event.value);
|
||||
break;
|
||||
case ABS_MT_TOOL_Y: /* Center Y tool position */
|
||||
// printf("ABS_MT_TOOL_Y [CENTER Y TOOL POSITION] %d\n", event.value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* common keyboard codes from 0 up to KEY_MACRO, before KEY_MUTE */
|
||||
void dispatch_keyboard_keys( device_event event){
|
||||
printf("IGNORED KEY EVENT CODE %d with value %d [KEYBOARD GROUP]\n", event.code, event.value);
|
||||
}
|
||||
|
||||
/* interesting keys from KEY_MIN_INTERESTING = KEY_MUTE up to BTN_DEAD, before BTN_GAMEPAD */
|
||||
void dispatch_interesting_keys_1( device_event event){
|
||||
printf("UNKNOWN KEY EVENT CODE %d with value %d [INTERESTING GROUP]\n", event.code, event.value);
|
||||
}
|
||||
|
||||
/* joypad keys, from BTN_GAMEPAD up to BTN_THUMBR, gap of one before BTN_DIGI */
|
||||
void dispatch_interesting_keys_2( device_event event){
|
||||
|
||||
/* NO OFFSET NEEDED, THEY START FROM 0 */
|
||||
|
||||
/* could also store the transitions
|
||||
unsigned char buffered_keys_transition[KEY_CNT];
|
||||
*/
|
||||
printf("interesting key [JOYPAD] %x %x\n", event.code, event.value);
|
||||
buffered_keys[event.code] = (char) event.value; /* they only have 3 states : press, released, retriggered */
|
||||
}
|
||||
|
||||
|
||||
/* interesting keys, from BTN_DIGI up to the MAX */
|
||||
void dispatch_interesting_keys_3( device_event event){
|
||||
if( event.code == BTN_TOUCH){
|
||||
printf("TOUCH EVENT %s\n", (event.value) ? "BEGIN" : "END");
|
||||
}
|
||||
else{
|
||||
printf("UNKNOWN KEY EVENT CODE %d with value %d [INTERESTING GROUP]\n", event.code, event.value);
|
||||
buffered_keys[event.code] = (char) event.value; /* they only have 3 states : press, released, retriggered */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* reserving the NULL character code for unsupported keys
|
||||
maps from linux input.h key codes to ascii
|
||||
*/
|
||||
/*
|
||||
UPPERCASE REQUIRES QUERYING THE STATE OF THE SHIFT KEY
|
||||
*/
|
||||
char get_ascii_code( unsigned short linux_code){
|
||||
/* yanderedev would be proud of me... :'( */
|
||||
switch( linux_code){
|
||||
case KEY_DELETE:
|
||||
return 0x18; /* refer to ascii CANCEL (non printable) instead of DELETE (printable)*/
|
||||
case KEY_ESC:
|
||||
return 0x1b;
|
||||
/* KEY_1 is 0x2 KEY_9 is 0xA KEY_0 is 0xB */
|
||||
/* ASCII 0 is 0x30 ASCII 9 is 0x39 */
|
||||
case KEY_1:
|
||||
case KEY_2:
|
||||
case KEY_3:
|
||||
case KEY_4:
|
||||
case KEY_5:
|
||||
case KEY_6:
|
||||
case KEY_7:
|
||||
case KEY_8:
|
||||
case KEY_9:
|
||||
/* ASCII 1 - (lin_1 - lin_code) */
|
||||
return ( 0x31 + ( 0x2 - linux_code));
|
||||
case KEY_0:
|
||||
return 0x30;
|
||||
|
||||
case KEY_BACKSPACE:
|
||||
return 0x8;
|
||||
case KEY_TAB:
|
||||
return 0x9;
|
||||
case KEY_SPACE:
|
||||
return 0x20;
|
||||
|
||||
case KEY_A:
|
||||
return 0x41;
|
||||
case KEY_B:
|
||||
return 0x42;
|
||||
case KEY_C:
|
||||
return 0x43;
|
||||
case KEY_D:
|
||||
return 0x44;
|
||||
case KEY_E:
|
||||
return 0x45;
|
||||
case KEY_F:
|
||||
return 0x46;
|
||||
case KEY_G:
|
||||
return 0x47;
|
||||
case KEY_H:
|
||||
return 0x48;
|
||||
case KEY_I:
|
||||
return 0x49;
|
||||
case KEY_J:
|
||||
return 0x4a;
|
||||
case KEY_K:
|
||||
return 0x4b;
|
||||
case KEY_L:
|
||||
return 0x4c;
|
||||
case KEY_M:
|
||||
return 0x4d;
|
||||
case KEY_N:
|
||||
return 0x4e;
|
||||
case KEY_O:
|
||||
return 0x4f;
|
||||
case KEY_P:
|
||||
return 0x50;
|
||||
case KEY_Q:
|
||||
return 0x51;
|
||||
case KEY_R:
|
||||
return 0x52;
|
||||
case KEY_S:
|
||||
return 0x53;
|
||||
case KEY_T:
|
||||
return 0x54;
|
||||
case KEY_U:
|
||||
return 0x55;
|
||||
case KEY_V:
|
||||
return 0x56;
|
||||
case KEY_W:
|
||||
return 0x57;
|
||||
case KEY_X:
|
||||
return 0x58;
|
||||
case KEY_Y:
|
||||
return 0x59;
|
||||
case KEY_Z:
|
||||
return 0x5a;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user