UITask.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 "NodePrefs.h"
  10. #include "Button.h"
  11. enum class UIEventType
  12. {
  13. none,
  14. contactMessage,
  15. channelMessage,
  16. roomMessage,
  17. newContactMessage,
  18. ack
  19. };
  20. class UITask {
  21. DisplayDriver* _display;
  22. mesh::MainBoard* _board;
  23. SensorManager* _sensors;
  24. #ifdef PIN_BUZZER
  25. genericBuzzer buzzer;
  26. #endif
  27. unsigned long _next_refresh, _auto_off;
  28. bool _connected;
  29. NodePrefs* _node_prefs;
  30. char _version_info[32];
  31. char _origin[62];
  32. char _msg[80];
  33. char _alert[80];
  34. int _msgcount;
  35. bool _need_refresh = true;
  36. bool _displayWasOn = false; // Track display state before button press
  37. unsigned long ui_started_at;
  38. // Button handlers
  39. #ifdef PIN_USER_BTN
  40. Button* _userButton = nullptr;
  41. #endif
  42. #ifdef PIN_USER_BTN_ANA
  43. Button* _userButtonAnalog = nullptr;
  44. #endif
  45. void renderCurrScreen();
  46. void userLedHandler();
  47. void renderBatteryIndicator(uint16_t batteryMilliVolts);
  48. // Button action handlers
  49. void handleButtonAnyPress();
  50. void handleButtonShortPress();
  51. void handleButtonDoublePress();
  52. void handleButtonTriplePress();
  53. void handleButtonQuadruplePress();
  54. void handleButtonLongPress();
  55. public:
  56. UITask(mesh::MainBoard* board) : _board(board), _display(NULL), _sensors(NULL) {
  57. _next_refresh = 0;
  58. ui_started_at = 0;
  59. _connected = false;
  60. }
  61. void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
  62. void setHasConnection(bool connected) { _connected = connected; }
  63. bool hasDisplay() const { return _display != NULL; }
  64. void clearMsgPreview();
  65. void msgRead(int msgcount);
  66. void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount);
  67. void soundBuzzer(UIEventType bet = UIEventType::none);
  68. void shutdown(bool restart = false);
  69. void loop();
  70. };