fixed layer and numpad bugs - appears to work!

- rewrote the layer functions in main() (easiest way to get the to
  work.. :) )
- fixed the keymap (i had the numpad keys pushing layer 2 instead of
  layer 3)
- changed the numlock keycode.. i was using the wrong one, lol
- and some minor aesthetic changes
partial-rewrite
Ben Blazak 2012-12-03 16:19:12 -08:00
parent 52200b262f
commit 1b41491115
4 changed files with 49 additions and 51 deletions

View File

@ -35,11 +35,11 @@ _capsLock, _A, _S, _D, _F, _G,
_del, 0, _ctrlL, _del, 0, _ctrlL,
_end, _home, _altL, _end, _home, _altL,
// right hand // right hand
2, _6, _7, _8, _9, _0, _dash, 3, _6, _7, _8, _9, _0, _dash,
_bracketL, _Y, _U, _I, _O, _P, _bracketR, _bracketL, _Y, _U, _I, _O, _P, _bracketR,
_H, _J, _K, _L, _semicolon, _quote, _H, _J, _K, _L, _semicolon, _quote,
1, _N, _M, _comma, _period, _slash, _shiftR, 1, _N, _M, _comma, _period, _slash, _shiftR,
_arrowL, _arrowD, _arrowU, _arrowR, _guiR, _arrowL, _arrowD, _arrowU, _arrowR, _guiR,
0, _space, 0, _space,
_ctrlR, 0, _enter, _ctrlR, 0, _enter,
_altR, _pageU, _pageD ), _altR, _pageU, _pageD ),
@ -106,7 +106,7 @@ _ctrlR, 0, _enter,
0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
// right hand // right hand
2, 0, 2, _equal_kp, _div_kp, _mul_kp, 0, 3, 0, 3, _equal_kp, _div_kp, _mul_kp, 0,
0, 0, _7_kp, _8_kp, _9_kp, _sub_kp, 0, 0, 0, _7_kp, _8_kp, _9_kp, _sub_kp, 0,
0, _4_kp, _5_kp, _6_kp, _add_kp, 0, 0, _4_kp, _5_kp, _6_kp, _add_kp, 0,
0, 0, _1_kp, _2_kp, _3_kp, _enter_kp, 0, 0, 0, _1_kp, _2_kp, _3_kp, _enter_kp, 0,

View File

