summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2015-12-20 20:09:21 +0100
committerFlorian Baumann <derflob@derflob.de>2015-12-20 20:09:21 +0100
commit20c2c49095c65377eed31fcca9b7153c78b8b8cd (patch)
tree95f28832304910654932dd9a6d903a8ea676ee96
parenta001684c9b21b1e2ea208a655a23dcdd0d09dca6 (diff)
downloadmFeTAp-20c2c49095c65377eed31fcca9b7153c78b8b8cd.tar.gz
mFeTAp-20c2c49095c65377eed31fcca9b7153c78b8b8cd.tar.bz2
ringing on sms; 90% workingsms
-rw-r--r--mFeTAp.ino67
1 files changed, 63 insertions, 4 deletions
diff --git a/mFeTAp.ino b/mFeTAp.ino
index 2542bf2..1f00167 100644
--- a/mFeTAp.ino
+++ b/mFeTAp.ino
@@ -3,6 +3,8 @@
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
+#include "morse_code.h"
+
#define FONA_RX A4
#define FONA_TX A5
#define FONA_RST A3
@@ -49,6 +51,8 @@ volatile int number_dialed = 0;
char number[NUMBER_LEN] = { '\0' };
int number_len = 0;
+unsigned long sms_available = 0;
+
enum adv_states {
IDLE,
WAIT_FOR_NUMBER,
@@ -92,12 +96,17 @@ void setup() {
enableGSMBusy(false);
+ //sms_available = millis();
+
+
}
void loop() {
static long inc_time = 0;
+ sms_available = 0;
+
while (fonaSerial->available()) {
Serial.write(fonaSerial->read());
}
@@ -134,6 +143,7 @@ void process_input_RI() {
} else {
if (pin_down > 0 && millis() - pin_down < SMS_SIGNAL) {
Serial.println("SMS incoming");
+ sms_available = millis();
// handle SMS
pin_down = 0;
}
@@ -276,11 +286,60 @@ void process_output_bell() {
digitalWrite(PIN_B_BELL, !!p);
}
} else {
- inc_time = 0;
- digitalWrite(PIN_LED, LOW);
+ if (sms_available > 0) {
+ static char *sms = "sos";
+ uint16_t sms_units = units_in_str(sms, 3);
+
+ uint16_t cunit = ((millis() - sms_available) / 150) % sms_units;
+
+ //Serial.print("units: ");
+ //Serial.print(sms_units);
+ //Serial.print("; ");
+ Serial.print("cunit: ");
+ Serial.print(cunit);
+ Serial.print("; ");
+
+ for (char *c = sms; *c != '\0'; c++) {
+ if (cunit >= units_in_char(c) + 3) {
+ cunit -= (units_in_char(c) + 3);
+ continue;
+ } else {
+ Serial.print(*c);
+ Serial.print("; ");
+ Serial.print(cunit);
+ if (cunit < units_in_char(c)) {
+ uint16_t on = morse_unit(c, cunit);
+ Serial.print("; on: ");
+ Serial.print(on);
+ if (on != 0) {
+ digitalWrite(PIN_LED, HIGH);
+
+ unsigned int p = (millis() / RINGING_PERIOD) % 2;
+ digitalWrite(PIN_A_BELL, !p);
+ digitalWrite(PIN_B_BELL, !!p);
+ } else {
+ digitalWrite(PIN_LED, LOW);
+
+ digitalWrite(PIN_A_BELL, LOW);
+ digitalWrite(PIN_B_BELL, LOW);
+ }
+ } else {
+ digitalWrite(PIN_LED, LOW);
+
+ digitalWrite(PIN_A_BELL, LOW);
+ digitalWrite(PIN_B_BELL, LOW);
+ }
+ break;
+ }
+ }
+ Serial.println();
+ } else {
+ digitalWrite(PIN_LED, LOW);
- digitalWrite(PIN_A_BELL, LOW);
- digitalWrite(PIN_B_BELL, LOW);
+ digitalWrite(PIN_A_BELL, LOW);
+ digitalWrite(PIN_B_BELL, LOW);
+ }
+ inc_time = 0;
}
}