Smart Clock

Dependencies:   AlarmClock DigitalClock EthernetInterface FourDigitLED HTTPClient NTPClient SDFileSystem TrainStat WeatherInfo XML_aide mbed-rtos mbed picojson wolfSSL

Committer:
takashikojo
Date:
Sat Jun 27 06:20:59 2015 +0000
Revision:
3:2cb03c287c22
Parent:
2:bcc1a40ffa04
Child:
4:8a2d1544d6e0
Added yahoo Train

Who changed what in which revision?

UserRevisionLine numberNew contents of line
takashikojo 0:0689619f2486 1 #include "mbed.h"
takashikojo 0:0689619f2486 2
takashikojo 0:0689619f2486 3 #include "EthernetInterface.h"
takashikojo 0:0689619f2486 4 #include "NTPClient.h"
takashikojo 0:0689619f2486 5 #include "AlarmClock.h"
takashikojo 2:bcc1a40ffa04 6 #include "TrainStat.h"
takashikojo 1:1a28aaca601d 7
takashikojo 1:1a28aaca601d 8 AlarmClock alarmclock (
takashikojo 0:0689619f2486 9 /* Segment 0 - 6, Dot */ D11,D6, D3, D1, D0, D10,D4, D2 ,
takashikojo 0:0689619f2486 10 /* Digit 1 - 4 */ D5, D7, D9, D12,
takashikojo 0:0689619f2486 11 /* Alarm, Hour, Min, Tone */D13, D14, D15, PTC11
takashikojo 0:0689619f2486 12 ) ;
takashikojo 0:0689619f2486 13
takashikojo 3:2cb03c287c22 14 TrainStat trainstat(YAHOO_TRAIN) ;
takashikojo 2:bcc1a40ffa04 15
takashikojo 1:1a28aaca601d 16 static void ntp(char *site)
takashikojo 1:1a28aaca601d 17 {
takashikojo 1:1a28aaca601d 18 NTPClient ntp;
takashikojo 1:1a28aaca601d 19
takashikojo 1:1a28aaca601d 20 alarmclock.setLED(33, 33) ;
takashikojo 1:1a28aaca601d 21 if (ntp.setTime(site) == 0) {
takashikojo 1:1a28aaca601d 22 alarmclock.flashLED() ;
takashikojo 1:1a28aaca601d 23 } else {
takashikojo 1:1a28aaca601d 24 alarmclock.setLED(0, 0) ;
takashikojo 1:1a28aaca601d 25 wait(30.0) ;
takashikojo 1:1a28aaca601d 26 return ;
takashikojo 1:1a28aaca601d 27 }
takashikojo 1:1a28aaca601d 28 }
takashikojo 0:0689619f2486 29
takashikojo 0:0689619f2486 30 void clock_main(void const *av)
takashikojo 0:0689619f2486 31 {
takashikojo 3:2cb03c287c22 32
takashikojo 1:1a28aaca601d 33 alarmclock.start() ;
takashikojo 1:1a28aaca601d 34 while(1){
takashikojo 1:1a28aaca601d 35 alarmclock.poll() ;
takashikojo 1:1a28aaca601d 36 Thread::wait(100);
takashikojo 1:1a28aaca601d 37 }
takashikojo 1:1a28aaca601d 38 }
takashikojo 3:2cb03c287c22 39
takashikojo 2:bcc1a40ffa04 40 void net_main(void const *av)
takashikojo 2:bcc1a40ffa04 41 {
takashikojo 2:bcc1a40ffa04 42 bool sw ;
takashikojo 2:bcc1a40ffa04 43
takashikojo 2:bcc1a40ffa04 44 trainstat.setLine("千代田線") ;
takashikojo 2:bcc1a40ffa04 45 while(1) {
takashikojo 2:bcc1a40ffa04 46 sw = !sw ;
takashikojo 2:bcc1a40ffa04 47 if(!trainstat.getStat())
takashikojo 2:bcc1a40ffa04 48 { printf("遅れあり\n") ; alarmclock.setBlink(true) ; }
takashikojo 2:bcc1a40ffa04 49 else
takashikojo 2:bcc1a40ffa04 50 { printf("遅れなし\n") ; alarmclock.setBlink(false) ; }
takashikojo 2:bcc1a40ffa04 51 wait(60.0) ;
takashikojo 2:bcc1a40ffa04 52 }
takashikojo 2:bcc1a40ffa04 53 }
takashikojo 2:bcc1a40ffa04 54
takashikojo 1:1a28aaca601d 55 int main() {
takashikojo 1:1a28aaca601d 56 EthernetInterface eth;
takashikojo 0:0689619f2486 57 int ret ;
takashikojo 1:1a28aaca601d 58
takashikojo 0:0689619f2486 59 alarmclock.setLED(11, 11) ;
takashikojo 0:0689619f2486 60 ret = eth.init();
takashikojo 0:0689619f2486 61 alarmclock.setLED(22, 22) ;
takashikojo 0:0689619f2486 62 while(1) {
takashikojo 0:0689619f2486 63 ret = eth.connect();
takashikojo 0:0689619f2486 64 if(ret == 0)break ;
takashikojo 0:0689619f2486 65 Thread::wait(10);
takashikojo 0:0689619f2486 66 }
takashikojo 3:2cb03c287c22 67 ntp("ntp.jst.mfeed.ad.jp") ;
takashikojo 3:2cb03c287c22 68
takashikojo 1:1a28aaca601d 69 #define NET_STACK 16000
takashikojo 1:1a28aaca601d 70 Thread t_clock(clock_main, NULL, osPriorityNormal);
takashikojo 1:1a28aaca601d 71 Thread t_net (net_main, NULL, osPriorityNormal, NET_STACK );
takashikojo 0:0689619f2486 72 while(1)Thread::wait(1000);
takashikojo 0:0689619f2486 73 }