Made player and playlist_manager pubilc members of Controller.
This commit is contained in:
parent
5fad39ee0e
commit
68ecc05712
@ -18,7 +18,6 @@ class Controller {
|
|||||||
private:
|
private:
|
||||||
MFRC522* _rfid;
|
MFRC522* _rfid;
|
||||||
HTTPServer* _http_server;
|
HTTPServer* _http_server;
|
||||||
PlaylistManager* _pm;
|
|
||||||
ControllerState _state = NORMAL;
|
ControllerState _state = NORMAL;
|
||||||
bool _rfid_enabled = true;
|
bool _rfid_enabled = true;
|
||||||
void _check_rfid();
|
void _check_rfid();
|
||||||
@ -30,7 +29,7 @@ private:
|
|||||||
bool _rfid_present = false;
|
bool _rfid_present = false;
|
||||||
String _last_rfid_uid = "";
|
String _last_rfid_uid = "";
|
||||||
String _last_rfid_data = "";
|
String _last_rfid_data = "";
|
||||||
Player* _player;
|
|
||||||
unsigned long _last_rfid_scan_at = 0;
|
unsigned long _last_rfid_scan_at = 0;
|
||||||
unsigned long _last_position_info_at = 0;
|
unsigned long _last_position_info_at = 0;
|
||||||
String _serial_buffer = String();
|
String _serial_buffer = String();
|
||||||
@ -42,6 +41,8 @@ private:
|
|||||||
bool _check_button(uint8_t btn);
|
bool _check_button(uint8_t btn);
|
||||||
public:
|
public:
|
||||||
Controller(Player* p, PlaylistManager* pm);
|
Controller(Player* p, PlaylistManager* pm);
|
||||||
|
PlaylistManager* pm;
|
||||||
|
Player* player;
|
||||||
void register_http_server(HTTPServer* h);
|
void register_http_server(HTTPServer* h);
|
||||||
void loop();
|
void loop();
|
||||||
void send_controller_status();
|
void send_controller_status();
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
#include "http_server.h"
|
#include "http_server.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
|
|
||||||
Controller::Controller(Player* p, PlaylistManager* pm) {
|
Controller::Controller(Player* p, PlaylistManager* playlist_manager) {
|
||||||
_player = p;
|
player = p;
|
||||||
_pm = pm;
|
pm = playlist_manager;
|
||||||
_rfid = new MFRC522(17, MFRC522::UNUSED_PIN);
|
_rfid = new MFRC522(17, MFRC522::UNUSED_PIN);
|
||||||
|
|
||||||
_player->register_controller(this);
|
player->register_controller(this);
|
||||||
|
|
||||||
BTN_NEXT_SETUP();
|
BTN_NEXT_SETUP();
|
||||||
BTN_PREV_SETUP();
|
BTN_PREV_SETUP();
|
||||||
@ -87,7 +87,7 @@ void Controller::_check_rfid() {
|
|||||||
_rfid_present = false;
|
_rfid_present = false;
|
||||||
INFO("No more RFID card.\n");
|
INFO("No more RFID card.\n");
|
||||||
if (_state != LOCKED) {
|
if (_state != LOCKED) {
|
||||||
_player->stop();
|
player->stop();
|
||||||
}
|
}
|
||||||
send_controller_status();
|
send_controller_status();
|
||||||
} else {
|
} else {
|
||||||
@ -106,7 +106,7 @@ void Controller::_check_rfid() {
|
|||||||
String data = _read_rfid_data();
|
String data = _read_rfid_data();
|
||||||
_last_rfid_data = data;
|
_last_rfid_data = data;
|
||||||
|
|
||||||
Playlist* pl = _pm->get_playlist_for_id(s_uid);
|
Playlist* pl = pm->get_playlist_for_id(s_uid);
|
||||||
if (data.indexOf("[lock]") != -1) {
|
if (data.indexOf("[lock]") != -1) {
|
||||||
if (_state == LOCKED) {
|
if (_state == LOCKED) {
|
||||||
_state = NORMAL;
|
_state = NORMAL;
|
||||||
@ -152,7 +152,7 @@ void Controller::_check_rfid() {
|
|||||||
DEBUG("ControllerState is now LOCKED.\n");
|
DEBUG("ControllerState is now LOCKED.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
_player->play(pl);
|
player->play(pl);
|
||||||
//send_playlist_manager_status();
|
//send_playlist_manager_status();
|
||||||
send_controller_status();
|
send_controller_status();
|
||||||
}
|
}
|
||||||
@ -248,38 +248,38 @@ bool Controller::process_message(String cmd) {
|
|||||||
DEBUG("Executing command: %s\n", cmd.c_str());
|
DEBUG("Executing command: %s\n", cmd.c_str());
|
||||||
|
|
||||||
if (cmd.startsWith("play ")) {
|
if (cmd.startsWith("play ")) {
|
||||||
Playlist* p = _pm->get_playlist_for_folder(cmd.substring(5));
|
Playlist* p = pm->get_playlist_for_folder(cmd.substring(5));
|
||||||
_player->play(p);
|
player->play(p);
|
||||||
//} else if (cmd.equals("ls")) {
|
//} else if (cmd.equals("ls")) {
|
||||||
// _execute_command_ls("/");
|
// _execute_command_ls("/");
|
||||||
//} else if (cmd.startsWith("ls ")) {
|
//} else if (cmd.startsWith("ls ")) {
|
||||||
// _execute_command_ls(cmd.substring(3));
|
// _execute_command_ls(cmd.substring(3));
|
||||||
} else if (cmd.equals("play")) {
|
} else if (cmd.equals("play")) {
|
||||||
_player->play();
|
player->play();
|
||||||
|
|
||||||
} else if (cmd.equals("stop")) {
|
} else if (cmd.equals("stop")) {
|
||||||
_player->stop();
|
player->stop();
|
||||||
} else if (cmd.equals("help")) {
|
} else if (cmd.equals("help")) {
|
||||||
_execute_command_help();
|
_execute_command_help();
|
||||||
} else if (cmd.equals("-")) {
|
} else if (cmd.equals("-")) {
|
||||||
_player->vol_down();
|
player->vol_down();
|
||||||
} else if (cmd.equals("+")) {
|
} else if (cmd.equals("+")) {
|
||||||
_player->vol_up();
|
player->vol_up();
|
||||||
} else if (cmd.startsWith("volume=")) {
|
} else if (cmd.startsWith("volume=")) {
|
||||||
uint8_t vol = cmd.substring(7).toInt();
|
uint8_t vol = cmd.substring(7).toInt();
|
||||||
_player->set_volume(vol);
|
player->set_volume(vol);
|
||||||
} else if (cmd.equals("track_prev")) {
|
} else if (cmd.equals("track_prev")) {
|
||||||
_player->track_prev();
|
player->track_prev();
|
||||||
} else if (cmd.equals("track_next")) {
|
} else if (cmd.equals("track_next")) {
|
||||||
_player->track_next();
|
player->track_next();
|
||||||
} else if (cmd.startsWith("track=")) {
|
} else if (cmd.startsWith("track=")) {
|
||||||
uint8_t track = cmd.substring(6).toInt();
|
uint8_t track = cmd.substring(6).toInt();
|
||||||
_player->set_track(track);
|
player->set_track(track);
|
||||||
} else if (cmd.equals("ids")) {
|
} else if (cmd.equals("ids")) {
|
||||||
_pm->dump_ids();
|
pm->dump_ids();
|
||||||
} else if (cmd.equals("reset_vs1053")) {
|
} else if (cmd.equals("reset_vs1053")) {
|
||||||
_player->stop();
|
player->stop();
|
||||||
_player->init();
|
player->init();
|
||||||
} else if (cmd.equals("reboot")) {
|
} else if (cmd.equals("reboot")) {
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
} else if (cmd.startsWith("add_mapping=")) {
|
} else if (cmd.startsWith("add_mapping=")) {
|
||||||
@ -287,7 +287,7 @@ bool Controller::process_message(String cmd) {
|
|||||||
uint8_t idx = rest.indexOf('=');
|
uint8_t idx = rest.indexOf('=');
|
||||||
String id = rest.substring(0, idx);
|
String id = rest.substring(0, idx);
|
||||||
String folder = rest.substring(idx + 1);
|
String folder = rest.substring(idx + 1);
|
||||||
_pm->add_mapping(id, folder);
|
pm->add_mapping(id, folder);
|
||||||
send_playlist_manager_status();
|
send_playlist_manager_status();
|
||||||
} else {
|
} else {
|
||||||
ERROR("Unknown command: %s\n", cmd.c_str());
|
ERROR("Unknown command: %s\n", cmd.c_str());
|
||||||
@ -299,7 +299,7 @@ bool Controller::process_message(String cmd) {
|
|||||||
void Controller::_execute_command_ls(String path) {
|
void Controller::_execute_command_ls(String path) {
|
||||||
INFO("Listing contents of %s:\n", path.c_str());
|
INFO("Listing contents of %s:\n", path.c_str());
|
||||||
// TODO
|
// TODO
|
||||||
//std::list<String> files = _player->ls(path);
|
//std::list<String> files = player->ls(path);
|
||||||
//for(std::list<String>::iterator it=files.begin(); it!=files.end(); ++it) {
|
//for(std::list<String>::iterator it=files.begin(); it!=files.end(); ++it) {
|
||||||
// INFO(" %s\n", (*it).c_str());
|
// INFO(" %s\n", (*it).c_str());
|
||||||
//}
|
//}
|
||||||
@ -321,17 +321,17 @@ void Controller::_check_buttons() {
|
|||||||
|
|
||||||
if (BTN_PREV() && _debounce_button(0)) {
|
if (BTN_PREV() && _debounce_button(0)) {
|
||||||
if (_state == NORMAL) {
|
if (_state == NORMAL) {
|
||||||
_player->track_prev();
|
player->track_prev();
|
||||||
} else {
|
} else {
|
||||||
DEBUG("Ignoring btn_prev because state is LOCKED.\n");
|
DEBUG("Ignoring btn_prev because state is LOCKED.\n");
|
||||||
}
|
}
|
||||||
} else if (BTN_VOL_UP() && _debounce_button(1)) {
|
} else if (BTN_VOL_UP() && _debounce_button(1)) {
|
||||||
_player->vol_up();
|
player->vol_up();
|
||||||
} else if (BTN_VOL_DOWN() && _debounce_button(2)) {
|
} else if (BTN_VOL_DOWN() && _debounce_button(2)) {
|
||||||
_player->vol_down();
|
player->vol_down();
|
||||||
} else if (BTN_NEXT() && _debounce_button(3)) {
|
} else if (BTN_NEXT() && _debounce_button(3)) {
|
||||||
if (_state == NORMAL) {
|
if (_state == NORMAL) {
|
||||||
_player->track_next();
|
player->track_next();
|
||||||
} else {
|
} else {
|
||||||
DEBUG("Ignoring btn_next because state is LOCKED.\n");
|
DEBUG("Ignoring btn_next because state is LOCKED.\n");
|
||||||
}
|
}
|
||||||
@ -367,22 +367,22 @@ void Controller::send_player_status() {
|
|||||||
TRACE("In send_player_status()...\n");
|
TRACE("In send_player_status()...\n");
|
||||||
|
|
||||||
if (_http_server->ws->count() > 0) {
|
if (_http_server->ws->count() > 0) {
|
||||||
_http_server->ws->textAll(_player->json());
|
_http_server->ws->textAll(player->json());
|
||||||
_http_server->ws->textAll(_player->position_json());
|
_http_server->ws->textAll(player->position_json());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::send_playlist_manager_status() {
|
void Controller::send_playlist_manager_status() {
|
||||||
TRACE("In send_playlist_manager_status()...\n");
|
TRACE("In send_playlist_manager_status()...\n");
|
||||||
if (_http_server->ws->count() > 0) {
|
if (_http_server->ws->count() > 0) {
|
||||||
_http_server->ws->textAll(_pm->json());
|
_http_server->ws->textAll(pm->json());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::send_position() {
|
void Controller::send_position() {
|
||||||
TRACE("In send_position()...\n");
|
TRACE("In send_position()...\n");
|
||||||
if (_http_server->ws->count() > 0 && _player->is_playing()) {
|
if (_http_server->ws->count() > 0) {
|
||||||
_http_server->ws->textAll(_player->position_json());
|
_http_server->ws->textAll(player->position_json());
|
||||||
}
|
}
|
||||||
_last_position_info_at = millis();
|
_last_position_info_at = millis();
|
||||||
}
|
}
|
||||||
@ -396,11 +396,11 @@ void Controller::send_controller_status() {
|
|||||||
|
|
||||||
void Controller::inform_new_client(AsyncWebSocketClient* client) {
|
void Controller::inform_new_client(AsyncWebSocketClient* client) {
|
||||||
String s;
|
String s;
|
||||||
s += _pm->json();
|
s += pm->json();
|
||||||
s += '\n';
|
s += '\n';
|
||||||
s += _player->json();
|
s += player->json();
|
||||||
s += '\n';
|
s += '\n';
|
||||||
s += _player->position_json();
|
s += player->position_json();
|
||||||
s += '\n';
|
s += '\n';
|
||||||
s += json();
|
s += json();
|
||||||
client->text(s);
|
client->text(s);
|
||||||
@ -412,6 +412,6 @@ void Controller::queue_command(String s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Controller::update_playlist_manager() {
|
void Controller::update_playlist_manager() {
|
||||||
_pm->scan_files();
|
pm->scan_files();
|
||||||
send_playlist_manager_status();
|
send_playlist_manager_status();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user