2019-08-02 21:48:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
#include <Arduino.h>
|
2019-11-16 22:03:13 +00:00
|
|
|
#include <ESPAsyncWebServer.h>
|
2019-08-06 18:50:11 +00:00
|
|
|
#include "config.h"
|
2019-11-16 22:03:13 +00:00
|
|
|
|
|
|
|
class Controller;
|
|
|
|
|
2019-08-02 21:48:36 +00:00
|
|
|
#include "player.h"
|
2019-11-14 19:42:02 +00:00
|
|
|
#include "playlist.h"
|
|
|
|
#include "playlist_manager.h"
|
2019-08-14 19:01:01 +00:00
|
|
|
#include "mqtt_client.h"
|
2019-11-16 22:03:13 +00:00
|
|
|
#include "http_server.h"
|
2019-08-06 18:50:11 +00:00
|
|
|
#include <MFRC522.h>
|
2019-08-02 21:48:36 +00:00
|
|
|
|
2019-11-14 19:42:02 +00:00
|
|
|
enum ControllerState { NORMAL, LOCKING, LOCKED };
|
|
|
|
|
2019-08-02 21:48:36 +00:00
|
|
|
class Controller {
|
|
|
|
private:
|
2019-08-06 18:50:11 +00:00
|
|
|
MFRC522* _rfid;
|
2019-08-14 19:01:01 +00:00
|
|
|
MQTTClient* _mqtt_client;
|
2019-11-16 22:03:13 +00:00
|
|
|
HTTPServer* _http_server;
|
2019-11-14 19:42:02 +00:00
|
|
|
PlaylistManager* _pm;
|
|
|
|
ControllerState _state = NORMAL;
|
2019-08-06 18:50:11 +00:00
|
|
|
bool _rfid_enabled = true;
|
|
|
|
void _check_rfid();
|
|
|
|
void _check_serial();
|
2019-08-11 15:15:22 +00:00
|
|
|
void _check_buttons();
|
2019-11-10 13:45:33 +00:00
|
|
|
bool _debounce_button(uint8_t index);
|
2019-08-08 04:49:35 +00:00
|
|
|
uint32_t _get_rfid_card_uid();
|
2019-11-14 05:48:21 +00:00
|
|
|
String _read_rfid_data();
|
|
|
|
bool _rfid_present = false;
|
2019-11-16 22:03:13 +00:00
|
|
|
String _last_rfid_uid = "";
|
|
|
|
String _last_rfid_data = "";
|
2019-08-02 21:48:36 +00:00
|
|
|
Player* _player;
|
2019-08-08 03:31:27 +00:00
|
|
|
unsigned long _last_rfid_scan_at = 0;
|
2019-11-16 22:03:13 +00:00
|
|
|
unsigned long _last_position_info_at = 0;
|
2019-08-09 04:27:33 +00:00
|
|
|
String _serial_buffer = String();
|
2019-11-16 22:03:13 +00:00
|
|
|
String _cmd_queue = "";
|
2019-08-09 04:27:33 +00:00
|
|
|
void _execute_command_ls(String path);
|
2019-11-13 05:51:38 +00:00
|
|
|
void _execute_command_ids();
|
2019-08-09 04:27:33 +00:00
|
|
|
void _execute_command_help();
|
2019-08-11 15:15:22 +00:00
|
|
|
unsigned long _button_last_pressed_at[NUM_BUTTONS];
|
|
|
|
bool _check_button(uint8_t btn);
|
2019-08-14 19:01:01 +00:00
|
|
|
unsigned long _last_mqtt_report_at = 0;
|
|
|
|
void _send_mqtt_report();
|
2019-08-02 21:48:36 +00:00
|
|
|
public:
|
2019-11-14 19:42:02 +00:00
|
|
|
Controller(Player* p, PlaylistManager* pm);
|
2019-09-03 04:06:51 +00:00
|
|
|
void set_mqtt_client(MQTTClient* m);
|
2019-11-16 22:03:13 +00:00
|
|
|
void register_http_server(HTTPServer* h);
|
2019-08-06 18:50:11 +00:00
|
|
|
void loop();
|
2019-11-16 23:35:23 +00:00
|
|
|
void send_controller_status();
|
2019-11-16 22:03:13 +00:00
|
|
|
void send_player_status();
|
|
|
|
void send_playlist_manager_status();
|
|
|
|
void send_position();
|
|
|
|
void inform_new_client(AsyncWebSocketClient* client);
|
|
|
|
String json();
|
|
|
|
bool process_message(String m);
|
|
|
|
void queue_command(String cmd);
|
2019-11-17 13:26:23 +00:00
|
|
|
void update_playlist_manager();
|
2019-08-02 21:48:36 +00:00
|
|
|
};
|