Closed jimtng closed 4 years ago
Hi Jim,
Very nice! Do you know how to mark setMicrosecondsToMetersFactor
as deprecated? Maybe that would be an option instead of dropping the method.
Do you know how to mark
setMicrosecondsToMetersFactor
as deprecated?
It seems that "deprecated" is only available in C++14. There are some suggestions on stackoverflow about implementing "deprecated" in earlier versions with macros.
OTOH would it really hurt, if you just remove the function? I guess that right now maybe 3-4 people are using the pingnode, because it was just recently submitted by @ArdKuijpers.
I can remove it if you're happy with that. It's just a single line.
I have also changed the constructor to include the node name. It was previously hard coded to "RCW-0001".
In the SensorNode, the arguments are called "name, type"
SensorNode::SensorNode(const char *name, const char *type)
: HomieNode(name, type, "sensor")
However, if you looked inside HomieNode (v3 - develop branch)
HomieNode(const char* id, const char* name, const char* type, bool range = false, uint16_t lower = 0, uint16_t upper = 0, const HomieInternals::NodeInputHandler& nodeInputHandler = [](const HomieRange& range, const String& property, const String& value) { return false; });
The first argument is id
and the second is name
, the third is type
So starting from SensorNode
and everything else that derives from it, including PingNode is calling it the wrong name. The "name" is passed to HomieNode as the "id" and the 'type" is passed to HomieNode as "name", and the actual "type" is hardcoded as "sensor".
Fixing this requires fixing everything... but that's probably for a different PR
Please remove it. I guess we'll be fine with that.
Good catch. I'll have a look at the id/name issue. IIUC, renaming the arguments in SensorNode properly should fix it.
Please remove it. I guess we'll be fine with that.
Done.
Thanks! BTW: does the info about pingnode in README need an update too?
BTW: does the info about pingnode in README need an update too?
The README is actually still valid as it is. It talks about setTemperature() which remains the same.
@jimtng Great work. I did some refactoring during the development myself and the SetMicroSecondsToMeterFactor should have been removed but was still there. Good you found it.
Changes:
setTemperature
setMicrosecondsToMeter()
accepting an actual "microseconds_to_m" factor as the argument. This will allow setting the factor without using a temperature sensor. For example, if I know that my object is 20cm when fully opened, and I know the microseconds (reported by the node), I can call setMicrosecondsToMeter( us_at_20cm / 0.2 )I deliberately changed the method's name from
setMicrosecondsToMetersFactor
tosetMicrosecondsToMeter
Code that calls setMicrosecondsToMetersFactor will need to rename it to setTemperature
Add a protected, virtual onChange() method that can be overridden by the descendent class.
Modify the logic within the loop() - decouple the change notifications (changeHandler) from the publish interval, so that changeHandler gets called as soon as a change is detected, subject to measurement interval.
Change the setXXX methods to return a reference to
this
, so that the setter method calls can be chained, e.g.