UITask.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include <helpers/sensors/LPPDataHelpers.h>
  9. #include "ScrollingStatusBar.h"
  10. #ifndef LED_STATE_ON
  11. #define LED_STATE_ON 1
  12. #endif
  13. #ifdef PIN_BUZZER
  14. #include <helpers/ui/buzzer.h>
  15. #endif
  16. #ifdef PIN_VIBRATION
  17. #include <helpers/ui/GenericVibration.h>
  18. #endif
  19. #include "../AbstractUITask.h"
  20. #include "../NodePrefs.h"
  21. class UITask : public AbstractUITask {
  22. DisplayDriver* _display;
  23. SensorManager* _sensors;
  24. ScrollingStatusBar _statusBar;
  25. #ifdef PIN_BUZZER
  26. genericBuzzer buzzer;
  27. #endif
  28. #ifdef PIN_VIBRATION
  29. GenericVibration vibration;
  30. #endif
  31. unsigned long _next_refresh, _auto_off;
  32. NodePrefs* _node_prefs;
  33. char _alert[80];
  34. unsigned long _alert_expiry;
  35. int _msgcount;
  36. unsigned long ui_started_at, next_batt_chck;
  37. int next_backlight_btn_check = 0;
  38. uint16_t _cached_batt_mv;
  39. #ifdef PIN_STATUS_LED
  40. int led_state = 0;
  41. int next_led_change = 0;
  42. int last_led_increment = 0;
  43. #endif
  44. #ifdef PIN_USER_BTN_ANA
  45. unsigned long _analogue_pin_read_millis = millis();
  46. #endif
  47. UIScreen* splash;
  48. UIScreen* home;
  49. // UIScreen* msg_preview;
  50. UIScreen* curr;
  51. void userLedHandler();
  52. // Button action handlers
  53. char checkDisplayOn(char c);
  54. char handleLongPress(char c);
  55. char handleDoubleClick(char c);
  56. char handleTripleClick(char c);
  57. void setCurrScreen(UIScreen* c);
  58. public:
  59. UITask(mesh::MainBoard* board, BaseSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
  60. next_batt_chck = _next_refresh = 0;
  61. _cached_batt_mv = 0;
  62. ui_started_at = 0;
  63. curr = NULL;
  64. }
  65. void begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs);
  66. void gotoHomeScreen() { setCurrScreen(home); }
  67. void showAlert(const char* text, int duration_millis);
  68. int getMsgCount() const { return _msgcount; }
  69. uint16_t getCachedBattMV() const { return _cached_batt_mv; }
  70. bool hasDisplay() const { return _display != NULL; }
  71. bool isButtonPressed() const;
  72. bool isBuzzerQuiet() {
  73. #ifdef PIN_BUZZER
  74. return buzzer.isQuiet();
  75. #else
  76. return true;
  77. #endif
  78. }
  79. void toggleBuzzer();
  80. bool getGPSState();
  81. void toggleGPS();
  82. // from AbstractUITask
  83. void msgRead(int msgcount) override;
  84. void newMsg(uint8_t path_len, const char* from_name, const char* text, int msgcount) override;
  85. void notify(UIEventType t = UIEventType::none) override;
  86. void loop() override;
  87. void shutdown(bool restart = false);
  88. };