Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SmartHome
NodeManager_GasSensor
Commits
d296022b
Commit
d296022b
authored
May 08, 2017
by
user2684
Browse files
Add option to define which state means for relay open/close #77
parent
9a485cdc
Changes
3
Hide whitespace changes
Inline
Side-by-side
NodeManager.cpp
View file @
d296022b
...
...
@@ -790,6 +790,9 @@ void SensorDigitalOutput::setInitialValue(int value) {
void
SensorDigitalOutput
::
setPulseWidth
(
int
value
)
{
_pulse_width
=
value
;
}
void
SensorDigitalOutput
::
setOnValue
(
int
value
)
{
_on_value
=
value
;
}
// main task
void
SensorDigitalOutput
::
onLoop
()
{
...
...
@@ -812,15 +815,21 @@ void SensorDigitalOutput::onReceive(const MyMessage & message) {
Serial
.
print
(
F
(
" P="
));
Serial
.
println
(
_pulse_width
);
#endif
// reverse the value if needed
int
value_to_write
=
value
;
if
(
_on_value
==
LOW
)
{
if
(
value
==
HIGH
)
value_to_write
=
LOW
;
if
(
value
==
LOW
)
value_to_write
=
HIGH
;
}
// set the value
digitalWrite
(
_pin
,
value
);
_state
=
value
;
digitalWrite
(
_pin
,
value_to_write
);
if
(
_pulse_width
>
0
)
{
// if this is a pulse output, restore the value to the original value after the pulse
wait
(
_pulse_width
);
digitalWrite
(
_pin
,
value
==
0
?
HIGH
:
LOW
);
digitalWrite
(
_pin
,
value
_to_write
==
0
?
HIGH
:
LOW
);
}
// store the current value so it will be sent to the controller
_state
=
value
;
_value_int
=
value
;
}
if
(
message
.
getCommand
()
==
C_REQ
)
{
...
...
NodeManager.h
View file @
d296022b
...
...
@@ -578,6 +578,8 @@ class SensorDigitalOutput: public Sensor {
void
setInitialValue
(
int
value
);
// if greater than 0, send a pulse of the given duration in ms and then restore the output back to the original value (default: 0)
void
setPulseWidth
(
int
value
);
// define which value to set to the output when set to on (default: HIGH)
void
setOnValue
(
int
value
);
// define what to do at each stage of the sketch
void
onBefore
();
void
onSetup
();
...
...
@@ -585,6 +587,7 @@ class SensorDigitalOutput: public Sensor {
void
onReceive
(
const
MyMessage
&
message
);
protected:
int
_initial_value
=
LOW
;
int
_on_value
=
HIGH
;
int
_state
=
0
;
int
_pulse_width
=
0
;
};
...
...
README.md
View file @
d296022b
...
...
@@ -442,6 +442,8 @@ Each sensor class can expose additional methods.
void
setInitialValue
(
int
value
);
// if greater than 0, send a pulse of the given duration in ms and then restore the output back to the original value (default: 0)
void
setPulseWidth
(
int
value
);
// define which value to set to the output when set to on (default: HIGH)
void
setOnValue
(
int
value
);
~~~
#### SensorSwitch / SensorDoor / SensorMotion
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment