Skip to content
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

Closed
Closed
Changes from 20 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
df81d3d
Merge branch 'mega' into P013_OPMODE_COMBINED
clumsy-stefan Jul 6, 2020
f2c4065
[P013_HCSR04] Add COMBINED mode
clumsy-stefan Jul 6, 2020
6ce1bee
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Jul 19, 2020
7ede755
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Jul 23, 2020
1554b26
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Jul 31, 2020
3478e3a
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Aug 1, 2020
f1f3f9e
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Aug 2, 2020
45d2c35
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Aug 7, 2020
f99b762
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Aug 9, 2020
fdb602d
Merge remote-tracking branch 'clumsy-stefan/P013_OPMODE_COMBINED' int…
clumsy-stefan Aug 11, 2020
05c2216
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Aug 11, 2020
6e40555
Merge remote-tracking branch 'clumsy-stefan/P013_OPMODE_COMBINED' int…
clumsy-stefan Sep 1, 2020
489547c
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Sep 1, 2020
b8c7b8c
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Sep 15, 2020
28d73ab
Merge remote-tracking branch 'clumsy-stefan/P013_OPMODE_COMBINED' int…
clumsy-stefan Sep 17, 2020
7f8c9c6
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Sep 23, 2020
1bcd01c
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Sep 24, 2020
d37a9a8
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Sep 26, 2020
00660ad
Merge branch 'ArduinoIDE' into P013_OPMODE_COMBINED
clumsy-stefan Sep 26, 2020
8e05631
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Sep 26, 2020
8ced635
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Sep 30, 2020
6522b3e
Merge remote-tracking branch 'clumsy-stefan/P013_OPMODE_COMBINED' int…
clumsy-stefan Sep 30, 2020
284ac5b
Change Sensor VType
clumsy-stefan Oct 1, 2020
a252b52
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Oct 2, 2020
f9443da
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Oct 5, 2020
d22646a
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Oct 8, 2020
eefb48b
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Oct 20, 2020
e45843e
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Oct 22, 2020
775cf07
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Oct 22, 2020
4c4d667
Merge remote-tracking branch 'origin/mega' into P013_OPMODE_COMBINED
clumsy-stefan Oct 24, 2020
9815dc8
Merge remote-tracking branch 'clumsy-stefan/P013_OPMODE_COMBINED' int…
clumsy-stefan Oct 24, 2020
c780808
Merge branch 'mega' into P013_OPMODE_COMBINED
TD-er Mar 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/_P013_HCSR04.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define PLUGIN_ID_013 13
#define PLUGIN_NAME_013 "Position - HC-SR04, RCW-0001, etc."
#define PLUGIN_VALUENAME1_013 "Distance"
#define PLUGIN_VALUENAME2_013 "Switch"

#include <Arduino.h>
#include <map>
Expand All @@ -19,6 +20,7 @@
// operatingMode
#define OPMODE_VALUE (0)
#define OPMODE_STATE (1)
#define OPMODE_COMBINED (2)

// measuringUnit
#define UNIT_CM (0)
Expand All @@ -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;
Copy link
Member

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.

Copy link
Contributor Author

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;
Copy link
Member

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;

Copy link
Contributor Author

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

Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
Expand All @@ -64,6 +66,7 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_013));
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_013));
break;
}

Expand All @@ -89,16 +92,16 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
PCONFIG(5) = filterSize;
}


String strUnit = (measuringUnit == UNIT_CM) ? F("cm") : F("inch");

String optionsOpMode[2];
int optionValuesOpMode[2] = { 0, 1 };
String optionsOpMode[3];
int optionValuesOpMode[3] = { 0, 1, 2 };
optionsOpMode[0] = F("Value");
optionsOpMode[1] = F("State");
addFormSelector(F("Mode"), F("p013_mode"), 2, optionsOpMode, optionValuesOpMode, operatingMode);
optionsOpMode[2] = F("Combined");
addFormSelector(F("Mode"), F("p013_mode"), 3, optionsOpMode, optionValuesOpMode, operatingMode);

if (operatingMode == OPMODE_STATE)
if ((operatingMode == OPMODE_STATE) || (operatingMode == OPMODE_COMBINED))
{
addFormNumericBox(F("Threshold"), F("p013_threshold"), threshold);
addUnit(strUnit);
Expand Down Expand Up @@ -132,7 +135,7 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
int16_t filterType = PCONFIG(4);

PCONFIG(0) = getFormItemInt(F("p013_mode"));
if (operatingMode == OPMODE_STATE)
if ((operatingMode == OPMODE_STATE) || (operatingMode == OPMODE_COMBINED))
PCONFIG(1) = getFormItemInt(F("p013_threshold"));
PCONFIG(2) = getFormItemInt(F("p013_max_distance"));

Expand Down Expand Up @@ -213,8 +216,10 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
{
int16_t operatingMode = PCONFIG(0);
int16_t measuringUnit = PCONFIG(3);

if (operatingMode == OPMODE_VALUE)
event->sensorType = SENSOR_TYPE_SINGLE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here


if ((operatingMode == OPMODE_VALUE) || (operatingMode == OPMODE_COMBINED))
{
float value = Plugin_013_read(event->TaskIndex);
String log = F("ULTRASONIC : TaskNr: ");
Expand All @@ -240,7 +245,7 @@ boolean Plugin_013(byte function, struct EventStruct *event, String& string)
int16_t operatingMode = PCONFIG(0);
int16_t threshold = PCONFIG(1);

if (operatingMode == OPMODE_STATE)
if ((operatingMode == OPMODE_STATE) || (operatingMode == OPMODE_COMBINED))
{
byte state = 0;
float value = Plugin_013_read(event->TaskIndex);
Expand All @@ -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;
Copy link
Member

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

sendData(event);
}
}
Expand Down