2019-08-02 21:48:36 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-08-06 18:50:11 +00:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include "config.h"
|
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-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-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-08-08 04:49:35 +00:00
|
|
|
uint32_t _last_rfid_card_uid = 0;
|
2019-08-12 18:15:00 +00:00
|
|
|
uint8_t _no_rfid_card_count = 0;
|
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-08-09 04:27:33 +00:00
|
|
|
String _serial_buffer = String();
|
|
|
|
void _execute_serial_command(String cmd);
|
|
|
|
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-08-14 19:01:01 +00:00
|
|
|
String get_status_json();
|
2019-08-06 18:50:11 +00:00
|
|
|
void loop();
|
2019-08-02 21:48:36 +00:00
|
|
|
};
|