Skip to content

Commit

Permalink
Merge pull request #5140 from tonhuisman/feature/P159-threshold
Browse files Browse the repository at this point in the history
[P159] Extend max threshold
  • Loading branch information
TD-er authored Dec 9, 2024
2 parents 6070275 + f858cb8 commit a5f3682
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/source/Plugin/P159.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ After checking the checkbox to enabled state, the settings will be available imm
* **Idle seconds**: The number of seconds the *Presence* stays active after presence is removed, can be set here. Default value 5 sec. max. value is 65535 sec.
* **Max. Moving gates**: The number of active gates for detecting Moving presence. Range 2 .. 8.
* **Max. Stationary gates**: The number of active gates for detecting Stationary presence. Range 2 .. 8.
* **Sensitivity, Gate 0 .. 8**: For each type of detection, the sensitivity treshold can be set, range 0 .. 100, where 0 is the most sensitive, and 100 means it won't trigger, as that's the max. value that will be reported.
* **Sensitivity, Gate 0 .. 8**: For each type of detection, the sensitivity treshold can be set, range 0 .. 101, where 0 is the most sensitive, and 101 means it won't trigger, as 100 is the max. value that will be reported.

For each gate the distance range in meters is also shown. When the highest enabled Gate is less that the default 8, then only up to that gate-number is shown and configurable.
For each gate the distance range in meters is also shown. When the highest enabled Gate is less than the default 8, then only up to that gate-number is shown and configurable.

If the **Modify sensor settings** checkbox is checked when submitting the page, the settings are sent to the sensor, and the sensor will be restarted to activate them. The configured values are persistently stored in the LD2410 sensor.

Expand Down
3 changes: 3 additions & 0 deletions src/_P159_LD2410.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// #######################################################################################################

/** Changelog:
* 2024-12-09 tonhuisman: Fix: Reduced max sensitivity to configure to 101, as the max value that vill be reported by the sensor is 100,
* so checking up to 100 was an off-by-one error.
* 2024-10-09 tonhuisman: Extend sensitivity max. value to 110 (experimental, was 100)
* 2023-10-29 tonhuisman: Rework processing, allow Interval = 0, as now the events will be generated when a value changes,
* but at most once per 100 msec, to not overload the ESP. Fixed the LD2410 library to work correctly
* with the event-driven scheduler model of ESPEasy, instead of the continuous loop() run of Arduino
Expand Down
12 changes: 7 additions & 5 deletions src/src/PluginStructs/P159_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool P159_data_struct::processSensor(struct EventStruct *event) {

for (uint8_t i = 0; i <= mMax; ++i) {
addLog(LOG_LEVEL_INFO, strformat(F("LD2410: Sensitivity, gate %d (%.2f - %.2f mtr): moving:%3d, stationary:%3d"),
i, i * 0.75f, (i + 1) * 0.75f,
i, i * P159_GATE_DISTANCE_METERS, (i + 1) * P159_GATE_DISTANCE_METERS,
i <= mMvGate ? radar->cfgMovingGateSensitivity(i) : 0,
i <= mStGate ? radar->cfgStationaryGateSensitivity(i) : 0));
}
Expand Down Expand Up @@ -297,11 +297,11 @@ bool P159_data_struct::plugin_webform_load(struct EventStruct *event) {

for (uint8_t i = 0; i <= mMax; ++i) {
html_TR_TD();
addHtml(strformat(F("Gate %d (%.2f - %.2f mtr)"), i, i * 0.75f, (i + 1) * 0.75f));
addHtml(strformat(F("Gate %d (%.2f - %.2f mtr)"), i, i * P159_GATE_DISTANCE_METERS, (i + 1) * P159_GATE_DISTANCE_METERS));
html_TD();
addNumericBox(getPluginCustomArgName(idx++), radar->cfgMovingGateSensitivity(i), 0, 100, true);
addNumericBox(getPluginCustomArgName(idx++), radar->cfgMovingGateSensitivity(i), 0, P159_MAX_SENSITIVITY_VALUE, true);
html_TD();
addNumericBox(getPluginCustomArgName(idx++), radar->cfgStationaryGateSensitivity(i), 0, 100, true);
addNumericBox(getPluginCustomArgName(idx++), radar->cfgStationaryGateSensitivity(i), 0, P159_MAX_SENSITIVITY_VALUE, true);
}
html_end_table();
addHtml(strformat(F("\n<script type='text/javascript'>document.getElementById('saveSens')."
Expand Down Expand Up @@ -332,7 +332,9 @@ bool P159_data_struct::plugin_webform_save(struct EventStruct *event) {
const uint16_t sStat = getFormItemIntCustomArgName(idx++);

// Set sensitivity (level) to 100 to effectively disable sensitivity
radar->setGateSensitivityThreshold(gate, gate <= gMove ? sMove : 100, gate <= gStat ? sStat : 100);
radar->setGateSensitivityThreshold(gate,
gate <= gMove ? sMove : P159_MAX_SENSITIVITY_VALUE,
gate <= gStat ? sStat : P159_MAX_SENSITIVITY_VALUE);
}
radar->requestConfigurationModeEnd();
addLog(LOG_LEVEL_INFO, F("LD2410: Save sensitivity settings to sensor, done."));
Expand Down
13 changes: 8 additions & 5 deletions src/src/PluginStructs/P159_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@
# define P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE0 37
# define P159_OUTPUT_MOVING_SENSOR_ENERGY_GATE8 45

# define P159_NR_OUTPUT_OPTIONS 8 // Last P159_OUTPUT_*_DISTANCE value + 1 (count)
# define P159_NR_ENGINEERING_OUTPUT_OPTIONS 28 // Last P159_OUTPUT_*_DISTANCE value + 1 (count) ENGINEERING
# define P159_NR_MAX_OUTPUT_OPTIONS 46 // Last P159_OUTPUT_*_SENSOR value + 1 (count)
# define P159_NR_OUTPUT_OPTIONS 8 // Last P159_OUTPUT_*_DISTANCE value + 1 (count)
# define P159_NR_ENGINEERING_OUTPUT_OPTIONS 28 // Last P159_OUTPUT_*_DISTANCE value + 1 (count) ENGINEERING
# define P159_NR_MAX_OUTPUT_OPTIONS 46 // Last P159_OUTPUT_*_SENSOR value + 1 (count)

# define P159_DELAY_RESTART 2500 // milliseconds to 'wait' (ignore) after a device-restart
# define P159_DELAY_SENDOUT 100 // Minimal milliseconds between sending data/events
# define P159_DELAY_RESTART 2500 // milliseconds to 'wait' (ignore) after a device-restart
# define P159_DELAY_SENDOUT 100 // Minimal milliseconds between sending data/events

# define P159_MAX_SENSITIVITY_VALUE 101 // Max sensitivity 0 = most sensitive, 101 = no output (max = 100) (docs)
# define P159_GATE_DISTANCE_METERS 0.75f // Size of each gate in meters (0.75f)

enum class P159_state_e : uint8_t {
Initializing = 0u,
Expand Down

0 comments on commit a5f3682

Please sign in to comment.