Big Mouth Billy Bass player that takes raw wavefiles and decision list text files from an SD card

Dependencies:   SDFileSystem mbed BillyBass

Revision:
7:ce27f959813b
Parent:
6:e90a12ca056f
Child:
8:1dd2bb31dec6
--- a/main.cpp	Sat Jun 15 04:08:25 2013 +0000
+++ b/main.cpp	Mon Jun 17 22:18:12 2013 +0000
@@ -1,4 +1,5 @@
 #include "billybass.hpp"
+#include "SDFileSystem.h"
 #include "song.hpp"
 #include "player.hpp"
 #include "action.hpp"
@@ -7,17 +8,15 @@
 // Power GND  J9/14
 // Vin (6V)   J9/16
 
-// Digital:
-DigitalOut tail(PTA13);                // J3/2
-DigitalOut mouth(PTC12);               // J3/1
-DigitalOut head(PTC13);                // J3/3
+//                 tailPin,  mouthPin, bodyPin
+BillyBass testBass(LED_RED, LED_GREEN, LED_BLUE);
+
+//               tailPin, mouthPin, bodyPin
+//                  J3/2,  J3/1, J3/3
+BillyBass realBass(PTA13, PTC12, PTC13);
 
 DigitalIn pushbutton(PTD5); // J3/4
 
-PwmOut redLED(LED_RED);
-PwmOut greenLED(LED_GREEN);
-PwmOut blueLED(LED_BLUE);
-
 // Analog:
 // GND   J3/14
 // VrefH J3/16
@@ -28,44 +27,33 @@
 // PTD3 D12 - Used for MISO of SPI
 // PTC5 J1/9  Used for SCLK of SPI
 
-//              MOSI, MISO, SCLK, CS, name
+//              MOSI, MISO, SCLK,   CS, name
 SDFileSystem sd(PTD2, PTD3, PTC5, PTD0, SD_NAME);
+
 Serial pc(USBTX, USBRX);
 
-std::list<Song> songs;
-
 int main()
 {
     SongPlayer player;
     pc.baud(SERIAL_BAUD);
-    redLED = 1.0;
-    greenLED = 1.0;
-    blueLED = 1.0;
+
+    pc.printf("*** REBOOT ***\r\n");
 
     // read the directory
-    DIR *bassDir = opendir(BASS_DIRECTORY);
-    if (bassDir)
-    {
-        while (dirent *dir = bassDir->readdir())
-        {
-            char fn[ MAX_FILENAME_LENGTH ];
-            snprintf(fn, sizeof(fn), "%s/%s", BASS_DIRECTORY, dir->d_name);
-            pc.printf(fn);
-            // if this is a valid wave filename
-            if (Song::isValidWaveFileName(fn))
-            {
-                pc.printf("\tvalid\r\n");
-                player.playEntireSong(fn);
-                pc.printf("Song time: %f\r\n", player.timeInSong);
-            }
-            else
-            {
-                pc.printf("\tnot valid\r\n");
-            }
+    DIR *bassDir = 0;
+    while (!bassDir) {
+        if ((bassDir = opendir(BASS_DIRECTORY)) != 0)
+            break;
+        pc.printf("Error opening " BASS_DIRECTORY "\r\n");
+        wait(1.0);
+    }
+
+    if (!Song::readAllSongs(bassDir)) {
+        pc.printf("Found no songs!\r\n");
+    } else {
+        for (std::list<Song *>::const_iterator song_it = Song::songs.begin(); song_it != Song::songs.end(); song_it++) {
+            Song *song = *song_it;
+            song->print(pc);
         }
     }
-    else
-    {
-        pc.printf("Error opening " BASS_DIRECTORY);
-    }
 }