mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-08 04:27:12 +03:00
add battery led
This commit is contained in:
@@ -204,7 +204,7 @@ CONFIG_AMP_GPIO=21
|
|||||||
CONFIG_JACK_GPIO=34
|
CONFIG_JACK_GPIO=34
|
||||||
CONFIG_SPKFAULT_GPIO=-1
|
CONFIG_SPKFAULT_GPIO=-1
|
||||||
CONFIG_BAT_CHANNEL=-1
|
CONFIG_BAT_CHANNEL=-1
|
||||||
CONFIG_LED_GREEN_GPIO=22
|
CONFIG_LED_GREEN_GPIO=-1
|
||||||
CONFIG_LED_RED_GPIO=-1
|
CONFIG_LED_RED_GPIO=-1
|
||||||
CONFIG_TARGET="muse"
|
CONFIG_TARGET="muse"
|
||||||
# end of Target
|
# end of Target
|
||||||
|
|||||||
@@ -52,51 +52,27 @@ const struct target_s target_muse = { "muse", init };
|
|||||||
static bool init(void) {
|
static bool init(void) {
|
||||||
battery_handler_chain = battery_handler_svc;
|
battery_handler_chain = battery_handler_svc;
|
||||||
battery_handler_svc = battery_svc;
|
battery_handler_svc = battery_svc;
|
||||||
|
ws2812_control_init();
|
||||||
ESP_LOGI(TAG, "Initializing for Muse");
|
ESP_LOGI(TAG, "Initializing for Muse");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void battery_svc(float value) {
|
#define VGREEN 4.0
|
||||||
ESP_LOGI(TAG, "Called for battery service with %f", value);
|
#define VRED 3.6
|
||||||
// put here your code for LED according to value
|
|
||||||
if (battery_handler_chain) battery_handler_chain(value);
|
static void battery_svc(float value) {
|
||||||
}
|
struct led_state new_state;
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Called for battery service with %f", value);
|
||||||
|
|
||||||
|
if (value > VGREEN) new_state.leds[0] = GREEN;
|
||||||
|
else if (value < VRED) new_state.leds[0] = RED;
|
||||||
|
else new_state.leds[0] = YELLOW;
|
||||||
|
|
||||||
// Battery monitoring
|
|
||||||
/*
|
|
||||||
static void battery(void *data)
|
|
||||||
{
|
|
||||||
#define VGREEN 2300
|
|
||||||
#define VRED 2000
|
|
||||||
#define NM 10
|
|
||||||
static int val;
|
|
||||||
static int V[NM];
|
|
||||||
static int I=0;
|
|
||||||
int S;
|
|
||||||
for(int i=0;i<NM;i++)V[i]=VGREEN;
|
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
||||||
struct led_state new_state;
|
|
||||||
ws2812_control_init();
|
|
||||||
// init ADC interface for battery survey
|
|
||||||
adc1_config_width(ADC_WIDTH_BIT_12);
|
|
||||||
adc1_config_channel_atten(ADC1_GPIO33_CHANNEL, ADC_ATTEN_DB_11);
|
|
||||||
while(true)
|
|
||||||
{
|
|
||||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
|
||||||
V[I++] = adc1_get_raw(ADC1_GPIO33_CHANNEL);
|
|
||||||
if(I >= NM)I = 0;
|
|
||||||
S = 0;
|
|
||||||
for(int i=0;i<NM;i++)S = S + V[i];
|
|
||||||
val = S / NM;
|
|
||||||
new_state.leds[0] = YELLOW;
|
|
||||||
if(val > VGREEN) new_state.leds[0] = GREEN;
|
|
||||||
if(val < VRED) new_state.leds[0] = RED;
|
|
||||||
printf("====> %d %6x\n", val, new_state.leds[0]);
|
|
||||||
ws2812_write_leds(new_state);
|
ws2812_write_leds(new_state);
|
||||||
|
|
||||||
}
|
if (battery_handler_chain) battery_handler_chain(value);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// This is the buffer which the hw peripheral will access while pulsing the output pin
|
// This is the buffer which the hw peripheral will access while pulsing the output pin
|
||||||
rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS];
|
rmt_item32_t led_data_buffer[LED_BUFFER_ITEMS];
|
||||||
@@ -139,5 +115,5 @@ void setup_rmt_data_buffer(struct led_state new_state)
|
|||||||
mask >>= 1;
|
mask >>= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ menu "Squeezelite-ESP32"
|
|||||||
config BAT_CONFIG
|
config BAT_CONFIG
|
||||||
string
|
string
|
||||||
default "channel=7,scale=20.24,atten=0" if SQUEEZEAMP
|
default "channel=7,scale=20.24,atten=0" if SQUEEZEAMP
|
||||||
default "channel=5,scale=1,atten=3,cells=1" if MUSE
|
default "channel=5,scale=7.48,atten=3,cells=1" if MUSE
|
||||||
default ""
|
default ""
|
||||||
config TARGET
|
config TARGET
|
||||||
string
|
string
|
||||||
@@ -163,7 +163,6 @@ menu "Squeezelite-ESP32"
|
|||||||
config LED_GREEN_GPIO
|
config LED_GREEN_GPIO
|
||||||
int
|
int
|
||||||
default 12 if SQUEEZEAMP
|
default 12 if SQUEEZEAMP
|
||||||
default 22 if MUSE
|
|
||||||
default -1
|
default -1
|
||||||
config LED_RED_GPIO
|
config LED_RED_GPIO
|
||||||
int
|
int
|
||||||
|
|||||||
Reference in New Issue
Block a user