Add Rescan and RetryRead to onewire scan for bulletproove onewire (#19700)

Co-authored-by: Peter Rustler <peter@rustlerit.de>
This commit is contained in:
chefpro 2023-10-13 11:29:19 +02:00 committed by GitHub
parent f245821828
commit 32cbd330aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 7 deletions

View File

@ -793,7 +793,9 @@
#define D_CMND_ADCPARAM "AdcParam"
// Commands xsns_05_ds18x20.ino
#define D_CMND_DS_ALIAS "DS18Alias"
#define D_CMND_DS_ALIAS "Alias"
#define D_CMND_DS_RESCAN "Rescan"
#define D_CMND_DS_RETRYREAD "RetryRead"
// xsns_70_veml6075.ino
#define D_JSON_UVA_INTENSITY "UvaIntensity"

View File

@ -574,7 +574,7 @@ void Ds18x20Show(bool json) {
}
#ifdef DS18x20_USE_ID_ALIAS
const char kds18Commands[] PROGMEM = "|" // No prefix
const char kds18Commands[] PROGMEM = "DS18|" // prefix
D_CMND_DS_ALIAS;
void (* const DSCommand[])(void) PROGMEM = {

View File

@ -76,11 +76,13 @@ struct {
char name[17];
uint8_t sensors;
uint8_t gpios; // Count of GPIO found
uint8_t retryRead;
} DS18X20Data;
/********************************************************************************************/
void Ds18x20Init(void) {
DS18X20Data.retryRead = 0;
DS18X20Data.gpios = 0;
for (uint32_t pins = 0; pins < MAX_DSB; pins++) {
if (PinUsed(GPIO_DSB, pins)) {
@ -254,7 +256,18 @@ void Ds18x20EverySecond(void) {
float t;
for (uint32_t i = 0; i < DS18X20Data.sensors; i++) {
// 12mS per device
if (Ds18x20Read(i, t)) { // Read temperature
bool result = false;
uint8_t counter = 0;
while (counter++ < DS18X20Data.retryRead+1) {
if(Ds18x20Read(i, t)) {
result = true;
break;
}
}
if (!result)
AddLog(LOG_LEVEL_ERROR, PSTR("Read sensor %u failed in Ds18x20EverySecond."), i);
if (result) { // Read temperature
if (Settings->flag5.ds18x20_mean) {
if (ds18x20_sensor[i].numread++ == 0) {
ds18x20_sensor[i].temp_sum = 0;
@ -279,7 +292,17 @@ void Ds18x20Show(bool json) {
if (ds18x20_sensor[i].valid) {
t = ds18x20_sensor[i].temperature;
#else
if (Ds18x20Read(i, t)) { // Check if read failed
bool result = false;
uint8_t counter = 0;
while (counter++ < DS18X20Data.retryRead+1) {
if(Ds18x20Read(i, t)) {
result = true;
break;
}
}
if (!result)
AddLog(LOG_LEVEL_ERROR, PSTR("Read sensor %u failed in Ds18x20Show."), i);
if (result) { // Check if read failed
#endif
Ds18x20Name(i);
@ -317,11 +340,54 @@ void Ds18x20Show(bool json) {
}
#ifdef DS18x20_USE_ID_ALIAS
const char kds18Commands[] PROGMEM = "|" // No prefix
D_CMND_DS_ALIAS;
const char kds18Commands[] PROGMEM = "DS18|" // prefix
D_CMND_DS_ALIAS "|" D_CMND_DS_RESCAN "|" D_CMND_DS_RETRYREAD;
void (* const DSCommand[])(void) PROGMEM = {
&CmndDSAlias };
&CmndDSAlias, &CmndDSRescan ,&CmndDSRetryRead };
void CmndDSRetryRead(void) {
char argument[XdrvMailbox.data_len];
if (ArgC()==1) {
DS18X20Data.retryRead = atoi(ArgV(argument, 1));
}
Response_P(PSTR("{\"DS18" D_CMND_DS_RETRYREAD "\": %d}"),DS18X20Data.retryRead);
}
void CmndDSRescan(void) {
char argument[XdrvMailbox.data_len];
uint8_t retries = 1;
uint8_t sensorsToFind = 1;
if (ArgC()>0 && ArgC()<3) {
sensorsToFind = atoi(ArgV(argument, 1));
}
if (ArgC()==2) {
retries = atoi(ArgV(argument, 2));
}
DS18X20Data.sensors = 0;
memset(&ds18x20_sensor, 0, sizeof(ds18x20_sensor));
while (DS18X20Data.sensors < sensorsToFind && retries-- > 0) {
Ds18x20Search();
AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_DSB D_SENSORS_FOUND " %d"), DS18X20Data.sensors);
}
Response_P(PSTR("{"));
for (uint32_t i = 0; i < DS18X20Data.sensors; i++) {
Ds18x20Name(i);
char address[17];
for (uint32_t j = 0; j < 8; j++) {
sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]); // Skip sensor type and crc
}
ResponseAppend_P(PSTR("\"%s\":{\"" D_JSON_ID "\":\"%s\"}"),DS18X20Data.name, address);
if (i < DS18X20Data.sensors-1) {ResponseAppend_P(PSTR(","));}
}
ResponseAppend_P(PSTR("}"));
}
void CmndDSAlias(void) {
char Argument1[XdrvMailbox.data_len];