mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 13:37:03 +03:00
fix led & prepare spdif
This commit is contained in:
@@ -26,7 +26,8 @@ static struct led_s {
|
||||
bool on;
|
||||
int onstate;
|
||||
int ontime, offtime;
|
||||
int waiton, waitoff;
|
||||
int pushedon, pushedoff;
|
||||
bool pushed;
|
||||
TimerHandle_t timer;
|
||||
} leds[MAX_LED];
|
||||
|
||||
@@ -45,19 +46,25 @@ static void vCallbackFunction( TimerHandle_t xTimer ) {
|
||||
xTimerChangePeriod(xTimer, (led->on ? led->ontime : led->offtime) / portTICK_RATE_MS, BLOCKTIME);
|
||||
}
|
||||
|
||||
bool led_blink_core(int idx, int ontime, int offtime, bool wait) {
|
||||
bool led_blink_core(int idx, int ontime, int offtime, bool pushed) {
|
||||
if (!leds[idx].gpio) return false;
|
||||
|
||||
if (leds[idx].timer) {
|
||||
// low priority timers will wait
|
||||
if (wait && xTimerIsTimerActive(leds[idx].timer)) {
|
||||
leds[idx].waiton = ontime;
|
||||
leds[idx].waitoff = offtime;
|
||||
// normal requests waits if a pop is pending
|
||||
if (!pushed && leds[idx].pushed) {
|
||||
leds[idx].pushedon = ontime;
|
||||
leds[idx].pushedoff = offtime;
|
||||
return true;
|
||||
}
|
||||
xTimerStop(leds[idx].timer, BLOCKTIME);
|
||||
}
|
||||
|
||||
// save current state
|
||||
leds[idx].pushedon = leds[idx].ontime;
|
||||
leds[idx].pushedoff = leds[idx].offtime;
|
||||
leds[idx].pushed = pushed;
|
||||
|
||||
// then set new one
|
||||
leds[idx].ontime = ontime;
|
||||
leds[idx].offtime = offtime;
|
||||
|
||||
@@ -75,15 +82,11 @@ bool led_blink_core(int idx, int ontime, int offtime, bool wait) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool led_release(int idx) {
|
||||
bool led_unpush(int idx) {
|
||||
if (!leds[idx].gpio) return false;
|
||||
|
||||
if (leds[idx].waiton) {
|
||||
led_blink_core(idx, leds[idx].waiton, leds[idx].waitoff, false);
|
||||
leds[idx].waiton = 0;
|
||||
} else {
|
||||
gpio_set_level(leds[idx].gpio, !leds[idx].onstate);
|
||||
}
|
||||
led_blink_core(idx, leds[idx].pushedon, leds[idx].pushedoff, true);
|
||||
leds[idx].pushed = false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -99,3 +102,11 @@ bool led_config(int idx, gpio_num_t gpio, int onstate) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool led_unconfig(int idx) {
|
||||
if (idx >= MAX_LED) return false;
|
||||
|
||||
if (leds[idx].timer) xTimerDelete(leds[idx].timer, BLOCKTIME);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -28,10 +28,11 @@ enum { LED_GREEN = 0, LED_RED };
|
||||
#define led_on(idx) led_blink_core(idx, 1, 0, false)
|
||||
#define led_off(idx) led_blink_core(idx, 0, 0, false)
|
||||
#define led_blink(idx, on, off) led_blink_core(idx, on, off, false)
|
||||
#define led_blink_wait(idx, on, off) led_blink_core(idx, on, off, true)
|
||||
#define led_blink_pushed(idx, on, off) led_blink_core(idx, on, off, true)
|
||||
|
||||
bool led_blink_core(int idx, int ontime, int offtime, bool wait);
|
||||
bool led_release(int idx);
|
||||
bool led_config(int idx, gpio_num_t gpio, int onstate);
|
||||
bool led_unconfig(int idx);
|
||||
bool led_blink_core(int idx, int ontime, int offtime, bool push);
|
||||
bool led_unpush(int idx);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user