sensor list command

This commit is contained in:
Florent de Lamotte
2025-10-06 14:08:16 +02:00
parent 7be65c148e
commit 341b69e3c9
2 changed files with 42 additions and 10 deletions

View File

@@ -440,6 +440,31 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, const char* command, ch
} else { } else {
strcpy(reply, "can't find custom var"); strcpy(reply, "can't find custom var");
} }
} else if (memcmp(command, "sensor list", 11) == 0) {
char* dp = reply;
int start = 0;
int end = sensors.getNumSettings();
if (strlen(command) > 11) {
start = _atoi(command+12);
}
if (start >= end) {
strcpy(reply, "no custom var");
} else {
sprintf(dp, "%d vars\n", end);
dp = strchr(dp, 0);
int i;
for (i = start; i < end && (dp-reply < 134); i++) {
sprintf(dp, "%s=%s\n",
sensors.getSettingName(i),
sensors.getSettingValue(i));
dp = strchr(dp, 0);
}
if (i < end) {
sprintf(dp, "... next:%d", i);
} else {
*(dp-1) = 0; // remove last CR
}
}
#if ENV_INCLUDE_GPS == 1 #if ENV_INCLUDE_GPS == 1
} else if (memcmp(command, "gps on", 6) == 0) { } else if (memcmp(command, "gps on", 6) == 0) {
if (sensorSetCustomVar("gps", "1")) { if (sensorSetCustomVar("gps", "1")) {

View File

@@ -387,27 +387,34 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
int EnvironmentSensorManager::getNumSettings() const { int EnvironmentSensorManager::getNumSettings() const {
int settings = 0;
#if ENV_INCLUDE_GPS #if ENV_INCLUDE_GPS
return gps_detected ? 1 : 0; // only show GPS setting if GPS is detected if (gps_detected) settings++; // only show GPS setting if GPS is detected
#else
return 0;
#endif #endif
return settings;
} }
const char* EnvironmentSensorManager::getSettingName(int i) const { const char* EnvironmentSensorManager::getSettingName(int i) const {
int settings = 0;
#if ENV_INCLUDE_GPS #if ENV_INCLUDE_GPS
return (gps_detected && i == 0) ? "gps" : NULL; if (gps_detected && i == settings++) {
#else return "gps";
return NULL; }
#endif #endif
// convenient way to add params (needed for some tests)
// if (i == settings++) return "param.2";
return NULL;
} }
const char* EnvironmentSensorManager::getSettingValue(int i) const { const char* EnvironmentSensorManager::getSettingValue(int i) const {
int settings = 0;
#if ENV_INCLUDE_GPS #if ENV_INCLUDE_GPS
if (gps_detected && i == 0) { if (gps_detected && i == settings++) {
return gps_active ? "1" : "0"; return gps_active ? "1" : "0";
} }
#endif #endif
// convenient way to add params ...
// if (i == settings++) return "2";
return NULL; return NULL;
} }