Massive changes. Added a quite nice webinterface with live data using WebSockets. Removed the FTP server (wasn't that useful anyways). JSON creating using ArduinoJson instead of String concatenation. Ans, and, and.

This commit is contained in:
2019-11-16 23:03:13 +01:00
parent e471a57578
commit b9a4770ff2
21 changed files with 620 additions and 2806 deletions

View File

@ -3,6 +3,7 @@
#include "config.h"
#include <SD.h>
#include <algorithm>
#include <ArduinoJson.h>
Playlist::Playlist(String path) {
// Add files to _files
@ -29,6 +30,17 @@ Playlist::Playlist(String path) {
ext.equals(".mpa"))) {
TRACE(" Adding entry %s\n", entry.name());
_files.push_back(entry.name());
bool non_ascii_chars = false;
for(int i=0; i<filename.length(); i++) {
char c = filename.charAt(i);
if (c < 0x20 || c >= 0x7F) {
non_ascii_chars = true;
break;
}
}
if (non_ascii_chars) {
ERROR("WARNING: File '%s' contains non-ascii chars!\n", filename.c_str());
}
} else {
TRACE(" Ignoring entry %s\n", filename.c_str());
}
@ -39,6 +51,10 @@ Playlist::Playlist(String path) {
std::sort(_files.begin(), _files.end());
}
void Playlist::start() {
_started = true;
}
bool Playlist::has_track_prev() {
return _current_track > 0;
}
@ -65,6 +81,14 @@ bool Playlist::track_next() {
return false;
}
bool Playlist::set_track(uint8_t track) {
if (track < _files.size()) {
_current_track = track;
return true;
}
return false;
}
void Playlist::track_restart() {
_position = 0;
}
@ -84,11 +108,21 @@ void Playlist::shuffle(uint8_t random_offset) {
TRACE("Done.\n");
}
void Playlist::advent_shuffle(uint8_t day) {
if (day > 24) day = 24;
if (day > _files.size()) return;
_files.insert(_files.begin(), _files[day - 1]);
_files.erase(_files.begin() + day - 1, _files.end());
}
void Playlist::reset() {
std::sort(_files.begin(), _files.end());
_current_track = 0;
_position = 0;
_shuffled = false;
_started = false;
}
String Playlist::get_current_file() {
@ -104,5 +138,22 @@ void Playlist::set_position(uint32_t p) {
}
bool Playlist::is_fresh() {
return !_shuffled && _position==0 && _current_track==0;
}
return !_shuffled && !_started && _position==0 && _current_track==0;
}
void Playlist::dump() {
for (int i=0; i<_files.size(); i++) {
DEBUG(" %02d %2s %s\n", i+1, (i==_current_track) ? "->" : "", _files[i].c_str());
}
}
void Playlist::json(JsonObject json) {
json["_type"] = "playlist";
JsonArray files = json.createNestedArray("files");
for (String file: _files) {
files.add(file);
}
json["current_track"] = _current_track;
json["has_track_next"] = has_track_next();
json["has_track_prev"] = has_track_prev();
}