don't deepsleep if we have USB power

This commit is contained in:
geeksville 2020-02-12 09:13:49 -08:00
parent c18306076a
commit 556ad310fc
3 changed files with 20 additions and 22 deletions

View File

@ -38,11 +38,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Select which T-Beam board is being used. Only uncomment one. Note: these options now come from platformio standard build file flags // Select which T-Beam board is being used. Only uncomment one. Note: these options now come from platformio standard build file flags
//#ifdef ARDUINO_T_Beam //#ifdef ARDUINO_T_Beam
//#define T_BEAM_V10 // AKA Rev1 (second board released) #define T_BEAM_V10 // AKA Rev1 (second board released)
//#endif //#endif
//#ifdef ARDUINO_HELTEC_WIFI_LORA_32_V2 //#ifdef ARDUINO_HELTEC_WIFI_LORA_32_V2
#define HELTEC_LORA32 //#define HELTEC_LORA32
//#endif //#endif
// If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled) // If we are using the JTAG port for debugging, some pins must be left free for that (and things like GPS have to be disabled)
@ -62,7 +62,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// If not defined, we will wait for lock forever // If not defined, we will wait for lock forever
#define MINWAKE_MSECS (30 * 60 * 1000) // stay awake a long time (30 mins) for debugging #define MINWAKE_MSECS (30 * 1000) // stay awake a long time (30 mins) for debugging
// #define MINWAKE_MSECS (30 * 1000) // Wait after every boot for GPS lock (may need longer than 5s because we turned the gps off during deep sleep) // #define MINWAKE_MSECS (30 * 1000) // Wait after every boot for GPS lock (may need longer than 5s because we turned the gps off during deep sleep)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -122,6 +122,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define DIO0_GPIO 26 #define DIO0_GPIO 26
#define DIO1_GPIO 33 // Note: not really used on this board #define DIO1_GPIO 33 // Note: not really used on this board
#define DIO2_GPIO 32 // Note: not really used on this board #define DIO2_GPIO 32 // Note: not really used on this board
// Leave undefined to disable our PMU IRQ handler
#define PMU_IRQ 35 #define PMU_IRQ 35
#elif defined(HELTEC_LORA32) #elif defined(HELTEC_LORA32)

View File

@ -37,8 +37,9 @@
#include "axp20x.h" #include "axp20x.h"
AXP20X_Class axp; AXP20X_Class axp;
bool pmu_irq = false; bool pmu_irq = false;
String baChStatus = "No charging";
#endif #endif
bool isCharging = false;
bool ssd1306_found = false; bool ssd1306_found = false;
bool axp192_found = false; bool axp192_found = false;
@ -268,6 +269,7 @@ void axp192Init()
axp.debugCharging(); axp.debugCharging();
#ifdef PMU_IRQ
pinMode(PMU_IRQ, INPUT_PULLUP); pinMode(PMU_IRQ, INPUT_PULLUP);
attachInterrupt(PMU_IRQ, [] { attachInterrupt(PMU_IRQ, [] {
pmu_irq = true; pmu_irq = true;
@ -277,11 +279,9 @@ void axp192Init()
axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1); axp.adc1Enable(AXP202_BATT_CUR_ADC1, 1);
axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1); axp.enableIRQ(AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_BATT_REMOVED_IRQ | AXP202_BATT_CONNECT_IRQ, 1);
axp.clearIRQ(); axp.clearIRQ();
#endif
if (axp.isChargeing()) isCharging = axp.isChargeing();
{
baChStatus = "Charging";
}
} }
else else
{ {
@ -412,26 +412,21 @@ void loop()
// blink the axp led // blink the axp led
axp.setChgLEDMode(ledon ? AXP20X_LED_LOW_LEVEL : AXP20X_LED_OFF); axp.setChgLEDMode(ledon ? AXP20X_LED_LOW_LEVEL : AXP20X_LED_OFF);
#ifdef PMU_IRQ
if (pmu_irq) if (pmu_irq)
{ {
pmu_irq = false; pmu_irq = false;
axp.readIRQ(); axp.readIRQ();
if (axp.isChargingIRQ()) isCharging = axp.isChargingIRQ();
{
baChStatus = "Charging";
}
else
{
baChStatus = "No Charging";
}
if (axp.isVbusRemoveIRQ()) if (axp.isVbusRemoveIRQ())
{ isCharging = false;
baChStatus = "No Charging";
}
// This is not a GPIO actually connected on the tbeam board // This is not a GPIO actually connected on the tbeam board
// digitalWrite(2, !digitalRead(2)); // digitalWrite(2, !digitalRead(2));
axp.clearIRQ(); axp.clearIRQ();
} }
#endif
} }
#endif #endif
@ -465,7 +460,8 @@ void loop()
#endif #endif
#ifdef MINWAKE_MSECS #ifdef MINWAKE_MSECS
if (millis() > MINWAKE_MSECS) // Don't deepsleep if we have USB power
if (millis() > MINWAKE_MSECS && !isCharging)
{ {
sleep(); sleep();
} }

View File

@ -29,8 +29,8 @@ typedef enum _ChannelSettings_ModemConfig {
typedef enum _DeviceState_Version { typedef enum _DeviceState_Version {
DeviceState_Version_Unset = 0, DeviceState_Version_Unset = 0,
DeviceState_Version_Minimum = 5, DeviceState_Version_Minimum = 6,
DeviceState_Version_Current = 5 DeviceState_Version_Current = 6
} DeviceState_Version; } DeviceState_Version;
/* Struct definitions */ /* Struct definitions */