reform

MNT Reform: Open Source Portable Computer
Log (Feed) | Files | Refs (Tags) | README

commit d0bc0555bfb9237861374abd0329316b9958d5ce
parent 865f0292f038e5d9742822d8e3f269d344ee34ba
Author: René Wagner <rwa@clttr.info>
Date:   Mon, 18 Dec 2023 21:07:39 +0100

show currently pressed key modifiers in OLED display

applies to: shift, ctrl, super, alt, alt-gr
Up to 4 modifiers are shown each on its own row.

Diffstat:
Mreform2-keyboard-fw/keyboard.c | 48++++++++++++++++++++++++++++++++++++++++++++++--
Mreform2-keyboard-fw/menu.c | 23+++++++++++++++++++++++
2 files changed, 69 insertions(+), 2 deletions(-)

diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c @@ -80,6 +80,14 @@ USB_ClassInfo_HID_Device_t MediaControl_HID_Interface = }, }; +enum keymods { + SHIFT = 1, + CONTROL = 2, + AGR = 4, + ALT = 8, + SUPER = 16, +}; + uint8_t matrix_debounce[KBD_COLS*KBD_ROWS]; uint8_t matrix_state[KBD_COLS*KBD_ROWS]; @@ -87,6 +95,7 @@ int active_meta_mode = 0; uint8_t last_meta_key = 0; uint8_t* active_matrix = matrix; +int active_keymods = 0; bool media_toggle = 0; bool fn_key = 0; // Am I holding FN? bool circle = 0; // Am I holding circle? @@ -145,6 +154,9 @@ int process_keyboard(uint8_t* resulting_scancodes) { // 8 -> 0b11111111 uint8_t debounce_bitmask = (1<<DEBOUNCE_BITS)-1; + int old_keymods = active_keymods; + bool left_ctrl_pressed = 1; + bool left_shift_pressed = 1; // pull ROWs low one after the other for (int y = 0; y < KBD_ROWS; y++) { switch (y) { @@ -201,7 +213,18 @@ int process_keyboard(uint8_t* resulting_scancodes) { if (debounced_pressed) { total_pressed++; - + // set active keymod for OLED display + if (keycode == HID_KEYBOARD_SC_LEFT_CONTROL || keycode == HID_KEYBOARD_SC_RIGHT_CONTROL) { + active_keymods |= CONTROL; + } else if (keycode == HID_KEYBOARD_SC_LEFT_SHIFT || keycode == HID_KEYBOARD_SC_RIGHT_SHIFT) { + active_keymods |= SHIFT; + } else if (keycode == HID_KEYBOARD_SC_RIGHT_ALT) { + active_keymods |= AGR; + } else if (keycode == HID_KEYBOARD_SC_LEFT_ALT) { + active_keymods |= ALT; + } else if (keycode == HID_KEYBOARD_SC_LEFT_GUI) { + active_keymods |= SUPER; + } // Is circle key pressed? if (keycode == KEY_CIRCLE) { if (fn_key) { @@ -271,6 +294,22 @@ int process_keyboard(uint8_t* resulting_scancodes) { } } circle = 0; + } + // disable active keymod for OLED display + if (keycode == HID_KEYBOARD_SC_LEFT_CONTROL) { + left_ctrl_pressed = 0; + } else if (keycode == HID_KEYBOARD_SC_LEFT_SHIFT) { + left_shift_pressed = 0; + } else if (!left_ctrl_pressed && keycode == HID_KEYBOARD_SC_RIGHT_CONTROL) { + active_keymods &= ~ CONTROL; + } else if (!left_shift_pressed && keycode == HID_KEYBOARD_SC_RIGHT_SHIFT) { + active_keymods &= ~ SHIFT; + } else if (keycode == HID_KEYBOARD_SC_RIGHT_ALT) { + active_keymods &= ~ AGR; + } else if (keycode == HID_KEYBOARD_SC_LEFT_ALT) { + active_keymods &= ~ ALT; + } else if (keycode == HID_KEYBOARD_SC_LEFT_GUI) { + active_keymods &= ~ SUPER; } } } @@ -285,6 +324,10 @@ int process_keyboard(uint8_t* resulting_scancodes) { } } + if (old_keymods != active_keymods) { + //render_line(active_keymods); + render_keymods(active_keymods); + } // if no more keys are held down, allow a new meta command if (total_pressed<1) last_meta_key = 0; @@ -401,7 +444,7 @@ void EVENT_USB_Device_ConfigurationChanged(void) bool ConfigSuccess = true; ConfigSuccess &= HID_Device_ConfigureEndpoints(&Keyboard_HID_Interface); - ConfigSuccess &= HID_Device_ConfigureEndpoints(&MediaControl_HID_Interface); + ConfigSuccess &= HID_Device_ConfigureEndpoints(&MediaControl_HID_Interface); USB_Device_EnableSOFEvents(); } @@ -483,3 +526,4 @@ void CALLBACK_HID_Device_ProcessHIDReport(USB_ClassInfo_HID_Device_t* const HIDI hid_report_cmd(data); } +/* vim: set tabstop=2:softtabstop=2:shiftwidth=2:expandtab */ diff --git a/reform2-keyboard-fw/menu.c b/reform2-keyboard-fw/menu.c @@ -18,6 +18,15 @@ int current_scroll_y = 0; int current_menu_page = 0; int8_t logo_timeout_ticks = 0; +#define KEYMODS_NUM_ITEMS 5 +const MenuItem keymods_items[] = { + { " SHIFT ", KEY_ESCAPE }, + { " CNTRL ", KEY_ESCAPE }, + { " AGR ", KEY_ESCAPE }, + { " ALT ", KEY_ESCAPE }, + { " SUPER ", KEY_ESCAPE }, +}; + #define HYPER_HELP_NUM_ITEMS 4 const MenuItem help_items[] = { { "Delete Backspace", KEY_ESCAPE }, @@ -76,6 +85,19 @@ void render_menu(int y) { gfx_flush(); } +void render_keymods(int keymods) { + gfx_clear(); + int line=0; + for (int i=0; i<KEYMODS_NUM_ITEMS; i++) { + if ((int)(pow(2, i)+0.5) & keymods) { + gfx_poke_str(0,line++,keymods_items[i].title); + } + if (line>3) break; + } + gfx_on(); + gfx_flush(); +} + void render_help() { gfx_clear(); for (int i=0; i<HYPER_HELP_NUM_ITEMS; i++) { @@ -266,3 +288,4 @@ void anim_goodbye(void) { } gfx_off(); } +/* vim: set tabstop=2:softtabstop=2:shiftwidth=2:expandtab */