UITask.cpp 3.2 KB

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