Fengrui Zuo, Benjamin Leverett, Rahil Ajani, Kombundit Chitranuwatkul

Dependencies:   mbed mbed-rtos 4DGL-uLCD-SE SDFileSystem ATParser

Revision:
6:8a29a9680023
Parent:
5:1fe352831712
--- a/main.cpp	Wed Apr 29 03:09:00 2020 +0000
+++ b/main.cpp	Wed Apr 29 04:41:57 2020 +0000
@@ -20,7 +20,7 @@
 uLCD_4DGL uLCD(p28,p27,p30);
 SDFileSystem sd(p5, p6, p7, p8, "sd");
 PwmOut speaker(p21);
-DigitalOut speaker_on(p23);
+//DigitalOut speaker_on(p23);
 
 //AT command data handlers
 bool datalogged = 0;
@@ -99,36 +99,33 @@
 {
     while(1) {
         if(risk_level == 2 && datalogged) {
-            for (int i=0; i<5; i=i+2) {
+            for (int i=0; i<10; i=i+2) {
                 speaker.period(1.0/969.0);
                 speaker = float(i)/50.0;
                 wait(.8);
                 speaker.period(1.0/800.0);
                 wait(.8);
+                speaker = 0;
             }
-            speaker = 0;
         } else if(risk_level == 3 && datalogged) {
-            for (int i=0; i<5; i=i+2) {
+            for (int i=0; i<26; i=i+2) {
                 speaker.period(1.0/969.0);
                 speaker = float(i)/50.0;
                 wait(.25);
                 speaker.period(1.0/800.0);
                 wait(.25);
-            }
-            speaker = 0;
-        } else if(risk_level <= 1 && datalogged){
-            for (int i=0; i<5; i=i+2) {
-                speaker.period(0);
                 speaker = 0;
             }
-        } else{
+        } else if(risk_level <= 1 && datalogged) {
+            speaker = 0;
+        } else {
             speaker = 0;
         }
     }
 }
 
 
-void logging_SD_card()
+void log_sd_card()
 {
     while(1) {
         mutex_lock.lock();
@@ -136,17 +133,29 @@
         if(fp == NULL) {
             error("Could not open file for write\n");
         }
+        int curr_time = (int)ctime(&seconds) % 86400;
+        int curr_hour = curr_time / 3600;
+        int curr_min = curr_time / 60;
+        int curr_sec = curr_time % 60;
 
-        if(risk_level <= 1) {
-            fprintf(fp, "Risk level 1");
-            fprintf(fp, "Time", ctime(&seconds));
-        } else if(risk_level == 2) {
-            fprintf(fp, "Risk level 2");
-            fprintf(fp, "Time", ctime(&seconds));
-        } else if(risk_level == 3) {
-            fprintf(fp, "Risk level 3");
-            fprintf(fp, "Time", ctime(&seconds));
+
+        fprintf(fp, "Date & time: Tuesday 28, April 2020 ");
+        fprintf(fp, "%i", curr_hour);
+        fprintf(fp, ":");
+        fprintf(fp, "%i", curr_min);
+        fprintf(fp, ":");
+        fprintf(fp, "%i", curr_sec);
+        fprintf(fp, "\n");
+        fprintf(fp, "Risk Level: ");
+        fprintf(fp, "%i", risk_level);
+        fprintf(fp, "\n");
+        for (int i = 0; i < 15; i++) {
+            fprintf(fp, "%i", RSSI_array[i]);
+            if (i < 14) {
+                fprintf(fp, ", ");
+            }
         }
+        fprintf(fp, "\n\n");
         fclose(fp);
         mutex_lock.unlock();
     }
@@ -221,7 +230,6 @@
 
 int main()
 {
-    speaker_on = 0;
     cmdstuff = 1;
     at.send("AT") && at.recv("OK");
     at.send("AT+AB ChangeDefaultBaud [9600]", 3) && at.recv("OK");