UITask.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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, const char* firmware_version) {
  21. _prevBtnState = HIGH;
  22. _auto_off = millis() + AUTO_OFF_MILLIS;
  23. _node_name = node_name;
  24. _display->turnOn();
  25. // strip off dash and commit hash by changing dash to null terminator
  26. // e.g: v1.2.3-abcdef -> v1.2.3
  27. char *version = strdup(firmware_version);
  28. char *dash = strchr(version, '-');
  29. if(dash){
  30. *dash = 0;
  31. }
  32. // v1.2.3 (1 Jan 2025)
  33. sprintf(_version_info, "%s (%s)", version, build_date);
  34. }
  35. void UITask::renderCurrScreen() {
  36. // render 'home' screen
  37. _display->drawXbm(0, 0, meshcore_logo, 128, 13);
  38. _display->setCursor(0, 20);
  39. _display->setTextSize(1);
  40. _display->print(_node_name);
  41. _display->setCursor(0, 32);
  42. _display->print(_version_info);
  43. _display->setCursor(0, 43);
  44. _display->print("< Room Server >");
  45. //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf);
  46. //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr);
  47. }
  48. void UITask::loop() {
  49. #ifdef PIN_USER_BTN
  50. if (millis() >= _next_read) {
  51. int btnState = digitalRead(PIN_USER_BTN);
  52. if (btnState != _prevBtnState) {
  53. if (btnState == LOW) { // pressed?
  54. if (_display->isOn()) {
  55. // TODO: any action ?
  56. } else {
  57. _display->turnOn();
  58. }
  59. _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
  60. }
  61. _prevBtnState = btnState;
  62. }
  63. _next_read = millis() + 200; // 5 reads per second
  64. }
  65. #endif
  66. if (_display->isOn()) {
  67. if (millis() >= _next_refresh) {
  68. _display->startFrame();
  69. renderCurrScreen();
  70. _display->endFrame();
  71. _next_refresh = millis() + 1000; // refresh every second
  72. }
  73. if (millis() > _auto_off) {
  74. _display->turnOff();
  75. }
  76. }
  77. }