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-11-16 22:03:13 +00:00
|
|
|
#include "http_server.h"
|
2019-11-29 04:36:59 +00:00
|
|
|
|
|
|
|
#undef DEPRECATED
|
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-11-16 22:03:13 +00:00
|
|
|
HTTPServer* _http_server;
|
2019-11-14 19:42:02 +00:00
|
|
|
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-11-19 19:46:04 +00:00
|
|
|
|
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-11-28 05:42:30 +00:00
|
|
|
unsigned long _last_update_check_at = 0;
|
2019-11-29 04:45:21 +00:00
|
|
|
unsigned long _last_wifi_try_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-02 21:48:36 +00:00
|
|
|
public:
|
2019-11-14 19:42:02 +00:00
|
|
|
Controller(Player* p, PlaylistManager* pm);
|
2019-11-19 19:46:04 +00:00
|
|
|
PlaylistManager* pm;
|
|
|
|
Player* player;
|
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
|
|
|
};
|