mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-11 05:57:05 +03:00
Merge pull request #102 from wizmo2/battery_atten
Add Attenuation parameter to battery service
This commit is contained in:
@@ -361,9 +361,9 @@ The benefit of the "raw" mode is that you can build a player which is as close a
|
|||||||
There is no good or bad option, it's your choice. Use the NVS parameter "lms_ctrls_raw" to change that option
|
There is no good or bad option, it's your choice. Use the NVS parameter "lms_ctrls_raw" to change that option
|
||||||
|
|
||||||
### Battery / ADC
|
### Battery / ADC
|
||||||
The NVS parameter "bat_config" sets the ADC1 channel used to measure battery/DC voltage. Scale is a float ratio applied to every sample of the 12 bits ADC. A measure is taken every 10s and an average is made every 5 minutes (not a sliding window). Syntax is
|
The NVS parameter "bat_config" sets the ADC1 channel used to measure battery/DC voltage. The "atten" value attenuates the input voltage to the ADC input (the read value maintains a 0-1V rage) where: 0=no attenuation(0..800mV), 1=2.5dB attenuation(0..1.1V), 2=6dB attenuation(0..1.35V), 3=11dB attenuation(0..2.6V). Scale is a float ratio applied to every sample of the 12 bits ADC. A measure is taken every 10s and an average is made every 5 minutes (not a sliding window). Syntax is
|
||||||
```
|
```
|
||||||
channel=0..7,scale=<scale>,cells=<2|3>
|
channel=0..7,scale=<scale>,cells=<2|3>,[atten=<0|1|2|3>]
|
||||||
```
|
```
|
||||||
NB: Set parameter to empty to disable battery reading. For well-known configuration, this is ignored (except for SqueezeAMP where number of cells is required)
|
NB: Set parameter to empty to disable battery reading. For well-known configuration, this is ignored (except for SqueezeAMP where number of cells is required)
|
||||||
# Configuration
|
# Configuration
|
||||||
|
|||||||
@@ -33,11 +33,12 @@ static struct {
|
|||||||
int channel;
|
int channel;
|
||||||
float sum, avg, scale;
|
float sum, avg, scale;
|
||||||
int count;
|
int count;
|
||||||
int cells;
|
int cells, attenuation;
|
||||||
TimerHandle_t timer;
|
TimerHandle_t timer;
|
||||||
} battery = {
|
} battery = {
|
||||||
.channel = CONFIG_BAT_CHANNEL,
|
.channel = CONFIG_BAT_CHANNEL,
|
||||||
.cells = 2,
|
.cells = 2,
|
||||||
|
.attenuation = ADC_ATTEN_DB_0,
|
||||||
};
|
};
|
||||||
|
|
||||||
/****************************************************************************************
|
/****************************************************************************************
|
||||||
@@ -82,6 +83,7 @@ void battery_svc_init(void) {
|
|||||||
#ifndef CONFIG_BAT_LOCKED
|
#ifndef CONFIG_BAT_LOCKED
|
||||||
if ((p = strcasestr(nvs_item, "channel")) != NULL) battery.channel = atoi(strchr(p, '=') + 1);
|
if ((p = strcasestr(nvs_item, "channel")) != NULL) battery.channel = atoi(strchr(p, '=') + 1);
|
||||||
if ((p = strcasestr(nvs_item, "scale")) != NULL) battery.scale = atof(strchr(p, '=') + 1);
|
if ((p = strcasestr(nvs_item, "scale")) != NULL) battery.scale = atof(strchr(p, '=') + 1);
|
||||||
|
if ((p = strcasestr(nvs_item, "atten")) != NULL) battery.attenuation = atoi(strchr(p, '=') + 1);
|
||||||
#endif
|
#endif
|
||||||
if ((p = strcasestr(nvs_item, "cells")) != NULL) battery.cells = atof(strchr(p, '=') + 1);
|
if ((p = strcasestr(nvs_item, "cells")) != NULL) battery.cells = atof(strchr(p, '=') + 1);
|
||||||
free(nvs_item);
|
free(nvs_item);
|
||||||
@@ -89,7 +91,7 @@ void battery_svc_init(void) {
|
|||||||
|
|
||||||
if (battery.channel != -1) {
|
if (battery.channel != -1) {
|
||||||
adc1_config_width(ADC_WIDTH_BIT_12);
|
adc1_config_width(ADC_WIDTH_BIT_12);
|
||||||
adc1_config_channel_atten(battery.channel, ADC_ATTEN_DB_0);
|
adc1_config_channel_atten(battery.channel, battery.attenuation);
|
||||||
|
|
||||||
battery.avg = adc1_get_raw(battery.channel) * battery.scale / 4095.0;
|
battery.avg = adc1_get_raw(battery.channel) * battery.scale / 4095.0;
|
||||||
battery.timer = xTimerCreate("battery", BATTERY_TIMER / portTICK_RATE_MS, pdTRUE, NULL, battery_callback);
|
battery.timer = xTimerCreate("battery", BATTERY_TIMER / portTICK_RATE_MS, pdTRUE, NULL, battery_callback);
|
||||||
|
|||||||
Reference in New Issue
Block a user