Skip to content

Commit

Permalink
still working out some issues related to the slab keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
headblockhead committed Sep 1, 2024
1 parent a7a15cb commit ecfba5d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion include/squirrel_keymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 7 additions & 9 deletions src/squirrel_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
31 changes: 17 additions & 14 deletions src/squirrel_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);*/
}
3 changes: 1 addition & 2 deletions src/squirrel_keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#include "squirrel_quantum.h"
#include <stdlib.h>

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];
}
}

Expand Down

0 comments on commit ecfba5d

Please sign in to comment.