58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <Arduino.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
#include "config.h"
|
|
|
|
class Controller;
|
|
|
|
#include "player.h"
|
|
#include "playlist.h"
|
|
#include "playlist_manager.h"
|
|
#include "http_server.h"
|
|
#include <MFRC522.h>
|
|
|
|
enum ControllerState { NORMAL, LOCKING, LOCKED };
|
|
|
|
class Controller {
|
|
private:
|
|
MFRC522* _rfid;
|
|
HTTPServer* _http_server;
|
|
ControllerState _state = NORMAL;
|
|
bool _rfid_enabled = true;
|
|
void _check_rfid();
|
|
void _check_serial();
|
|
void _check_buttons();
|
|
bool _debounce_button(uint8_t index);
|
|
uint32_t _get_rfid_card_uid();
|
|
String _read_rfid_data();
|
|
bool _rfid_present = false;
|
|
String _last_rfid_uid = "";
|
|
String _last_rfid_data = "";
|
|
|
|
unsigned long _last_rfid_scan_at = 0;
|
|
unsigned long _last_position_info_at = 0;
|
|
String _serial_buffer = String();
|
|
String _cmd_queue = "";
|
|
void _execute_command_ls(String path);
|
|
void _execute_command_ids();
|
|
void _execute_command_help();
|
|
unsigned long _button_last_pressed_at[NUM_BUTTONS];
|
|
bool _check_button(uint8_t btn);
|
|
public:
|
|
Controller(Player* p, PlaylistManager* pm);
|
|
PlaylistManager* pm;
|
|
Player* player;
|
|
void register_http_server(HTTPServer* h);
|
|
void loop();
|
|
void send_controller_status();
|
|
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);
|
|
void update_playlist_manager();
|
|
};
|