commit 1ef6549c684799a51dcdf20819837942aa7368a0 Author: Brendan Haines Date: Tue Nov 1 10:52:31 2016 -0600 adds arduino code diff --git a/hohm_phone.ino b/hohm_phone.ino new file mode 100644 index 0000000..5babd9c --- /dev/null +++ b/hohm_phone.ino @@ -0,0 +1,107 @@ +#include +#include "Adafruit_FONA.h" + +////////////////////// +///// PARAMETERS ///// +////////////////////// + +// Arduino will wake from sleep when WAKE_PIN is pulled low +#define WAKE_PIN 2 +#define BUT_ANS 7 +#define BUT_END 8 + +// RX/TX are in reference to the Arduino +#define GSM_RX 3 +#define GSM_TX 4 +#define GSM_RST 5 +#define GSM_RING 6 + +// TIMEOUT_SLEEP is the time to stay awake from last activity until sleep (milliseconds) +#define TIMEOUT_SLEEP + +// Comment the following line to use HW serial +#define usb_testing_config + +////////////////////////// +///// END PARAMETERS ///// +////////////////////////// + +char replybuffer[255]; +uint8_t phonenumber[15]; +uint8_t phonenumberlength = 0; + +#ifdef usb_testing_config +#include "SoftwareSerial.h" +SoftwareSerial fonaSS = SoftwareSerial(GSM_RX, GSM_TX); +SoftwareSerial *fonaSerial = &fonaSS; +#else +HardwareSerial *fonaSerial = &Serial; +#endif + +Adafruit_FONA fona = Adafruit_FONA(GSM_RST); + +uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); + + +void wake_from_sleep() { + sleep_disable(); + detachInterrupt(WAKE_PIN); +} + +void go_to_sleep() { + sleep_enable(); + attachInterrupt(WAKE_PIN, wake_from_sleep, LOW); + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + cli(); + sleep_bod_disable(); + sei(); + sleep_cpu(); +} + +void in_call() { + while (1) { + if ( !digitalRead(BUT_END) ) { // End button pressed + if ( fona.hangUp() ) { + break; + } + } + // numpad stuff + } +} + +void begin_call() { + fona.sendCheckReply( F("AT+STTONE=0"), F("OK") ); // End tone + for(int i = 0; ibegin(4800); + if (! fona.begin(*fonaSerial)) while (1); //fona didn't start +} + +void loop() { + if ( !digitalRead(GSM_RING) ) { + while ( digitalRead(BUT_ANS) & !digitalRead(GSM_RING) ) delay(10); // Wait for answer button or end ring/call + if ( !digitalRead(BUT_ANS) ) { + if ( fona.pickUp() ) { + in_call(); + } + } + } + + fona.sendCheckReply( F("AT+STTONE=1,20,1000"), F("OK") ); // Start tone +} + + + + +