Smart Clock
Dependencies: AlarmClock DigitalClock EthernetInterface FourDigitLED HTTPClient NTPClient SDFileSystem TrainStat WeatherInfo XML_aide mbed-rtos mbed picojson wolfSSL
Diff: main.cpp
- Revision:
- 1:1a28aaca601d
- Parent:
- 0:0689619f2486
- Child:
- 2:bcc1a40ffa04
--- a/main.cpp Thu Jun 25 23:31:17 2015 +0000 +++ b/main.cpp Fri Jun 26 08:02:30 2015 +0000 @@ -4,18 +4,42 @@ #include "NTPClient.h" #include "AlarmClock.h" -static AlarmClock alarmclock ( +extern void net_main(void const *av) ; + +AlarmClock alarmclock ( /* Segment 0 - 6, Dot */ D11,D6, D3, D1, D0, D10,D4, D2 , /* Digit 1 - 4 */ D5, D7, D9, D12, /* Alarm, Hour, Min, Tone */D13, D14, D15, PTC11 ) ; -static EthernetInterface eth; +static void ntp(char *site) +{ + NTPClient ntp; + + alarmclock.setLED(33, 33) ; + if (ntp.setTime(site) == 0) { + alarmclock.flashLED() ; + } else { + alarmclock.setLED(0, 0) ; + wait(30.0) ; + return ; + } +} void clock_main(void const *av) { + ntp("ntp.jst.mfeed.ad.jp") ; + alarmclock.start() ; + while(1){ + alarmclock.poll() ; + Thread::wait(100); + } +} + +int main() { + EthernetInterface eth; int ret ; - NTPClient ntp; + alarmclock.setLED(11, 11) ; ret = eth.init(); alarmclock.setLED(22, 22) ; @@ -24,23 +48,9 @@ if(ret == 0)break ; Thread::wait(10); } - alarmclock.setLED(33, 33) ; - if (ntp.setTime("ntp.jst.mfeed.ad.jp") == 0) { - alarmclock.flashLED() ; - } else { - alarmclock.setLED(0, 0) ; - wait(30.0) ; - return ; - } - alarmclock.start() ; - while(1){ - alarmclock.poll() ; - Thread::wait(100); - } -} - -int main() { - #define STACK_SIZE 16000 - Thread t(clock_main, NULL, osPriorityNormal, STACK_SIZE); + + #define NET_STACK 16000 + Thread t_clock(clock_main, NULL, osPriorityNormal); + Thread t_net (net_main, NULL, osPriorityNormal, NET_STACK ); while(1)Thread::wait(1000); }