UITask.h 2.1 KB

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