-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[P013_HCSR04] Add COMBINED mode #3157
[P013_HCSR04] Add COMBINED mode #3157
Conversation
Add a "COMBINED" mode to HCSR04 plugin to be able to use the switch feature together with periodic distance metering. Should be 100% backwards compatible.
src/_P013_HCSR04.ino
Outdated
event->sensorType = SENSOR_TYPE_SWITCH; | ||
if (operatingMode == OPMODE_STATE) { | ||
UserVar[event->BaseVarIndex] = state; | ||
event->sensorType = SENSOR_TYPE_SWITCH; |
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.
+ValueCount
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.
??
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.
@uzi18 Can you explain what you meant with your comment?
I also don't really see what you're missing here.
@TD-er this PR runs for some weeks now stable at my site as well with "traditional" distance meters as in combined mode. So it would be great if it could be merged into mega, if there are no objections…. cheers. |
I can only think of a possible issue when it is used to send data to specific controllers (e.g. Domoticz) or shared via p2p to another node running the 'older' version of this plugin. So I guess that may be the warning @uzi18 tried to make here, that changing the number of output values may lead to these issues I mention here now. |
hmm… but the number of output values only changes in COMBINED mode, in the (old) switch or distance mode the output count is still the same… |
Nope, this is what is set as the default: |
could that be changed at runtime? |
Well... that's what I do for the sysinfo, dummy and SenseAir plugin. For example for the Dummy plugin, if you have multiple instances of that plugin, all tasks with that plugin will be set to the.... last changed one :( |
…o P013_OPMODE_COMBINED
…o P013_OPMODE_COMBINED
Hmm… Any chance this is beeing integrated? If not, what should be adapted? |
I still don't know for sure what @uzi18 meant. Right now you do seem to make it selectable to output multiple values instead of 1. |
@TD-er @clumsy-stefan when change from/to combined mode please change also valuecount and device type in device configuration. |
For this PR, it is good to know I am now dealing with the buggy handling of changing number of output values. |
Ok, I'm happy to change this PR accordingly, but first have to find out how to do that (changing the number of output values at runtime)… |
I will add some documentation to the PR, and you may be the first one to check if it is sufficient :) |
It has been merged, good luck :) |
src/_P013_HCSR04.ino
Outdated
@@ -42,12 +44,12 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string) | |||
{ | |||
Device[++deviceCount].Number = PLUGIN_ID_013; | |||
Device[deviceCount].Type = DEVICE_TYPE_DUAL; | |||
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE; | |||
Device[deviceCount].VType = SENSOR_TYPE_DUAL; |
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.
Should be using the Sensor_VType::
prefix.
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.
Yep, sure, otherwise it won't compile anyway… I changed it but did not yet commit…
Device[deviceCount].Ports = 0; | ||
Device[deviceCount].PullUpOption = false; | ||
Device[deviceCount].InverseLogicOption = false; | ||
Device[deviceCount].FormulaOption = true; | ||
Device[deviceCount].ValueCount = 1; | ||
Device[deviceCount].ValueCount = 2; |
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.
You should leave the default to 1, as it is used by all instances out there.
And make it configurable to select a different number of outputs.
See the P026_Sysinfo.ino for an example and I also added the new Plugin functions to the Pxxx_Template.ino.
For example, also add this:
Device[deviceCount].OutputDataType = Output_Data_type_t::Simple;
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.
ok, I'll have a look at it
src/_P013_HCSR04.ino
Outdated
@@ -257,7 +262,7 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string) | |||
addLog(LOG_LEVEL_INFO,log); | |||
switchstate[event->TaskIndex] = state; | |||
UserVar[event->BaseVarIndex] = state; | |||
event->sensorType = Sensor_VType::SENSOR_TYPE_SWITCH; | |||
event->sensorType = SENSOR_TYPE_SWITCH; |
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.
Should use the Sensor_VType::
prefix
src/_P013_HCSR04.ino
Outdated
if (operatingMode == OPMODE_VALUE) | ||
event->sensorType = SENSOR_TYPE_SINGLE; |
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.
Same here
…o P013_OPMODE_COMBINED
Adapt to new VType definition
…o P013_OPMODE_COMBINED
Is included in #4442 |
Add a "COMBINED" mode to HCSR04 plugin to be able to use the switch feature together with periodic distance metering. Should be 100% backwards compatible.