switch from alarm to update fn for comms led blink
This commit is contained in:
parent
f484586742
commit
f3a418af4c
1 changed files with 24 additions and 13 deletions
37
node1.c
37
node1.c
|
|
@ -5,6 +5,7 @@
|
|||
#include <hardware/i2c.h>
|
||||
#include <hardware/uart.h>
|
||||
#include <pico/time.h>
|
||||
#include <pico/types.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue