![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
wave cancel
Dependencies: 4DGL-uLCD-SE EthernetInterface HTTPClient NTPClient PinDetect SDFileSystem mbed-rtos mbed wave_player
Fork of 4180_Final_Project by
Diff: main.cpp
- Revision:
- 11:89e778e985d5
- Parent:
- 10:6b27fafad047
- Child:
- 12:27470e8c0556
--- a/main.cpp Mon Apr 25 15:48:53 2016 +0000 +++ b/main.cpp Thu Apr 28 16:52:38 2016 +0000 @@ -15,10 +15,13 @@ // Graphic LCD - TX, RX, and RES pins uLCD_4DGL uLCD(p28,p27,p29); SDFileSystem sd(p11, p12, p13, p14, "sd"); //SD card +Serial pc(USBTX, USBRX); +Serial time_weth(p9, p10); AnalogOut DACout(p18); wave_player waver(&DACout); PinDetect snooze(p19); //snooze button PinDetect off(p20); //turn alarm off +PinDetect settings(p17); //turn alarm off DigitalOut myled1(LED1); DigitalOut myled2(LED2); DigitalOut myled3(LED3); @@ -28,12 +31,13 @@ char* time_domain_name = "0.uk.pool.ntp.org"; //char* weth_domain_name = "http://weather.yahooapis.com/forecastrss?w=2502265"; //char* weth_domain_name = "http://developer.mbed.org/media/uploads/mbed_official/hello.txt"; -char* weth_domain_name = "https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20in%20%28select%20woeid%20from%20geo.places%281%29%20where%20text%3D%22atlanta%2C%20ga%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"; +//char* weth_domain_name = "https://query.yahooapis.com/v1/public/yql?q=select%20item.condition%20from%20weather.forecast%20where%20woeid%20in%20%28select%20woeid%20from%20geo.places%281%29%20where%20text%3D%22atlanta%2C%20ga%22%29&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys"; int port_number = 123; // Networking EthernetInterface eth; #define snoozeTime 10 +#define locationLength 50 //global variables time_t ct_time; @@ -44,6 +48,10 @@ int curAlarmHour = 18; //0-23 int curAlarmMin = 9; bool play = true; +//traffic +char location[locationLength]; +char destination[locationLength]; + //time thread void time_thread(void const *args) @@ -61,61 +69,20 @@ Thread::wait(100); } } - -void parseWeather(char* buf) -{ - char * pch; - char * key; - pch = strtok (buf,"{"); - while (pch != NULL) { - pch = strtok (NULL,"{"); - } - pch = strtok (buf,","); - while (pch != NULL) { - key = strtok (pch,":"); - if(strcmp(key, "\"text\"")) { - uLCD.printf("Condition = %s",pch); - } else if(strcmp(key, "\"temp\"")) { - uLCD.printf("temp = %s",pch); - } - } -} - -void getWeather() +/* +//communication thread +void comm_thread(void const *args) { - //lcd_mutex.lock(); - /*** WEATHER****/ - char buf[250]; - uLCD.printf("Getting weather..\n"); - HTTPClient http; - int retHttp = http.get(weth_domain_name, buf, sizeof(buf)); - uLCD.printf("%d", retHttp); - switch(retHttp) { - case HTTP_OK: - uLCD.printf("Read completely\n"); - uLCD.printf("%c",buf); - wait(2); - uLCD.printf("%s",buf); - wait(2); - parseWeather(buf); - break; - case HTTP_TIMEOUT: - uLCD.printf("Connection Timeout\n"); - break; - case HTTP_CONN: - uLCD.printf("Connection Error\n"); - break; - default: - uLCD.printf("Error\n"); - } - //lcd_mutex.unlock(); + time_weth.putc("w"); + time_weth.putc("e"); + time_weth.putc("t"); + time_weth.putc("h"); + for(i = 0; i < locationLength; i++){ + time_weth.putc(location[i]); + time_weth.putc(destination[i]); + } } - -void weth_thread(void const *args) -{ - - Thread::wait(3600000); -} +*/ //pushbutton (p19) void snooze_hit_callback (void) @@ -139,6 +106,30 @@ curAlarmHour = baseAlarmHour; } +void settings_hit_callback (void) +{ + while(1) { + char buff[100]; + int i = 0; + bool flag = false; + while(!flag) { + buff[i] = pc.getc(); + pc.putc(buff[i]); + flag = buff[i] == '^'; + i++; + } + uLCD.printf("%s", buff); + + mkdir("/sd/mydir", 0777); + FILE *fp = fopen("/sd/mydir/sdtest.txt", "w"); + if(fp == NULL) { + error("Could not open file for write\n"); + } + fprintf(fp, buff); + fclose(fp); + } +} + void play_file() { bool* play_point = &play; @@ -164,11 +155,14 @@ { snooze.mode(PullUp); off.mode(PullUp); + settings.mode(PullUp); wait(0.01); snooze.attach_deasserted(&snooze_hit_callback); off.attach_deasserted(&off_hit_callback); + settings.attach_deasserted(&off_hit_callback); snooze.setSampleFrequency(); off.setSampleFrequency(); + settings.setSampleFrequency(); //play_file(); @@ -187,9 +181,6 @@ return -1; } uLCD.printf("IP address is \n%s\n\n",eth.getIPAddress()); - Thread::wait(1000); - getWeather(); - wait(500); // Read time from server { uLCD.printf("Reading time...\n\r"); @@ -207,8 +198,8 @@ uLCD.cls(); uLCD.text_height(2); - //Thread t1(time_thread); - //Thread t2(weth_thread); + Thread t1(time_thread); + //Thread t2(comm_thread); while(true) { timeCompare(); Thread::wait(100);