rev1

Dependencies:   4DGL-uLCD-SE EthernetInterface NTPClient SDFileSystem mbed-rtos mbed wave_player PinDetect

Fork of WavePlayer_HelloWorld by jim hamblen

Files at this revision

API Documentation at this revision

Comitter:
ashea6
Date:
Fri Apr 22 17:38:25 2016 +0000
Parent:
4:55035e20ae61
Commit message:
snooze, time compare

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 55035e20ae61 -r 3c880df67e2e main.cpp
--- a/main.cpp	Fri Apr 22 17:20:59 2016 +0000
+++ b/main.cpp	Fri Apr 22 17:38:25 2016 +0000
@@ -10,7 +10,7 @@
 #include "rtos.h"
 #include "PinDetect.h"
 
-//pinouts 
+//pinouts
 SDFileSystem sd(p11, p12, p13, p14, "sd"); //SD card
 AnalogOut DACout(p18);
 wave_player waver(&DACout);
@@ -18,6 +18,7 @@
 PinDetect off(p20);     //turn alarm off
 DigitalOut myled1(LED1);
 DigitalOut myled2(LED2);
+DigitalOut myled3(LED3);
 
 // Parameters
 char* domain_name = "0.uk.pool.ntp.org";
@@ -30,15 +31,22 @@
 // Graphic LCD - TX, RX, and RES pins
 uLCD_4DGL uLCD(p28,p27,p29);
 
+#define snoozeTime 10
+
 //global variables
 time_t ct_time;
+// Base alarm time-24 hour clock
+int baseAlarmHour = 0; //0-23
+int baseAlarmMin = 0;
+// Current alarm time
+int curAlarmHour = 18; //0-23
+int curAlarmMin = 9;
 
 //time thread
 void time_thread(void const *args)
 {
-   
     char time_buffer[80];
-     // Loop and update clock
+    // Loop and update clock
     while (1) {
         uLCD.locate(0, 1);
         ct_time = time(NULL);
@@ -52,7 +60,14 @@
 //pushbutton (p19)
 void snooze_hit_callback (void)
 {
-     myled1 = !myled1;
+    myled1 = !myled1;
+    time_t newtime;
+    struct tm * timeinfo;
+    newtime = ct_time + snoozeTime;
+//time (&newtime);
+    timeinfo = localtime (&newtime);
+    curAlarmMin = timeinfo->tm_min;
+    curAlarmHour = timeinfo->tm_hour;
 }
 
 void off_hit_callback (void)
@@ -68,6 +83,18 @@
     waver.play(wave_file);
     fclose(wave_file);
 }
+
+void timeCompare()
+{
+    struct tm * timeinfo;
+    timeinfo = localtime (&ct_time);
+    if (timeinfo->tm_min == curAlarmMin && timeinfo->tm_hour == curAlarmHour) {
+        //playing = true;
+        play_file();
+        myled3 = true;
+    }
+}
+
 int main()
 {
     snooze.mode(PullUp);
@@ -111,7 +138,9 @@
     uLCD.text_height(2);
 
     Thread thread_time(time_thread);
-
-    play_file();
+    while(!myled3) {
+        timeCompare();
+        Thread::wait(100);
+    }
 
 }
\ No newline at end of file