Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: emerrill/RBC-2011
base: fddba2938e
...
head fork: emerrill/RBC-2011
compare: a65293115f
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 236 additions and 0 deletions.
  1. +26 −0 TimeRadio/TimeRadio.pde
  2. +36 −0 TimeRadio/tracks.h
  3. +174 −0 TimeRadio/tracks.pde
View
26 TimeRadio/TimeRadio.pde
@@ -5,6 +5,8 @@
#include <Servo.h>
#include <RogueMP3.h>
#include <NewSoftSerial.h>
+#include "tracks.h"
+
#define FAIL 0
#define SUCCESS 1
@@ -41,6 +43,8 @@
#define POT_1_ADDY 0x28
#define POT_1_ADDY 0x29
+DateCode track_table[TRACK_TABLE_MAX_SZ];
+int track_table_sz;
#define MAX_ENCODER 2000
#define MIN_ENCODER 0
@@ -80,6 +84,7 @@ void setup() {
//Servo
servo.attach(SERVO_PIN);
servo.writeMicroseconds(1500); //No movement
+ Serial.println("start");
//FM
fm_init();
@@ -89,9 +94,17 @@ void setup() {
mp3_init();
+
+ tracks_init();
+ Serial.print(track_table_sz);
+ Serial.println(" tracks on the card");
}
+int trackIdx=0;
+
void loop() {
+ char filename[FILE_NAME_MAX_SZ];
+
delay(500);
Serial.print("Encoder: ");
Serial.println(encoderPos);
@@ -100,6 +113,19 @@ void loop() {
Serial.print("Free RAM: ");
Serial.println(get_free_memory());
+
+ Serial.print("play file: ");
+ track_table[trackIdx].get_filename(filename);
+ Serial.println(filename);
+
+ play_track_idx(trackIdx);
+
+ delay(5000);
+
+ trackIdx++;
+ trackIdx %= track_table_sz;
+
+
}
View
36 TimeRadio/tracks.h
@@ -0,0 +1,36 @@
+#ifndef _TRACKS_H_
+#define _TRACKS_H_
+
+#define TRACK_TABLE_MAX_SZ 128
+#define FILE_NAME_MAX_SZ 16
+
+class DateCode
+{
+ public:
+
+ union
+ {
+ long whole;
+ struct
+ {
+ int low_word;
+ int high_word;
+ };
+ } value;
+
+ DateCode();
+ DateCode(long);
+ DateCode(int, int);
+ int set_str(char *);
+ void set(int, int);
+ int get_filename(char *);
+ bool operator>(DateCode);
+ bool operator<(DateCode);
+ long operator-(DateCode);
+ int epoch(void);
+ int year(void);
+};
+
+
+#endif
+
View
174 TimeRadio/tracks.pde
@@ -0,0 +1,174 @@
+#include <NewSoftSerial.h>
+#include <RogueMP3.h>
+#include <limits.h>
+#include "tracks.h"
+
+#if 1
+#define DEBUG_UMP3(x) Serial.println((x))
+#else
+#define DEBUG_UMP3(x) ;
+#endif
+
+
+ DateCode::DateCode(){};
+
+ DateCode::DateCode(long v)
+ {
+ this->value.whole = v;
+ }
+
+ DateCode::DateCode(int y, int e)
+ {
+ this->set(y, e);
+ }
+
+ int DateCode::set_str(char * str)
+ {
+ int year;
+ int epoch;
+
+ sscanf(str, "%de%d.MP3", &year, &epoch);
+
+ this->set(year, epoch);
+ }
+
+ void DateCode::set(int year, int epoch)
+ {
+ if(year < 0)
+ epoch = -epoch;
+
+ this->value.high_word = epoch;
+ this->value.low_word = year;
+ }
+
+ int DateCode::get_filename(char * str)
+ {
+ int year, epoch;
+
+ year = this->value.low_word;
+ epoch = this->value.high_word;
+ epoch = abs(epoch);
+
+ return sprintf(str, "%de%02d.MP3", year, epoch);
+ }
+
+ bool DateCode::operator>(DateCode other)
+ {
+ return this->value.whole > other.value.whole;
+ }
+
+ bool DateCode::operator<(DateCode other)
+ {
+ return this->value.whole < other.value.whole;
+ }
+
+ long DateCode::operator-(DateCode other)
+ {
+ return this->value.whole - other.value.whole;
+ }
+
+ int DateCode::epoch()
+ {
+ return abs(this->value.high_word);
+ }
+
+ int DateCode::year()
+ {
+ return this->value.low_word;
+ }
+
+
+
+
+NewSoftSerial ump3_serial(RX2_PIN, TX2_PIN);
+RogueMP3 ump3(ump3_serial);
+
+
+#define LINE_BUF_SZ 64
+
+
+//
+// tracks_init
+//
+// Initialize the interface to the mp3 board.
+// Also populates the track table.
+//
+int tracks_init(void)
+{
+ int idx;
+ char buf[LINE_BUF_SZ];
+ char file_name[FILE_NAME_MAX_SZ];
+
+ DEBUG_UMP3("tracks_init");
+
+ ump3_serial.begin(9600);
+ idx = ump3.sync();
+ DEBUG_UMP3(String("ump3.sync() ") + String(idx));
+ ump3.stop();
+
+ track_table_sz = 0;
+ idx = 0;
+ ump3_serial.print("FC L /\r");
+
+ while(ump3_serial.peek() != '>')
+ {
+ idx = 0;
+
+ // read the whole line
+ do
+ {
+ while(!ump3_serial.available());
+ buf[idx++] = ump3_serial.read();
+ DEBUG_UMP3(String(idx) + String(": ") + String(buf[idx-1]) +
+ String(" ") + String((int)buf[idx-1]));
+ } while(buf[idx-1] != 0x0D);
+
+ // replace the trailing CR with a null
+ buf[idx-1] = 0;
+
+ DEBUG_UMP3(String("uMP3 rx: ") + String(buf));
+
+ if( 1 == sscanf(buf, "%*d %s", &file_name))
+ {
+ track_table[track_table_sz++].set_str(file_name);
+ }
+
+ }
+ ump3_serial.read();
+
+ return 0;
+}
+
+
+
+int find_track_idx(DateCode target)
+{
+ int idx;
+ int closest_idx = 0;
+ long diff;
+ long closest_diff = LONG_MAX;
+
+ // this is pretty dumb, i know.
+ // but can we be sure that the table is sorted?
+ for(idx=0; idx<track_table_sz; idx++)
+ {
+ diff = track_table[idx] - target;
+ if(abs(diff) < abs(closest_diff))
+ {
+ closest_idx = idx;
+ closest_diff = diff;
+ }
+ }
+
+ return idx;
+}
+
+void play_track_idx(int idx)
+{
+ char file_name[FILE_NAME_MAX_SZ];
+ track_table[idx].get_filename(file_name);
+
+ ump3_serial.print("PC F /");
+ ump3_serial.print(file_name);
+ ump3_serial.print("\n");
+}

No commit comments for this range

Something went wrong with that request. Please try again.