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:
60
src/playlist_manager.cpp
Normal file
60
src/playlist_manager.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include "playlist_manager.h"
|
||||
#include <SD.h>
|
||||
#include "spi_master.h"
|
||||
|
||||
PlaylistManager::PlaylistManager() {
|
||||
SPIMaster::select_sd();
|
||||
File root = SD.open("/");
|
||||
File entry;
|
||||
while (entry = root.openNextFile()) {
|
||||
String foldername = entry.name();
|
||||
// Remove trailing slash
|
||||
foldername.remove(foldername.length());
|
||||
TRACE("Looking at %s...", foldername.c_str());
|
||||
if (!entry.isDirectory() || foldername.startsWith("/.")) continue;
|
||||
if (!SD.exists(foldername + "/ids.txt")) {
|
||||
TRACE("No ids.txt -> ignoring\n");
|
||||
continue;
|
||||
}
|
||||
File f = SD.open(foldername + "/ids.txt");
|
||||
String buffer = "";
|
||||
if (f.available()) {
|
||||
do {
|
||||
char c = f.read();
|
||||
if (!f.available() && c!='\n' && c!='\r') {
|
||||
buffer.concat(c);
|
||||
c='\n';
|
||||
}
|
||||
|
||||
if (c=='\n' || c=='\r') {
|
||||
if (buffer.length() > 0) {
|
||||
_map[buffer] = foldername;
|
||||
TRACE(" ID %s", buffer.c_str());
|
||||
buffer="";
|
||||
}
|
||||
} else {
|
||||
buffer.concat(c);
|
||||
}
|
||||
} while(f.available());
|
||||
}
|
||||
f.close();
|
||||
entry.close();
|
||||
}
|
||||
root.close();
|
||||
SPIMaster::select_sd(false);
|
||||
}
|
||||
|
||||
Playlist* PlaylistManager::get_playlist_for_id(String id) {
|
||||
if (!_map.count(id)) return NULL;
|
||||
String folder = _map[id];
|
||||
if (!_playlists.count(folder)) {
|
||||
_playlists[folder] = new Playlist(folder);
|
||||
}
|
||||
return _playlists[folder];
|
||||
}
|
||||
|
||||
void PlaylistManager::dump_ids() {
|
||||
for (std::map<String, String>::iterator it = _map.begin(); it!=_map.end(); it++) {
|
||||
INFO(" %s -> %s\n", it->first.c_str(), it->second.c_str());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user