Settings for use with distance alarm mode.
More...
#include <JSN-SR04_Gen3_RK.h>
|
enum class | Direction : int { LESS_THAN = -1
, GREATER_THAN = +1
} |
| This enum specifies whether being in alarm is when the distance is less than or greater than the current distance. More...
|
|
|
Direction | direction = Direction::LESS_THAN |
| Stores the direction of the test. Default: LESS_THAN.
|
|
Distance | hysteresis = 0.0005 |
| Stores the distance for hysteresis. Default: 0.5 cm.
|
|
unsigned long | periodMs = 500 |
| How often check the sensor for alarm condition. More...
|
|
double | distanceM = 0.0 |
| The value of the distance in meters.
|
|
Settings for use with distance alarm mode.
If you need fine control over the alarm mode, use this class directly. For simple use cases, you can use DistanceAlarmLessThan or DistanceAlarmGreaterThan which are easier to set up.
◆ Direction
This enum specifies whether being in alarm is when the distance is less than or greater than the current distance.
Enumerator |
---|
LESS_THAN | Alarm when less than distance (you are too close)
|
GREATER_THAN | Alarm when greater than distance (you are too far away)
|
◆ isValid()
bool JSN_SR04_Gen3::DistanceAlarm::isValid |
( |
| ) |
const |
|
inline |
Returns true if a distance has been configured.
- Returns
- true
-
false
◆ withDirection()
Direction LESS_THAN or GREATER_THAN.
- Parameters
-
direction | the direction enum to test |
- Returns
- DistanceAlarm& This object, for chaining options, fluent-style
◆ withDistance()
Sets the distance for the alarm.
- Parameters
-
distance | The distance value to set |
- Returns
- DistanceAlarm& This object, for chaining options, fluent-style
The Distance object contains a distance in meters, but for convenience, the classes DistanceCm and DistanceInch can make setting the value easy in other units.
◆ withHysteresis()
Hystersis value (default: 0.5 cm)
- Parameters
-
hysteresis | The distance value to set |
- Returns
- DistanceAlarm& This object, for chaining options, fluent-style
The Distance object contains a distance in meters, but for convenience, the classes DistanceCm and DistanceInch can make setting the value easy in other units.
When in LESS_THAN mode, you enter alarm mode when the distance is less than the alarm distance. You exit alarm mode when the distance is greater than the alarm distance + hysteresis.
When in GREATER_THAN mode, you enter alarm mode when the distance is greater than the alarm distance. You exit alarm mode when the distance is less than the alarm distance - hysteresis.
◆ withPeriod()
DistanceAlarm & JSN_SR04_Gen3::DistanceAlarm::withPeriod |
( |
std::chrono::milliseconds |
period | ) |
|
|
inline |
The period to test (default: 500 milliseconds, twice per second)
- Parameters
-
period | The period as a chrono literal |
- Returns
- DistanceAlarm& This object, for chaining options, fluent-style
The default is 500ms, but you can pass constants like 10s for 10 seconds (10000 ms).
◆ periodMs
unsigned long JSN_SR04_Gen3::DistanceAlarm::periodMs = 500 |
How often check the sensor for alarm condition.
This probably should be longer than safetyTimeoutMs but can be shorter.
The documentation for this class was generated from the following file: