From ecfba5d9aa592d0250db44c11c3474b9ddef1c21 Mon Sep 17 00:00:00 2001 From: Edward Hesketh Date: Sun, 1 Sep 2024 04:52:17 +0100 Subject: [PATCH] still working out some issues related to the slab keyboard --- include/squirrel_keymap.h | 2 +- src/squirrel_init.c | 16 +++++++--------- src/squirrel_key.c | 31 +++++++++++++++++-------------- src/squirrel_keymap.c | 3 +-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/include/squirrel_keymap.h b/include/squirrel_keymap.h index b9e0dcb..151a6a2 100644 --- a/include/squirrel_keymap.h +++ b/include/squirrel_keymap.h @@ -2,7 +2,7 @@ #define SQUIRREL_KEYMAP_H #include "squirrel_key.h" -void new_layer(int layer, struct key *keys, int key_count); +void new_layer(int layer); struct key nop(void); struct key keyboard(uint8_t keycode); diff --git a/src/squirrel_init.c b/src/squirrel_init.c index 8bf2545..c1d36b7 100644 --- a/src/squirrel_init.c +++ b/src/squirrel_init.c @@ -8,18 +8,16 @@ enum squirrel_error squirrel_init(int total_keys) { key_count = total_keys; - struct key passthrough_key; - passthrough_key.pressed = quantum_passthrough_press; - passthrough_key.pressed_argument_count = 0; - passthrough_key.released = quantum_passthrough_release; - passthrough_key.released_argument_count = 0; - for (uint8_t j = 16; j != 255; j--) { - layers[j].keys = (struct key *)malloc(total_keys * sizeof(struct key)); + for (signed int j = 16; j >= 0; j--) { + layers[j].keys = malloc(total_keys * sizeof(struct key)); for (int i = 0; i < total_keys; i++) { - copy_key(&passthrough_key, &(layers[j].keys[i])); + layers[j].keys[i].pressed = quantum_passthrough_press; + layers[j].keys[i].released = quantum_passthrough_release; + layers[j].keys[i].pressed_arguments = 0; + layers[j].keys[i].released_arguments = 0; } } - key_states = (bool *)malloc(total_keys * sizeof(bool)); + key_states = malloc(total_keys * sizeof(bool)); layers[16].active = true; return ERR_NONE; }; diff --git a/src/squirrel_key.c b/src/squirrel_key.c index fb50939..206393c 100644 --- a/src/squirrel_key.c +++ b/src/squirrel_key.c @@ -11,27 +11,27 @@ void copy_key(struct key *source, struct key *destination) { } enum squirrel_error press_key(uint8_t key_index) { - for (uint8_t i = 16; i != 255; i--) { + for (signed int i = 16; i >= 0; i--) { if (!layers[i].active) { continue; } - struct key *selected_key = &(layers[i].keys[key_index]); - enum squirrel_error err = selected_key->pressed( - selected_key, i, key_index, selected_key->pressed_argument_count, - selected_key->pressed_arguments); + struct key selected_key = layers[i].keys[key_index]; + enum squirrel_error err = selected_key.pressed( + &selected_key, i, key_index, selected_key.pressed_argument_count, + selected_key.pressed_arguments); if (err != ERR_NONE) { return err; } if (i == 16) { continue; } - copy_key(selected_key, &layers[16].keys[key_index]); + copy_key(&selected_key, &layers[16].keys[key_index]); } return ERR_NONE; } enum squirrel_error release_key(uint8_t key_index) { - for (uint8_t i = 16; i != 255; i--) { + for (signed int i = 16; i >= 0; i--) { if (!layers[i].active) { continue; } @@ -61,15 +61,18 @@ enum squirrel_error release_key(uint8_t key_index) { bool *key_states; enum squirrel_error check_key(uint8_t key_index, bool is_pressed) { - enum squirrel_error err; - if (key_states[key_index] == is_pressed) { - return ERR_NONE; - } if (is_pressed) { - key_states[key_index] = true; return press_key(key_index); } - key_states[key_index] = false; return release_key(key_index); - return ERR_NONE; + /* enum squirrel_error err;*/ + /*if (key_states[key_index] == is_pressed) {*/ + /*return ERR_NONE;*/ + /*}*/ + /*if (is_pressed) {*/ + /*key_states[key_index] = true;*/ + /*return press_key(key_index);*/ + /*}*/ + /*key_states[key_index] = false;*/ + /*return release_key(key_index);*/ } diff --git a/src/squirrel_keymap.c b/src/squirrel_keymap.c index d37dcf0..5144ee3 100644 --- a/src/squirrel_keymap.c +++ b/src/squirrel_keymap.c @@ -2,9 +2,8 @@ #include "squirrel_quantum.h" #include -void new_layer(int layer, struct key *keys, int key_count) { +void new_layer(int layer) { for (int i = 0; i < key_count; i++) { - layers[layer].keys[i] = keys[i]; } }