repair broken battery measure function

This commit is contained in:
Verkehrsrot 2019-04-13 19:22:48 +02:00
parent ef09c9d7a4
commit 22286a9a13
7 changed files with 9 additions and 9 deletions

View File

@ -139,7 +139,7 @@ extern time_t userUTCTime;
#include "button.h"
#endif
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
#include "battery.h"
#endif

View File

@ -3,7 +3,7 @@
// Local logging tag
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 *)calloc(
1, sizeof(esp_adc_cal_characteristics_t));
@ -14,7 +14,7 @@ static const adc_unit_t unit = ADC_UNIT_1;
#endif
void calibrate_voltage(void) {
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
// configure ADC
ESP_ERROR_CHECK(adc1_config_width(ADC_WIDTH_BIT_12));
ESP_ERROR_CHECK(adc1_config_channel_atten(adc_channel, atten));
@ -35,7 +35,7 @@ void calibrate_voltage(void) {
}
uint16_t read_voltage() {
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
// multisample ADC
uint32_t adc_reading = 0;
for (int i = 0; i < NO_OF_SAMPLES; i++) {

View File

@ -54,7 +54,7 @@ void doHousekeeping() {
#endif
// read battery voltage into global variable
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
batt_voltage = read_voltage();
ESP_LOGI(TAG, "Voltage: %dmV", batt_voltage);
#endif

View File

@ -185,7 +185,7 @@ void draw_page(time_t t, uint8_t page) {
case 0:
// update Battery status (line 2)
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
u8x8.setCursor(0, 2);
u8x8.printf("B:%.2fV", batt_voltage / 1000.0);
#endif

View File

@ -366,7 +366,7 @@ void PayloadConvert::addStatus(uint16_t voltage, uint64_t uptime, float celsius,
uint32_t mem, uint8_t reset1, uint8_t reset2) {
uint16_t temp = celsius * 10;
uint16_t volt = voltage / 10;
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
#if (PAYLOAD_ENCODER == 3)
buffer[cursor++] = LPP_BATT_CHANNEL;
#endif

View File

@ -239,7 +239,7 @@ void get_config(uint8_t val[]) {
void get_status(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get device status");
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
uint16_t voltage = read_voltage();
#else
uint16_t voltage = 0;

View File

@ -114,7 +114,7 @@ void sendCounter() {
break;
#endif
#ifdef HAS_BATTERY_PROBE
#ifdef BAT_MEASURE_ADC
case BATT_DATA:
payload.reset();
payload.addVoltage(read_voltage());