Code written by Paul Rabbat, Angel Daruna, Jarel Hawkins, and Cordel Williams

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

Fork of ECE4180_FinalProject by Angel Daruna

Files at this revision

API Documentation at this revision

Comitter:
adaruna3
Date:
Wed Dec 03 17:59:07 2014 +0000
Parent:
8:548f413118e9
Child:
10:89cd9b6a251e
Commit message:
All features working

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Dec 02 17:12:59 2014 +0000
+++ b/main.cpp	Wed Dec 03 17:59:07 2014 +0000
@@ -30,7 +30,6 @@
 DigitalOut led3(LED3); // Indicates the alarm has been set 
 DigitalOut led4(LED4);  // Indiciates the alarm is going off
 
-//Jarel's globals
 int alarmSignaled = 0;
 PwmOut alarm(p25);
 AnalogOut DACout(p18);
@@ -72,11 +71,10 @@
 HTTPServer create_simple_server();
 HTTPServer create_interactive_server();
 
-//New Jarel's
-void play_wake_up(void);
 void stop_hit_callback(void);
 void snooze_hit_callback(void);
 void read_file_names(char *dir);
+void play_wake_up(void);
 
 void thread_server(void const *args);
 void thread_display(void const *args);
@@ -88,9 +86,6 @@
 
 /** Weather **/
 #include "HTTPClient.h"
-//#include "spdomparser.hpp"
-//#include "spxmlnode.hpp"
-//#include "spxmlhandle.hpp"
 char* getWeather();
 void getTime();
 void parseResults(char*);
@@ -105,8 +100,10 @@
     snooze.attach_deasserted(&snooze_hit_callback);
     stop.attach_deasserted(&stop_hit_callback);
     stop.setSampleFrequency(); 
-
-    if(insert = sd.SD_inserted()){
+    snooze.setSampleFrequency(); //default is 20KHz sampling
+    
+    insert = sd.SD_inserted();
+    if(insert){
         printf("Inserted worked.");
     }
     printf("Attempting to read file names");
@@ -201,11 +198,9 @@
 void parseResults(char* buf){
     printf("Starting parser\n");  
     int i=0;
-    //printf("\n----------%s----------\n",buf);
     char* chars_array = strtok(buf, "\"");
     while(chars_array)
     {
-        //printf("%d: %s\n", i, chars_array);
         if(i==63){
             lowTemperature = chars_array;
             printf("Low temp: %s F\n", lowTemperature);
@@ -246,9 +241,14 @@
             led3 = 1;
             if(_alarm.hours == hour && _alarm.minutes == minute && _alarm.amPm == ampm){
                 alarmSignaled = 1;
-                turn_on();
+                //increase brightness
+                for(dim = 0.0; dim <= 1.0; dim += 0.025) {
+                    led1 = (dim < 0 ? 0 : dim);
+                    wait(0.3);
+                }
+                dim = 1.0;
+                led4 = 1;
                 play_wake_up();
-                led4 = 1;
             }
         }
         Thread::wait(100);
@@ -276,7 +276,6 @@
         
         int i=0;
         char* chars_array = strtok(buffer, " :");
-        //printf("Chars array: \n");
         while(chars_array)
         {
             switch(i){
@@ -290,7 +289,6 @@
                     dayNum = chars_array;
                     break;    
                 case 3:
-                    //chars_array = chars_array - 1;
                     int hourTemp = atoi(chars_array); 
                     hourTemp--; //Daylight savings
                     if(hourTemp > 12) hourTemp -= 12;
@@ -304,6 +302,7 @@
                     break; 
                 case 6:
                     ampm = chars_array;
+                    ampm = "PM";
                     break;
             }
             i++;
@@ -375,30 +374,27 @@
 
 void turn_on(){
     //increase brightness
-    for(dim = 0.0; dim <= 1.0; dim += 0.025) {
+    for(dim = 0.0; dim <= 1.0; dim += 0.005) {
         led1 = (dim < 0 ? 0 : dim);
-        wait(0.10);
+        wait(0.3);
     }
     dim = 1.0;
 }
 
 void stop_hit_callback(void){
-    //alarm = 0.0;
-    //state = off;
    vol = 0.0;
-   //wait(1000);
    t = false;
    if (insert == true){
-       play =! play;
-       }
+       play = !play;
+    }
 }
 
 void snooze_hit_callback(void) {
     alarm = 0.0;
-    wait(20);
+    wait(5);
     if (insert == true) {
         play =! play;
-        wait(20);
+        wait(5);
         play =! play;
     }
 }
@@ -417,47 +413,38 @@
 }
 
 void play_wake_up(void){
-    while(t == true) {
-        printf("play_wake_up started");
-        if ((insert == true) && (play ==true)) {
-                printf("File names read.");
-                //string str2 = filenames[index].substr(0,filenames[index].length()-4);
-                waver.play(wave_file, &play);
-                printf("Wav file playing");
-               if (feof(wave_file)) // when playback ends file will close and play will equal false
-                {
-                fclose(wave_file);
-                printf("Wav ended.");
-                //play=!play;
+            while(t == true) {
+                printf("Started playing.");
+                if ((insert == true) && (play ==true)) {
+                        waver.play(wave_file, &play);
+                       if (feof(wave_file)) // when playback ends file will close and play will equal false
+                        {
+                        fclose(wave_file);
+                        printf("Wav ended.");
+                        } 
+                         
+                    }
+                if ((insert == false)&&(play == true)) {
+                    // generate a 500Hz tone using PWM hardware output
+                    for (int j=0; j<26; j=j+2) {
+                        alarm.period(1.0/500.0); // 500hz period
+                        alarm =vol; //50% duty cycle - max volume
+                        wait(.5);
+                        alarm.period(0.0/500.0);
+                        wait(.5);
+                        } // end of for
+                
+                    // two tone police siren effect -  two periods or two frequencies
+                    // increase volume - by changing the PWM duty cycle
+                    for (int i=0; i<26; i=i+2) {
+                        alarm = vol;
+                        alarm.period(1.0/969.0);
+                        wait(.5);
+                        alarm.period(1.0/800.0);
+                        wait(.5);
+                    } 
                 } 
-                 
+        
             }
-        if ((insert == false)&&(play == true)) {
-            // generate a 500Hz tone using PWM hardware output
-            printf("Playing tune sound.");
-            for (int j=0; j<26; j=j+2) {
-                alarm.period(1.0/500.0); // 500hz period
-                alarm =vol; //50% duty cycle - max volume
-                wait(.5);
-                //alarm=0.0; // turn off audio
-                alarm.period(0.0/500.0);
-                wait(.5);
-                } // end of for
-        
-            // two tone police siren effect -  two periods or two frequencies
-            // increase volume - by changing the PWM duty cycle
-            for (int i=0; i<26; i=i+2) {
-                alarm = vol;
-                alarm.period(1.0/969.0);
-                wait(.5);
-                alarm.period(1.0/800.0);
-                wait(.5);
-              } //end of for
-        
-            //alarm = 0.0;
-        } //end of if
-
-    }// end of while
-    alarm = 0.0;
-    printf("Alarm sound turned off.");
+            alarm = 0.0;
 }
\ No newline at end of file