MeshCore/examples/companion_radio/UITask.h

83 lines
1.9 KiB
C
Raw Normal View History

#pragma once
#include <MeshCore.h>
#include <helpers/ui/DisplayDriver.h>
#include <helpers/SensorManager.h>
#include <stddef.h>
#ifdef PIN_BUZZER
#include <helpers/ui/buzzer.h>
#endif
#include "NodePrefs.h"
2025-05-27 19:10:56 -07:00
#include "Button.h"
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
};
class UITask {
DisplayDriver* _display;
mesh::MainBoard* _board;
SensorManager* _sensors;
#ifdef PIN_BUZZER
genericBuzzer buzzer;
#endif
unsigned long _next_refresh, _auto_off;
bool _connected;
NodePrefs* _node_prefs;
char _version_info[32];
char _origin[62];
char _msg[80];
char _alert[80];
int _msgcount;
bool _need_refresh = true;
bool _displayWasOn = false; // Track display state before button press
unsigned long ui_started_at;
2025-05-27 19:10:56 -07:00
// Button handlers
#ifdef PIN_USER_BTN
2025-05-27 19:10:56 -07:00
Button* _userButton = nullptr;
#endif
#ifdef PIN_USER_BTN_ANA
Button* _userButtonAnalog = nullptr;
#endif
2025-05-27 19:10:56 -07:00
void renderCurrScreen();
void userLedHandler();
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
public:
UITask(mesh::MainBoard* board) : _board(board), _display(NULL), _sensors(NULL) {
_next_refresh = 0;
ui_started_at = 0;
_connected = false;
}
void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
void setHasConnection(bool connected) { _connected = connected; }
bool hasDisplay() const { return _display != NULL; }
void clearMsgPreview();
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);
void shutdown(bool restart = false);
void loop();
};