UITask.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <helpers/ui/DisplayDriver.h>
  4. #include <helpers/SensorManager.h>
  5. #include <stddef.h>
  6. #ifdef PIN_BUZZER
  7. #include <helpers/ui/buzzer.h>
  8. #endif
  9. #include "../AbstractUITask.h"
  10. #include "../NodePrefs.h"
  11. #include "Button.h"
  12. class UITask : public AbstractUITask {
  13. DisplayDriver* _display;
  14. SensorManager* _sensors;
  15. #ifdef PIN_BUZZER
  16. genericBuzzer buzzer;
  17. #endif
  18. unsigned long _next_refresh, _auto_off;
  19. NodePrefs* _node_prefs;
  20. char _version_info[32];
  21. char _origin[62];
  22. char _msg[80];
  23. char _alert[80];
  24. int _msgcount;
  25. bool _need_refresh = true;
  26. bool _displayWasOn = false; // Track display state before button press
  27. unsigned long ui_started_at;
  28. // Button handlers
  29. #ifdef PIN_USER_BTN
  30. Button* _userButton = nullptr;
  31. #endif
  32. #ifdef PIN_USER_BTN_ANA
  33. Button* _userButtonAnalog = nullptr;
  34. #endif
  35. void renderCurrScreen();
  36. void userLedHandler();
  37. void renderBatteryIndicator(uint16_t batteryMilliVolts);
  38. // Button action handlers
  39. void handleButtonAnyPress();
  40. void handleButtonShortPress();
  41. void handleButtonDoublePress();
  42. void handleButtonTriplePress();
  43. void handleButtonQuadruplePress();
  44. void handleButtonLongPress();
  45. public:
  46. UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
  47. _next_refresh = 0;
  48. ui_started_at = 0;
  49. }
  50. void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
  51. bool hasDisplay() const { return _display != NULL; }
  52. void clearMsgPreview();
  53. // from AbstractUITask
  54. void msgRead(int msgcount) override;
  55. void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
  56. void notify(UIEventType t = UIEventType::none) override;
  57. void loop() override;
  58. void shutdown(bool restart = false);
  59. };