Smart Clock

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

main.cpp

Committer:
takashikojo
Date:
2015-06-28
Revision:
4:8a2d1544d6e0
Parent:
3:2cb03c287c22
Child:
5:e4891827f7b1

File content as of revision 4:8a2d1544d6e0:

#include "mbed.h"

#include "EthernetInterface.h"
#include "HTTPClient.h"
#include "NTPClient.h"
#include "AlarmClock.h"
#include "TrainStat.h"
#include "WeatherInfo.h"

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
)  ;
 
TrainStat   trainstat(YAHOO_TRAIN) ;
WeatherInfo weatherinfo(WEATHER_HACKS) ;
HTTPClient httpClient;

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)
{

    alarmclock.start() ; 
    while(1){        
        alarmclock.poll() ;
        Thread::wait(100);
    } 
} 
#define BUFF_SIZE 1024*64
static char recvBuff[BUFF_SIZE] ;
void net_main(void const *av)
{
    bool sw ;
    int count = 0 ;
    
    trainstat.setBuff(recvBuff, BUFF_SIZE) ;
    weatherinfo.setBuff(recvBuff, BUFF_SIZE) ;
    
    trainstat.setLine("千代田線") ;
    while(1) {

        sw = !sw ;
        /*
        if(!trainstat.getStat())
        {    printf("遅れあり\n") ; alarmclock.setBlink(true) ; }
        else
        {    printf("遅れなし\n") ; alarmclock.setBlink(false) ; }
        */
        trainstat.getStat() ;
        if(count%1 ==0)
            weatherinfo.getInfo() ;
        
        wait(60.0) ;
        count++ ;
    }
}

int main() {
    EthernetInterface eth;
    int ret ;
    
    alarmclock.setLED(11, 11) ;
    ret = eth.init(); 
    alarmclock.setLED(22, 22) ;
    while(1) {
        ret = eth.connect();
        if(ret == 0)break ;
        Thread::wait(10);
    }
    ntp("ntp.jst.mfeed.ad.jp") ;

    #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);
}