Browse Source

Display current playing track on the display.

As part of the individual assignment.
Jordy Sipkema 9 years ago
parent
commit
14b73f42b2
4 changed files with 50 additions and 10 deletions
  1. 18 8
      displayHandler.c
  2. 10 2
      displayHandler.h
  3. 21 0
      mp3stream.c
  4. 1 0
      mp3stream.h

+ 18 - 8
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();
     }
 }
 
@@ -71,13 +73,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 +89,7 @@ void displayDateTime(void){
 
 void displayAlarm(char idx)
 {
-    if(idx == -1){
+    if (idx == -1){
         currentViewDisplay = DISPLAY_DateTime;
     }
 	int i;
@@ -179,9 +181,17 @@ void displayTwitter(char* text)
 }
 
 void displayTwitch(char name[], char title[], char game[])
-    {
+{
     ClearLcd();
     LcdArrayLineOne(name, strlen(name));
     LcdArrayLineTwo("Streaming", 9);
     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);
+}

+ 10 - 2
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);
@@ -20,8 +27,9 @@ void refreshScreen(void);
 
 void displayDateTime(void);
 void displayAlarm(char idx);
-void displayVolume();
+void displayVolume(void);
 void displayTwitter(char text[]);
 void displayTwitch(char name[], char title[], char game[]);
+void displayStreamInfo(void);
 
 #endif //MUTLI_OS_BUILD_DISPLAYHANDLER_H

+ 21 - 0
mp3stream.c

@@ -35,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;
@@ -162,6 +163,10 @@ u_char getVolume(void){
     return VS_volume;
 }
 
+char* getStreamInfo(void){
+    return VS_StreamInfo;
+}
+
 
 void killPlayerThread(void)
 {
@@ -308,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);
@@ -334,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;

+ 1 - 0
mp3stream.h

@@ -22,5 +22,6 @@ 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