From f2495b07ccc0758e63697e6474d06c309c0be9f9 Mon Sep 17 00:00:00 2001 From: heiso Date: Mon, 28 Oct 2024 19:04:50 +0100 Subject: [PATCH] feat: let the keyboard scream --- firmware/Core/Inc/main.h | 2 ++ firmware/Core/Src/main.c | 9 ++++++++- web-app/app/routes/_layout.configurator.tsx | 21 +++++++++++++++++++++ web-app/app/useDevice.ts | 5 ++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/firmware/Core/Inc/main.h b/firmware/Core/Inc/main.h index 14bf695..b4d529e 100644 --- a/firmware/Core/Inc/main.h +++ b/firmware/Core/Inc/main.h @@ -38,6 +38,7 @@ extern "C" { #define DEFAULT_TRIGGER_OFFSET 64 #define DEFAULT_RESET_THRESHOLD 3 #define DEFAULT_RAPID_TRIGGER_OFFSET 40 +#define DEFAULT_SCREAMING_VELOCITY_TRIGGER 40 #define IDLE_VALUE_APPROX 1800 #define MAX_DISTANCE_APPROX 500 @@ -134,6 +135,7 @@ struct user_config { uint8_t trigger_offset; uint8_t reset_threshold; uint8_t rapid_trigger_offset; + uint8_t screaming_velocity_trigger; uint16_t keymaps[LAYERS_COUNT][MATRIX_ROWS][MATRIX_COLS]; }; /* USER CODE END ET */ diff --git a/firmware/Core/Src/main.c b/firmware/Core/Src/main.c index 8111821..a3d23a3 100644 --- a/firmware/Core/Src/main.c +++ b/firmware/Core/Src/main.c @@ -71,6 +71,7 @@ const struct user_config default_user_config = { .trigger_offset = DEFAULT_TRIGGER_OFFSET, .reset_threshold = DEFAULT_RESET_THRESHOLD, .rapid_trigger_offset = DEFAULT_RAPID_TRIGGER_OFFSET, + .screaming_velocity_trigger = DEFAULT_SCREAMING_VELOCITY_TRIGGER .keymaps = { // clang-format off [_BASE_LAYER] = { @@ -292,7 +293,13 @@ int main(void) { add_to_hid_report(key, _TAP_LAYER); } else if (!is_before_timeout || key_triggered) { key->actuation.status = STATUS_TRIGGERED; - add_to_hid_report(key, _BASE_LAYER); + // if the key is violently pressed, automatically add the MAJ modifier :) + if (key->layers[_BASE_LAYER].type == KEY_TYPE_NORMAL && key->state.velocity > user_config.screaming_velocity_trigger && key->) { + modifiers |= HID_KEY_SHIFT_RIGHT; + add_to_hid_report(key, _BASE_LAYER); + } else { + add_to_hid_report(key, _BASE_LAYER); + } } } } diff --git a/web-app/app/routes/_layout.configurator.tsx b/web-app/app/routes/_layout.configurator.tsx index cf18474..838aa5c 100644 --- a/web-app/app/routes/_layout.configurator.tsx +++ b/web-app/app/routes/_layout.configurator.tsx @@ -109,6 +109,27 @@ export default function Index() { {Number(((userConfig.resetThreshold * 4) / 255).toFixed(2))} mm + +
+ + { + setUserConfig({ + ...userConfig, + screamingVelocityTrigger: Number(event.target.value), + }) + }} + value={userConfig.screamingVelocityTrigger} + /> + + {Number(((userConfig.screamingVelocityTrigger * 4) / 255).toFixed(2))} mm/tick + +
diff --git a/web-app/app/useDevice.ts b/web-app/app/useDevice.ts index a9a1ed3..312b2d2 100644 --- a/web-app/app/useDevice.ts +++ b/web-app/app/useDevice.ts @@ -36,6 +36,7 @@ type UserConfig = { triggerOffset: number resetThreshold: number rapidTriggerOffset: number + screamingVelocityTrigger: number keymaps: ArrayBuffer } @@ -44,7 +45,8 @@ function parseUserConfig(config: DataView): UserConfig { triggerOffset: config.getUint8(0), resetThreshold: config.getUint8(1), rapidTriggerOffset: config.getUint8(2), - keymaps: config.buffer.slice(3), + screamingVelocityTrigger: config.getUint8(3), + keymaps: config.buffer.slice(4), } } @@ -53,6 +55,7 @@ function formatUserConfig(config: UserConfig): BufferSource { config.triggerOffset, config.resetThreshold, config.rapidTriggerOffset, + config.screamingVelocityTrigger, ...new Uint8Array(config.keymaps), ]) }