Просмотр исходного кода

Merge remote-tracking branch 'origin/developer' into Twitch

Conflicts:
	main.c
Aareschluchtje 9 лет назад
Родитель
Сommit
67f88b3db6
5 измененных файлов с 76 добавлено и 45 удалено
  1. 1 1
      contentparser.c
  2. 38 42
      main.c
  3. 7 1
      ntp.c
  4. 4 1
      ntp.h
  5. 26 0
      typedefs.h

+ 1 - 1
contentparser.c

@@ -101,7 +101,7 @@ void parseAlarmJson(char* content){
 void parsetimezone(char* content)
 {
     int timezone = atoi(content);
-    printf("%d", timezone);
+    setTimeZone(timezone);
 }
 
 void parseTwitch(char* content)

+ 38 - 42
main.c

@@ -182,10 +182,11 @@ static void SysControlMainBeat(u_char OnOff)
 /*-------------------------------------------------------------------------*/
 /* global variable definitions                                             */
 /*-------------------------------------------------------------------------*/
-int isAlarmSyncing;
-int initialized;
-int running = 0;
-unsigned char VOL = 64;
+bool isAlarmSyncing = false;
+bool initialized = false;
+bool running = false;
+
+u_char VS_volume = 7; //[0-15];
 
 /*-------------------------------------------------------------------------*/
 /* local variable definitions                                              */
@@ -196,44 +197,37 @@ unsigned char VOL = 64;
 /*-------------------------------------------------------------------------*/
 THREAD(StartupInit, arg)
 {
+    NutThreadSetPriority(5);
+
     NetworkInit();
 
-    NtpSync();
+    initialized = true;
 
-    initialized = 1;
     NutThreadExit();
 }
 
-THREAD(NTPSync, arg)
+THREAD(AlarmSync, arg)
 {
-    for(;;)
-    {
-        if(initialized && (hasNetworkConnection() == true))
-        {
-            while(isAlarmSyncing)
-            {
-                NutSleep(2000);
-            }
-            NtpSync();
-        }
-        NutSleep(86400000);
+    NutThreadSetPriority(200);
+
+    while(initialized == false){
+        NutSleep(1000);
     }
-}
 
-THREAD(AlarmSync, arg)
-{
+    NtpSync();
+
     for(;;)
     {
-        if(initialized && (hasNetworkConnection() == true))
+        if((initialized == true) && (hasNetworkConnection() == true))
         {
-            isAlarmSyncing = 1;
-            char url[43];           //cause of memory leak maybe?
-            sprintf(url, "%s%s", "/getAlarmen.php?radiomac=", getMacAdress());
+            isAlarmSyncing = true;
+            char url[49];
+            sprintf(url, "/getAlarmen.php?radiomac=%s&tz=%d", getMacAdress(), getTimeZone());
             httpGet(url, parseAlarmJson);
             char url2[43];
             sprintf(url2, "/getTwitch.php?radiomac=%s", getMacAdress());
             httpGet(url2, parseTwitch);
-            isAlarmSyncing = 0;
+            isAlarmSyncing = false;
         }
         NutSleep(3000);
     }
@@ -305,7 +299,7 @@ int main(void)
 
     NutThreadCreate("BackgroundThread", StartupInit, NULL, 1024);
     NutThreadCreate("BackgroundThread", AlarmSync, NULL, 2500);
-    NutThreadCreate("BackgroundThread", NTPSync, NULL, 700);
+    //NutThreadCreate("BackgroundThread", NTPSync, NULL, 700);
     /** Quick fix for turning off the display after 10 seconds boot */
 
     RcInit();
@@ -344,7 +338,7 @@ int main(void)
 		//Check if a button is pressed
 		if (checkOffPressed() == 1){
 			X12RtcGetClock(&start);
-			running = 1;
+			running = true;
             LcdBackLight(LCD_BACKLIGHT_ON);
 		}
 
@@ -354,33 +348,36 @@ int main(void)
         }
 
 		//Check if background LED is on, and compare to timer
-		if (running == 1){
+		if (running == true){
 			if (timerStruct(start) >= 10 || running > 1){
-				running = 0;
+				running = false;
 				LcdBackLight(LCD_BACKLIGHT_OFF);
 			}
 		}
 
-        VOL = VOL2;
         if(KbGetKey() == KEY_DOWN)
         {
             NutSleep(150);
-             X12RtcGetClock(&timeCheck);
-            if(VOL > 8){
-                VOL -= 8;
-                VsSetVolume (127-VOL, 127-VOL);
-                displayVolume(VOL/8);
+            X12RtcGetClock(&timeCheck);
+
+            if (VS_volume > 0){
+                --VS_volume;
+                VS_volume = VS_volume % 17;
+                VsSetVolume((127 - (VS_volume * 8)) % 128);
             }
+            displayVolume(VS_volume);
         }
         else if(KbGetKey() == KEY_UP)
         {
             NutSleep(150);
-             X12RtcGetClock(&timeCheck);
-            if(VOL < 128) {
-                VOL += 8;
-                VsSetVolume(128-VOL, 128-VOL);
-                displayVolume(VOL/8);
+            X12RtcGetClock(&timeCheck);
+
+            if (VS_volume < 16){
+                ++VS_volume;
+                VS_volume = VS_volume % 17;
+                VsSetVolume((127 - (VS_volume * 8)) % 128);
             }
+            displayVolume(VS_volume);
         }
         else if(timerStruct(timeCheck) >= 5 && checkAlarms() == 1)
         {
@@ -408,7 +405,6 @@ int main(void)
             displayDate(1);
 		}
 
-        VOL2 = VOL;
         WatchDogRestart();
     }
     return(0);

+ 7 - 1
ntp.c

@@ -104,6 +104,7 @@ void NtpSync(void){
     /* Ophalen van pool.ntp.org */
     isSyncing = true;
     httpGet("/gettimezone.php", parsetimezone);
+    _daylight = 0;
     printf(TIME_ZONE);
     NutDelay(100);
     //puts("Tijd ophalen van pool.ntp.org (213.154.229.24)");
@@ -144,5 +145,10 @@ void NtpWriteTimeToEeprom(tm time_struct){
 }
 
 void setTimeZone(int timezone){
-    _timezone = -timezone * 3600;
+    TIME_ZONE = timezone;
+    _timezone = -1*timezone * 3600;
+}
+
+int getTimeZone(){
+    return TIME_ZONE;
 }

+ 4 - 1
ntp.h

@@ -5,7 +5,7 @@
 #ifndef _Ntp_H
 #define _Ntp_H
 
-typedef enum {false, true} bool;
+#include "typedefs.h"
 
 extern bool NtpIsSyncing(void);
 extern void NtpInit(void);
@@ -16,4 +16,7 @@ extern bool NtpTimeIsValid(void);
 void NtpCheckValidTime(void);
 void NtpWriteTimeToEeprom(tm);
 bool NtpCompareTime(tm, tm);
+
+void setTimeZone(int timezone);
+int getTimeZone();
 #endif /* _Ntp_H */

+ 26 - 0
typedefs.h

@@ -12,6 +12,22 @@
  * [PURPOSE]    global typedefs
  * ======================================================================== */
 
+/*
+ *  Copyright 20152016-TI2.3a6, 2016.
+ *
+ *  Project             : 20152016-TI2.3a6-Internet Radio
+ *  Module              : Type definitions
+ *  File name           : Typedefs.h
+ *  Revision            : 1.1
+ *  Creation Date       : 2016/03/04
+ *
+ *  Description         : Global type definitions for the SIR100/120
+ *                        firmware.
+ *
+ *  Changelog       1.1 : Add type definitions for TI2.3a6 software.
+ *                        - Add bool
+ */
+
 
 /*--------------------------------------------------------------------------*/
 /*  Include files                                                           */
@@ -29,6 +45,16 @@
 /*     Make sure that any modification made to this table are reflected by  */
 /*     the LcdErrorStirngs table! (an error is bad but showing the wrong    */
 /*     error is too much....) */
+
+// Additions based on version 1.1
+
+typedef enum {false, true} bool;
+
+
+
+
+
+
 typedef enum _TERRORCODE
 {
     OK = 0,                             /* All ok */