|
| 1 | +#include "UITask.h" |
| 2 | +#include <Arduino.h> |
| 3 | + |
| 4 | +#define AUTO_OFF_MILLIS 20000 // 20 seconds |
| 5 | + |
| 6 | +// 'meshcore', 128x13px |
| 7 | +static const uint8_t meshcore_logo [] PROGMEM = { |
| 8 | + 0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, |
| 9 | + 0x3c, 0x03, 0xe3, 0xff, 0xc7, 0xff, 0x8e, 0x03, 0x8f, 0xfe, 0x3f, 0xfe, 0x1f, 0xff, 0x1f, 0xfe, |
| 10 | + 0x3e, 0x03, 0xc3, 0xff, 0x8f, 0xff, 0x0e, 0x07, 0x8f, 0xfe, 0x7f, 0xfe, 0x1f, 0xff, 0x1f, 0xfc, |
| 11 | + 0x3e, 0x07, 0xc7, 0x80, 0x0e, 0x00, 0x0e, 0x07, 0x9e, 0x00, 0x78, 0x0e, 0x3c, 0x0f, 0x1c, 0x00, |
| 12 | + 0x3e, 0x0f, 0xc7, 0x80, 0x1e, 0x00, 0x0e, 0x07, 0x1e, 0x00, 0x70, 0x0e, 0x38, 0x0f, 0x3c, 0x00, |
| 13 | + 0x7f, 0x0f, 0xc7, 0xfe, 0x1f, 0xfc, 0x1f, 0xff, 0x1c, 0x00, 0x70, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, |
| 14 | + 0x7f, 0x1f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, |
| 15 | + 0x7f, 0x3f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x1e, 0x3f, 0xfe, 0x3f, 0xf0, |
| 16 | + 0x77, 0x3b, 0x87, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xfc, 0x38, 0x00, |
| 17 | + 0x77, 0xfb, 0x8f, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xf8, 0x38, 0x00, |
| 18 | + 0x73, 0xf3, 0x8f, 0xff, 0x0f, 0xff, 0x1c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x78, 0x7f, 0xf8, |
| 19 | + 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfe, 0x3c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x3c, 0x7f, 0xf8, |
| 20 | + 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, |
| 21 | +}; |
| 22 | + |
| 23 | +void UITask::begin(const char* node_name, const char* build_date) { |
| 24 | + _prevBtnState = HIGH; |
| 25 | + _auto_off = millis() + AUTO_OFF_MILLIS; |
| 26 | + _node_name = node_name; |
| 27 | + _build_date = build_date; |
| 28 | + _display->turnOn(); |
| 29 | +} |
| 30 | + |
| 31 | +void UITask::renderCurrScreen() { |
| 32 | + char tmp[80]; |
| 33 | + // render 'home' screen |
| 34 | + _display->drawXbm(0, 0, meshcore_logo, 128, 13); |
| 35 | + _display->setCursor(0, 20); |
| 36 | + _display->setTextSize(1); |
| 37 | + _display->print(_node_name); |
| 38 | + |
| 39 | + sprintf(tmp, "Build: %s", _build_date); |
| 40 | + _display->setCursor(0, 32); |
| 41 | + _display->print(tmp); |
| 42 | + _display->setCursor(0, 43); |
| 43 | + _display->print("< Room Server >"); |
| 44 | + //_display->printf("freq : %03.2f sf %d\n", _prefs.freq, _prefs.sf); |
| 45 | + //_display->printf("bw : %03.2f cr %d\n", _prefs.bw, _prefs.cr); |
| 46 | +} |
| 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 | + |
| 67 | + if (_display->isOn()) { |
| 68 | + if (millis() >= _next_refresh) { |
| 69 | + _display->startFrame(); |
| 70 | + renderCurrScreen(); |
| 71 | + _display->endFrame(); |
| 72 | + |
| 73 | + _next_refresh = millis() + 1000; // refresh every second |
| 74 | + } |
| 75 | + if (millis() > _auto_off) { |
| 76 | + _display->turnOff(); |
| 77 | + } |
| 78 | + } |
| 79 | +} |
0 commit comments