-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding support multiple GPIO for DS18x20 sensors. Aliases of DS18x20 optimization. #16833
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put some comments because I think this could be optimized and impact on code size reduced
snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("DS18Alias%c%d"), IndexSeparator(), ds18x20_sensor[sensor].alias); | ||
} else { | ||
#endif | ||
snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("%s%c%d"), DS18X20Data.name, IndexSeparator(), sensor +1); | ||
#ifdef DS18x20_USE_ID_ALIAS | ||
snprintf_P(DS18X20Data.name, sizeof(DS18X20Data.name), PSTR("DS18Sens")); | ||
print_ind = ds18x20_sensor[sensor].alias; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing from "DS18Alias" to "DS18Sens" is now a breaking change
I know you introduced that recently so probably not much is use yet but just raising the point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I recently added this functionality and it hasn't been released yet. DS18Sens is a more correct name. I will try to avoid such edits. Also fixed aliases output to the accepted style.
#ifdef DS18x20_MULTI_GPIOs | ||
struct { | ||
int8_t pin = 0; // Shelly GPIO3 input only | ||
int8_t pin_out = 0; // Shelly GPIO00 output only | ||
bool dual_mode = false; // Single pin mode | ||
} ds18x20_gpios[MAX_DSB]; | ||
uint8_t ds18x20_ngpio = 0; // Count of GPIO found | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why introducing a new data structure instead of modulating the size of the existing DS18X20Data
between [1]
and [MAX_DSB]
That should simplify the rest of the code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new structure uses only 12 bytes of RAM. DS18X20Data uses 22 bytes and increasing to 4 copies will add another 66 bytes.
And will also have to pass GPIO numbers to all low-level functions: OneWire1ReadBit(void), OneWire2ReadBit(void), OneWireWriteBit(uint8_t v), OneWireReset(void). Such changes can lead to a significant increase in the final code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was wondering : passing some parameters to function vs copying
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a test module, replaced copying with transferring the index of the gpio array.
With copying use 687300 bytes of flash.
With passing the parameter to the low-level functions 687364 bytes of flash.
Loss of 64 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for trying
Set to on hold to merge after next release. |
Add DS18x20 support on up to four GPIOs by md5sum-as (#16833)
Description:
Adding support multiple GPIO for DS18x20 sensors.
To enable this function, use the DS18x20_MULTI_GPIOs flag in my_user_config.h or user_config_override.h
Discussion: #16811
Optimization a code in xsns_05_ds18x20.ino and xsns_05_esp32_ds18x20.ino in function Ds18x20Name()
Checklist:
NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass