Smart Clock
Dependencies: AlarmClock DigitalClock EthernetInterface FourDigitLED HTTPClient NTPClient SDFileSystem TrainStat WeatherInfo XML_aide mbed-rtos mbed picojson wolfSSL
Diff: main.cpp
- Revision:
- 7:53dd54df1441
- Parent:
- 5:e4891827f7b1
--- a/main.cpp Fri Oct 23 06:10:11 2015 +0000 +++ b/main.cpp Sun Nov 22 08:52:05 2015 +0000 @@ -22,11 +22,9 @@ #define ERR(x, ...) std::printf("[Main : ERR]"x"\r\n", ##__VA_ARGS__); AlarmClock alarmclock ( - /* Segment 0 - 6, Dot */ //D11,D6, D3, D1, D0, D10,D4, D2 , - PTB19,PTC0, D3, D1, D0, PTC1, D4, D2, - /* Digit 1 - 4 */ //D5, D7, D9, D12, - D5, PTC9, PTC8, PTB18, - /* Alarm, Hour, Min, Tone */D13, D15, D14, PTC11 + /* Segment 0 - 6, Dot */ PTB19,PTC0, D3, D1, D0, PTC1, D4, D2, + /* Digit 1 - 4 */ D5, PTC9, PTC8, PTB18, + /* Alarm, Hour, Min, Tone */ D13, D15, D14, PTC11 ) ; TrainStat trainstat(/* YAHOO_TRAIN*/ TOKYO_METRO) ; @@ -55,14 +53,16 @@ while(1) { alarmclock.poll() ; } - printf("clock_main\n") ; + } +#if defined(ANIMATION) #define FRONT0 0x06 #define FRONT1 0x79 #define FRONT2 0x49 #define MIDDLE 0x49 #define TAIL0 0x49 + #define TAIL1 0x4f #define TAIL2 0x30 #define ROCK 0x5c @@ -86,9 +86,6 @@ } ; static unsigned int noDelayPtn[14][4] = { - -// { MIDDLE, FRONT1,BLANK, BLANK } , -// { MIDDLE, FRONT2,FRONT0, BLANK } , { BLANK, BLANK, BLANK, BLANK } , { MIDDLE, FRONT1,BLANK, BLANK } , { TAIL0, FRONT2,FRONT0, BLANK } , @@ -104,32 +101,36 @@ { BLANK, BLANK, BLANK, BLANK } , { BLANK, BLANK, BLANK, BLANK } } ; - +#endif + static void setLED_Tdelay(bool delay) { +#if !defined(ANIMATION) /* Delay/No Delay */ -// const unsigned int d[4] = { 0x6e, 0x77, 0x38, 0x5e} ; -// const unsigned int n[4] = { 0x5c, 0x37, 0x38, 0x5e,} ; -/*const unsigned int n[4] = { 0x09, 0x09, 0x29, 0x58} ; -const unsigned int d[4] = { 0x09, 0x29, 0x58, 0x14} ; + const unsigned int d[4] = { 0x6e, 0x77, 0x38, 0x5e} ; + const unsigned int n[4] = { 0x38, 0x5e, 0x5c, 0x37} ; + int index ; if(delay){ DBG("Delay\n") ; - for(index=8*3; index<8*4; index++) + for(index=8*4; index<8*5; index++) alarmclock.setOptVal(index, d, 8) ; } else { DBG("No Delay\n") ; - for(index=8*3; index<8*4; index++) + for(index=8*4; index<8*5; index++) alarmclock.setOptVal(index, n, 8) ; } -*/ +#else #define TRAIN_INDEX (8*4) for(int i=0; i<14; i++) alarmclock.setOptVal(i+TRAIN_INDEX, delay ? delayPtn[i] : noDelayPtn[i], 1) ; +#endif + } -#define DUSH 0x40 +#define DUSH 0x40 +#define BLANK 0x00 static void char2LED(const char *str, unsigned int *ptn) { int i ; @@ -137,6 +138,9 @@ i = atoi(str) ; ptn[0] = alarmclock.getPtn(i%10) ; ptn[1] = alarmclock.getPtn(i/10) ; + } else if((str[0] == ' ')&&(str[1] == '0')) { + ptn[0] = alarmclock.getPtn(0) ; + ptn[1] = BLANK ; } else { ptn[0] = DUSH ; ptn[1] = DUSH ; @@ -180,41 +184,11 @@ } } -static EthernetInterface eth ; -#if 0 -static bool restartEth(void) -{ - int ret ; - printf("==== RESTARTING Ethernet ===\n") ; - eth->disconnect(); - printf("eth.disconnect\n") ; - /*free(eth) ; - printf("free(eth)\n") ; - eth = new EthernetInterface ; - if(eth == NULL) { - ERR("Ethernet can not Restart") ; - return false ; - } - printf("new EthernetInterface|n") ; - alarmclock.setLED(11, 11) ; - ret = eth->init();*/ - alarmclock.setLED(22, 22) ; - while(1) { - ret = eth->connect(); - if(ret == 0)break ; - Thread::wait(10); - } - return true ; -} -#endif - #define BUFF_SIZE 1024*64 static char recvBuff[BUFF_SIZE] ; void net_main(void const *av) { int count = 0 ; - time_t t ; - char *p[1000] ; int i ; #define TEMP_SIZE 5 char hiTemp[TEMP_SIZE], loTemp[TEMP_SIZE], prec[TEMP_SIZE] ; @@ -223,41 +197,32 @@ weatherinfo.setBuff(recvBuff, BUFF_SIZE) ; while(1) { - setLED_Tdelay(trainstat.getStat()) ; - if(count%1 ==0) { + if(count%60 ==0){ + int stat = trainstat.getStat() ; + setLED_Tdelay(stat) ; + if(stat)alarmclock.alarmAhead(1*60*60) ; + else alarmclock.alarmAhead(0) ; + + } + if(count%60 ==0) { DBG("weatherinfo.getInfo") ; weatherinfo.getInfo(hiTemp, loTemp, prec) ; setLED_WInfo(hiTemp, loTemp, prec) ; } - t = time(NULL); - for( i=0; i<sizeof(p) ; i++) { - p[i] = (char *)malloc(1000) ; - if(p[i]==NULL) { - printf("\nHeap=%d\n", (unsigned int)i) ; - break ; - } else printf("+") ; - } - for(i=0; p[i] != NULL; i++){ printf("-") ; free(p[i]) ;} - printf("\n") ; - Thread::wait(60) ; - printf("wait=%d\n", time(NULL) - t ) ; + if(count%60*60*24) + ntp("ntp.jst.mfeed.ad.jp") ; count++ ; - /* - if((count % 1) == 0) - if(restartEth() == false)break ; - */ + wait(1.0) ; } - printf("net_main\n") ; } int main() { int ret ; - + EthernetInterface eth ; #define RESTART_TIMES 3 - //eth = new EthernetInterface ; alarmclock.setLED(11, 11) ; ret = eth.init(); alarmclock.setLED(22, 22) ;