adds charging handling logic

This commit is contained in:
Brendan Haines 2016-11-03 10:43:45 -06:00
parent d01b9fd99c
commit 6c35e0f594

View File

@ -22,6 +22,11 @@
// TIMEOUT_SLEEP is the time to stay awake from last activity until sleep (milliseconds)
#define TIMEOUT_SLEEP 6000
// Charging voltage thresholds. Will turn on charging at CHG_VLO and turn off charging at CHG_VHI (millivolts)
#define CHG_VLO 3900
#define CHG_VHI 4100
#define CHG_PIN A0
// Comment the following line to use HW serial for Fona and disable debugging information
#define USB_DEBUG
@ -144,9 +149,11 @@ void setup() {
pinMode( GSM_RST, OUTPUT );
pinMode( GSM_RING, INPUT_PULLUP );
pinMode( GSM_KEY, OUTPUT );
pinMode( CHG_PIN, OUTPUT );
digitalWrite( GSM_KEY, LOW );
digitalWrite( GSM_RST, HIGH );
digitalWrite( CHG_PIN, HIGH );
fonaSerial->begin(4800);
if (! fona.begin(*fonaSerial)) {
@ -222,6 +229,14 @@ void loop() {
resumeDialtone();
}
uint16_t vbat;
fona.getBattVoltage(&vbat);
if ( vbat < CHG_VLO ) {
digitalWrite( CHG_PIN, HIGH );
} else if ( vbat > CHG_VHI ) {
digitalWrite( CHG_PIN, LOW );
}
#ifdef SLEEP
// Autoshutdown if inactive for extended period
// Typecast to long avoids "rollover" issues