Files
MeshCore-Evo/examples/companion_radio/UITask.h

65 lines
1.7 KiB
C
Raw Normal View History

2025-06-01 09:25:17 -07:00
#pragma once
#include <MeshCore.h>
#include <helpers/ui/DisplayDriver.h>
#include <stddef.h>
#ifdef PIN_BUZZER
2025-06-01 09:25:17 -07:00
#include <helpers/ui/buzzer.h>
#endif
2025-05-27 19:10:56 -07:00
#include "Button.h"
2025-06-01 09:25:17 -07:00
#include "NodePrefs.h"
2025-06-01 09:25:17 -07:00
enum class UIEventType { none, contactMessage, channelMessage, roomMessage, newContactMessage, ack };
2025-05-20 19:33:21 +12:00
class UITask {
2025-06-01 09:25:17 -07:00
DisplayDriver *_display;
mesh::MainBoard *_board;
#ifdef PIN_BUZZER
genericBuzzer buzzer;
#endif
unsigned long _next_refresh, _auto_off;
bool _connected;
uint32_t _pin_code;
2025-06-01 09:25:17 -07:00
NodePrefs *_node_prefs;
char _version_info[32];
char _origin[62];
char _msg[80];
int _msgcount;
bool _need_refresh = true;
2025-06-01 09:25:17 -07:00
bool _displayWasOn = false; // Track display state before button press
2025-05-27 19:10:56 -07:00
// Button handlers
#if defined(PIN_USER_BTN) || defined(PIN_USER_BTN_ANA)
2025-06-01 09:25:17 -07:00
Button *_userButton = nullptr;
2025-05-27 19:10:56 -07:00
#endif
void renderCurrScreen();
void userLedHandler();
void renderBatteryIndicator(uint16_t batteryMilliVolts);
2025-06-01 09:25:17 -07:00
2025-05-27 19:10:56 -07:00
// Button action handlers
void handleButtonAnyPress();
void handleButtonShortPress();
void handleButtonDoublePress();
void handleButtonTriplePress();
void handleButtonLongPress();
public:
2025-06-01 09:25:17 -07:00
UITask(mesh::MainBoard *board) : _board(board), _display(NULL)
{
_next_refresh = 0;
_connected = false;
}
2025-06-01 09:25:17 -07:00
void begin(DisplayDriver *display, NodePrefs *node_prefs, const char *build_date,
const char *firmware_version, uint32_t pin_code);
void setHasConnection(bool connected) { _connected = connected; }
bool hasDisplay() const { return _display != NULL; }
void clearMsgPreview();
void msgRead(int msgcount);
2025-06-01 09:25:17 -07:00
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();
2025-06-01 09:25:17 -07:00
};