commit 7ff3ef30e0db76fe357d3247efeba0596e59dcec
parent cada2d62d2820a6b804b302c837b845e3ff99a93
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:
2 files changed, 69 insertions(+), 3 deletions(-)
diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c
@@ -76,6 +76,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];
@@ -83,6 +91,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?
@@ -129,7 +138,9 @@ int process_keyboard(uint8_t* resulting_scancodes) {
// how many keys are pressed this round
uint8_t total_pressed = 0;
uint8_t used_key_codes = 0;
-
+ 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) {
@@ -184,7 +195,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) {
@@ -254,6 +276,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;
}
}
}
@@ -268,6 +306,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;
@@ -377,7 +419,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();
}
@@ -459,3 +501,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 */