Example #1
0
void NtpCheckValidTime(void){

    Eeprom_tm eeprom_tm_struct;

    NutNvMemLoad(256, &eeprom_tm_struct, sizeof(eeprom_tm_struct));

    if (eeprom_tm_struct.len != sizeof(eeprom_tm_struct)){
        // Size mismatch: There is no valid configuration present.
        puts("NtpCheckValidTime(): Size mismatch \n");
        validTime = false;
        return;
    }

    // Valid configuration available.
    puts("NtpCheckValidTime(): Valid config available \n");
    tm stored_tm = eeprom_tm_struct.tm_struct;

    // Check time is valid;
    tm current_tm;
    X12RtcGetClock(&current_tm);

    validTime = compareTime(current_tm, stored_tm);
    if (validTime){
        puts("NtpCheckValidTime(): Time was valid \n");
    }else {
        puts("NtpCheckValidTime(): Invalid time! \n");
    }
}
Example #2
0
void showMenu()
{
    ClearLcd();
    LcdArrayLineOne("Main menu", 9);
    switch (isSettings)
    {
        case 0:
        {
            tm time;
            X12RtcGetClock(&time);
            char str1[16];
            sprintf(str1, "<   %02d:%02d:%02d   >", time.tm_hour, time.tm_min, time.tm_sec);
            LcdArrayLineTwo(str1, 16);
            break;
        }
        case 1:
        {
            showSettings();
            break;
        }
        case 2:
        {
            showPlay();
            break;
        }
    }
}
Example #3
0
int checkWeekend()
{
    tm time;
    X12RtcGetClock(&time);

    printf("\n checkWeekend = %d-%d-%d, day if the week %d",time.tm_year, time.tm_mon, time.tm_mday, time.tm_wday);

    if(time.tm_wday == 0)
    {
        printf("X12RTC_DW: %d day of the week: %s \n", time.tm_wday, "Sunday");
        //setAlarmA(weekendtime.hour, weekendtime.minute, weekendtime.second);
        return 3;
    }
    else if(time.tm_wday == 1)
    {
        printf("X12RTC_DW: %d day of the week: %s \n", time.tm_wday, "Monday");
        //setAlarmA(weekendtime.hour, weekendtime.minute, weekendtime.second);

        return 0;
    }
    else if(time.tm_wday == 2)
    {
        printf("X12RTC_DW: %d day of the week: %s \n", time.tm_wday, "Teusday");
        //setAlarmA(weekendtime.hour, weekendtime.minute, weekendtime.second);

        return 0;
    }
    else if(time.tm_wday == 3)
    {
        printf("X12RTC_DW: %d day of the week: %s \n", time.tm_wday, "Wednesday");
       // setAlarmA(weekendtime.hour, weekendtime.minute, weekendtime.second);

        return 0;
    }
    else if(time.tm_wday == 4)
    {
        printf("X12RTC_DW: %d day of the week: %s \n", time.tm_wday, "Thursday");
       // setAlarmA(weekendtime.hour, weekendtime.minute, weekendtime.second);

        return 0;
    }
    else if(time.tm_wday == 5)
    {
        printf("X12RTC_DW: %d day of the week: %s \n", time.tm_wday, "Friday");
        //setAlarmA(weekendtime.hour, weekendtime.minute, weekendtime.second);

        return 1;
    }
    else if(time.tm_wday == 6)
    {
        printf("X12RTC_DW: %d day of the week: %s \n", time.tm_wday, "Saturday");
        //setAlarmA(weekendtime.hour, weekendtime.minute, weekendtime.second);
        return 2;
    }
    else
    {
        return 0;
    }

}
int main(void)
{
	tm gmt;
	WatchDogDisable();
	NutDelay(100);
	SysInitIO();
	SPIinit();
	LedInit();
	LcdLowLevelInit();
	Uart0DriverInit();
	Uart0DriverStart();
	LogInit();
	LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------"));
	CardInit();
	X12Init();
	if (X12RtcGetClock(&gmt) == 0)
	{
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
	}
	if (At45dbInit() == AT45DB041B)
	{
		
	}
	RcInit();
	KbInit();
	SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	NutThreadSetPriority(1);
	NutTimerInit();
	sei();

	printf("\nreading EEPROM\n");
	NutSleep(1000);
	readEEPROM();
	printf("UTC: %d\n",IMCconfig.UTC);
	NutSleep(1000);

	IMCconfig.UTC++;	
	printf("na ophoging UTC: %d\n",IMCconfig.UTC);
	saveEEPROM();
	NutSleep(1000);
	readEEPROM();
	printf("na saving en reading UTC: %d\n",IMCconfig.UTC);

	printf("\nResetting EEPROM\n");
	NutSleep(1000);
	resetEEPROM();
	NutSleep(1000);
	readEEPROM();

	for (;;)
	{
		
	}

	return(0);      // never reached, but 'main()' returns a non-void, so.....
}
Example #5
0
THREAD(TimeUpdater, arg){
	for(;;){
		NutSleep(100);
		if (X12RtcGetClock(&gmt) == 0)
    	{
			TimeToBuffer(time);
    	}
		LcdBufferLoader(NULL,time);

	}
}
Example #6
0
/**
 * Changes 'displaymode' to display the 'main screen'.
 */
void lcd_display_main_screen()
{
    tm time_stamp;
    X12RtcGetClock(&time_stamp);
    lcd_display_timestamp(&time_stamp);         //Shows the time and date on first line of the screen.
    if(alarmstatus_changed)                     //Only print if alarmstatus changes to make sure the cursor doesn't bug.
    {
        lcd_display_alarmstatus(alarm_a_on, alarm_b_on); //Shows the status of the alarms on the screen in the bottom right corner.
        alarmstatus_changed = false;
    }
   
}
Example #7
0
long timerStruct(struct _tm s){
    struct _tm ct;
    X12RtcGetClock(&ct);

    long stime = (s.tm_hour * 3600) + (s.tm_min * 60) + s.tm_sec;
    long ctime = (ct.tm_hour * 3600) + (ct.tm_min * 60) + ct.tm_sec;

 /*   if(ctime < 0){
        return 0;
    }*/
    
    return ctime - stime;
}
int main(void)
{
	tm gmt;
	WatchDogDisable();
	NutDelay(100);
	SysInitIO();
	SPIinit();
	LedInit();
	LcdLowLevelInit();
	Uart0DriverInit();
	Uart0DriverStart();
	LogInit();
	LogMsg_P(LOG_INFO, PSTR("-----------------------------------------------------------------------------------------------"));
	CardInit();
	X12Init();
	if (X12RtcGetClock(&gmt) == 0)
	{
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
	}
	if (At45dbInit() == AT45DB041B)
	{
		
	}
	RcInit();
	KbInit();
	SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	initMenu();
	sei();
	NutTimerInit();
	NutThreadSetPriority(1);
	int keyvalue = KbGetKey();
	int old;
	LcdBackLight(LCD_BACKLIGHT_ON);
	if(NutRegisterDevice(&DEV_ETHER, 0x8300, 5))printf("Error: No LAN device\n");
	else printf("Lan device initialized\n");
	
	for (;;)
	{
		keyvalue = KbGetKey();
		if(old != keyvalue){
			stateMenu(keyvalue);
			old = keyvalue;
		}		
		NutSleep(100);
		WatchDogRestart();
	}

	return(0);      // never reached, but 'main()' returns a non-void, so.....
}
Example #9
0
void displayDateTime(void){
    tm time;
    X12RtcGetClock(&time);

    char str1[16];
    char str2[16];
    if (1){
        sprintf(str1, "    %02d:%02d:%02d    ", time.tm_hour, time.tm_min, time.tm_sec);
        sprintf(str2, "   %02d-%02d-%04d      ", time.tm_mday, time.tm_mon + MONTH_OFFSET, time.tm_year + YEAR_OFFSET);
    } else {
        sprintf(str1, "    ??:??:??    ");
        sprintf(str2, "    ??:??:??    ");
    }
    if (NtpIsSyncing()) {
        str2[1] = 'S';
    } else if(NetworkIsReceiving()){
        str2[1] = 'N';
    }

    (*write_display_ptr[0])(str1, 16);
    (*write_display_ptr[1])(str2, 16);
}
Example #10
0
void setCurrentDisplay(viewDisplays d, u_long dt){
    X12RtcGetClock(&lastDisplayTime);
    LcdBackLight(LCD_BACKLIGHT_ON);
    currentViewDisplay = d;
    displayTime = dt;
}
Example #11
0
	int main(void) {
		//audioInit();
		//setVolume(254);
		WatchDogDisable();		//disable watchdog
		NutDelay(100);			//wait for it to disable
		SysInitIO();			//initialise input and output
		SPIinit();				//initialise SPI-registers (speed, mode)
		LedInit();				//initialise led
		initLCD();				//initialise lcd
		Uart0DriverInit();		//initialise Universal asynchronous receiver/transmitter  
		Uart0DriverStart();		//start Uart
		printf("\n\n\n\nHardware initialization done\n\n");
		LogInit();				//initialise ability to log
		CardInit();				//initialise cardreader
		printf("\n----------------------------------------------START OF PROGRAM------------------------------------------------------------\n");

		if (NutSegBufInit(8192) == 0) {
			puts("NutSegBufInit: Fatal error");
		}
		
		/*
		* Initialize the MP3 decoder hardware.
		*/
		if (VsPlayerInit() || VsPlayerReset(0)) {
			puts("VsPlayer: Fatal error");
		}
		
		if(X12Init() == -1){
			printf("error initializing RTC");	//initialise X12RTC 
		}				
		tm gmt;
		if (X12RtcGetClock(&gmt) == 0) {
			LogMsg_P(LOG_INFO, PSTR("local storage time [%02d:%02d:%02d] (in RTC)\n"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec);
		}

		if (At45dbInit() == AT45DB041B) {
			// ......
		}

		RcInit();					//Initialise the Remote Control module
		KbInit();					//Initialise keyboard
		initMenu();					//Initialise menu
		NutThreadCreate("Bh", ButtonHandlerThread, NULL, 512);	//create thread to handle button presses
		printf("\nInitialization done.\n");
		initAlarms();
		SysControlMainBeat(ON); 	//enable 4.4 msecs heartbeat interrupt
		printf("Heartbeat on.\n");
		NutThreadSetPriority(1);	//Increase our priority so we can feed the watchdog.
		sei();						//enable global interrupts
		NutThreadCreate("Bg", TimeSyncThread, NULL, 512);
		NutThreadCreate("Bq", RefreshSceenThread, NULL, 512);
		NutThreadCreate("Bl", AlarmCheckerThread, NULL, 512);
		printf("\nEntering main loop.\n");
		LcdBackLight(LCD_BACKLIGHT_ON);
		for(;;){
			NutSleep(100);
			WatchDogRestart();			//restart watchdog
		}
		
		return(0);
	}
Example #12
0
int main(void)
{
	
    WatchDogDisable();

    NutDelay(100);

    SysInitIO();
	
	SPIinit();
    
	LedInit();
	
	LcdLowLevelInit();
	LcdBackLight(1);
	PrintStr("Starting System");
    Uart0DriverInit();
    Uart0DriverStart();
	LogInit();

    CardInit();

	char custom[48] = ALL;
	
	LoadCustomChars(custom, 6);
	
    X12Init();
    if (X12RtcGetClock(&gmt) == 0)
    {
		LogMsg_P(LOG_INFO, PSTR("RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );
    }

    if (At45dbInit()==AT45DB041B)
    {
        // ......
    }


    RcInit();
    
	KbInit();

    SysControlMainBeat(ON);             // enable 4.4 msecs hartbeat interrupt
	
	ClearLcdScreen();

	//Nieuwe threads aanmaken
    NutThreadCreate("t01", Thread1, NULL, 512);
	NutThreadCreate("time", TimeUpdater, NULL, 512);
	
	//Start netwerk
	int i = initNetworkDHCP();
	LogMsg_P(LOG_INFO, PSTR("Ethernet Startup Message: [%d]"),i);

	//Haal Internet tijd op
	pgmt = getNTPTime();
	X12RtcSetClock(&pgmt);
	//LogMsg_P(LOG_INFO, PSTR("New RTC time [%02d:%02d:%02d]"), gmt.tm_hour, gmt.tm_min, gmt.tm_sec );

    /*
     * Increase our priority so we can feed the watchdog.
     */
    NutThreadSetPriority(1);

	/* Enable global interrupts */
	sei();

	/******************NETWERK**TEST*****************************************************/

	//Maak nieuwe socket
	TCPSOCKET *sock;
	sock = NutTcpCreateSocket();
	//Connect met google.nl
	LogMsg_P(LOG_INFO, PSTR("Connecting client"));
	clientConnect(sock);
	//Zend http req
	clientSend(sock,buffer,sizeof(buffer));

	//Ontvang response in buffer --> grotere buffer (1500)= crash-->heapsize??(8k ram)
	char rcvbuffer [500];
	int rec;
	rec = clientReceive(sock,rcvbuffer,sizeof(rcvbuffer));
	LogMsg_P(LOG_INFO, PSTR("received [%d]"),rec);

	//0 terminate buffer(string)
	//rcvbuffer[499] = 0;

	//Print buffer(http response enz)
	LogMsg_P(LOG_INFO, PSTR("received [%s]"),rcvbuffer);
	
	//Sluit connectie
	clientClose(sock);
	/***********************************************************************************/

	//Main gui besturing??
    for (;;)
    {
        NutSleep(100);
        WatchDogRestart();
    }

    return(0);      
}
Example #13
0
/*!
 * \brief thread that checks the alarms every 10 seconds
 * 
 * \author Matthijs
 */
THREAD(AlarmThread, args)
{
    //time struct datetime can't be found when placed in main.h
    tm datetime;
    u_long flags;
       
    X12RtcGetClock(&datetime);
    
    for(;;)
    {
        int succes = X12RtcGetStatus(&flags);
        int i;
        
        for(i = 0; i <=10; i++)
        {
                NutSleep(1000);
        }
        
        //power fail
        if(flags == 0)
        {
            //printf("\n ========== Power Fail ========== \n");
            X12RtcClearStatus(0);
        }

        //alarm A
        if(flags == 32)
        {
            printf("\n ========== Alarm 0 =========== \n");       


            //get current alarm time to compare to the weekendtime, if weekendtime is
            //equal to currentAlarm and the day of the week is friday. The alarm should
            //not go off.
            tm currentAlarm;
            int iets = 0;
            X12RtcGetAlarm(0, &currentAlarm, &iets);

            int alarmASeconds = 0;
            alarmASeconds = (currentAlarm.tm_hour * 360) + (currentAlarm.tm_min * 6) + (currentAlarm.tm_sec / 10);

            int weekendtimeSeconds = 0;
            weekendtimeSeconds = (weekendtime.hour * 360) + (weekendtime.minute * 6) + (weekendtime.second / 10);


            printf("\nalarmASeconds: %d, weekendtimeSeconds: %d", alarmASeconds, weekendtimeSeconds);
            if((alarmASeconds != weekendtimeSeconds) && checkWeekend() == 1)
            {
                printf("\nHet is VRIJDAG!!! alarm is niet gelijk aan de weekendtijd en moet dus nog geset worden\n SOUND IS PLAYING");
                //SoundA();
                startSnoozeThreadA();
            }
            else if(((alarmASeconds != weekendtimeSeconds) && (checkWeekend() == 2)) || ((alarmASeconds != weekendtimeSeconds) && (checkWeekend() == 3)))
            {
                printf("\nalarm is niet gelijk aan de weekendtijd en het is weekend, dus set");
            }
            else if(((alarmASeconds == weekendtimeSeconds) && (checkWeekend() == 2)) || ((alarmASeconds == weekendtimeSeconds) && (checkWeekend() == 3)))
            {
                printf("\nalarm is gelijk aan de weekendtijd en het is weekend,\n SOUND IS PLAYING");
                //SoundA();
                startSnoozeThreadA();

                //if the alarm goes off and it is sunday set the alarm back to its
                //original settings
                if(checkWeekend() == 3)
                {
                    printf("het is blijkbaar zondag dus terug naar doordeweekse tijd");
                    setAlarmA(alarmA.tm_hour, alarmA.tm_min, alarmA.tm_sec);
                }
            }
            else if(checkWeekend() == 0)
            {
                printf("\nhet is doordeweeks,\nSOUND IS PLAYING");
                startSnoozeThreadA();
                //SoundA();
            }
            //else
            //{
            //	printf("weekendAlarm gaat af!!!");
            //}

            //when checkWeekend returns 1(Friday) or 2(Saturday) it means that it
            //will be weekend the next day. Therefore we set the alarm to the weekend
            //settings. Problem is that most likely the alarm in the weekends will go
            //off later then it would during the week. This problem is solved underneath
            //the if(checkWeekend() == 3){}.
            int currentTime = (datetime.tm_hour * 360) + (datetime.tm_min * 6) + (datetime.tm_sec / 10);

            if(checkWeekend() > 0 && checkWeekend() < 3)
            {
                printf("alarmA set to weekend time");
                setAlarmA(weekendtime.hour,weekendtime.minute,weekendtime.second);
            }
            else if(checkWeekend() == 3 && (currentTime <= weekendtimeSeconds))
            {
                setAlarmA(weekendtime.hour,weekendtime.minute,weekendtime.second);
            }

            X12RtcClearStatus(32);
        }

        //alarm B
        if(flags == 64)
        {
            printf("\n ============ Alarm 1================== \n");
           
            startSnoozeThreadB();
            ClearAlarm('b');
            X12RtcClearStatus(64);
			alarmBArray[currentAlarm.index].set = 0;
            alarmBStruct newSet = checkFirst();
            X12RtcSetAlarm(1, &newSet.timeSet, 31);
            currentAlarm = newSet;
        }

        //both alarms
        if(flags == 96)
        {
            //kijkt of alarm a of b nog niet heeft geluid, en speelt die dan
            printf("\n ========== Alarm 0 en 1  ========= \n");
            //kijkt welke van de 2 nog niet is afgegaan en speelt die dan nog af
            SoundA();  
            X12RtcClearStatus(32);
            SoundB();
            X12RtcClearStatus(64);
        }

        if(succes == 0)
        {
            //succes
        }
        else
        {
            //error
        }
    }
}
Example #14
0
int main(void)
{
    struct _tm timeCheck;

    WatchDogDisable();

    NutDelay(100);

    SysInitIO();

	SPIinit();

	LedInit();

	LcdLowLevelInit();

    Uart0DriverInit();
    Uart0DriverStart();
	LogInit();

    X12Init();

    VsPlayerInit();

    NtpInit();

    NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
    NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500);
    NutThreadCreate("BackgroundThread", AlarmCheck, NULL, 256);

	KbInit();

    SysControlMainBeat(ON);             // enable 4.4 msecs heartbeat interrupt

    /*
     * Increase our priority so we can feed the watchdog.
     */
    NutThreadSetPriority(1);

	/* Enable global interrupts */
	sei();
	
	LcdBackLight(LCD_BACKLIGHT_ON);
    setCurrentDisplay(DISPLAY_DateTime, 5);

    X12RtcGetClock(&timeCheck);
    int hours;
    int mins;
    int secs;
    if(!NutNvMemLoad(100, &hours, sizeof(hours)))
    {
        printf("uren: %d", hours);
    }
    if(!NutNvMemLoad(105, &mins, sizeof(mins)))
    {
        printf(" minuten: %d", mins);
    }
    if(!NutNvMemLoad(110, &secs, sizeof(secs)))
    {
        printf(" seconden %d", secs);
    }
    printf("Welcome to Saltyradio.\nI'm using mac address:  %s\n\n\n", getMacAdress());

    for (;;)
    {
        //Key detecten
        if(KbGetKey() == KEY_01){
            setCurrentDisplay(DISPLAY_DateTime, 5);
        }
        else if(KbGetKey() == KEY_OK)
        {
            if(getCurrentDisplay() == DISPLAY_MainMenu)
            {
                clickOk();
            }
            else if(getCurrentDisplay() == DISPLAY_SettingsMenu)
            {
                clickOkSettings();
            }
            else if(getCurrentDisplay() == DISPLAY_Play || getCurrentDisplay() == DISPLAY_Song)
            {
                clickOkPlay();
            }
            else
            {
                setCurrentDisplay(DISPLAY_MainMenu, 10000);
            }
        }
        else if(KbGetKey() == KEY_LEFT)
        {
            switchLeft();
        }
        else if(KbGetKey() == KEY_RIGHT)
        {
            switchItem();
        }
        else if(KbGetKey() == KEY_DOWN){
            setCurrentDisplay(DISPLAY_Volume, 5);
            volumeDown();
        }else if(KbGetKey() == KEY_UP) {
            setCurrentDisplay(DISPLAY_Volume, 5);
            volumeUp();
        }
        refreshScreen();
        WatchDogRestart();
        NutSleep(100);
    }
    return(0);
}