adds sleeping

This commit is contained in:
Brendan Haines 2016-12-02 20:50:18 -07:00
parent eb5aee66bc
commit fed15da794

View File

@ -19,7 +19,7 @@
#define CHG_VLO 3800 #define CHG_VLO 3800
// Time in miliseconds to stop listening for keypad input // Time in miliseconds to stop listening for keypad input
#define SLEEP_TIMEOUT 120000 #define SLEEP_TIMEOUT 30000
// RSSI value below which No Service LED will light // RSSI value below which No Service LED will light
#define RSSI_THRESHOLD 3 #define RSSI_THRESHOLD 3
@ -51,7 +51,6 @@ HardwareSerial *fonaSerial = &Serial;
Adafruit_FONA fona = Adafruit_FONA(GSM_RST); Adafruit_FONA fona = Adafruit_FONA(GSM_RST);
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, 4, 3 ); Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, 4, 3 );
/////////////////////////////// ///////////////////////////////
////////// FUNCTIONS ////////// ////////// FUNCTIONS //////////
/////////////////////////////// ///////////////////////////////
@ -92,6 +91,12 @@ void clearPhoneNumber() {
phoneNumberLength = 0; phoneNumberLength = 0;
} }
void goToSleep() {
digitalWrite( LED_NO_SERVICE, LOW );
digitalWrite( LED_BAT_LOW, LOW );
awake = false;
}
////////////////////////////////// //////////////////////////////////
///// ARDUINO CORE FUNCTIONS ///// ///// ARDUINO CORE FUNCTIONS /////
////////////////////////////////// //////////////////////////////////
@ -113,12 +118,11 @@ void setup() {
while (1); //fona didn't start while (1); //fona didn't start
digitalWrite( LED_BAT_LOW, HIGH ); digitalWrite( LED_BAT_LOW, HIGH );
} }
//while ( !fona.setAudio(FONA_EXTAUDIO) ) {}
startDialtone = true; startDialtone = true;
lastActiveTime = millis(); lastActiveTime = millis();
fona.sendCheckReply( F("AT+CLVL=100"), F("OK") ); // set dialtone volume fona.sendCheckReply( F("AT+CLVL=100"), F("OK") ); // set volume
digitalWrite( LED_BAT_LOW, LOW ); digitalWrite( LED_BAT_LOW, LOW );
digitalWrite( LED_NO_SERVICE, LOW ); digitalWrite( LED_NO_SERVICE, LOW );
@ -126,7 +130,7 @@ void setup() {
void loop() { void loop() {
if ( awake ) { if ( awake ) {
// Handle Incoming Call // Handle Incoming Call
if ( !digitalRead(GSM_RING) ) { if ( !digitalRead(GSM_RING) ) {
while ( digitalRead(BUT_ANS) & !digitalRead(GSM_RING) ) delay(10); // Wait for answer button or end ring/call while ( digitalRead(BUT_ANS) & !digitalRead(GSM_RING) ) delay(10); // Wait for answer button or end ring/call
@ -180,20 +184,22 @@ void loop() {
uint8_t rssi; uint8_t rssi;
rssi = fona.getRSSI(); rssi = fona.getRSSI();
if( rssi < RSSI_THRESHOLD | rssi == 99 ) { if ( rssi < RSSI_THRESHOLD || rssi == 99 ) {
digitalWrite( LED_NO_SERVICE, HIGH ); digitalWrite( LED_NO_SERVICE, HIGH );
} else { } else {
digitalWrite( LED_NO_SERVICE, LOW ); digitalWrite( LED_NO_SERVICE, LOW );
} }
// If inactive, sleep
if ( (long)(millis() - lastActiveTime) > SLEEP_TIMEOUT ) {
goToSleep();
}
} else { } else {
// sleeping // sleeping
delay(100); delay(100);
if ( !digitalRead( BUT_ANS ) || !digitalRead( BUT_END ) || !digitalRead( GSM_RING ) ) {
lastActiveTime = millis();
awake = true;
}
} }
} }