Skip to content

Commit

Permalink
[DS18x20] change to calloc()
Browse files Browse the repository at this point in the history
  • Loading branch information
SteWers committed Jul 4, 2023
1 parent d3aeba0 commit d0a1ce0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions tasmota/tasmota_xsns_sensor/xsns_05_ds18x20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#define DS18X20_MAX_SENSORS 8
#endif

#define DS18X20_ALIAS_LEN 17

const char kDs18x20Types[] PROGMEM = "DS18x20|DS18S20|DS1822|DS18B20|MAX31850";

uint8_t ds18x20_chipids[] = { 0, DS18S20_CHIPID, DS1822_CHIPID, DS18B20_CHIPID, MAX31850_CHIPID };
Expand All @@ -63,7 +65,7 @@ struct {
uint8_t valid;
int8_t pins_id;
#ifdef DS18x20_USE_ID_ALIAS
char alias[17] = "0";
char *alias = (char*)calloc(DS18X20_ALIAS_LEN, 1);
#endif // DS18x20_USE_ID_ALIAS
} ds18x20_sensor[DS18X20_MAX_SENSORS];

Expand Down Expand Up @@ -357,6 +359,9 @@ void Ds18x20Init(void) {
for (uint32_t j = 6; j > 0; j--) {
ids[DS18X20Data.sensors] = ids[DS18X20Data.sensors] << 8 | ds18x20_sensor[DS18X20Data.sensors].address[j];
}
#ifdef DS18x20_USE_ID_ALIAS
ds18x20_sensor[DS18X20Data.sensors].alias[0] = '0';
#endif
ds18x20_sensor[DS18X20Data.sensors].pins_id = pins;
DS18X20Data.sensors++;
}
Expand Down Expand Up @@ -590,7 +595,7 @@ void CmndDSAlias(void) {
sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]);
}
if (!strncmp(Argument1, address, 12) && Argument2[0]) {
snprintf_P(ds18x20_sensor[i].alias, sizeof(ds18x20_sensor[i].alias), PSTR("%s"), Argument2);
snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2);
break;
}
}
Expand Down
9 changes: 7 additions & 2 deletions tasmota/tasmota_xsns_sensor/xsns_05_esp32_ds18x20.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
#define DS18X20_MAX_SENSORS 8
#endif

#define DS18X20_ALIAS_LEN 17

const char kDs18x20Types[] PROGMEM = "DS18x20|DS18S20|DS1822|DS18B20|MAX31850";

uint8_t ds18x20_chipids[] = { 0, DS18S20_CHIPID, DS1822_CHIPID, DS18B20_CHIPID, MAX31850_CHIPID };
Expand All @@ -62,7 +64,7 @@ struct {
uint8_t valid;
int8_t pins_id;
#ifdef DS18x20_USE_ID_ALIAS
char alias[17] = "0";
char *alias = (char*)calloc(DS18X20_ALIAS_LEN, 1);
#endif //DS18x20_USE_ID_ALIAS
} ds18x20_sensor[DS18X20_MAX_SENSORS];

Expand Down Expand Up @@ -108,6 +110,9 @@ void Ds18x20Search(void) {
(ds18x20_sensor[num_sensors].address[0] == DS1822_CHIPID) ||
(ds18x20_sensor[num_sensors].address[0] == DS18B20_CHIPID) ||
(ds18x20_sensor[num_sensors].address[0] == MAX31850_CHIPID))) {
#ifdef DS18x20_USE_ID_ALIAS
ds18x20_sensor[DS18X20Data.sensors].alias[0] = '0';
#endif
ds18x20_sensor[num_sensors].pins_id = pins;
num_sensors++;
}
Expand Down Expand Up @@ -333,7 +338,7 @@ void CmndDSAlias(void) {
sprintf(address+2*j, "%02X", ds18x20_sensor[i].address[7-j]);
}
if (!strncmp(Argument1, address, 12) && Argument2[0]) {
snprintf_P(ds18x20_sensor[i].alias, sizeof(ds18x20_sensor[i].alias), PSTR("%s"), Argument2);
snprintf_P(ds18x20_sensor[i].alias, DS18X20_ALIAS_LEN, PSTR("%s"), Argument2);
break;
}
}
Expand Down

0 comments on commit d0a1ce0

Please # to comment.