Extend breathing led to support enbale once and separated breathing index
This commit is contained in:
parent
4cbf23148b
commit
201c28e23b
@ -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_state = 0;
|
||||||
|
static led_pack_t breathing_led_once = 0;
|
||||||
static uint8_t breathing_led_duration = 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)
|
void breathing_led_enable(uint8_t index)
|
||||||
{
|
{
|
||||||
LED_BIT_SET(breathing_led_state, 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)
|
void breathing_led_enable_all(void)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
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;
|
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
|
#endif
|
||||||
|
|
||||||
#ifdef SOFTPWM_LED_TIMER3
|
#ifdef SOFTPWM_LED_TIMER3
|
||||||
@ -348,36 +375,38 @@ void fading_led_proc(void)
|
|||||||
void breathing_led_proc(void)
|
void breathing_led_proc(void)
|
||||||
{
|
{
|
||||||
static uint8_t step = 0;
|
static uint8_t step = 0;
|
||||||
static uint8_t index = 0;
|
|
||||||
static uint8_t direction = 0;
|
|
||||||
if (breathing_led_state) {
|
if (breathing_led_state) {
|
||||||
if (++step > breathing_led_duration) {
|
if (++step > breathing_led_duration) {
|
||||||
step = 0;
|
step = 0;
|
||||||
uint8_t value = pgm_read_byte(&breathing_table[index]);
|
|
||||||
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
for (uint8_t i = 0; i < LED_COUNT; i++) {
|
||||||
if (breathing_led_state & LED_BIT(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
|
#ifdef CUSTOM_LED_ENABLE
|
||||||
breathing_led_custom(softpwm_led_ocr);
|
breathing_led_custom(softpwm_led_ocr);
|
||||||
#endif
|
#endif
|
||||||
if (direction) {
|
|
||||||
if (index == 0) {
|
|
||||||
direction = 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
index--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (index == 0x7F) {
|
|
||||||
direction = 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,12 +56,17 @@ void fading_led_set_delay_all(uint8_t delay);
|
|||||||
#ifdef BREATHING_LED_ENABLE
|
#ifdef BREATHING_LED_ENABLE
|
||||||
#define breathing_led_init()
|
#define breathing_led_init()
|
||||||
void breathing_led_enable(uint8_t index);
|
void breathing_led_enable(uint8_t index);
|
||||||
|
void breathing_led_enable_once(uint8_t index);
|
||||||
void breathing_led_enable_all(void);
|
void breathing_led_enable_all(void);
|
||||||
void breathing_led_disable(uint8_t index);
|
void breathing_led_disable(uint8_t index);
|
||||||
void breathing_led_disable_all(void);
|
void breathing_led_disable_all(void);
|
||||||
void breathing_led_toggle(uint8_t index);
|
void breathing_led_toggle(uint8_t index);
|
||||||
void breathing_led_toggle_all(void);
|
void breathing_led_toggle_all(void);
|
||||||
void breathing_led_set_duration(uint8_t dur);
|
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
|
#else
|
||||||
#define breathing_led_init()
|
#define breathing_led_init()
|
||||||
#define breathing_led_enable()
|
#define breathing_led_enable()
|
||||||
@ -71,7 +76,10 @@ void breathing_led_set_duration(uint8_t dur);
|
|||||||
#define breathing_led_toggle()
|
#define breathing_led_toggle()
|
||||||
#define breathing_led_toggle_all()
|
#define breathing_led_toggle_all()
|
||||||
#define breathing_led_set_duration()
|
#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
|
#endif
|
||||||
|
|
||||||
#ifdef CUSTOM_LED_ENABLE
|
#ifdef CUSTOM_LED_ENABLE
|
||||||
|
Reference in New Issue
Block a user