Browse Source

Merge branch 'developer' into Twitch

Conflicts:
	displayHandler.c
Aareschluchtje 9 năm trước cách đây
mục cha
commit
8df650b3be
7 tập tin đã thay đổi với 74 bổ sung17 xóa
  1. 3 2
      alarm.c
  2. 7 5
      contentparser.c
  3. 21 7
      displayHandler.c
  4. 9 1
      displayHandler.h
  5. 3 1
      main.c
  6. 29 0
      mp3stream.c
  7. 2 1
      mp3stream.h

+ 3 - 2
alarm.c

@@ -160,6 +160,7 @@ void setState(int idx){
 	
 	//Check if alarm has to snooze
 	if (alarm[idx].state == 1 && compareTime(ct, snooze[idx].snoozeTime) >= 1 && alarm[idx].state < 3){
+		printf("Alarm stopt nu!");
 		alarm[idx].state = 2;
 		snooze[idx].snoozeTime = ct;
 		AddSnoozeMinutes(idx, alarm[idx].snooze);
@@ -168,8 +169,9 @@ void setState(int idx){
 	}
 	
 	if (alarm[idx].state == 2 && compareTime(ct, snooze[idx].snoozeTime) >= 1 && alarm[idx].state < 3){
+		AddSnoozeMinutes(idx, 1);
+		printf("Alarm komt nu uit snooze!!");
 		if(alarm[idx].state != 1){
-			printf("Alarm komt nu uit snooze!!");
 			bool success = connectToStream(alarm[idx].ip, alarm[idx].port, alarm[idx].url);
 			if (success == true){
 				play();
@@ -178,7 +180,6 @@ void setState(int idx){
 			}
 			alarm[idx].state = 1;
 		}
-		AddSnoozeMinutes(idx, 1);
 	}
 	
 }

+ 7 - 5
contentparser.c

@@ -47,8 +47,8 @@ void parseAlarmJson(char* content){
         u_short port = 0;
         char url[24];
         char ip[24];
-        char name[16];
-		char str2[16];
+        char name[17];
+        char str2[16];
         char st = -1;
         char oo = -1;
         memset(url, 0, 24);
@@ -77,7 +77,7 @@ void parseAlarmJson(char* content){
             }else if (jsoneq(content, &token[i], "url") == 0) {
                 getStringToken(content, &token[i + 1], url, 24);
             }else if (jsoneq(content, &token[i], "name") == 0) {
-                getStringToken(content, &token[i + 1], name, 16);
+                getStringToken(content, &token[i + 1], name, 18);
             }else if (jsoneq(content, &token[i], "oo") == 0) {
                 oo = getIntegerToken(content, &token[i + 1]);
             }else if (jsoneq(content, &token[i], "st") == 0) {
@@ -160,8 +160,10 @@ void parseCommandQue(char* content){
         if (jsoneq(content, &token[i], "command") == 0) {
             if(jsoneq(content, &token[i + 1], "volume") == 0){
                 char vol = getIntegerToken(content, &token[i + 3]);
-                vol = 128 - ((vol * 128) / 100);
-                VsSetVolume(vol, vol);
+                printf("Updating volume: \n");
+                setVolumeManual(vol);
+                //vol = 128 - ((vol * 128) / 100);
+                //VsSetVolume(vol, vol);
                 i += 3;
             }else if(jsoneq(content, &token[i + 1], "stopstream") == 0){
                 killPlayerThread();

+ 21 - 7
displayHandler.c

@@ -39,14 +39,16 @@ void refreshScreen(){
 
     if(currentViewDisplay == DISPLAY_DateTime){
         displayDateTime();
-    }else if(currentViewDisplay == DISPLAY_Volume){
+    } else if(currentViewDisplay == DISPLAY_Volume){
         displayVolume();
-    }else if(currentViewDisplay == DISPLAY_Alarm){
+    } else if(currentViewDisplay == DISPLAY_Alarm){
         displayAlarm(getRunningAlarmID());
-    }else if(currentViewDisplay == DISPLAY_Twitch){
+    } else if(currentViewDisplay == DISPLAY_Twitch){
         displayTwitch(data.name, data.title, data.game);
-    }else if(currentViewDisplay == DISPLAY_Twitter){
+    } else if(currentViewDisplay == DISPLAY_Twitter){
         displayTwitter(TweetFeed.tweet);
+    } else if(currentViewDisplay == DISPLAY_StreamInfo){
+        displayStreamInfo();
     }
 }
 
@@ -57,6 +59,10 @@ long timerStruct(struct _tm s){
     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;
 }
 
@@ -71,13 +77,13 @@ void displayDateTime(void){
     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 {
+    } else {
         sprintf(str1, "    ??:??:??    ");
         sprintf(str2, "    ??:??:??    ");
     }
     if (NtpIsSyncing()) {
         str2[1] = 'S';
-    }else if(NetworkIsReceiving()){
+    } else if(NetworkIsReceiving()){
         str2[1] = 'N';
     }
 
@@ -87,7 +93,7 @@ void displayDateTime(void){
 
 void displayAlarm(char idx)
 {
-    if(idx == -1){
+    if (idx == -1){
         currentViewDisplay = DISPLAY_DateTime;
     }
 	int i;
@@ -184,3 +190,11 @@ void displayTwitch(char name[], char title[], char game[]) {
     }
     LcdBackLight(LCD_BACKLIGHT_ON);
 }
+
+void displayStreamInfo(){
+    LcdBackLight(LCD_BACKLIGHT_ON);
+
+    (*write_display_ptr[0])("  Station Info  ", 17);
+    (*write_display_ptr[1])("                ", 17);
+    (*write_display_ptr[1])(getStreamInfo(), 17);
+}

+ 9 - 1
displayHandler.h

@@ -11,7 +11,14 @@
 #define MONTH_OFFSET 1
 #define YEAR_OFFSET 1900
 
-typedef enum {DISPLAY_DateTime, DISPLAY_Alarm, DISPLAY_Volume, DISPLAY_Twitch, DISPLAY_Twitter} viewDisplays;
+typedef enum {
+    DISPLAY_DateTime,
+    DISPLAY_Alarm,
+    DISPLAY_Volume,
+    DISPLAY_Twitch,
+    DISPLAY_Twitter,
+    DISPLAY_StreamInfo,
+} viewDisplays;
 
 long timerStruct(struct _tm s);
 void setCurrentDisplay(viewDisplays d, u_long dt);
@@ -23,5 +30,6 @@ void displayAlarm(char idx);
 void displayVolume(void);
 void displayTwitter(char text[]);
 void displayTwitch(char name[], char title[], char game[]);
+void displayStreamInfo(void);
 
 #endif //MUTLI_OS_BUILD_DISPLAYHANDLER_H

+ 3 - 1
main.c

@@ -316,7 +316,9 @@ int main(void)
 
     X12RtcGetClock(&timeCheck);
 
- 	for (;;)
+    printf("Welcome to Saltyradio.\nI'm using mac address:  %s\n\n\n", getMacAdress());
+
+    for (;;)
     {
         //Key detecten
         if(KbGetKey() != KEY_UNDEFINED){

+ 29 - 0
mp3stream.c

@@ -10,6 +10,7 @@
 #include <sys/thread.h>
 #include <sys/timer.h>
 
+#include "displayHandler.h"
 #include "vs10xx.h"
 
 #define OK              1
@@ -34,6 +35,7 @@ static bool stream_stopped = false;
 
 static u_char VS_volume = DEFAULT_VOLUME; //[0-16]; (Default volume = 7/16
 static u_long metaInt = 0;
+static char VS_StreamInfo[17] = "    No  info    ";
 
 FILE *stream;
 TCPSOCKET *socket;
@@ -144,6 +146,13 @@ void volumeDown(void)
     setVolume();
 }
 
+void setVolumeManual(char level){
+    u_char v_level = level * 16 / 100;
+    VS_volume = v_level % 17;
+    setVolume();
+    setCurrentDisplay(DISPLAY_Volume, 5);
+}
+
 void setVolume(void){
     u_char volumeToSet = (128 - (VS_volume * 8)) % 129;
     VsSetVolume(volumeToSet, volumeToSet);
@@ -154,6 +163,10 @@ u_char getVolume(void){
     return VS_volume;
 }
 
+char* getStreamInfo(void){
+    return VS_StreamInfo;
+}
+
 
 void killPlayerThread(void)
 {
@@ -300,6 +313,7 @@ int ProcessStreamMetaData(FILE *stream)
     if(got != 1) {
         return -1;
     }
+
     if (blks) {
         if (blks > 32) {
             printf("Error: Metadata too large, %u blocks\n", blks);
@@ -326,7 +340,22 @@ int ProcessStreamMetaData(FILE *stream)
             mbuf[rc] = 0;
         }
 
+        printf("================================================ Func: ProcessStreamMetaData\n");
         printf("\nMeta='%s'\n", mbuf);
+
+        char* found = strstr(mbuf, "StreamTitle=");
+        if (found != 0){
+            char* first = strstr(mbuf, "'") + 1;
+            char* last = strstr(first, "'");
+            size_t diff = last - first;
+
+            if (diff > 16){ diff = 16; }
+            strncpy(VS_StreamInfo, first, diff);
+            VS_StreamInfo[16] = '\0';
+            printf("Found: %s\n\n", VS_StreamInfo);
+        }
+
+        setCurrentDisplay(DISPLAY_StreamInfo, 6);
         free(mbuf);
     }
     return 0;

+ 2 - 1
mp3stream.h

@@ -19,8 +19,9 @@ void killPlayerThread(void);
 
 void volumeUp(void);
 void volumeDown(void);
+void setVolumeManual(char);
 void setVolume(void); // Do not use this one, this is invoked by volumeUp/Down
 u_char getVolume(void);
-
+char* getStreamInfo(void);
 
 #endif //MUTLI_OS_BUILD_MP3STREAM_H