@ -67,7 +67,7 @@ void kbfun_toggle(void) {
void kbfun_transparent(void) { void kbfun_transparent(void) {
LAYER_OFFSET++; LAYER_OFFSET++;
LAYER = main_layers_peek(LAYER_OFFSET); LAYER = main_layers_peek(LAYER_OFFSET);
main_layers_pressed[row][col] = LAYER; main_layers_pressed[ROW][COL] = LAYER;
main_exec_key(); main_exec_key();
} }

View File

@ -88,9 +88,9 @@ void kbfun_2_keys_capslock_press_release(void) {
static uint8_t numpad_layer_id; static uint8_t numpad_layer_id;
static inline void numpad_toggle_numlock(void) { static inline void numpad_toggle_numlock(void) {
_kbfun_press_release(true, KEYPAD_NumLock_Clear); _kbfun_press_release(true, KEY_LockingNumLock);
usb_keyboard_send(); usb_keyboard_send();
_kbfun_press_release(false, KEYPAD_NumLock_Clear); _kbfun_press_release(false, KEY_LockingNumLock);
usb_keyboard_send(); usb_keyboard_send();
} }

View File

@ -165,20 +165,18 @@ void main_exec_key(void) {
* Implemented as a fixed size stack. * Implemented as a fixed size stack.
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
// ----------------------------------------------------------------------------
struct layers { struct layers {
uint8_t layer; uint8_t layer;
uint8_t id; uint8_t id;
}; };
struct layers_info {
uint8_t head;
bool ids_in_use[MAX_ACTIVE_LAYERS];
};
static struct layers layers[MAX_ACTIVE_LAYERS]; // ----------------------------------------------------------------------------
static struct layers_info layers_info = {
// .head = 0, // default struct layers layers[MAX_ACTIVE_LAYERS];
.ids_in_use = {true}, // id 0 = true; id's 1..max = false uint8_t layers_head = 0;
}; uint8_t layers_ids_in_use[MAX_ACTIVE_LAYERS] = {true};
/* /*
* peek() * peek()
@ -191,10 +189,10 @@ static struct layers_info layers_info = {
* - failure: 0 (default) (out of bounds) * - failure: 0 (default) (out of bounds)
*/ */
uint8_t main_layers_peek(uint8_t offset) { uint8_t main_layers_peek(uint8_t offset) {
if (offset > layers_info.head) // uint8_t, so they're both >0 if (offset <= layers_head)
return 0; // default return layers[layers_head - offset].layer;
return layers[layers_info.head - offset].layer; return 0; // default, or error
} }
/* /*
@ -208,25 +206,18 @@ uint8_t main_layers_peek(uint8_t offset) {
* - failure: 0 (the stack was already full) * - failure: 0 (the stack was already full)
*/ */
uint8_t main_layers_push(uint8_t layer) { uint8_t main_layers_push(uint8_t layer) {
if (layers_info.head == MAX_ACTIVE_LAYERS) // look for an available id
return 0; // error
layers_info.head++;
for (uint8_t id=1; id<MAX_ACTIVE_LAYERS; id++) for (uint8_t id=1; id<MAX_ACTIVE_LAYERS; id++)
if (layers_info.ids_in_use[id] == false) { // if one is found
// claim the unused id if (layers_ids_in_use[id] == false) {
layers_info.ids_in_use[id] = true; layers_ids_in_use[id] = true;
// assign the element values layers_head++;
layers[layers_info.head].layer = layer; layers[layers_head].layer = layer;
layers[layers_info.head].id = id; layers[layers_head].id = id;
// return the id
return id; return id;
} }
// if no id was found return 0; // default, or error
// (this should never happen, since we check if the array's full above)
return 0; // error
} }
/* /*
@ -236,16 +227,21 @@ uint8_t main_layers_push(uint8_t layer) {
* - 'id': the id of the element to pop from the stack * - 'id': the id of the element to pop from the stack
*/ */
void main_layers_pop_id(uint8_t id) { void main_layers_pop_id(uint8_t id) {
for (uint8_t i=1; i<MAX_ACTIVE_LAYERS; i++) // look for the element with the id we want to pop
if (layers[i].id == id) { for (uint8_t element=1; element<=layers_head; element++)
// clear the entry // if we find it
layers[i].layer = 0; if (layers[element].id == id) {
layers[i].id = 0; // move all layers above it down one
// if there are elements above it, move them down for (; element<layers_head; element++) {
for (uint8_t pos=i+1; i<=layers_info.head; i++) layers[element].layer = layers[element+1].layer;
layers[pos-1] = layers[pos]; layers[element].id = layers[element+1].id;
// decrement 'head' }
layers_info.head--; // reinitialize the topmost (now unused) slot
layers[layers_head].layer = 0;
layers[layers_head].id = 0;
// record keeping
layers_ids_in_use[id] = false;
layers_head--;
} }
} }
@ -261,12 +257,14 @@ void main_layers_pop_id(uint8_t id) {
* - failure: 0 (default) (id unassigned) * - failure: 0 (default) (id unassigned)
*/ */
uint8_t main_layers_get_offset_id(uint8_t id) { uint8_t main_layers_get_offset_id(uint8_t id) {
for (uint8_t i=1; i<=layers_info.head; i++) // look for the element with the id we want to get the offset of
if (layers[i].id == id) for (uint8_t element=1; element<=layers_head; element++)
return layers_info.head - i; // if we find it
if (layers[element].id == id)
return (layers_head - element);
return 0; // default, or error
// if no element with the given id was found
return 0;
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------