Skip to content

Commit 63a76c8

Browse files
authored
Merge pull request #67 from Lyr3x/fix-wdt
Fix presence sensor and wdt crashes
2 parents 4d65ed5 + eda1c3c commit 63a76c8

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

components/roode/roode.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ namespace esphome
174174
}
175175
}
176176

177-
if (CurrentZoneStatus == NOBODY && LeftPreviousStatus == NOBODY && RightPreviousStatus == NOBODY)
178-
{
179-
// nobody is in the sensing area
180-
presence_sensor->publish_state(false);
181-
}
182-
183177
// if an event has occured
184178
if (AnEventHasOccured)
185179
{
@@ -243,6 +237,11 @@ namespace esphome
243237
PathTrack[PathTrackFillingSize - 1] = AllZonesCurrentStatus;
244238
}
245239
}
240+
if (CurrentZoneStatus == NOBODY && LeftPreviousStatus == NOBODY && RightPreviousStatus == NOBODY)
241+
{
242+
// nobody is in the sensing area
243+
presence_sensor->publish_state(false);
244+
}
246245
}
247246

248247
void Roode::sendCounter(uint16_t counter)
@@ -265,13 +264,9 @@ namespace esphome
265264
{
266265
// the value of the average distance is used for computing the optimal size of the ROI and consequently also the center of the two zones
267266
int function_of_the_distance = 16 * (1 - (0.15 * 2) / (0.34 * (min(optimized_zone_0, optimized_zone_1) / 1000)));
268-
delay(1000);
269267
int ROI_size = min(8, max(4, function_of_the_distance));
270268
Roode::roi_width_ = ROI_size;
271269
Roode::roi_height_ = ROI_size * 2;
272-
273-
delay(250);
274-
275270
// now we set the position of the center of the two zones
276271
if (advised_sensor_orientation_)
277272
{
@@ -326,7 +321,6 @@ namespace esphome
326321
break;
327322
}
328323
}
329-
delay(2000);
330324
// we will now repeat the calculations necessary to define the thresholds with the updated zones
331325
zone = 0;
332326
int *values_zone_0 = new int[number_attempts];
@@ -354,7 +348,7 @@ namespace esphome
354348
values_zone_1[i] = distance;
355349
zone++;
356350
zone = zone % 2;
357-
yield();
351+
App.feed_wdt();
358352
}
359353
optimized_zone_0 = getOptimizedValues(values_zone_0, getSum(values_zone_0, number_attempts), number_attempts);
360354
optimized_zone_1 = getOptimizedValues(values_zone_1, getSum(values_zone_1, number_attempts), number_attempts);
@@ -541,7 +535,6 @@ namespace esphome
541535
if (roi_calibration_)
542536
{
543537
roi_calibration(distanceSensor, optimized_zone_0, optimized_zone_1);
544-
yield();
545538
}
546539

547540
DIST_THRESHOLD_MAX[0] = optimized_zone_0 * max_threshold_percentage_ / 100; // they can be int values, as we are not interested in the decimal part when defining the threshold

components/roode/roode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "esphome/components/binary_sensor/binary_sensor.h"
55
#include "esphome/components/text_sensor/text_sensor.h"
66
#include "esphome/components/i2c/i2c.h"
7+
#include "esphome/core/application.h"
78
#include "EEPROM.h"
89
#include <VL53L1X.h>
910
#include <math.h>
@@ -14,7 +15,7 @@ namespace esphome
1415
{
1516
#define NOBODY 0
1617
#define SOMEONE 1
17-
#define VERSION "v1.4.0-alpha"
18+
#define VERSION "v1.4.0-alpha-2"
1819
#define EEPROM_SIZE 512
1920
static int LEFT = 0;
2021
static int RIGHT = 1;

0 commit comments

Comments
 (0)