Skip to content

Commit

Permalink
feat: let the keyboard scream
Browse files Browse the repository at this point in the history
  • Loading branch information
heiso committed Oct 28, 2024
1 parent 8f0bd27 commit f2495b0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 2 additions & 0 deletions firmware/Core/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down
9 changes: 8 additions & 1 deletion firmware/Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions web-app/app/routes/_layout.configurator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,27 @@ export default function Index() {
{Number(((userConfig.resetThreshold * 4) / 255).toFixed(2))} mm
</span>
</div>

<div className="flex gap-2 items-center">
<Label>Screaming Velocity Trigger</Label>
<input
className="cursor-pointer"
min={1}
max={255}
step={1}
type="range"
onChange={(event) => {
setUserConfig({
...userConfig,
screamingVelocityTrigger: Number(event.target.value),
})
}}
value={userConfig.screamingVelocityTrigger}
/>
<span className="text-slate-400">
{Number(((userConfig.screamingVelocityTrigger * 4) / 255).toFixed(2))} mm/tick
</span>
</div>
</div>

<div className="space-x-4">
Expand Down
5 changes: 4 additions & 1 deletion web-app/app/useDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type UserConfig = {
triggerOffset: number
resetThreshold: number
rapidTriggerOffset: number
screamingVelocityTrigger: number
keymaps: ArrayBuffer
}

Expand All @@ -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),
}
}

Expand All @@ -53,6 +55,7 @@ function formatUserConfig(config: UserConfig): BufferSource {
config.triggerOffset,
config.resetThreshold,
config.rapidTriggerOffset,
config.screamingVelocityTrigger,
...new Uint8Array(config.keymaps),
])
}
Expand Down

0 comments on commit f2495b0

Please sign in to comment.