Smart Clock

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

Committer:
takashikojo
Date:
Fri Jun 26 08:02:30 2015 +0000
Revision:
1:1a28aaca601d
Parent:
0:0689619f2486
Child:
2:bcc1a40ffa04
Smart Clock, initial version

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 0:0689619f2486 6
takashikojo 1:1a28aaca601d 7 extern void net_main(void const *av) ;
takashikojo 1:1a28aaca601d 8
takashikojo 1:1a28aaca601d 9 AlarmClock alarmclock (
takashikojo 0:0689619f2486 10 /* Segment 0 - 6, Dot */ D11,D6, D3, D1, D0, D10,D4, D2 ,
takashikojo 0:0689619f2486 11 /* Digit 1 - 4 */ D5, D7, D9, D12,
takashikojo 0:0689619f2486 12 /* Alarm, Hour, Min, Tone */D13, D14, D15, PTC11
takashikojo 0:0689619f2486 13 ) ;
takashikojo 0:0689619f2486 14
takashikojo 1:1a28aaca601d 15 static void ntp(char *site)
takashikojo 1:1a28aaca601d 16 {
takashikojo 1:1a28aaca601d 17 NTPClient ntp;
takashikojo 1:1a28aaca601d 18
takashikojo 1:1a28aaca601d 19 alarmclock.setLED(33, 33) ;
takashikojo 1:1a28aaca601d 20 if (ntp.setTime(site) == 0) {
takashikojo 1:1a28aaca601d 21 alarmclock.flashLED() ;
takashikojo 1:1a28aaca601d 22 } else {
takashikojo 1:1a28aaca601d 23 alarmclock.setLED(0, 0) ;
takashikojo 1:1a28aaca601d 24 wait(30.0) ;
takashikojo 1:1a28aaca601d 25 return ;
takashikojo 1:1a28aaca601d 26 }
takashikojo 1:1a28aaca601d 27 }
takashikojo 0:0689619f2486 28
takashikojo 0:0689619f2486 29 void clock_main(void const *av)
takashikojo 0:0689619f2486 30 {
takashikojo 1:1a28aaca601d 31 ntp("ntp.jst.mfeed.ad.jp") ;
takashikojo 1:1a28aaca601d 32 alarmclock.start() ;
takashikojo 1:1a28aaca601d 33 while(1){
takashikojo 1:1a28aaca601d 34 alarmclock.poll() ;
takashikojo 1:1a28aaca601d 35 Thread::wait(100);
takashikojo 1:1a28aaca601d 36 }
takashikojo 1:1a28aaca601d 37 }
takashikojo 1:1a28aaca601d 38
takashikojo 1:1a28aaca601d 39 int main() {
takashikojo 1:1a28aaca601d 40 EthernetInterface eth;
takashikojo 0:0689619f2486 41 int ret ;
takashikojo 1:1a28aaca601d 42
takashikojo 0:0689619f2486 43 alarmclock.setLED(11, 11) ;
takashikojo 0:0689619f2486 44 ret = eth.init();
takashikojo 0:0689619f2486 45 alarmclock.setLED(22, 22) ;
takashikojo 0:0689619f2486 46 while(1) {
takashikojo 0:0689619f2486 47 ret = eth.connect();
takashikojo 0:0689619f2486 48 if(ret == 0)break ;
takashikojo 0:0689619f2486 49 Thread::wait(10);
takashikojo 0:0689619f2486 50 }
takashikojo 1:1a28aaca601d 51
takashikojo 1:1a28aaca601d 52 #define NET_STACK 16000
takashikojo 1:1a28aaca601d 53 Thread t_clock(clock_main, NULL, osPriorityNormal);
takashikojo 1:1a28aaca601d 54 Thread t_net (net_main, NULL, osPriorityNormal, NET_STACK );
takashikojo 0:0689619f2486 55 while(1)Thread::wait(1000);
takashikojo 0:0689619f2486 56 }