Skip to content

Commit d51564f

Browse files
angeloINTJclaude
andcommitted
fix: add sensor type parameter to 'sensor define' command
Extended syntax: sensor define <gpio> <rom> <type> <hwId> <friendlyName> type = ds18b20 | dht22 | bme280 (case-insensitive) Legacy syntax (4 tokens) still works — auto-detects type from ROM: sensor define <gpio> <rom> <hwId> <friendlyName> Also sets sensorType in SensorRecord explicitly instead of relying solely on the initRuntimeSensors() legacy fallback. Added strVal3[32] + setStrVal3() to CliDemand for the type name. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 32aa76d commit d51564f

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/AppManager_Commands.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,18 @@ void AppManager::executeCommand(CliDemand cmd) {
393393
r.active = true;
394394
r.pins[0] = cmd.intVal1;
395395
memcpy(r.rom, cmd.rom, 8);
396+
/* Determine sensor type: explicit (v16 extended syntax) or auto-detect from ROM. */
397+
if (cmd.strVal3[0] != '\0') {
398+
if (strcmp(cmd.strVal3, "dht22") == 0) r.sensorType = TYPE_DHT22;
399+
else if (strcmp(cmd.strVal3, "ds18b20") == 0) r.sensorType = TYPE_DS18B20;
400+
else if (strcmp(cmd.strVal3, "bme280") == 0) r.sensorType = TYPE_BME280;
401+
else r.sensorType = TYPE_NONE;
402+
} else {
403+
/* Legacy: auto-detect from ROM (non-zero = DS18B20, zero = DHT22). */
404+
bool isDs18 = false;
405+
for (int k = 0; k < 8; k++) if (cmd.rom[k] != 0) isDs18 = true;
406+
r.sensorType = isDs18 ? TYPE_DS18B20 : TYPE_DHT22;
407+
}
396408
safeCopy(r.hwId, cmd.strVal1, sizeof(r.hwId));
397409
safeCopy(r.friendlyName, cmd.strVal2, sizeof(r.friendlyName));
398410
_cmdMgr->printSuccess(pt ? "Sensor mapeado em RAM."
@@ -562,14 +574,14 @@ void AppManager::executeCommand(CliDemand cmd) {
562574

563575
case CMD_USER_DEL: {
564576
const bool pt = _cmdMgr->isPt( );
565-
if (strcasecmp(cmd.strVal1, "admin") == 0) {
577+
if (strcmp(cmd.strVal1, "admin") == 0) {
566578
_cmdMgr->printError(pt ? "Nao e permitido deletar 'admin'"
567579
: "Cannot delete 'admin'");
568580
break;
569581
}
570582
bool found = false;
571583
for (int i = 1; i < MAX_USERS; i++) {
572-
if (cfg.users[i].active && strcasecmp(cmd.strVal1, cfg.users[i].username) == 0) {
584+
if (cfg.users[i].active && strcmp(cmd.strVal1, cfg.users[i].username) == 0) {
573585
cfg.users[i].active = false;
574586
memset(cfg.users[i].password, 0, sizeof(cfg.users[i].password));
575587
_cmdMgr->printSuccess(String(pt ? "Usuario removido: " : "User deleted: ") + cmd.strVal1);

src/SystemDefs_Cli.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ struct CliDemand {
9494
DemandType type;
9595
char strVal1[64] = {0};
9696
char strVal2[64] = {0};
97+
char strVal3[32] = {0};
9798
int intVal1;
9899
bool boolVal;
99100
uint8_t rom[8];
@@ -104,4 +105,5 @@ struct CliDemand {
104105
* `cmd.strVal1 = <String|const char*>`. */
105106
void setStrVal1(const char* s) { safeCopy(strVal1, s ? s : "", sizeof(strVal1)); }
106107
void setStrVal2(const char* s) { safeCopy(strVal2, s ? s : "", sizeof(strVal2)); }
108+
void setStrVal3(const char* s) { safeCopy(strVal3, s ? s : "", sizeof(strVal3)); }
107109
};

0 commit comments

Comments
 (0)