|
|
@@ -20,35 +20,35 @@
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
#include <stdio.h>
|
|
|
#include <string.h>
|
|
|
-#include <time.h>
|
|
|
|
|
|
#include <sys/thread.h>
|
|
|
#include <sys/timer.h>
|
|
|
#include <sys/version.h>
|
|
|
#include <dev/irqreg.h>
|
|
|
|
|
|
-// Jordy: Please keep this in alphabetical order!
|
|
|
-#include "alarm.h"
|
|
|
-#include "display.h"
|
|
|
#include "displayHandler.h"
|
|
|
-#include "eeprom.h"
|
|
|
-#include "flash.h"
|
|
|
-#include "httpstream.h"
|
|
|
+#include "system.h"
|
|
|
+#include "portio.h"
|
|
|
+#include "display.h"
|
|
|
+#include "remcon.h"
|
|
|
#include "keyboard.h"
|
|
|
#include "led.h"
|
|
|
#include "log.h"
|
|
|
-#include "mmc.h"
|
|
|
-#include "network.h"
|
|
|
-#include "ntp.h"
|
|
|
-#include "portio.h"
|
|
|
-#include "remcon.h"
|
|
|
-#include "rtc.h"
|
|
|
-#include "spidrv.h"
|
|
|
-#include "system.h"
|
|
|
#include "uart0driver.h"
|
|
|
+#include "mmc.h"
|
|
|
#include "watchdog.h"
|
|
|
+#include "flash.h"
|
|
|
+#include "spidrv.h"
|
|
|
+#include "network.h"
|
|
|
+#include "typedefs.h"
|
|
|
|
|
|
|
|
|
+#include <time.h>
|
|
|
+#include "rtc.h"
|
|
|
+#include "alarm.h"
|
|
|
+#include "ntp.h"
|
|
|
+#include "httpstream.h"
|
|
|
+
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
/* local routines (prototyping) */
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
@@ -181,9 +181,8 @@ static void SysControlMainBeat(u_char OnOff)
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
/* global variable definitions */
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
-bool isAlarmSyncing;
|
|
|
-bool initialized = false;
|
|
|
-unsigned char VS_volume = 7; //[0-15];
|
|
|
+int isAlarmSyncing;
|
|
|
+int initialized;
|
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
@@ -199,27 +198,37 @@ THREAD(StartupInit, arg)
|
|
|
|
|
|
NtpSync();
|
|
|
|
|
|
- initialized = true;
|
|
|
+ initialized = 1;
|
|
|
NutThreadExit();
|
|
|
}
|
|
|
|
|
|
-THREAD(Sync, arg)
|
|
|
+THREAD(NTPSync, arg)
|
|
|
{
|
|
|
for(;;)
|
|
|
{
|
|
|
- if((initialized == true) && (hasNetworkConnection() == true))
|
|
|
+ if(initialized && (hasNetworkConnection() == true))
|
|
|
{
|
|
|
- // NTP
|
|
|
- if (0){ // TODO: Do a normal check
|
|
|
- NtpSync();
|
|
|
+ while(isAlarmSyncing)
|
|
|
+ {
|
|
|
+ NutSleep(2000);
|
|
|
}
|
|
|
+ NtpSync();
|
|
|
+ }
|
|
|
+ NutSleep(86400000);
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
- // Regular alarms
|
|
|
- isAlarmSyncing = true;
|
|
|
+THREAD(AlarmSync, arg)
|
|
|
+{
|
|
|
+ for(;;)
|
|
|
+ {
|
|
|
+ if(initialized && (hasNetworkConnection() == true))
|
|
|
+ {
|
|
|
+ isAlarmSyncing = 1;
|
|
|
char* content = httpGet("/getAlarmen.php?radioid=DE370");
|
|
|
parseAlarmJson(content);
|
|
|
free(content);
|
|
|
- isAlarmSyncing = false;
|
|
|
+ isAlarmSyncing = 0;
|
|
|
}
|
|
|
NutSleep(3000);
|
|
|
}
|
|
|
@@ -248,6 +257,7 @@ int checkOffPressed(){
|
|
|
|
|
|
int main(void)
|
|
|
{
|
|
|
+ initialized = 0;
|
|
|
int VOL2;
|
|
|
time_t start;
|
|
|
int idx = 0;
|
|
|
@@ -280,7 +290,8 @@ int main(void)
|
|
|
NtpInit();
|
|
|
|
|
|
NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
|
|
|
- NutThreadCreate("BackgroundThread", Sync, NULL, 2500);
|
|
|
+ NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500);
|
|
|
+ NutThreadCreate("BackgroundThread", NTPSync, NULL, 700);
|
|
|
/** Quick fix for turning off the display after 10 seconds boot */
|
|
|
|
|
|
RcInit();
|
|
|
@@ -297,7 +308,18 @@ int main(void)
|
|
|
/* Enable global interrupts */
|
|
|
sei();
|
|
|
|
|
|
+ /* struct _tm tm;
|
|
|
+ tm = GetRTCTime();
|
|
|
+ tm.tm_sec += 10;
|
|
|
+ setAlarm(tm," test1234 ", "0.0.0.0", 8001,1,0,0);
|
|
|
+ tm.tm_sec +=20;
|
|
|
+ setAlarm(tm," test5678 ", "0.0.0.0", 8001,1,0,1);*/
|
|
|
+
|
|
|
+/* if(hasNetworkConnection() == true){
|
|
|
+ playStream("145.58.53.152", 80, "/3fm-bb-mp3");
|
|
|
+ }*/
|
|
|
start = time(0) - 10;
|
|
|
+ unsigned char VOL = 64;
|
|
|
|
|
|
running = 1;
|
|
|
|
|
|
@@ -318,28 +340,25 @@ int main(void)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (KbGetKey() == KEY_01){
|
|
|
- playStream("145.58.53.152", 80, "/3fm-bb-mp3");
|
|
|
- }
|
|
|
-
|
|
|
+ VOL = VOL2;
|
|
|
if(KbGetKey() == KEY_DOWN)
|
|
|
{
|
|
|
NutSleep(150);
|
|
|
start = time(0);
|
|
|
- if (VS_volume >= 1){
|
|
|
- VS_volume = (--VS_volume) % 17;
|
|
|
- VsSetVolume (128-(VS_volume*8), 128-(VS_volume*8));
|
|
|
- displayVolume(VS_volume);
|
|
|
+ if(VOL > 8){
|
|
|
+ VOL -= 8;
|
|
|
+ VsSetVolume (128-VOL, 128-VOL);
|
|
|
+ displayVolume(VOL/8);
|
|
|
}
|
|
|
}
|
|
|
else if(KbGetKey() == KEY_UP)
|
|
|
{
|
|
|
NutSleep(150);
|
|
|
start = time(0);
|
|
|
- if (VS_volume <= 15){
|
|
|
- VS_volume = (++VS_volume) % 17;
|
|
|
- VsSetVolume (128-(VS_volume*8), 128-(VS_volume*8));
|
|
|
- displayVolume(VS_volume);
|
|
|
+ if(VOL < 128) {
|
|
|
+ VOL += 8;
|
|
|
+ VsSetVolume(128-VOL, 128-VOL);
|
|
|
+ displayVolume(VOL/8);
|
|
|
}
|
|
|
}
|
|
|
else if(timer(start) >= 5 && checkAlarms() == 1)
|
|
|
@@ -362,6 +381,7 @@ int main(void)
|
|
|
displayDate(1);
|
|
|
}
|
|
|
|
|
|
+ VOL2 = VOL;
|
|
|
WatchDogRestart();
|
|
|
}
|
|
|
return(0);
|