From 660172378f4ee083635fa4771c5409bc95533eab Mon Sep 17 00:00:00 2001 From: Vasil Zlatanov Date: Thu, 2 Mar 2017 15:00:12 +0000 Subject: move source into src to aid compilation --- Makefile | 4 +-- main.ino | 112 ------------------------------------------------------------ src/src.ino | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 114 deletions(-) delete mode 100644 main.ino create mode 100644 src/src.ino diff --git a/Makefile b/Makefile index b831f77..15b9a9c 100755 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: - arduino --board adafruit:avr:feather32u4 --pref build.path=./build --verify ./main.ino + arduino --board adafruit:avr:feather32u4 --pref build.path=./build --verify ./src/src.ino clean: rm -rf ./build upload: - arduino --board adafruit:avr:feather32u4 --port /dev/ttyACM0 --upload ./main.ino + arduino --board adafruit:avr:feather32u4 --port /dev/ttyACM0 --upload ./src/src.ino diff --git a/main.ino b/main.ino deleted file mode 100644 index 90f5d41..0000000 --- a/main.ino +++ /dev/null @@ -1,112 +0,0 @@ -#include "Adafruit_FONA.h" - -// Pin for actiaving LifeLarm -#define activateLarm 5 - -// Pins on PCB that connect to Sim -#define FONA_RX 9 -#define FONA_TX 8 -#define FONA_RST 4 -#define FONA_RI 7 - -// this is a large buffer for replies -char replybuffer[255]; - -// Phone number we send emergency text to -char callerIDbuffer[32]; - -#include -SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); -SoftwareSerial *fonaSerial = &fonaSS; - -Adafruit_FONA fona = Adafruit_FONA(FONA_RST); - -uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); - -void setup() { - while (!Serial); - - Serial.begin(115200); - Serial.println(F("LifeLarm turning on!")); - Serial.println(F("Initializing....(May take 3 seconds)")); - - // make it slow so its easy to read! - fonaSerial->begin(4800); - if (! fona.begin(*fonaSerial)) { - Serial.println(F("Couldn't find FONA")); - while(1); - } - - // Set button to active low - pinmode(activateLarm, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(activateLarm), sendHelp, CHANGE); - - Serial.println("LifeLarm Ready"); -} - - -char fonaInBuffer[64]; //for notifications from the FONA - -void loop() { - - char* bufPtr = fonaInBuffer; //handy buffer pointer - - - if (fona.available()) //any data available from the FONA? - { - int slot = 0; //this will be the slot number of the SMS - int charCount = 0; - - //Read the notification into fonaInBuffer - do { - *bufPtr = fona.read(); - Serial.write(*bufPtr); - delay(1); - } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-1))); - - //Add a terminal NULL to the notification string - *bufPtr = 0; - - // Scan the notification string for an SMS received notification. - // If it's an SMS message, we'll get the slot number in 'slot' - if (1 == sscanf(fonaInBuffer, "+CMTI: \"SM\",%d", &slot)) { - Serial.print("slot: "); Serial.println(slot); - - - // Retrieve SMS sender address/phone number. - if (! fona.getSMSSender(slot, callerIDbuffer, 31)) { - Serial.println("Didn't find SMS message in slot!"); - } - Serial.print(F("Retreived number: ")); Serial.println(callerIDbuffer); - Serial.print(F("Stored in slot: ")); Serial.println(slot); - - //Send back an automatic response - Serial.println("Sending confirmation..."); - if (!fona.sendSMS(callerIDbuffer, "Your phone number has been set as the emergency number!")) { - Serial.println(F("Failed to send!")); - } else { - Serial.println(F("Sent!")); - } - - // delete the original msg after it is processed - // otherwise, we will fill up all the slots - // and then we won't be able to receive SMS anymore - /* if (fona.deleteSMS(slot)) { - Serial.println(F("OK!")); - } else { - Serial.println(F("Couldn't delete")); - } - */ - } - } -} - -void sendHelp() [ - Serial.println("Sending text..."); - if (!fona.sendSMS(callerIDbuffer, "HELP! ... --- ... I will be sending my location to you!")) { - Serial.println(F("Failed to send!")); - failed++; - } else { - Serial.println(F("Sent!")); - } -} diff --git a/src/src.ino b/src/src.ino new file mode 100644 index 0000000..2950d6a --- /dev/null +++ b/src/src.ino @@ -0,0 +1,111 @@ +#include "Adafruit_FONA.h" + +// Pin for actiaving LifeLarm +#define activateLarm 5 + +// Pins on PCB that connect to Sim +#define FONA_RX 9 +#define FONA_TX 8 +#define FONA_RST 4 +#define FONA_RI 7 + +// this is a large buffer for replies +char replybuffer[255]; + +// Phone number we send emergency text to +char callerIDbuffer[32]; + +#include +SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX); +SoftwareSerial *fonaSerial = &fonaSS; + +Adafruit_FONA fona = Adafruit_FONA(FONA_RST); + +uint8_t readline(char *buff, uint8_t maxbuff, uint16_t timeout = 0); + +void setup() { + while (!Serial); + + Serial.begin(115200); + Serial.println(F("LifeLarm turning on!")); + Serial.println(F("Initializing....(May take 3 seconds)")); + + // make it slow so its easy to read! + fonaSerial->begin(4800); + if (! fona.begin(*fonaSerial)) { + Serial.println(F("Couldn't find FONA")); + while(1); + } + + // Set button to active low + pinMode(activateLarm, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(activateLarm), sendHelp, CHANGE); + + Serial.println("LifeLarm Ready"); +} + + +char fonaInBuffer[64]; //for notifications from the FONA + +void loop() { + + char* bufPtr = fonaInBuffer; //handy buffer pointer + + + if (fona.available()) //any data available from the FONA? + { + int slot = 0; //this will be the slot number of the SMS + int charCount = 0; + + //Read the notification into fonaInBuffer + do { + *bufPtr = fona.read(); + Serial.write(*bufPtr); + delay(1); + } while ((*bufPtr++ != '\n') && (fona.available()) && (++charCount < (sizeof(fonaInBuffer)-1))); + + //Add a terminal NULL to the notification string + *bufPtr = 0; + + // Scan the notification string for an SMS received notification. + // If it's an SMS message, we'll get the slot number in 'slot' + if (1 == sscanf(fonaInBuffer, "+CMTI: \"SM\",%d", &slot)) { + Serial.print("slot: "); Serial.println(slot); + + + // Retrieve SMS sender address/phone number. + if (! fona.getSMSSender(slot, callerIDbuffer, 31)) { + Serial.println("Didn't find SMS message in slot!"); + } + Serial.print(F("Retreived number: ")); Serial.println(callerIDbuffer); + Serial.print(F("Stored in slot: ")); Serial.println(slot); + + //Send back an automatic response + Serial.println("Sending confirmation..."); + if (!fona.sendSMS(callerIDbuffer, "Your phone number has been set as the emergency number!")) { + Serial.println(F("Failed to send!")); + } else { + Serial.println(F("Sent!")); + } + + // delete the original msg after it is processed + // otherwise, we will fill up all the slots + // and then we won't be able to receive SMS anymore + /* if (fona.deleteSMS(slot)) { + Serial.println(F("OK!")); + } else { + Serial.println(F("Couldn't delete")); + } + */ + } + } +} + +void sendHelp() { + Serial.println("Sending text..."); + if (!fona.sendSMS(callerIDbuffer, "HELP! ... --- ... I will be sending my location to you!")) { + Serial.println(F("Failed to send!")); + } else { + Serial.println(F("Sent!")); + } +} -- cgit v1.2.3