Changed the playing code to use Playlists managed by a PlaylistManager. This allows you to have randomized playlists and stuff. Also, you can now access special functions via the contents of RFID tags. See the README for a list of available modes.
This commit is contained in:
@ -3,14 +3,19 @@
|
||||
#include <Arduino.h>
|
||||
#include "config.h"
|
||||
#include "player.h"
|
||||
#include "playlist.h"
|
||||
#include "playlist_manager.h"
|
||||
#include "mqtt_client.h"
|
||||
#include <MFRC522.h>
|
||||
|
||||
enum ControllerState { NORMAL, LOCKING, LOCKED };
|
||||
|
||||
class Controller {
|
||||
private:
|
||||
MFRC522* _rfid;
|
||||
SPIMaster* _spi;
|
||||
MQTTClient* _mqtt_client;
|
||||
PlaylistManager* _pm;
|
||||
ControllerState _state = NORMAL;
|
||||
bool _rfid_enabled = true;
|
||||
void _check_rfid();
|
||||
void _check_serial();
|
||||
@ -33,7 +38,7 @@ private:
|
||||
unsigned long _last_mqtt_report_at = 0;
|
||||
void _send_mqtt_report();
|
||||
public:
|
||||
Controller(Player* p, SPIMaster* s);
|
||||
Controller(Player* p, PlaylistManager* pm);
|
||||
void set_mqtt_client(MQTTClient* m);
|
||||
String get_status_json();
|
||||
void loop();
|
||||
|
@ -2,9 +2,8 @@
|
||||
#include "config.h"
|
||||
#include <SPI.h>
|
||||
#include <SD.h>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include "spi_master.h"
|
||||
#include "playlist.h"
|
||||
|
||||
#define SCI_MODE 0x00
|
||||
#define SCI_STATUS 0x01
|
||||
@ -38,13 +37,7 @@
|
||||
class Player {
|
||||
private:
|
||||
enum state { uninitialized, idle, playing, stopping,
|
||||
system_sound_while_playing, system_sound_while_stopped,
|
||||
sleeping, recording };
|
||||
struct album_state {
|
||||
uint8_t index;
|
||||
uint32_t position;
|
||||
};
|
||||
void _check_system_sound(String filename);
|
||||
void _reset();
|
||||
void _init();
|
||||
void _wait();
|
||||
@ -59,11 +52,8 @@ private:
|
||||
void _flush_and_cancel();
|
||||
int8_t _get_endbyte();
|
||||
void _flush(uint count, int8_t fill_byte);
|
||||
void _set_last_track(const char* album, uint8_t track, uint32_t position);
|
||||
std::map<String, album_state> _last_tracks;
|
||||
String _random_album();
|
||||
void _play_file(String filename, uint32_t offset);
|
||||
uint32_t _id3_tag_offset(File f);
|
||||
void _play_file(String filename, uint32_t offset);
|
||||
void _finish_playing();
|
||||
void _finish_stopping(bool turn_speaker_off);
|
||||
void _mute();
|
||||
@ -74,21 +64,15 @@ private:
|
||||
void _patch_adpcm();
|
||||
void _speaker_off();
|
||||
void _speaker_on();
|
||||
void _fill_id_to_folder_map();
|
||||
String _foldername_for_id(String id);
|
||||
|
||||
SPISettings _spi_settings_slow = SPISettings(250000, MSBFIRST, SPI_MODE0);
|
||||
SPISettings _spi_settings_fast = SPISettings(4000000, MSBFIRST, SPI_MODE0);
|
||||
SPISettings* _spi_settings = &_spi_settings_slow;
|
||||
|
||||
std::list<String> _files_in_dir(String dir);
|
||||
String _find_album_dir(String album);
|
||||
File _file;
|
||||
uint8_t _buffer[32];
|
||||
String _playing_album;
|
||||
uint8_t _playing_index;
|
||||
uint8_t _playing_album_songs;
|
||||
uint32_t _current_play_position;
|
||||
Playlist* _current_playlist;
|
||||
uint _refills;
|
||||
uint8_t _volume;
|
||||
uint16_t _stop_delay;
|
||||
@ -96,26 +80,17 @@ private:
|
||||
SPIMaster* _spi;
|
||||
unsigned long _stopped_at;
|
||||
public:
|
||||
std::map<String, String> id_to_folder_map;
|
||||
|
||||
Player(SPIMaster* s);
|
||||
void vol_up();
|
||||
void vol_down();
|
||||
void track_next();
|
||||
void track_prev();
|
||||
bool is_playing();
|
||||
|
||||
bool play_id(String id);
|
||||
bool play_album(String album);
|
||||
void play_random_album();
|
||||
bool play_song(String album, uint8_t song_index, uint32_t offset=0);
|
||||
void play_system_sound(String filename);
|
||||
bool play();
|
||||
bool play(Playlist* p);
|
||||
void stop(bool turn_speaker_off=true);
|
||||
bool loop();
|
||||
void set_volume(uint8_t vol, bool save = true);
|
||||
std::list<String> ls(String path, bool withFiles=true, bool withDirs=true, bool withHidden=false);
|
||||
String album() { return _playing_album; }
|
||||
uint8_t track() { return _playing_index; }
|
||||
uint32_t position() { return _current_play_position; }
|
||||
uint8_t volume() { return _volume; }
|
||||
};
|
||||
|
25
include/playlist.h
Normal file
25
include/playlist.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
#include <vector>
|
||||
|
||||
class Playlist {
|
||||
private:
|
||||
uint32_t _position = 0;
|
||||
uint32_t _current_track = 0;
|
||||
bool _shuffled = false;
|
||||
std::vector<String> _files;
|
||||
public:
|
||||
Playlist(String path);
|
||||
bool has_track_next();
|
||||
bool has_track_prev();
|
||||
bool track_next();
|
||||
bool track_prev();
|
||||
void track_restart();
|
||||
void reset();
|
||||
bool is_empty();
|
||||
String get_current_file();
|
||||
uint32_t get_position();
|
||||
void set_position(uint32_t p);
|
||||
void shuffle(uint8_t random_offset=0);
|
||||
bool is_fresh();
|
||||
};
|
14
include/playlist_manager.h
Normal file
14
include/playlist_manager.h
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include "playlist.h"
|
||||
|
||||
class PlaylistManager {
|
||||
private:
|
||||
std::map<String, String> _map;
|
||||
std::map<String, Playlist*> _playlists;
|
||||
public:
|
||||
PlaylistManager();
|
||||
Playlist* get_playlist_for_id(String id);
|
||||
void dump_ids();
|
||||
};
|
@ -6,7 +6,7 @@
|
||||
|
||||
class SPIMaster {
|
||||
public:
|
||||
SPIMaster() {
|
||||
static void init() {
|
||||
PIN_SD_CS_SETUP();
|
||||
PIN_VS1053_XCS_SETUP();
|
||||
PIN_VS1053_XDCS_SETUP();
|
||||
@ -14,27 +14,27 @@ public:
|
||||
disable();
|
||||
}
|
||||
|
||||
void select_sd(bool enabled=true) {
|
||||
static void select_sd(bool enabled=true) {
|
||||
PIN_SD_CS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void select_vs1053_xcs(bool enabled=true) {
|
||||
static void select_vs1053_xcs(bool enabled=true) {
|
||||
PIN_VS1053_XCS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void select_vs1053_xdcs(bool enabled=true) {
|
||||
static void select_vs1053_xdcs(bool enabled=true) {
|
||||
PIN_VS1053_XDCS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void select_rc522(bool enabled=true) {
|
||||
static void select_rc522(bool enabled=true) {
|
||||
PIN_RC522_CS(enabled ? LOW : HIGH);
|
||||
delayMicroseconds(MCP_SPI_SETTING_DELAY);
|
||||
}
|
||||
|
||||
void disable() {
|
||||
static void disable() {
|
||||
PIN_SD_CS(HIGH);
|
||||
PIN_VS1053_XCS(HIGH);
|
||||
PIN_VS1053_XDCS(HIGH);
|
||||
|
Reference in New Issue
Block a user