|
|
@@ -9,8 +9,8 @@
|
|
|
*/
|
|
|
|
|
|
/*! \file
|
|
|
- * COPYRIGHT (C) STREAMIT BV 2010
|
|
|
- * \date 19 december 2003
|
|
|
+ * COPYRIGHT (C) SaltyRadio 2016
|
|
|
+ * \date 20-02-2016
|
|
|
*/
|
|
|
|
|
|
#define LOG_MODULE LOG_MAIN_MODULE
|
|
|
@@ -41,22 +41,11 @@
|
|
|
#include "spidrv.h"
|
|
|
#include "network.h"
|
|
|
|
|
|
-
|
|
|
#include <time.h>
|
|
|
#include "rtc.h"
|
|
|
#include "alarm.h"
|
|
|
#include "ntp.h"
|
|
|
|
|
|
-
|
|
|
-/*-------------------------------------------------------------------------*/
|
|
|
-/* global variable definitions */
|
|
|
-/*-------------------------------------------------------------------------*/
|
|
|
-
|
|
|
-/*-------------------------------------------------------------------------*/
|
|
|
-/* local variable definitions */
|
|
|
-/*-------------------------------------------------------------------------*/
|
|
|
-
|
|
|
-
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
/* local routines (prototyping) */
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
@@ -79,7 +68,6 @@ static void SysControlMainBeat(u_char);
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
/*!
|
|
|
* \brief ISR MainBeat Timer Interrupt (Timer 2 for Mega128, Timer 0 for Mega256).
|
|
|
*
|
|
|
@@ -90,7 +78,6 @@ static void SysControlMainBeat(u_char);
|
|
|
*
|
|
|
* \param *p not used (might be used to pass parms from the ISR)
|
|
|
*/
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
static void SysMainBeatInterrupt(void *p)
|
|
|
{
|
|
|
|
|
|
@@ -101,8 +88,6 @@ static void SysMainBeatInterrupt(void *p)
|
|
|
CardCheckCard();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
/*!
|
|
|
* \brief Initialise Digital IO
|
|
|
* init inputs to '0', outputs to '1' (DDRxn='0' or '1')
|
|
|
@@ -110,7 +95,6 @@ static void SysMainBeatInterrupt(void *p)
|
|
|
* Pull-ups are enabled when the pin is set to input (DDRxn='0') and then a '1'
|
|
|
* is written to the pin (PORTxn='1')
|
|
|
*/
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
void SysInitIO(void)
|
|
|
{
|
|
|
/*
|
|
|
@@ -166,12 +150,11 @@ void SysInitIO(void)
|
|
|
*/
|
|
|
outp(0x18, DDRG);
|
|
|
}
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
+
|
|
|
/*!
|
|
|
* \brief Starts or stops the 4.44 msec mainbeat of the system
|
|
|
* \param OnOff indicates if the mainbeat needs to start or to stop
|
|
|
*/
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
static void SysControlMainBeat(u_char OnOff)
|
|
|
{
|
|
|
int nError = 0;
|
|
|
@@ -191,89 +174,56 @@ static void SysControlMainBeat(u_char OnOff)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-/*void handleAlarm(){
|
|
|
- struct _tm alarmtime;
|
|
|
- alarmtime = GetRTCTime();
|
|
|
- long flags;
|
|
|
-
|
|
|
- X12RtcGetAlarm(0,&alarmtime,0b11111111);
|
|
|
- alarmtime.tm_min = (alarmtime.tm_min-79);
|
|
|
-
|
|
|
- LogMsg_P(LOG_INFO, PSTR("Alarm : day = %02d,[%02d:%02d:%02d]"),alarmtime.tm_mday, alarmtime.tm_hour, alarmtime.tm_min, alarmtime.tm_sec);
|
|
|
-
|
|
|
- X12RtcSetAlarm(0,&alarmtime, 0b11111111);
|
|
|
- NutDelay(100);
|
|
|
-}*/
|
|
|
-
|
|
|
-int timer(time_t start){
|
|
|
- time_t diff = time(0) - start;
|
|
|
- return diff;
|
|
|
-}
|
|
|
|
|
|
-int checkOffPressed(){
|
|
|
- if (KbScan() < -1){
|
|
|
- LcdBackLight(LCD_BACKLIGHT_ON);
|
|
|
- return 1;
|
|
|
- } else {
|
|
|
- return 0;
|
|
|
- }
|
|
|
-}
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
+/* global variable definitions */
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
+int isAlarmSyncing;
|
|
|
|
|
|
-/*void displayAlarm()
|
|
|
-{
|
|
|
- struct _tm alarmtime;
|
|
|
- alarmtime = GetRTCTime();
|
|
|
- long flags;
|
|
|
- X12RtcGetAlarm(0,&alarmtime,0b11111111);
|
|
|
- NutDelay(100);
|
|
|
- char str[12];
|
|
|
- sprintf(str, " %02d:%02d:%02d", alarmtime.tm_hour, alarmtime.tm_min - 80, alarmtime.tm_sec);
|
|
|
- LogMsg_P(LOG_INFO, PSTR("Alarm : [%02d:%02d:%02d]"), alarmtime.tm_hour, alarmtime.tm_min - 80, alarmtime.tm_sec );
|
|
|
- LcdArrayLineOne(str,12);
|
|
|
-
|
|
|
- char str2[6];
|
|
|
- sprintf(str2,"Wekker");
|
|
|
- LcdArrayLineTwo(str2,6);
|
|
|
- LcdBacklightKnipperen(startLCD);
|
|
|
-}*/
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
-/*!
|
|
|
- * \brief Main entry of the SIR firmware
|
|
|
- *
|
|
|
- * All the initialisations before entering the for(;;) loop are done BEFORE
|
|
|
- * the first key is ever pressed. So when entering the Setup (POWER + VOLMIN) some
|
|
|
- * initialisatons need to be done again when leaving the Setup because new values
|
|
|
- * might be current now
|
|
|
- *
|
|
|
- * \return \b never returns
|
|
|
- */
|
|
|
-/* ����������������������������������������������������������������������� */
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
+/* local variable definitions */
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
+/* Thread init */
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
THREAD(StartupInit, arg)
|
|
|
{
|
|
|
+ isAlarmSyncing = 1;
|
|
|
NetworkInit();
|
|
|
NtpSync();
|
|
|
+
|
|
|
char* content = httpGet("/getAlarmen.php?radioid=DE370");
|
|
|
parseAlarmJson(content);
|
|
|
+ isAlarmSyncing = 0;
|
|
|
+
|
|
|
free(content);
|
|
|
NutThreadExit();
|
|
|
}
|
|
|
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
+/* Global functions */
|
|
|
+/*-------------------------------------------------------------------------*/
|
|
|
+
|
|
|
+int timer(time_t start){
|
|
|
+ time_t diff = time(0) - start;
|
|
|
+ return diff;
|
|
|
+}
|
|
|
+
|
|
|
+int checkOffPressed(){
|
|
|
+ if (KbScan() < -1){
|
|
|
+ LcdBackLight(LCD_BACKLIGHT_ON);
|
|
|
+ return 1;
|
|
|
+ } else {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
int main(void)
|
|
|
{
|
|
|
time_t start;
|
|
|
int running = 0;
|
|
|
- /*
|
|
|
- * Kroeske: time struct uit nut/os time.h (http://www.ethernut.de/api/time_8h-source.html)
|
|
|
- *
|
|
|
- */
|
|
|
- struct _tm alarmtime;
|
|
|
- /*
|
|
|
- * Kroeske: Ook kan 'struct _tm gmt' Zie bovenstaande link
|
|
|
- */
|
|
|
- /*
|
|
|
- * First disable the watchdog
|
|
|
- */
|
|
|
+
|
|
|
WatchDogDisable();
|
|
|
|
|
|
NutDelay(100);
|
|
|
@@ -303,22 +253,11 @@ int main(void)
|
|
|
start = time(0);
|
|
|
running = 1;
|
|
|
|
|
|
- /*
|
|
|
- * Kroeske: sources in rtc.c en rtc.h
|
|
|
- */
|
|
|
-
|
|
|
- if (At45dbInit()==AT45DB041B)
|
|
|
- {
|
|
|
- // ......
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
RcInit();
|
|
|
|
|
|
KbInit();
|
|
|
|
|
|
- SysControlMainBeat(ON); // enable 4.4 msecs hartbeat interrupt
|
|
|
+ SysControlMainBeat(ON); // enable 4.4 msecs heartbeat interrupt
|
|
|
|
|
|
/*
|
|
|
* Increase our priority so we can feed the watchdog.
|
|
|
@@ -327,14 +266,7 @@ int main(void)
|
|
|
|
|
|
/* Enable global interrupts */
|
|
|
sei();
|
|
|
-
|
|
|
- alarmtime = GetRTCTime();
|
|
|
- alarmtime.tm_sec = alarmtime.tm_sec+10;
|
|
|
- LogMsg_P(LOG_INFO, PSTR("alarmtime %02d-%02d-%04d || %02d-%02d-%02d"), alarmtime.tm_mday, alarmtime.tm_mon+1, alarmtime.tm_year+1900, alarmtime.tm_hour, alarmtime.tm_min, alarmtime.tm_sec);
|
|
|
-
|
|
|
- X12RtcSetAlarm(0,&alarmtime,0b11111111);
|
|
|
- NutDelay(100);
|
|
|
-
|
|
|
+
|
|
|
for (;;)
|
|
|
{
|
|
|
//Check if a button is pressed
|
|
|
@@ -351,9 +283,8 @@ int main(void)
|
|
|
LcdBackLight(LCD_BACKLIGHT_OFF);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- if(X12RtcGetStatus(5) > 0)
|
|
|
+
|
|
|
+ if(!isAlarmSyncing && X12RtcGetStatus(5) > 0)
|
|
|
{
|
|
|
displayAlarm(0,1);
|
|
|
if (KbScan() < -1 || checkTime() == 1){
|
|
|
@@ -368,5 +299,5 @@ int main(void)
|
|
|
WatchDogRestart();
|
|
|
}
|
|
|
|
|
|
- return(0); // never reached, but 'main()' returns a non-void, so.....
|
|
|
+ return(0);
|
|
|
}
|