reformats code

This commit is contained in:
Brendan Haines 2016-12-02 20:00:37 -07:00
parent aa1ed81a6f
commit 7f35b88b81

View File

@ -18,6 +18,9 @@
// Low battery light threshold // Low battery light threshold
#define CHG_VLO 3800 #define CHG_VLO 3800
// Time in miliseconds to stop listening for keypad input
#define SLEEP_TIMEOUT 120000
// Keypad pinout // Keypad pinout
byte rowPins[4] = {5, 10, 9, 7}; byte rowPins[4] = {5, 10, 9, 7};
byte colPins[3] = {6, 4, 8}; byte colPins[3] = {6, 4, 8};
@ -39,6 +42,7 @@ char keys[4][3] = {
unsigned long lastActiveTime; unsigned long lastActiveTime;
bool dialtoneActive = false; bool dialtoneActive = false;
bool startDialtone = false; bool startDialtone = false;
bool awake = true;
HardwareSerial *fonaSerial = &Serial; HardwareSerial *fonaSerial = &Serial;
Adafruit_FONA fona = Adafruit_FONA(GSM_RST); Adafruit_FONA fona = Adafruit_FONA(GSM_RST);
@ -78,6 +82,13 @@ void resumeDialtone() {
dialtoneActive = true; dialtoneActive = true;
} }
void clearPhoneNumber() {
for ( int j = 0; j < phoneNumberLength; j++) {
phoneNumber[j] = 0;
}
phoneNumberLength = 0;
}
////////////////////////////////// //////////////////////////////////
///// ARDUINO CORE FUNCTIONS ///// ///// ARDUINO CORE FUNCTIONS /////
////////////////////////////////// //////////////////////////////////
@ -111,6 +122,9 @@ void setup() {
} }
void loop() { void loop() {
if ( awake ) {
// 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
if ( !digitalRead(BUT_ANS) ) { if ( !digitalRead(BUT_ANS) ) {
@ -120,12 +134,13 @@ void loop() {
} }
} }
// Begin dialtone if necessary
if ( startDialtone ) { if ( startDialtone ) {
resumeDialtone(); resumeDialtone();
startDialtone = false; startDialtone = false;
} }
// Read from keypad // Read keypad input
char key = keypad.getKey(); char key = keypad.getKey();
if ( key != NO_KEY ) { if ( key != NO_KEY ) {
phoneNumber[ phoneNumberLength ] = key; phoneNumber[ phoneNumberLength ] = key;
@ -145,13 +160,9 @@ void loop() {
} }
} }
// Clear stored phone number on press of end button // Clear stored phone number on press of end button
if ( !digitalRead(BUT_END) ) { if ( !digitalRead(BUT_END) ) {
for ( int j = 0; j < phoneNumberLength; j++) { clearPhoneNumber();
phoneNumber[j] = 0;
}
phoneNumberLength = 0;
resumeDialtone(); resumeDialtone();
} }
@ -163,9 +174,14 @@ void loop() {
} else { } else {
digitalWrite( LED_BAT_LOW, LOW ); digitalWrite( LED_BAT_LOW, LOW );
} }
} else {
// sleeping
delay(100);
}
} }