-
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
Changes from 20 commits
df81d3d
f2c4065
6ce1bee
7ede755
1554b26
3478e3a
f1f3f9e
45d2c35
f99b762
fdb602d
05c2216
6e40555
489547c
b8c7b8c
28d73ab
7f8c9c6
1bcd01c
d37a9a8
00660ad
8e05631
8ced635
6522b3e
284ac5b
a252b52
f9443da
d22646a
eefb48b
e45843e
775cf07
4c4d667
9815dc8
c780808
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -19,6 +20,7 @@ | |
// operatingMode | ||
#define OPMODE_VALUE (0) | ||
#define OPMODE_STATE (1) | ||
#define OPMODE_COMBINED (2) | ||
|
||
// measuringUnit | ||
#define UNIT_CM (0) | ||
|
@@ -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; | ||
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 commentThe 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. 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 commentThe 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; | ||
|
@@ -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; | ||
} | ||
|
||
|
@@ -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); | ||
|
@@ -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")); | ||
|
||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: "); | ||
|
@@ -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); | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Should use the |
||
sendData(event); | ||
} | ||
} | ||
|
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…