Răsfoiți Sursa

Merge pull request #56 from jancoow/metadata

Display current playing track on the display.
Jordy Sipkema 9 ani în urmă
părinte
comite
95247765e5
6 a modificat fișierele cu 66 adăugiri și 14 ștergeri
  1. 4 2
      contentparser.c
  2. 18 8
      displayHandler.c
  3. 10 2
      displayHandler.h
  4. 3 1
      main.c
  5. 29 0
      mp3stream.c
  6. 2 1
      mp3stream.h

+ 4 - 2
contentparser.c

@@ -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();

+ 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;
@@ -160,9 +162,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

+ 3 - 1
main.c

@@ -307,7 +307,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