Skip to content

Commit

Permalink
trunk reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabrielerusso committed Feb 14, 2024
1 parent 5ef0709 commit 7d72ede
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
15 changes: 8 additions & 7 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ class AnalogBatteryLevel : public HasBatteryLevel
scaled = operativeAdcMultiplier * ((1000 * AREF_VOLTAGE) / pow(2, BATTERY_SENSE_RESOLUTION_BITS)) * raw;
#endif
last_read_value += (scaled - last_read_value) * 0.5; // Virtual LPF
//LOG_DEBUG("battery gpio %d raw val=%u scaled=%u filtered=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled), (uint32_t) (last_read_value));
// LOG_DEBUG("battery gpio %d raw val=%u scaled=%u filtered=%u\n", BATTERY_PIN, raw, (uint32_t)(scaled), (uint32_t)
// (last_read_value));
}
return last_read_value;
#endif // BATTERY_PIN
Expand All @@ -224,23 +225,23 @@ class AnalogBatteryLevel : public HasBatteryLevel
{

uint32_t raw = 0;
uint8_t raw_c = 0; //raw reading counter
uint8_t raw_c = 0; // raw reading counter

#ifndef BAT_MEASURE_ADC_UNIT // ADC1
#ifdef ADC_CTRL //enable adc voltage divider when we need to read
#ifdef ADC_CTRL // enable adc voltage divider when we need to read
pinMode(ADC_CTRL, OUTPUT);
digitalWrite(ADC_CTRL, ADC_CTRL_ENABLED);
delay(10);
#endif
for (int i = 0; i < BATTERY_SENSE_SAMPLES; i++) {
int val_ = adc1_get_raw(adc_channel);
if(val_ >= 0){ //save only valid readings
if (val_ >= 0) { // save only valid readings
raw += val_;
raw_c ++;
raw_c++;
}
// delayMicroseconds(100);
}
#ifdef ADC_CTRL //disable adc voltage divider when we need to read
#ifdef ADC_CTRL // disable adc voltage divider when we need to read
digitalWrite(ADC_CTRL, !ADC_CTRL_ENABLED);
#endif
#else // ADC2
Expand All @@ -252,7 +253,7 @@ class AnalogBatteryLevel : public HasBatteryLevel
SET_PERI_REG_MASK(SENS_SAR_READ_CTRL2_REG, SENS_SAR2_DATA_INV);
adc2_get_raw(adc_channel, ADC_WIDTH_BIT_12, &adc_buf);
raw += adc_buf;
raw_c ++;
raw_c++;
}
#endif // BAT_MEASURE_ADC_UNIT
return (raw / (raw_c < 1 ? 1 : raw_c));
Expand Down
9 changes: 4 additions & 5 deletions variants/chatter2/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@
#define BATTERY_PIN 34 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage
#define ADC_CHANNEL ADC1_GPIO34_CHANNEL
#define ADC_ATTENUATION \
ADC_ATTEN_DB_2_5 // 2_5-> 100mv-1250mv, 11-> 150mv-3100mv for ESP32
// ESP32-S2/C3/S3 are different
// lower dB for lower voltage rnage
#define ADC_MULTIPLIER \
5.0 // VBATT---10k--pin34---2.5K---GND
ADC_ATTEN_DB_2_5 // 2_5-> 100mv-1250mv, 11-> 150mv-3100mv for ESP32
// ESP32-S2/C3/S3 are different
// lower dB for lower voltage rnage
#define ADC_MULTIPLIER 5.0 // VBATT---10k--pin34---2.5K---GND
// Chatter2 uses 3 AAA cells
#define CELL_TYPE_ALKALINE
#define NUM_CELLS 3
Expand Down
4 changes: 2 additions & 2 deletions variants/heltec_v2.1/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
#define LORA_DIO1 35 // https://www.thethingsnetwork.org/forum/t/big-esp32-sx127x-topic-part-3/18436
#define LORA_DIO2 34 // Not really used

#define ADC_MULTIPLIER 3.2 //220k + 100k (320k/100k=3.2)
//#define ADC_WIDTH ADC_WIDTH_BIT_10
#define ADC_MULTIPLIER 3.2 // 220k + 100k (320k/100k=3.2)
// #define ADC_WIDTH ADC_WIDTH_BIT_10

#define BATTERY_PIN 37 // A battery voltage measurement pin, voltage divider connected here to measure battery voltage
#define ADC_CHANNEL ADC1_GPIO37_CHANNEL
Expand Down
2 changes: 1 addition & 1 deletion variants/station-g1/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#define ADC_CHANNEL ADC1_GPIO35_CHANNEL
#define BATTERY_SENSE_SAMPLES 30 // Set the number of samples, It has an effect of increasing sensitivity.
#define ADC_MULTIPLIER 6.45
#define CELL_TYPE_LION //same curve for liion/lipo
#define CELL_TYPE_LION // same curve for liion/lipo
#define NUM_CELLS 3

// different screen
Expand Down

0 comments on commit 7d72ede

Please sign in to comment.