소스 검색

Extend breathing led to support enbale once and separated breathing index

old_master
Kai Ryu 9 년 전
부모
커밋
a74976d2db
2개의 변경된 파일58개의 추가작업 그리고 21개의 파일을 삭제
  1. 49
    20
      common/softpwm_led.c
  2. 9
    1
      common/softpwm_led.h

+ 49
- 20
common/softpwm_led.c 파일 보기

}; };


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++) {
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
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++;
}
}
} }
} }
} }

+ 9
- 1
common/softpwm_led.h 파일 보기

#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()
#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