Fix cycling key callbacks
This commit is contained in:
parent
dfbdb3407a
commit
1ade7300b5
|
@ -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
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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)
|
||||
|
|
17
app/pi.c
17
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) {
|
||||
|
|
Loading…
Reference in New Issue