Jelajahi Sumber

[WIP] Add mp3stream and move volume functions into there.

Also: Declared and ifndef-precompiler statement for better debugging.
Jordy Sipkema 9 tahun lalu
induk
melakukan
18ce857d94
3 mengubah file dengan 118 tambahan dan 28 penghapusan
  1. 24 28
      main.c
  2. 75 0
      mp3stream.c
  3. 19 0
      mp3stream.h

+ 24 - 28
main.c

@@ -15,40 +15,44 @@
 
 #define LOG_MODULE  LOG_MAIN_MODULE
 
+#define _SUPPRESS_ALARMSYNC
+
 /*--------------------------------------------------------------------------*/
 /*  Include files                                                           */
 /*--------------------------------------------------------------------------*/
 #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>
 
-#include "displayHandler.h"
-#include "system.h"
-#include "portio.h"
+// Note: Please keep the includes in alphabetical order!    - Jordy
+#include "alarm.h"
+#include "contentparser.h"
 #include "display.h"
-#include "remcon.h"
+#include "displayHandler.h"
+#include "flash.h"
+#include "httpstream.h"
 #include "keyboard.h"
 #include "led.h"
 #include "log.h"
-#include "uart0driver.h"
+#include "mp3stream.h"
 #include "mmc.h"
-#include "watchdog.h"
-#include "flash.h"
-#include "spidrv.h"
 #include "network.h"
+#include "ntp.h"
+#include "portio.h"
+#include "remcon.h"
+#include "rtc.h"
+#include "spidrv.h"
+#include "system.h"
 #include "typedefs.h"
+#include "uart0driver.h"
+#include "watchdog.h"
 
 
-#include <time.h>
-#include "rtc.h"
-#include "alarm.h"
-#include "ntp.h"
-#include "httpstream.h"
-#include "contentparser.h"
 
 /*-------------------------------------------------------------------------*/
 /* local routines (prototyping)                                            */
@@ -186,8 +190,6 @@ bool isAlarmSyncing = false;
 bool initialized = false;
 bool running = false;
 
-u_char VS_volume = 7; //[0-15];
-
 /*-------------------------------------------------------------------------*/
 /* local variable definitions                                              */
 /*-------------------------------------------------------------------------*/
@@ -216,6 +218,7 @@ THREAD(AlarmSync, arg)
 
     NtpSync();
 
+    #ifndef _SUPPRESS_ALARMSYNC
     for(;;)
     {
         if((initialized == true) && (hasNetworkConnection() == true))
@@ -232,6 +235,7 @@ THREAD(AlarmSync, arg)
         }
         NutSleep(3000);
     }
+    #endif
     NutThreadExit();
 }
 
@@ -358,24 +362,16 @@ int main(void)
             NutSleep(150);
             X12RtcGetClock(&timeCheck);
 
-            if (VS_volume > 0){
-                --VS_volume;
-                VS_volume = VS_volume % 17;
-                VsSetVolume((127 - (VS_volume * 8)) % 128);
-            }
-            displayVolume(VS_volume);
+            u_char newVolume = volumeDown();
+            displayVolume((int)newVolume);
         }
         else if(KbGetKey() == KEY_UP)
         {
             NutSleep(150);
             X12RtcGetClock(&timeCheck);
 
-            if (VS_volume < 16){
-                ++VS_volume;
-                VS_volume = VS_volume % 17;
-                VsSetVolume((127 - (VS_volume * 8)) % 128);
-            }
-            displayVolume(VS_volume);
+            u_char newVolume = volumeUp();
+            displayVolume((int)newVolume);
         }
         else if(timerStruct(timeCheck) >= 5 && checkAlarms() == 1)
         {

+ 75 - 0
mp3stream.c

@@ -0,0 +1,75 @@
+//
+// Created by Jordy Sipkema on 28/03/16.
+//
+
+#include "mp3stream.h"
+
+#include <sys/thread.h>
+
+
+
+// Prototypes - Functions for internal use only! (They wont be visible outside this file!)
+THREAD(Mp3Player, args);
+void setVolume(void);
+
+// Variables
+static bool stream_stopped = false;
+static bool stream_isplaying = false;
+static u_char VS_volume = 7; //[0-15]; (Default volume = 7 (50%) )
+
+bool play(FILE *stream)
+{
+    NutThreadCreate("Mp3Player", Mp3Player, stream, 512);
+    printf("Mp3Player thread created. Device should start playing the stream.\n");
+
+    return true;
+}
+
+u_char volumeUp(void)
+{
+    if (VS_volume >= 16)
+        return VS_volume;
+
+    //else:
+    ++VS_volume;
+    VS_volume = VS_volume % 17;
+
+    setVolume();
+
+    return VS_volume;
+}
+
+u_char volumeDown(void)
+{
+    if (VS_volume <= 0)
+        return VS_volume;
+
+    //else:
+    --VS_volume;
+    VS_volume = VS_volume % 17;
+    setVolume();
+
+    return VS_volume;
+}
+
+void setVolume(void){
+    VsSetVolume((127 - (VS_volume * 8)) % 128);
+}
+
+
+THREAD(Mp3Player, args)
+{
+    FILE *stream = (FILE *)args;
+    size_t rbytes = 0;
+    char *mp3buf;
+    int result = false;
+    int nrBytesRead = 0;
+    unsigned char iflag;
+
+    //Whatevahhh
+}
+
+void killPlayerThread(void)
+{
+    stream_stopped = true;
+}

+ 19 - 0
mp3stream.h

@@ -0,0 +1,19 @@
+//
+// Created by Jordy Sipkema on 28/03/16.
+//
+
+#ifndef MUTLI_OS_BUILD_MP3STREAM_H
+#define MUTLI_OS_BUILD_MP3STREAM_H
+
+#include <stdio.h>
+#include <string.h>
+
+#include "typedefs.h"
+
+bool play(FILE *stream);
+
+u_char volumeUp(void);
+u_char volumeDown(void);
+
+
+#endif //MUTLI_OS_BUILD_MP3STREAM_H