From a74976d2db36ed14e3e70bc59e14e5995e4ffd95 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Mon, 27 Apr 2015 18:55:50 +0900 Subject: [PATCH] Extend breathing led to support enbale once and separated breathing index --- common/softpwm_led.c | 69 +++++++++++++++++++++++++++++++------------- common/softpwm_led.h | 10 ++++++- 2 files changed, 58 insertions(+), 21 deletions(-) diff --git a/common/softpwm_led.c b/common/softpwm_led.c index 51d1e949..6d15ba97 100644 --- a/common/softpwm_led.c +++ b/common/softpwm_led.c @@ -240,13 +240,22 @@ static const uint8_t breathing_table[128] PROGMEM = { }; static led_pack_t breathing_led_state = 0; +static led_pack_t breathing_led_once = 0; static uint8_t breathing_led_duration = 0; +static uint8_t breathing_led_index[LED_COUNT] = {0}; +static led_pack_t breathing_led_direction = 0; void breathing_led_enable(uint8_t index) { LED_BIT_SET(breathing_led_state, index); } +void breathing_led_enable_once(uint8_t index) +{ + LED_BIT_SET(breathing_led_state, index); + LED_BIT_SET(breathing_led_once, index); +} + void breathing_led_enable_all(void) { for (uint8_t i = 0; i < LED_COUNT; i++) { @@ -281,6 +290,24 @@ void breathing_led_set_duration(uint8_t dur) breathing_led_duration = dur; } +void breathing_led_set_index(uint8_t index, uint8_t value) +{ + if (value & 0x80) { + LED_BIT_SET(breathing_led_direction, index); + } + else { + LED_BIT_CLEAR(breathing_led_direction, index); + } + breathing_led_index[index] = value & 0x7F; +} + +void breathing_led_set_index_all(uint8_t value) +{ + for (uint8_t i = 0; i < LED_COUNT; i++) { + breathing_led_set_index(i, value); + } +} + #endif #ifdef SOFTPWM_LED_TIMER3 @@ -348,36 +375,38 @@ void fading_led_proc(void) void breathing_led_proc(void) { static uint8_t step = 0; - static uint8_t index = 0; - static uint8_t direction = 0; if (breathing_led_state) { if (++step > breathing_led_duration) { step = 0; - uint8_t value = pgm_read_byte(&breathing_table[index]); for (uint8_t i = 0; i < LED_COUNT; i++) { if (breathing_led_state & LED_BIT(i)) { - softpwm_led_ocr_buff[i] = value; + softpwm_led_ocr_buff[i] = pgm_read_byte(&breathing_table[breathing_led_index[i]]); + if (breathing_led_direction & LED_BIT(i)) { + if (breathing_led_index[i] == 0) { + LED_BIT_CLEAR(breathing_led_direction, i); + if (breathing_led_once & LED_BIT(i)) { + LED_BIT_CLEAR(breathing_led_state, i); + LED_BIT_CLEAR(breathing_led_once, i); + } + } + else { + breathing_led_index[i]--; + } + + } + else { + if (breathing_led_index[i] == 127) { + LED_BIT_SET(breathing_led_direction, i); + } + else { + breathing_led_index[i]++; + } + } } } #ifdef CUSTOM_LED_ENABLE breathing_led_custom(softpwm_led_ocr); #endif - if (direction) { - if (index == 0) { - direction = 0; - } - else { - index--; - } - } - else { - if (index == 0x7F) { - direction = 1; - } - else { - index++; - } - } } } } diff --git a/common/softpwm_led.h b/common/softpwm_led.h index 3eb592a4..d6574841 100644 --- a/common/softpwm_led.h +++ b/common/softpwm_led.h @@ -56,12 +56,17 @@ void fading_led_set_delay_all(uint8_t delay); #ifdef BREATHING_LED_ENABLE #define breathing_led_init() void breathing_led_enable(uint8_t index); +void breathing_led_enable_once(uint8_t index); void breathing_led_enable_all(void); void breathing_led_disable(uint8_t index); void breathing_led_disable_all(void); void breathing_led_toggle(uint8_t index); void breathing_led_toggle_all(void); void breathing_led_set_duration(uint8_t dur); +void breathing_led_set_index(uint8_t index, uint8_t value); +void breathing_led_set_index_all(uint8_t value); +void breathing_led_set_delay(uint8_t index, uint8_t delay); +void breathing_led_set_delay_all(uint8_t delay); #else #define breathing_led_init() #define breathing_led_enable() @@ -71,7 +76,10 @@ void breathing_led_set_duration(uint8_t dur); #define breathing_led_toggle() #define breathing_led_toggle_all() #define breathing_led_set_duration() -#define breathing_led_set_duration_all() +#define breathing_led_set_index() +#define breathing_led_set_index_all() +#define breathing_led_set_delay() +#define breathing_led_set_delay_all() #endif #ifdef CUSTOM_LED_ENABLE