2025-03-04 23:09:43 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
2025-03-10 17:11:55 +01:00
|
|
|
#include <MeshCore.h>
|
2025-03-04 23:09:43 +11:00
|
|
|
#include <helpers/ui/DisplayDriver.h>
|
2025-06-19 17:26:58 +02:00
|
|
|
#include <helpers/SensorManager.h>
|
2025-03-16 13:42:36 +11:00
|
|
|
#include <stddef.h>
|
2025-03-04 23:09:43 +11:00
|
|
|
|
2025-05-20 11:52:55 +10:00
|
|
|
#ifdef PIN_BUZZER
|
|
|
|
|
#include <helpers/ui/buzzer.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-04-20 17:40:58 -07:00
|
|
|
#include "NodePrefs.h"
|
2025-05-27 19:10:56 -07:00
|
|
|
#include "Button.h"
|
2025-04-20 17:40:58 -07:00
|
|
|
|
2025-05-20 19:33:21 +12:00
|
|
|
enum class UIEventType
|
|
|
|
|
{
|
|
|
|
|
none,
|
|
|
|
|
contactMessage,
|
|
|
|
|
channelMessage,
|
|
|
|
|
roomMessage,
|
2025-05-30 22:55:53 -07:00
|
|
|
newContactMessage,
|
|
|
|
|
ack
|
2025-05-20 19:33:21 +12:00
|
|
|
};
|
|
|
|
|
|
2025-03-04 23:09:43 +11:00
|
|
|
class UITask {
|
|
|
|
|
DisplayDriver* _display;
|
2025-03-10 17:11:55 +01:00
|
|
|
mesh::MainBoard* _board;
|
2025-06-19 17:26:58 +02:00
|
|
|
SensorManager* _sensors;
|
2025-05-20 11:52:55 +10:00
|
|
|
#ifdef PIN_BUZZER
|
|
|
|
|
genericBuzzer buzzer;
|
|
|
|
|
#endif
|
2025-03-10 17:11:55 +01:00
|
|
|
unsigned long _next_refresh, _auto_off;
|
2025-03-05 15:47:29 +11:00
|
|
|
bool _connected;
|
2025-04-20 17:40:58 -07:00
|
|
|
NodePrefs* _node_prefs;
|
2025-04-08 22:58:17 +12:00
|
|
|
char _version_info[32];
|
2025-03-04 23:09:43 +11:00
|
|
|
char _origin[62];
|
|
|
|
|
char _msg[80];
|
2025-06-04 09:51:16 -07:00
|
|
|
char _alert[80];
|
2025-03-10 17:11:55 +01:00
|
|
|
int _msgcount;
|
2025-04-10 16:24:17 +02:00
|
|
|
bool _need_refresh = true;
|
2025-05-30 20:32:49 -07:00
|
|
|
bool _displayWasOn = false; // Track display state before button press
|
2025-06-04 21:33:48 +10:00
|
|
|
unsigned long ui_started_at;
|
2025-03-04 23:09:43 +11:00
|
|
|
|
2025-05-27 19:10:56 -07:00
|
|
|
// Button handlers
|
2025-06-19 16:47:31 -07:00
|
|
|
#ifdef PIN_USER_BTN
|
2025-05-27 19:10:56 -07:00
|
|
|
Button* _userButton = nullptr;
|
|
|
|
|
#endif
|
2025-06-19 16:47:31 -07:00
|
|
|
#ifdef PIN_USER_BTN_ANA
|
|
|
|
|
Button* _userButtonAnalog = nullptr;
|
|
|
|
|
#endif
|
2025-05-27 19:10:56 -07:00
|
|
|
|
2025-03-04 23:09:43 +11:00
|
|
|
void renderCurrScreen();
|
2025-03-10 17:11:55 +01:00
|
|
|
void userLedHandler();
|
2025-05-19 14:16:55 +10:00
|
|
|
void renderBatteryIndicator(uint16_t batteryMilliVolts);
|
2025-05-27 19:10:56 -07:00
|
|
|
|
|
|
|
|
// Button action handlers
|
|
|
|
|
void handleButtonAnyPress();
|
|
|
|
|
void handleButtonShortPress();
|
|
|
|
|
void handleButtonDoublePress();
|
|
|
|
|
void handleButtonTriplePress();
|
2025-06-18 11:52:16 +02:00
|
|
|
void handleButtonQuadruplePress();
|
2025-05-27 19:10:56 -07:00
|
|
|
void handleButtonLongPress();
|
|
|
|
|
|
2025-05-20 19:33:21 +12:00
|
|
|
|
2025-03-04 23:09:43 +11:00
|
|
|
public:
|
2025-03-10 17:11:55 +01:00
|
|
|
|
2025-06-19 17:26:58 +02:00
|
|
|
UITask(mesh::MainBoard* board) : _board(board), _display(NULL), _sensors(NULL) {
|
2025-06-04 21:33:48 +10:00
|
|
|
_next_refresh = 0;
|
|
|
|
|
ui_started_at = 0;
|
2025-03-10 17:11:55 +01:00
|
|
|
_connected = false;
|
|
|
|
|
}
|
2025-06-19 17:26:58 +02:00
|
|
|
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
|
2025-03-04 23:09:43 +11:00
|
|
|
|
2025-03-05 15:47:29 +11:00
|
|
|
void setHasConnection(bool connected) { _connected = connected; }
|
2025-03-16 13:42:36 +11:00
|
|
|
bool hasDisplay() const { return _display != NULL; }
|
2025-03-04 23:09:43 +11:00
|
|
|
void clearMsgPreview();
|
2025-03-10 17:11:55 +01:00
|
|
|
void msgRead(int msgcount);
|
|
|
|
|
void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount);
|
2025-05-20 19:33:21 +12:00
|
|
|
void soundBuzzer(UIEventType bet = UIEventType::none);
|
2025-05-27 11:07:51 +12:00
|
|
|
void shutdown(bool restart = false);
|
2025-03-04 23:09:43 +11:00
|
|
|
void loop();
|
2025-03-10 17:11:55 +01:00
|
|
|
};
|