-
Notifications
You must be signed in to change notification settings - Fork 242
ui: sensors page #739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ui: sensors page #739
Changes from 3 commits
2d65122
f974cb2
8fdaace
2d4b77c
d83cdc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ class HomeScreen : public UIScreen { | |
| RADIO, | ||
| BLUETOOTH, | ||
| ADVERT, | ||
| SENSORS, | ||
| SHUTDOWN, | ||
| Count // keep as last | ||
| }; | ||
|
|
@@ -113,9 +114,32 @@ class HomeScreen : public UIScreen { | |
| display.fillRect(iconX + 2, iconY + 2, fillWidth, iconHeight - 4); | ||
| } | ||
|
|
||
| DynamicJsonDocument _sensors_doc; | ||
| JsonArray _sensors_arr; | ||
|
||
| bool scroll = false; | ||
| int scroll_offset = 0; | ||
| int next_sensors_refresh = 0; | ||
|
|
||
| void refresh_sensors() { | ||
| CayenneLPP lpp(200); | ||
|
||
| if (millis() > next_sensors_refresh) { | ||
| lpp.addVoltage(TELEM_CHANNEL_SELF, (float)board.getBattMilliVolts() / 1000.0f); | ||
| sensors.querySensors(0xFF, lpp); | ||
| _sensors_arr.clear(); | ||
| lpp.decode(lpp.getBuffer(), lpp.getSize(), _sensors_arr); | ||
| scroll = _sensors_arr.size() > UI_RECENT_LIST_SIZE; // there is a status line | ||
| #if AUTO_OFF_MILLIS > 0 | ||
| next_sensors_refresh = millis() + 5000; // refresh sensor values every 5 sec | ||
| #else | ||
| next_sensors_refresh = millis() + 60000; // refresh sensor values every 1 min | ||
| #endif | ||
| } | ||
| } | ||
|
|
||
| public: | ||
| HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, NodePrefs* node_prefs) | ||
| : _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0), _shutdown_init(false) { } | ||
| : _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0), | ||
| _shutdown_init(false), _sensors_doc(2048) { _sensors_arr=_sensors_doc.to<JsonArray>(); } | ||
|
|
||
| void poll() override { | ||
| if (_shutdown_init && !_task->isButtonPressed()) { // must wait for USR button to be released | ||
|
|
@@ -211,6 +235,34 @@ class HomeScreen : public UIScreen { | |
| display.setColor(DisplayDriver::GREEN); | ||
| display.drawXbm((display.width() - 32) / 2, 18, advert_icon, 32, 32); | ||
| display.drawTextCentered(display.width() / 2, 64 - 11, "advert: " PRESS_LABEL); | ||
| } else if (_page == HomePage::SENSORS) { | ||
| int y = 18; | ||
| refresh_sensors(); | ||
| char buf[100]; | ||
| int s_size = _sensors_arr.size(); | ||
| for (int i = 0; i < (scroll?UI_RECENT_LIST_SIZE:s_size); i++) { | ||
| JsonObject v = _sensors_arr[(i+scroll_offset)%s_size]; | ||
| display.setCursor(0, y); | ||
| switch (v["type"].as<int>()) { | ||
| case 136: // GPS | ||
| sprintf(buf, "%.4f %.4f", | ||
| v["value"]["latitude"].as<float>(), | ||
| v["value"]["longitude"].as<float>()); | ||
| break; | ||
| default: // will be a float for now | ||
| sprintf(buf, "%.02f", | ||
| v["value"].as<float>()); | ||
| } | ||
| display.setCursor(0, y); | ||
| display.print(v["name"].as<JsonString>().c_str()); | ||
| display.setCursor( | ||
| display.width()-display.getTextWidth(buf)-1, y | ||
| ); | ||
| display.print(buf); | ||
| y = y + 12; | ||
| } | ||
| if (scroll) scroll_offset = (scroll_offset+1)%s_size; | ||
| else scroll_offset = 0; | ||
| } else if (_page == HomePage::SHUTDOWN) { | ||
| display.setColor(DisplayDriver::GREEN); | ||
| display.setTextSize(1); | ||
|
|
@@ -255,6 +307,11 @@ class HomeScreen : public UIScreen { | |
| } | ||
| return true; | ||
| } | ||
| if (c == KEY_ENTER && _page == HomePage::SENSORS) { | ||
| _task->toggleGPS(); | ||
| next_sensors_refresh=0; | ||
| return true; | ||
| } | ||
| if (c == KEY_ENTER && _page == HomePage::SHUTDOWN) { | ||
| _shutdown_init = true; // need to wait for button to be released | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am just wondering what % of users will use this, and if the majority will just always be having to button press over this to get to the menu they want(?) I have no idea. But only consideration is maybe a conditional compile of this feature(?) But, then we have the problem if mushrooming build variants for releases :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this problem will occur anyway, sooner or later. For devices with low screen size and low flash size at some point adding any additional feature will cause limitations for users that don't actually need that feature or use hardware that doesn't provide the necessary resources.
That's one reason for me to come up with this proposal. It won't prevent the mushrooming of build configurations in general, but it provides a way to handle them reasonably.