UITask.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #pragma once
  2. #include <MeshCore.h>
  3. #include <helpers/ui/DisplayDriver.h>
  4. #include <helpers/ui/UIScreen.h>
  5. #include <helpers/SensorManager.h>
  6. #include <helpers/BaseSerialInterface.h>
  7. #include <Arduino.h>
  8. #ifdef PIN_BUZZER
  9. #include <helpers/ui/buzzer.h>
  10. #endif
  11. #include "NodePrefs.h"
  12. enum class UIEventType {
  13. none,
  14. contactMessage,
  15. channelMessage,
  16. roomMessage,
  17. newContactMessage,
  18. ack
  19. };
  20. #define MAX_TOP_LEVEL 8
  21. class UITask {
  22. DisplayDriver* _display;
  23. mesh::MainBoard* _board;
  24. BaseSerialInterface* _serial;
  25. SensorManager* _sensors;
  26. #ifdef PIN_BUZZER
  27. genericBuzzer buzzer;
  28. #endif
  29. unsigned long _next_refresh, _auto_off;
  30. bool _connected;
  31. NodePrefs* _node_prefs;
  32. char _alert[80];
  33. unsigned long _alert_expiry;
  34. int _msgcount;
  35. unsigned long ui_started_at, next_batt_chck;
  36. UIScreen* splash;
  37. UIScreen* home;
  38. UIScreen* msg_preview;
  39. UIScreen* curr;
  40. void userLedHandler();
  41. // Button action handlers
  42. char checkDisplayOn(char c);
  43. char handleLongPress(char c);
  44. void setCurrScreen(UIScreen* c);
  45. public:
  46. UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : _board(board), _serial(serial), _display(NULL), _sensors(NULL) {
  47. next_batt_chck = _next_refresh = 0;
  48. ui_started_at = 0;
  49. _connected = false;
  50. curr = NULL;
  51. }
  52. void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
  53. void gotoHomeScreen() { setCurrScreen(home); }
  54. void showAlert(const char* text, int duration_millis);
  55. void setHasConnection(bool connected) { _connected = connected; }
  56. bool hasConnection() const { return _connected; }
  57. uint16_t getBattMilliVolts() const { return _board->getBattMilliVolts(); }
  58. bool isSerialEnabled() const { return _serial->isEnabled(); }
  59. void enableSerial() { _serial->enable(); }
  60. void disableSerial() { _serial->disable(); }
  61. int getMsgCount() const { return _msgcount; }
  62. bool hasDisplay() const { return _display != NULL; }
  63. bool isButtonPressed() const;
  64. void msgRead(int msgcount);
  65. void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount);
  66. void soundBuzzer(UIEventType bet = UIEventType::none);
  67. void shutdown(bool restart = false);
  68. void loop();
  69. };