update mailbox
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#if (ENVIRONMENT == TTGO_T18)
|
||||
#define VOLTAGE_DIVIDER 2 // ttgo has 100/100k voltage divider so need to reverse that reduction via (220k+100k)/100k on vbat GPIO37 or ADC1_1 (early revs were GPIO13 or ADC2_4 but do NOT use with WiFi.begin())
|
||||
#define VOLTAGEREF 3787 // measured 2,0474 / 2214 ticks (mv)
|
||||
#define VOLTAGEADC 0.9245
|
||||
#else
|
||||
|
||||
#define VOLTAGE_DIVIDER 2.08 // Lora has 220k/100k voltage divider so need to reverse that reduction via (220k+100k)/100k on vbat GPIO37 or ADC1_1 (early revs were GPIO13 or ADC2_4 but do NOT use with WiFi.begin())
|
||||
@@ -74,6 +75,8 @@ void powerInit(void)
|
||||
//digitalWrite(VEXT, LOW); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low
|
||||
//delay(ADC_READ_STABILIZE); // let GPIO stabilize
|
||||
Serial.println("Power init done");
|
||||
displayWriteLine("Power Init Done");
|
||||
|
||||
}
|
||||
|
||||
uint16_t powerGetVbatt(void)
|
||||
@@ -86,27 +89,27 @@ void powerHandler(void)
|
||||
voltage = Sample();
|
||||
//displayDrawBatt(voltage, voltage < LIGHT_SLEEP_VOLTAGE);
|
||||
|
||||
// if (voltage < MINBATT)
|
||||
// { // Low Voltage cut off shut down to protect battery as long as possible
|
||||
// displayDrawShutdown();
|
||||
// delay(2000);
|
||||
// #if defined(__DEBUG) && __DEBUG > 0
|
||||
// Serial.printf(" !! Shutting down...low battery volotage: %dmV.\n", voltage);
|
||||
// delay(10);
|
||||
// #endif
|
||||
// esp_sleep_enable_timer_wakeup(LO_BATT_SLEEP_TIME);
|
||||
// esp_deep_sleep_start();
|
||||
// }
|
||||
// else if (voltage < LIGHT_SLEEP_VOLTAGE)
|
||||
// { // Use light sleep once on battery
|
||||
// uint64_t s = VBATT_SAMPLE;
|
||||
// #if defined(__DEBUG) && __DEBUG > 0
|
||||
// Serial.printf(" - Light Sleep (%dms)...battery volotage: %dmV.\n", (int)s, voltage);
|
||||
// delay(20);
|
||||
// #endif
|
||||
// esp_sleep_enable_timer_wakeup(s * 1000); // Light Sleep does not flush buffer
|
||||
// esp_light_sleep_start();
|
||||
// }
|
||||
if (voltage < MINBATT)
|
||||
{ // Low Voltage cut off shut down to protect battery as long as possible
|
||||
displayDrawShutdown();
|
||||
delay(2000);
|
||||
#if defined(__DEBUG) && __DEBUG > 0
|
||||
Serial.printf(" !! Shutting down...low battery volotage: %dmV.\n", voltage);
|
||||
delay(10);
|
||||
#endif
|
||||
esp_sleep_enable_timer_wakeup(LO_BATT_SLEEP_TIME);
|
||||
esp_deep_sleep_start();
|
||||
}
|
||||
else if (voltage < LIGHT_SLEEP_VOLTAGE)
|
||||
{ // Use light sleep once on battery
|
||||
uint64_t s = VBATT_SAMPLE;
|
||||
#if defined(__DEBUG) && __DEBUG > 0
|
||||
Serial.printf(" - Light Sleep (%dms)...battery volotage: %dmV.\n", (int)s, voltage);
|
||||
delay(20);
|
||||
#endif
|
||||
esp_sleep_enable_timer_wakeup(s * 1000); // Light Sleep does not flush buffer
|
||||
esp_light_sleep_start();
|
||||
}
|
||||
delay(ADC_READ_STABILIZE);
|
||||
}
|
||||
|
||||
@@ -117,8 +120,8 @@ void powerHandler(void)
|
||||
// Poll the proper ADC for VBatt on Heltec Lora 32 with GPIO21 toggled
|
||||
uint16_t ReadVBatt()
|
||||
{
|
||||
Serial.println("start read batt");
|
||||
int reading = 666;
|
||||
//Serial.println("start read batt");
|
||||
//int reading = 666;
|
||||
uint16_t rawVoltage;
|
||||
|
||||
#if (defined(HELTEC_V2_1))
|
||||
@@ -131,12 +134,11 @@ uint16_t ReadVBatt()
|
||||
|
||||
#elif (ENVIRONMENT == TTGO_T18)
|
||||
pinMode(VBATT, ANALOG); // ADC GPIO13
|
||||
reading = analogRead(35);
|
||||
Serial.printf("battery analogread = %i\n", reading);
|
||||
rawVoltage = float(VOLTAGEREF / 4096) * reading;
|
||||
Serial.printf("raw voltage = %i\n", rawVoltage);
|
||||
rawVoltage = analogRead(35) * VOLTAGEADC;
|
||||
//Serial.printf("battery analogread = %i\n", reading);
|
||||
//Serial.printf("raw voltage = %i\n", rawVoltage);
|
||||
|
||||
//pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider
|
||||
pinMode(VBATT, INPUT); // Disconnect ADC before GPIO goes back high so we protect ADC from direct connect to VBATT (i.e. no divider
|
||||
#elif (ENVIRONMENT == LOLIN32)
|
||||
digitalWrite(VEXT, LOW); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low
|
||||
delay(ADC_READ_STABILIZE); // let GPIO stabilize
|
||||
@@ -147,7 +149,7 @@ uint16_t ReadVBatt()
|
||||
#endif
|
||||
//Serial.printf("battery rawvoltage = %i\n", rawVoltage);
|
||||
rawVoltage *= VOLTAGE_DIVIDER;
|
||||
Serial.printf("battery sample = %i\n", rawVoltage);
|
||||
//Serial.printf("battery voltage = %4.2f\n", rawVoltage/1000);
|
||||
//digitalWrite(VEXT, HIGH); // ESP32 Lora v2.1 reads on GPIO37 when GPIO21 is low
|
||||
|
||||
return rawVoltage;
|
||||
@@ -176,9 +178,9 @@ uint16_t Sample()
|
||||
|
||||
// ADC read
|
||||
samp[i] = ReadVBatt();
|
||||
#if defined(__DEBUG) && __DEBUG > 0
|
||||
Serial.printf("ADC Raw Reading[%d]: %d", i, voltage);
|
||||
#endif
|
||||
|
||||
//Serial.printf("ADC Raw Reading[%d]: %d", i, voltage);
|
||||
|
||||
t += samp[i];
|
||||
|
||||
if (++i >= VBATT_SMOOTH)
|
||||
@@ -186,9 +188,7 @@ uint16_t Sample()
|
||||
i = 0;
|
||||
}
|
||||
uint16_t s = round(((float)t / (float)VBATT_SMOOTH));
|
||||
#if defined(__DEBUG) && __DEBUG > 0
|
||||
Serial.printf(" Smoothed of %d/%d = %d\n", t, VBATT_S MOOTH, s);
|
||||
#endif
|
||||
Serial.printf("Vbatt = %4.3f Volt\n", (double(s)/1000));
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user