UITask.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include "UITask.h"
  2. #include <Arduino.h>
  3. #define AUTO_OFF_MILLIS 20000 // 20 seconds
  4. // 'meshcore', 128x13px
  5. static const uint8_t meshcore_logo [] PROGMEM = {
  6. 0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe,
  7. 0x3c, 0x03, 0xe3, 0xff, 0xc7, 0xff, 0x8e, 0x03, 0x8f, 0xfe, 0x3f, 0xfe, 0x1f, 0xff, 0x1f, 0xfe,
  8. 0x3e, 0x03, 0xc3, 0xff, 0x8f, 0xff, 0x0e, 0x07, 0x8f, 0xfe, 0x7f, 0xfe, 0x1f, 0xff, 0x1f, 0xfc,
  9. 0x3e, 0x07, 0xc7, 0x80, 0x0e, 0x00, 0x0e, 0x07, 0x9e, 0x00, 0x78, 0x0e, 0x3c, 0x0f, 0x1c, 0x00,
  10. 0x3e, 0x0f, 0xc7, 0x80, 0x1e, 0x00, 0x0e, 0x07, 0x1e, 0x00, 0x70, 0x0e, 0x38, 0x0f, 0x3c, 0x00,
  11. 0x7f, 0x0f, 0xc7, 0xfe, 0x1f, 0xfc, 0x1f, 0xff, 0x1c, 0x00, 0x70, 0x0e, 0x38, 0x0e, 0x3f, 0xf8,
  12. 0x7f, 0x1f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x0e, 0x38, 0x0e, 0x3f, 0xf8,
  13. 0x7f, 0x3f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x1e, 0x3f, 0xfe, 0x3f, 0xf0,
  14. 0x77, 0x3b, 0x87, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xfc, 0x38, 0x00,
  15. 0x77, 0xfb, 0x8f, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xf8, 0x38, 0x00,
  16. 0x73, 0xf3, 0x8f, 0xff, 0x0f, 0xff, 0x1c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x78, 0x7f, 0xf8,
  17. 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfe, 0x3c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x3c, 0x7f, 0xf8,
  18. 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8,
  19. };
  20. void UITask::begin(const char* node_name, const char* build_date) {
  21. _prevBtnState = HIGH;
  22. _auto_off = millis() + AUTO_OFF_MILLIS;
  23. _node_name = node_name;
  24. _build_date = build_date;
  25. _display->turnOn();
  26. }
  27. void UITask::renderCurrScreen() {
  28. char tmp[80];
  29. // render 'home' screen
  30. _display->drawXbm(0, 0, meshcore_logo, 128, 13);
  31. _display->setCursor(0, 20);
  32. _display->setTextSize(1);
  33. _display->print(_node_name);
  34. sprintf(tmp, "Build: %s", _build_date);
  35. _display->setCursor(0, 32);
  36. _display->print(tmp);
  37. _display->setCursor(0, 43);
  38. _display->print("< Repeater >");
  39. //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf);
  40. //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr);
  41. }
  42. void UITask::loop() {
  43. #ifdef PIN_USER_BTN
  44. if (millis() >= _next_read) {
  45. int btnState = digitalRead(PIN_USER_BTN);
  46. if (btnState != _prevBtnState) {
  47. if (btnState == LOW) { // pressed?
  48. if (_display->isOn()) {
  49. // TODO: any action ?
  50. } else {
  51. _display->turnOn();
  52. }
  53. _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
  54. }
  55. _prevBtnState = btnState;
  56. }
  57. _next_read = millis() + 200; // 5 reads per second
  58. }
  59. #endif
  60. if (_display->isOn()) {
  61. if (millis() >= _next_refresh) {
  62. _display->startFrame();
  63. renderCurrScreen();
  64. _display->endFrame();
  65. _next_refresh = millis() + 1000; // refresh every second
  66. }
  67. if (millis() > _auto_off) {
  68. _display->turnOff();
  69. }
  70. }
  71. }