From f3a418af4c22eff362c10a830794f35521f0d34f Mon Sep 17 00:00:00 2001 From: Travis Shears Date: Wed, 30 Apr 2025 13:28:21 +0200 Subject: [PATCH] switch from alarm to update fn for comms led blink --- node1.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/node1.c b/node1.c index 11aaede..96c4479 100644 --- a/node1.c +++ b/node1.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -22,21 +23,25 @@ void comms_led_init() { gpio_set_dir(16, GPIO_OUT); } -alarm_id_t comms_led_alarm_id; -int16_t comms_led_blink_count; -int64_t comms_led_disable(alarm_id_t id, __unused void *user_data) { - gpio_put(16, false); - comms_led_alarm_id = 0; - return 0; -} +absolute_time_t comms_led_off_time; +int16_t comms_led_blink_count = 0; +bool comms_led_state = false; + void comms_led_blink() { printf("COMMS LED BLINK COUNT: %d\n", comms_led_blink_count); comms_led_blink_count++; - gpio_put(16, true); - if (comms_led_alarm_id != 0) { - cancel_alarm(comms_led_alarm_id); + if(!comms_led_state) { + gpio_put(16, true); + comms_led_state = true; } - comms_led_alarm_id = add_alarm_in_ms(1000, comms_led_disable, NULL, false); + comms_led_off_time = make_timeout_time_ms(1000); +} + +void comms_led_update() { + if (comms_led_state && time_reached(comms_led_off_time)) { + gpio_put(16, false); + comms_led_state = false; + } } static pms5003_config pms_config; @@ -124,9 +129,15 @@ int main() { pms5003_init(&pms_config, uart1, 20, 21, 18, 19); struct repeating_timer timer_30; - add_repeating_timer_ms(LOOP_INTERVAL_MS, cb_30, NULL, &timer_30); - + // add_repeating_timer_ms(LOOP_INTERVAL_MS, cb_30, NULL, &timer_30); + absolute_time_t blink_time = make_timeout_time_ms(5000); + comms_led_blink(); while (true) { + if(time_reached(blink_time)) { + comms_led_blink(); + blink_time = make_timeout_time_ms(5000); + } + comms_led_update(); tight_loop_contents(); } }