repair broken battery measure function
This commit is contained in:
parent
ef09c9d7a4
commit
22286a9a13
@ -139,7 +139,7 @@ extern time_t userUTCTime;
|
|||||||
#include "button.h"
|
#include "button.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = __FILE__;
|
static const char TAG[] = __FILE__;
|
||||||
|
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
esp_adc_cal_characteristics_t *adc_characs =
|
esp_adc_cal_characteristics_t *adc_characs =
|
||||||
(esp_adc_cal_characteristics_t *)calloc(
|
(esp_adc_cal_characteristics_t *)calloc(
|
||||||
1, sizeof(esp_adc_cal_characteristics_t));
|
1, sizeof(esp_adc_cal_characteristics_t));
|
||||||
@ -14,7 +14,7 @@ static const adc_unit_t unit = ADC_UNIT_1;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void calibrate_voltage(void) {
|
void calibrate_voltage(void) {
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
// configure ADC
|
// configure ADC
|
||||||
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12));
|
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12));
|
||||||
ESP_ERROR_CHECK(adc1_config_channel_atten(adc_channel, atten));
|
ESP_ERROR_CHECK(adc1_config_channel_atten(adc_channel, atten));
|
||||||
@ -35,7 +35,7 @@ void calibrate_voltage(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint16_t read_voltage() {
|
uint16_t read_voltage() {
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
// multisample ADC
|
// multisample ADC
|
||||||
uint32_t adc_reading = 0;
|
uint32_t adc_reading = 0;
|
||||||
for (int i = 0; i < NO_OF_SAMPLES; i++) {
|
for (int i = 0; i < NO_OF_SAMPLES; i++) {
|
||||||
|
@ -54,7 +54,7 @@ void doHousekeeping() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// read battery voltage into global variable
|
// read battery voltage into global variable
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
batt_voltage = read_voltage();
|
batt_voltage = read_voltage();
|
||||||
ESP_LOGI(TAG, "Voltage: %dmV", batt_voltage);
|
ESP_LOGI(TAG, "Voltage: %dmV", batt_voltage);
|
||||||
#endif
|
#endif
|
||||||
|
@ -185,7 +185,7 @@ void draw_page(time_t t, uint8_t page) {
|
|||||||
case 0:
|
case 0:
|
||||||
|
|
||||||
// update Battery status (line 2)
|
// update Battery status (line 2)
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
u8x8.setCursor(0, 2);
|
u8x8.setCursor(0, 2);
|
||||||
u8x8.printf("B:%.2fV", batt_voltage / 1000.0);
|
u8x8.printf("B:%.2fV", batt_voltage / 1000.0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -366,7 +366,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius,
|
|||||||
uint32_t mem, uint8_t reset1, uint8_t reset2) {
|
uint32_t mem, uint8_t reset1, uint8_t reset2) {
|
||||||
uint16_t temp = celsius * 10;
|
uint16_t temp = celsius * 10;
|
||||||
uint16_t volt = voltage / 10;
|
uint16_t volt = voltage / 10;
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
#if (PAYLOAD_ENCODER == 3)
|
#if (PAYLOAD_ENCODER == 3)
|
||||||
buffer[cursor++] = LPP_BATT_CHANNEL;
|
buffer[cursor++] = LPP_BATT_CHANNEL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -239,7 +239,7 @@ void get_config(uint8_t val[]) {
|
|||||||
|
|
||||||
void get_status(uint8_t val[]) {
|
void get_status(uint8_t val[]) {
|
||||||
ESP_LOGI(TAG, "Remote command: get device status");
|
ESP_LOGI(TAG, "Remote command: get device status");
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
uint16_t voltage = read_voltage();
|
uint16_t voltage = read_voltage();
|
||||||
#else
|
#else
|
||||||
uint16_t voltage = 0;
|
uint16_t voltage = 0;
|
||||||
|
@ -114,7 +114,7 @@ void sendCounter() {
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef BAT_MEASURE_ADC
|
||||||
case BATT_DATA:
|
case BATT_DATA:
|
||||||
payload.reset();
|
payload.reset();
|
||||||
payload.addVoltage(read_voltage());
|
payload.addVoltage(read_voltage());
|
||||||
|
Loading…
Reference in New Issue
Block a user