2019-08-02 23:48:36 +02:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-06 20:50:11 +02:00
|
|
|
#include <Arduino.h>
|
2019-11-16 23:03:13 +01:00
|
|
|
#include <ESPAsyncWebServer.h>
|
2019-08-06 20:50:11 +02:00
|
|
|
#include "config.h"
|
2019-11-16 23:03:13 +01:00
|
|
|
|
|
|
|
class Controller;
|
|
|
|
|
2019-08-02 23:48:36 +02:00
|
|
|
#include "player.h"
|
2019-11-14 20:42:02 +01:00
|
|
|
#include "playlist.h"
|
|
|
|
#include "playlist_manager.h"
|
2019-11-16 23:03:13 +01:00
|
|
|
#include "http_server.h"
|
2019-11-29 05:36:59 +01:00
|
|
|
|
|
|
|
#undef DEPRECATED
|
2019-08-06 20:50:11 +02:00
|
|
|
#include <MFRC522.h>
|
2019-08-02 23:48:36 +02:00
|
|
|
|
2019-11-14 20:42:02 +01:00
|
|
|
enum ControllerState { NORMAL, LOCKING, LOCKED };
|
|
|
|
|
2019-08-02 23:48:36 +02:00
|
|
|
class Controller {
|
|
|
|
private:
|
2019-08-06 20:50:11 +02:00
|
|
|
MFRC522* _rfid;
|
2019-11-16 23:03:13 +01:00
|
|
|
HTTPServer* _http_server;
|
2019-11-14 20:42:02 +01:00
|
|
|
ControllerState _state = NORMAL;
|
2019-08-06 20:50:11 +02:00
|
|
|
bool _rfid_enabled = true;
|
|
|
|
void _check_rfid();
|
|
|
|
void _check_serial();
|
2019-08-11 17:15:22 +02:00
|
|
|
void _check_buttons();
|
2019-11-10 14:45:33 +01:00
|
|
|
bool _debounce_button(uint8_t index);
|
2019-08-08 06:49:35 +02:00
|
|
|
uint32_t _get_rfid_card_uid();
|
2019-11-14 06:48:21 +01:00
|
|
|
String _read_rfid_data();
|
|
|
|
bool _rfid_present = false;
|
2019-11-16 23:03:13 +01:00
|
|
|
String _last_rfid_uid = "";
|
|
|
|
String _last_rfid_data = "";
|
2019-11-19 20:46:04 +01:00
|
|
|
|
2019-08-08 05:31:27 +02:00
|
|
|
unsigned long _last_rfid_scan_at = 0;
|
2019-11-16 23:03:13 +01:00
|
|
|
unsigned long _last_position_info_at = 0;
|
2019-11-28 06:42:30 +01:00
|
|
|
unsigned long _last_update_check_at = 0;
|
2019-11-29 05:45:21 +01:00
|
|
|
unsigned long _last_wifi_try_at = 0;
|
2019-08-09 06:27:33 +02:00
|
|
|
String _serial_buffer = String();
|
2019-11-16 23:03:13 +01:00
|
|
|
String _cmd_queue = "";
|
2019-08-09 06:27:33 +02:00
|
|
|
void _execute_command_ls(String path);
|
2019-11-13 06:51:38 +01:00
|
|
|
void _execute_command_ids();
|
2019-08-09 06:27:33 +02:00
|
|
|
void _execute_command_help();
|
2019-08-11 17:15:22 +02:00
|
|
|
unsigned long _button_last_pressed_at[NUM_BUTTONS];
|
|
|
|
bool _check_button(uint8_t btn);
|
2019-08-02 23:48:36 +02:00
|
|
|
public:
|
2019-11-14 20:42:02 +01:00
|
|
|
Controller(Player* p, PlaylistManager* pm);
|
2019-11-19 20:46:04 +01:00
|
|
|
PlaylistManager* pm;
|
|
|
|
Player* player;
|
2019-11-16 23:03:13 +01:00
|
|
|
void register_http_server(HTTPServer* h);
|
2019-08-06 20:50:11 +02:00
|
|
|
void loop();
|
2019-11-17 00:35:23 +01:00
|
|
|
void send_controller_status();
|
2019-11-16 23:03:13 +01: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 14:26:23 +01:00
|
|
|
void update_playlist_manager();
|
2019-08-02 23:48:36 +02:00
|
|
|
};
|