/* * led.c * * Created on: Mar 30, 2017 * Author: Matthew Reed */ #include "led.h" #define LED_CYCLE_STATUS 2000 #define LED_CYCLE_CAN 0 #define LED_CYCLE_ERROR 0 uint16_t led_timers[3]; uint16_t led_thresholds[3]; uint16_t led_cycles[3]; void led_init(void) { memset(led_timers, 0, sizeof led_timers); memset(led_thresholds, 0, sizeof led_thresholds); memset(led_cycles, 0, sizeof led_cycles); led_cycles[LED_STATUS] = LED_CYCLE_STATUS; led_cycles[LED_CAN] = LED_CYCLE_CAN; led_cycles[LED_ERROR] = LED_CYCLE_ERROR; } void led_start(led_name_t led) { led_timers[led] = led_cycles[led]; led_thresholds[led] = led_cycles[led]/2; } void led_start_time(led_name_t led, uint16_t time) { if (led_timers[led] == 0) { led_timers[led] = time; led_thresholds[led] = time/2; } } void led_update(led_name_t led) { if (led_timers[led] > led_thresholds[led]) { led_set(led, 1); led_timers[led]--; } else if (led_timers[led] > 0) { led_set(led, 0); led_timers[led]--; } else { led_set(led, 0); led_timers[led] = led_cycles[led]; } } void led_update_all(void) { led_update(LED_STATUS); led_update(LED_CAN); led_update(LED_ERROR); } void led_set(led_name_t led, bool value) { gpio_set_led(led, value); } void led_toggle(led_name_t led) { gpio_toggle_led(led); } __weak bool gpio_set_led(led_name_t led, bool value) { return false; } __weak bool gpio_toggle_led(led_name_t led) { return false; }