UITask.h 2.4 KB

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