diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..592ab0f --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,22 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "make -C build", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": "$gcc", + "presentation": { + "echo": true, + "reveal": "always", + "focus": true, + "panel": "shared", + "showReuseMessage": false + }, + } + ] +} \ No newline at end of file diff --git a/app/keyboard.c b/app/keyboard.c index 8e1b4e7..86d5ed6 100644 --- a/app/keyboard.c +++ b/app/keyboard.c @@ -292,9 +292,16 @@ void keyboard_add_key_callback(struct key_callback *callback) // find last and insert after struct key_callback *cb = self.key_callbacks; while (cb->next) { + + // Only add callback once to avoid cycles + if (cb == callback) { + return; + } + cb = cb->next; } cb->next = callback; + callback->next = NULL; } void keyboard_remove_key_callback(void *func) diff --git a/app/pi.c b/app/pi.c index e656f50..d6d8c08 100644 --- a/app/pi.c +++ b/app/pi.c @@ -227,7 +227,10 @@ static void pi_led_stop_flash_alarm_callback(uint8_t key, enum key_state state) // Remove key callback keyboard_remove_key_callback(pi_led_stop_flash_alarm_callback); } -static struct key_callback pi_led_stop_flash_key_callback = { .func = pi_led_stop_flash_alarm_callback }; +static struct key_callback pi_led_stop_flash_key_callback = { + .func = pi_led_stop_flash_alarm_callback, + .next = NULL +}; void led_set(struct led_state const* state) { @@ -241,15 +244,11 @@ void led_set(struct led_state const* state) // Schedule flash callback if ((state->setting == LED_SET_FLASH_ON) || (state->setting == LED_SET_FLASH_UNTIL_KEY)) { - // Cancel any current flash timer - if (g_led_flash_alarm > 0) { - cancel_alarm(g_led_flash_alarm); - g_led_flash_alarm = -1; - } - // Apply LED setting and schedule new timer using callback - g_led_flash_alarm = 1; - (void)pi_led_flash_alarm_callback(0, NULL); + if (g_led_flash_alarm < 0) { + g_led_flash_alarm = 1; + (void)pi_led_flash_alarm_callback(0, NULL); + } // Add key calback to disable flash when key is pressed if (state->setting == LED_SET_FLASH_UNTIL_KEY) {