diff --git a/input.c b/input.c index a271c2a..d3467b1 100644 --- a/input.c +++ b/input.c @@ -799,254 +799,254 @@ static int ev2archie[] = }; /* - -// unmapped atari keys: -// 0x63 KP ( -// 0x64 KP ) - -// keycode translation table for atari -const unsigned short usb2atari[] = { -MISS, // 00: NoEvent -MISS, // 01: Overrun Error -MISS, // 02: POST fail -MISS, // 03: ErrorUndefined -0x1e, // 04: a -0x30, // 05: b -0x2e, // 06: c -0x20, // 07: d -0x12, // 08: e -0x21, // 09: f -0x22, // 0a: g -0x23, // 0b: h -0x17, // 0c: i -0x24, // 0d: j -0x25, // 0e: k -0x26, // 0f: l -0x32, // 10: m -0x31, // 11: n -0x18, // 12: o -0x19, // 13: p -0x10, // 14: q -0x13, // 15: r -0x1f, // 16: s -0x14, // 17: t -0x16, // 18: u -0x2f, // 19: v -0x11, // 1a: w -0x2d, // 1b: x -0x15, // 1c: y -0x2c, // 1d: z -0x02, // 1e: 1 -0x03, // 1f: 2 -0x04, // 20: 3 -0x05, // 21: 4 -0x06, // 22: 5 -0x07, // 23: 6 -0x08, // 24: 7 -0x09, // 25: 8 -0x0a, // 26: 9 -0x0b, // 27: 0 -0x1c, // 28: Return -0x01, // 29: Escape -0x0e, // 2a: Backspace -0x0f, // 2b: Tab -0x39, // 2c: Space -0x0c, // 2d: - -0x0d, // 2e: = -0x1a, // 2f: [ -0x1b, // 30: ] -0x29, // 31: backslash, only on us keyboard -0x29, // 32: Europe 1, only on int. keyboard -0x27, // 33: ; -0x28, // 34: ' -0x2b, // 35: ` -0x33, // 36: , -0x34, // 37: . -0x35, // 38: / -0x3a | CAPS_LOCK_TOGGLE, // 39: Caps Lock -0x3b, // 3a: F1 -0x3c, // 3b: F2 -0x3d, // 3c: F3 -0x3e, // 3d: F4 -0x3f, // 3e: F5 -0x40, // 3f: F6 -0x41, // 40: F7 -0x42, // 41: F8 -0x43, // 42: F9 -0x44, // 43: F10 -MISS, // 44: F11 -OSD_OPEN, // 45: F12 -MISS, // 46: Print Screen -NUM_LOCK_TOGGLE, // 47: Scroll Lock -MISS, // 48: Pause -0x52, // 49: Insert -0x47, // 4a: Home -0x62, // 4b: Page Up -0x53, // 4c: Delete -MISS, // 4d: End -0x61, // 4e: Page Down -0x4d, // 4f: Right Arrow -0x4b, // 50: Left Arrow -0x50, // 51: Down Arrow -0x48, // 52: Up Arrow -NUM_LOCK_TOGGLE, // 53: Num Lock -0x65, // 54: KP / -0x66, // 55: KP * -0x4a, // 56: KP - -0x4e, // 57: KP + -0x72, // 58: KP Enter -0x6d, // 59: KP 1 -0x6e, // 5a: KP 2 -0x6f, // 5b: KP 3 -0x6a, // 5c: KP 4 -0x6b, // 5d: KP 5 -0x6c, // 5e: KP 6 -0x67, // 5f: KP 7 -0x68, // 60: KP 8 -0x69, // 61: KP 9 -0x70, // 62: KP 0 -0x71, // 63: KP . -0x60, // 64: Europe 2 -OSD_OPEN, // 65: App -MISS, // 66: Power -MISS, // 67: KP = -MISS, // 68: F13 -MISS, // 69: F14 -MISS, // 6a: F15 -0x52, // 6b: insert (for keyrah) -NUM_LOCK_TOGGLE | 1, // 6c: F17 -NUM_LOCK_TOGGLE | 2, // 6d: F18 -NUM_LOCK_TOGGLE | 3, // 6e: F19 -NUM_LOCK_TOGGLE | 4 // 6f: F20 -}; + +// unmapped atari keys: +// 0x63 KP ( +// 0x64 KP ) + +// keycode translation table for atari +const unsigned short usb2atari[] = { +MISS, // 00: NoEvent +MISS, // 01: Overrun Error +MISS, // 02: POST fail +MISS, // 03: ErrorUndefined +0x1e, // 04: a +0x30, // 05: b +0x2e, // 06: c +0x20, // 07: d +0x12, // 08: e +0x21, // 09: f +0x22, // 0a: g +0x23, // 0b: h +0x17, // 0c: i +0x24, // 0d: j +0x25, // 0e: k +0x26, // 0f: l +0x32, // 10: m +0x31, // 11: n +0x18, // 12: o +0x19, // 13: p +0x10, // 14: q +0x13, // 15: r +0x1f, // 16: s +0x14, // 17: t +0x16, // 18: u +0x2f, // 19: v +0x11, // 1a: w +0x2d, // 1b: x +0x15, // 1c: y +0x2c, // 1d: z +0x02, // 1e: 1 +0x03, // 1f: 2 +0x04, // 20: 3 +0x05, // 21: 4 +0x06, // 22: 5 +0x07, // 23: 6 +0x08, // 24: 7 +0x09, // 25: 8 +0x0a, // 26: 9 +0x0b, // 27: 0 +0x1c, // 28: Return +0x01, // 29: Escape +0x0e, // 2a: Backspace +0x0f, // 2b: Tab +0x39, // 2c: Space +0x0c, // 2d: - +0x0d, // 2e: = +0x1a, // 2f: [ +0x1b, // 30: ] +0x29, // 31: backslash, only on us keyboard +0x29, // 32: Europe 1, only on int. keyboard +0x27, // 33: ; +0x28, // 34: ' +0x2b, // 35: ` +0x33, // 36: , +0x34, // 37: . +0x35, // 38: / +0x3a | CAPS_LOCK_TOGGLE, // 39: Caps Lock +0x3b, // 3a: F1 +0x3c, // 3b: F2 +0x3d, // 3c: F3 +0x3e, // 3d: F4 +0x3f, // 3e: F5 +0x40, // 3f: F6 +0x41, // 40: F7 +0x42, // 41: F8 +0x43, // 42: F9 +0x44, // 43: F10 +MISS, // 44: F11 +OSD_OPEN, // 45: F12 +MISS, // 46: Print Screen +NUM_LOCK_TOGGLE, // 47: Scroll Lock +MISS, // 48: Pause +0x52, // 49: Insert +0x47, // 4a: Home +0x62, // 4b: Page Up +0x53, // 4c: Delete +MISS, // 4d: End +0x61, // 4e: Page Down +0x4d, // 4f: Right Arrow +0x4b, // 50: Left Arrow +0x50, // 51: Down Arrow +0x48, // 52: Up Arrow +NUM_LOCK_TOGGLE, // 53: Num Lock +0x65, // 54: KP / +0x66, // 55: KP * +0x4a, // 56: KP - +0x4e, // 57: KP + +0x72, // 58: KP Enter +0x6d, // 59: KP 1 +0x6e, // 5a: KP 2 +0x6f, // 5b: KP 3 +0x6a, // 5c: KP 4 +0x6b, // 5d: KP 5 +0x6c, // 5e: KP 6 +0x67, // 5f: KP 7 +0x68, // 60: KP 8 +0x69, // 61: KP 9 +0x70, // 62: KP 0 +0x71, // 63: KP . +0x60, // 64: Europe 2 +OSD_OPEN, // 65: App +MISS, // 66: Power +MISS, // 67: KP = +MISS, // 68: F13 +MISS, // 69: F14 +MISS, // 6a: F15 +0x52, // 6b: insert (for keyrah) +NUM_LOCK_TOGGLE | 1, // 6c: F17 +NUM_LOCK_TOGGLE | 2, // 6d: F18 +NUM_LOCK_TOGGLE | 3, // 6e: F19 +NUM_LOCK_TOGGLE | 4 // 6f: F20 +}; */ /* - -// Archimedes unmapped keys -// Missing sterling -// Missing kp_hash -// Missing button_1 -// Missing button_2 -// Missing button_3 -// Missing button_4 -// Missing button_5 - -// keycode translation table -const unsigned short usb2archie[] = { -MISS, // 00: NoEvent -MISS, // 01: Overrun Error -MISS, // 02: POST fail -MISS, // 03: ErrorUndefined -0x3c, // 04: a -0x52, // 05: b -0x50, // 06: c -0x3e, // 07: d -0x29, // 08: e -0x3f, // 09: f -0x40, // 0a: g -0x41, // 0b: h -0x2e, // 0c: i -0x42, // 0d: j -0x43, // 0e: k -0x44, // 0f: l -0x54, // 10: m -0x53, // 11: n -0x2f, // 12: o -0x30, // 13: p -0x27, // 14: q -0x2a, // 15: r -0x3d, // 16: s -0x2b, // 17: t -0x2d, // 18: u -0x51, // 19: v -0x28, // 1a: w -0x4f, // 1b: x -0x2c, // 1c: y -0x4e, // 1d: z -0x11, // 1e: 1 -0x12, // 1f: 2 -0x13, // 20: 3 -0x14, // 21: 4 -0x15, // 22: 5 -0x16, // 23: 6 -0x17, // 24: 7 -0x18, // 25: 8 -0x19, // 26: 9 -0x1a, // 27: 0 -0x47, // 28: Return -0x00, // 29: Escape -0x1e, // 2a: Backspace -0x26, // 2b: Tab -0x5f, // 2c: Space -0x1b, // 2d: - -0x1c, // 2e: = -0x31, // 2f: [ -0x32, // 30: ] -0x33, // 31: backslash (only on us keyboards) -0x33, // 32: Europe 1 (only on international kbds) -0x45, // 33: ; -0x46, // 34: ' -0x10, // 35: ` -0x55, // 36: , -0x56, // 37: . -0x57, // 38: / -0x5d, // 39: Caps Lock -0x01, // 3a: F1 -0x02, // 3b: F2 -0x03, // 3c: F3 -0x04, // 3d: F4 -0x05, // 3e: F5 -0x06, // 3f: F6 -0x07, // 40: F7 -0x08, // 41: F8 -0x09, // 42: F9 -0x0a, // 43: F10 -0x0b, // 44: F11 -0x0c, // 45: F12 - Used heavily by the archie... OSD moved to printscreen. -// 0x0d, // 46: Print Screen -OSD_OPEN, // 46: Print Screen -0x0e, // 47: Scroll Lock -0x0f, // 48: Pause -0x1f, // 49: Insert -0x20, // 4a: Home -0x21, // 4b: Page Up -0x34, // 4c: Delete -0x35, // 4d: End -0x36, // 4e: Page Down -0x64, // 4f: Right Arrow -0x62, // 50: Left Arrow -0x63, // 51: Down Arrow -0x59, // 52: Up Arrow -0x22, // 53: Num Lock -0x23, // 54: KP / -0x24, // 55: KP * -0x3a, // 56: KP - -0x4b, // 57: KP + -0x67, // 58: KP Enter -0x5a, // 59: KP 1 -0x5b, // 5a: KP 2 -0x5c, // 5b: KP 3 -0x48, // 5c: KP 4 -0x49, // 5d: KP 5 -0x4a, // 5e: KP 6 -0x37, // 5f: KP 7 -0x38, // 60: KP 8 -0x39, // 61: KP 9 -0x65, // 62: KP 0 -0x66, // 63: KP decimal -MISS, // 64: Europe 2 -0x72, // 65: App (maps to middle mouse button) -MISS, // 66: Power -MISS, // 67: KP = -MISS, // 68: F13 -MISS, // 69: F14 -MISS, // 6a: F15 -0x1f, // 6b: insert (for keyrah) -MISS, // 6c: F17 -MISS, // 6d: F18 -MISS, // 6e: F19 -MISS, // 6f: F20 + +// Archimedes unmapped keys +// Missing sterling +// Missing kp_hash +// Missing button_1 +// Missing button_2 +// Missing button_3 +// Missing button_4 +// Missing button_5 + +// keycode translation table +const unsigned short usb2archie[] = { +MISS, // 00: NoEvent +MISS, // 01: Overrun Error +MISS, // 02: POST fail +MISS, // 03: ErrorUndefined +0x3c, // 04: a +0x52, // 05: b +0x50, // 06: c +0x3e, // 07: d +0x29, // 08: e +0x3f, // 09: f +0x40, // 0a: g +0x41, // 0b: h +0x2e, // 0c: i +0x42, // 0d: j +0x43, // 0e: k +0x44, // 0f: l +0x54, // 10: m +0x53, // 11: n +0x2f, // 12: o +0x30, // 13: p +0x27, // 14: q +0x2a, // 15: r +0x3d, // 16: s +0x2b, // 17: t +0x2d, // 18: u +0x51, // 19: v +0x28, // 1a: w +0x4f, // 1b: x +0x2c, // 1c: y +0x4e, // 1d: z +0x11, // 1e: 1 +0x12, // 1f: 2 +0x13, // 20: 3 +0x14, // 21: 4 +0x15, // 22: 5 +0x16, // 23: 6 +0x17, // 24: 7 +0x18, // 25: 8 +0x19, // 26: 9 +0x1a, // 27: 0 +0x47, // 28: Return +0x00, // 29: Escape +0x1e, // 2a: Backspace +0x26, // 2b: Tab +0x5f, // 2c: Space +0x1b, // 2d: - +0x1c, // 2e: = +0x31, // 2f: [ +0x32, // 30: ] +0x33, // 31: backslash (only on us keyboards) +0x33, // 32: Europe 1 (only on international kbds) +0x45, // 33: ; +0x46, // 34: ' +0x10, // 35: ` +0x55, // 36: , +0x56, // 37: . +0x57, // 38: / +0x5d, // 39: Caps Lock +0x01, // 3a: F1 +0x02, // 3b: F2 +0x03, // 3c: F3 +0x04, // 3d: F4 +0x05, // 3e: F5 +0x06, // 3f: F6 +0x07, // 40: F7 +0x08, // 41: F8 +0x09, // 42: F9 +0x0a, // 43: F10 +0x0b, // 44: F11 +0x0c, // 45: F12 - Used heavily by the archie... OSD moved to printscreen. +// 0x0d, // 46: Print Screen +OSD_OPEN, // 46: Print Screen +0x0e, // 47: Scroll Lock +0x0f, // 48: Pause +0x1f, // 49: Insert +0x20, // 4a: Home +0x21, // 4b: Page Up +0x34, // 4c: Delete +0x35, // 4d: End +0x36, // 4e: Page Down +0x64, // 4f: Right Arrow +0x62, // 50: Left Arrow +0x63, // 51: Down Arrow +0x59, // 52: Up Arrow +0x22, // 53: Num Lock +0x23, // 54: KP / +0x24, // 55: KP * +0x3a, // 56: KP - +0x4b, // 57: KP + +0x67, // 58: KP Enter +0x5a, // 59: KP 1 +0x5b, // 5a: KP 2 +0x5c, // 5b: KP 3 +0x48, // 5c: KP 4 +0x49, // 5d: KP 5 +0x4a, // 5e: KP 6 +0x37, // 5f: KP 7 +0x38, // 60: KP 8 +0x39, // 61: KP 9 +0x65, // 62: KP 0 +0x66, // 63: KP decimal +MISS, // 64: Europe 2 +0x72, // 65: App (maps to middle mouse button) +MISS, // 66: Power +MISS, // 67: KP = +MISS, // 68: F13 +MISS, // 69: F14 +MISS, // 6a: F15 +0x1f, // 6b: insert (for keyrah) +MISS, // 6c: F17 +MISS, // 6d: F18 +MISS, // 6e: F19 +MISS, // 6f: F20 }; */ @@ -1086,36 +1086,36 @@ return MISS; */ -uint32_t get_ps2_code(uint16_t key) -{ - if (key > 255) return NONE; - return ev2ps2[key]; -} +uint32_t get_ps2_code(uint16_t key) +{ + if (key > 255) return NONE; + return ev2ps2[key]; +} -uint32_t get_amiga_code(uint16_t key) -{ - if (key > 255) return NONE; - return ev2amiga[key]; -} +uint32_t get_amiga_code(uint16_t key) +{ + if (key > 255) return NONE; + return ev2amiga[key]; +} -uint32_t get_atari_code(uint16_t key) -{ - if (key > 255) return NONE; - return 0; // ev2atari[key]; -} - -uint32_t get_archie_code(uint16_t key) -{ - if (key > 255) return NONE; - return ev2archie[key]; -} +uint32_t get_atari_code(uint16_t key) +{ + if (key > 255) return NONE; + return 0; // ev2atari[key]; +} + +uint32_t get_archie_code(uint16_t key) +{ + if (key > 255) return NONE; + return ev2archie[key]; +} static uint32_t modifier = 0; -uint32_t get_key_mod() -{ - return modifier & MODMASK; -} +uint32_t get_key_mod() +{ + return modifier & MODMASK; +} typedef struct { @@ -2076,9 +2076,11 @@ int input_test(int getchar) //reduce flood from PS3 gamepad if (input[i].vid == 0x054c && input[i].pid == 0x0268) - { - if (ev.code <= 5 && ev.value > 118 && ev.value < 138) break; - } + { if (ev.code <= 5 && ev.value > 118 && ev.value < 138) break; } + + //aliexpress USB encoder floods messages + if (input[i].vid == 0x0079 && input[i].pid == 0x0006) + { if (ev.code == 2) break; } printf("Input event: type=EV_ABS, Axis=%d, Offset:=%d\n", ev.code, ev.value); break; @@ -2096,16 +2098,24 @@ int input_test(int getchar) // some pads use axis 16 for L/R PAD, axis 17 for U/D PAD // emulate PAD on axis 0/1 + // axis ranges vary per USB controller: some have 0-255, others -32768-32767 etc. + int16_t mid_axis = 127; + if (input[i].vid == 0x045e && input[i].pid == 0x028e) mid_axis = -1; // 8BitDo NES30 Retro Receiver + char l, r, u, d; l = r = u = d = 0; uint16_t offset = 0; if (ev.code < 16) offset += 4; if (ev.code < 2) offset += 4; - if(ev.code == 0 || ev.code == 2 || ev.code == 16) // x + uint16_t extra_axis = 2; + if (input[i].vid == 0x0079 && input[i].pid == 0x0006) extra_axis = 0; // AliExpress USB encoder PCB floods axis 2 + + + if(ev.code == 0 || ev.code == extra_axis || ev.code == 16) // x { - if ((ev.code < 16) ? ev.value < 64 : ev.value == -1) l = 1; - if ((ev.code < 16) ? ev.value > 192 : ev.value == 1) r = 1; + if ((ev.code < 16) ? ev.value < mid_axis - 64 : ev.value == -1) l = 1; + if ((ev.code < 16) ? ev.value > mid_axis + 64 : ev.value == 1) r = 1; ev.type = EV_KEY; if (input[i].last_l != l) @@ -2125,10 +2135,13 @@ int input_test(int getchar) } } - if (ev.code == 1 || ev.code == 5 || ev.code == 17) // y + uint16_t base_y_axis = 1; + if (input[i].vid == 0x0079 && input[i].pid == 0x0006) base_y_axis = 3; // AliExpress USB encoder PCB + + if (ev.code == base_y_axis || ev.code == 5 || ev.code == 17) // y { - if ((ev.code < 16) ? ev.value < 64 : ev.value == -1) u = 1; - if ((ev.code < 16) ? ev.value > 192 : ev.value == 1) d = 1; + if ((ev.code < 16) ? ev.value < mid_axis - 64 : ev.value == -1) u = 1; + if ((ev.code < 16) ? ev.value > mid_axis + 64 : ev.value == 1) d = 1; ev.type = EV_KEY; if (input[i].last_u != u)