Commit 3f68084b authored by Flax's avatar Flax

Added playlist function.

parent 75c57e19
......@@ -43,7 +43,7 @@
#define ACCEL_THRES_GYX 1000 // Detection threshold for X axis acceleration
#define ACCEL_THRES_GYY 1000 // Detection threshold for Y axis acceleration
#define ACCEL_THRES_GYZ 1000 // Detection threshold for Z axis acceleration
#define NUMBER_SONGS 2 // Number of different songs to be played
#define PLAYLIST_LENGTH 4 // Number of songs in the playlist
// Typedefs
// Main state machine : start actions
......@@ -71,8 +71,28 @@ typedef enum
STM_DEBOUNCE_DEBOUNCE_1,
} tStateMachineDebounce;
typedef struct
{
uint8_t song_index_u8; // Index of the song in the device /!\ counts from 0
uint8_t cycles_number_u8; // Number of times the song must be played before switching to the next
} tSongItem;
// Constant variables
/* Indifference table for songs cycles
* Contains the indexes of the songs to be played and the number of times each one must be played.
* Contains couples {index of the song in the MP3 device memory, number of times the song must be played},
* Playlist cycles from first element to last and loops.
* Don't forget to update PLAYLIST_LENGTH define.
*/
const tSongItem cPlaylistIndif_TA[PLAYLIST_LENGTH] =
{
{0, 2},
{2, 3},
{1, 1},
{3, 2},
};
// Local variables
String inputString = ""; // a String to hold incoming data
bool stringComplete = false; // whether the string is complete
......@@ -86,6 +106,9 @@ const int MPU=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
bool accel_detect;
uint8_t song_cycles_cnt_u8; // Counts the number of times the current song has been played
uint8_t song_playing_current_u8; // Holds the index of the playlist song actually being played
// State machines states
tStateMachine stmState;
tStateMachineDebounce stmDebounceState;
......@@ -118,7 +141,7 @@ void setup() {
// MP3 module ground switch command - See hardware constants for pin definition - Output push-pull
pinMode(PIN_GROUND_SWITCH, OUTPUT);
//Intianlise variable, do not define constants value here
//Initialise variables, do not define constants value here
play_blank_delay = 0;
mp3_reset_delay = 0;
stmState = STM_INIT;
......@@ -127,6 +150,8 @@ void setup() {
input_position_sensor = LOW;
input_touch_sensor1 = LOW;
input_touch_sensor2 = LOW;
song_cycles_cnt_u8 = 0;
song_playing_current_u8 = 0;
#ifdef SENSOR_ACCELEROMETER
// Accelerometer setup
......@@ -315,8 +340,20 @@ void loop() {
break;
case STM_PLAY:
//WritePlay();
WritePlaySong(1);
WritePlaySong(cPlaylistIndif_TA[song_playing_current_u8].song_index_u8 + 1U); // Play the current song
song_cycles_cnt_u8++; // Increment cycles counter
if (song_cycles_cnt_u8 >= cPlaylistIndif_TA[song_playing_current_u8].cycles_number_u8)
{ // Check cycles counter overflow
song_cycles_cnt_u8 = 0; // Reset the cycles counter
song_playing_current_u8++; // Increment the playlist counter
}
if (song_playing_current_u8 >= PLAYLIST_LENGTH)
{ // Check playlist song counter overflow
song_playing_current_u8 = 0;
}
play_blank_delay = millis();
stmState = STM_BLANK;
break;
......@@ -426,15 +463,6 @@ void WritePlaySong (uint16_t index)
Serial.write((int)buffer_u8A[3]); // Song number high byte
Serial.write((int)buffer_u8A[4]); // Song number low byte
Serial.write((int)crc_u8); // CRC
/*
Serial.write(170); // 0xAA
Serial.write(7); // 0x07
Serial.write(2); // 0x02
Serial.write(0); // Song number high byte
Serial.write(1); // Song number low byte
Serial.write(180); // CRC
*/
}
uint8_t CrcCalculate (uint8_t *buff, uint8_t size)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment