mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 23:08:11 +00:00
fix: show keyboard placeholders only for sensors with actual live data
Replace getAvailableLPPTypes() (hardware-detected) with a live querySensors() call so only placeholders for sensors currently returning values appear in the picker. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
// Populates a KeyboardWidget's placeholder list with sensor types currently
|
||||
// detected by SensorManager. Always adds {loc} and {time} via begin(); this
|
||||
// helper appends the sensor-specific entries on top.
|
||||
// Populates a KeyboardWidget's placeholder list based on live sensor data.
|
||||
// Only adds placeholders for types that actually returned a value right now.
|
||||
// Always adds {loc} and {time} via begin(); this helper appends the rest.
|
||||
|
||||
#include "KeyboardWidget.h"
|
||||
#include <helpers/SensorManager.h>
|
||||
@@ -9,8 +9,23 @@
|
||||
|
||||
inline void kbAddSensorPlaceholders(KeyboardWidget& kb, SensorManager* sm) {
|
||||
if (!sm) return;
|
||||
uint8_t types[16];
|
||||
int tc = sm->getAvailableLPPTypes(types, 16);
|
||||
|
||||
CayenneLPP lpp(100);
|
||||
sm->querySensors(0xFF, lpp);
|
||||
|
||||
// collect unique LPP types that have actual data
|
||||
uint8_t present[16];
|
||||
int pc = 0;
|
||||
{
|
||||
LPPReader r(lpp.getBuffer(), lpp.getSize());
|
||||
uint8_t ch, type;
|
||||
while (r.readHeader(ch, type)) {
|
||||
bool already = false;
|
||||
for (int i = 0; i < pc; i++) if (present[i] == type) { already = true; break; }
|
||||
if (!already && pc < 16) present[pc++] = type;
|
||||
r.skipData(type);
|
||||
}
|
||||
}
|
||||
|
||||
static const struct { uint8_t t; const char* ph; } MAP[] = {
|
||||
{ LPP_TEMPERATURE, "{temp}" },
|
||||
@@ -24,8 +39,8 @@ inline void kbAddSensorPlaceholders(KeyboardWidget& kb, SensorManager* sm) {
|
||||
};
|
||||
|
||||
for (const auto& m : MAP) {
|
||||
for (int i = 0; i < tc; i++) {
|
||||
if (types[i] == m.t) { kb.addPlaceholder(m.ph); break; }
|
||||
for (int i = 0; i < pc; i++) {
|
||||
if (present[i] == m.t) { kb.addPlaceholder(m.ph); break; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user