Skip to content

Commit d946b95

Browse files
authored
Merge pull request #53 from Lyr3x/v1.3.3
V1.3.3
2 parents 353f371 + 461d00d commit d946b95

File tree

2 files changed

+42
-14
lines changed

2 files changed

+42
-14
lines changed

components/roode/roode.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,42 @@ namespace esphome
8181
static int PathTrackFillingSize = 1; // init this to 1 as we start from state where nobody is any of the zones
8282
static int LeftPreviousStatus = NOBODY;
8383
static int RightPreviousStatus = NOBODY;
84-
84+
static uint16_t Distances[2][DISTANCES_ARRAY_SIZE];
85+
static uint8_t DistancesTableSize[2] = {0, 0};
8586
int CurrentZoneStatus = NOBODY;
8687
int AllZonesCurrentStatus = 0;
8788
int AnEventHasOccured = 0;
88-
89+
uint16_t MinDistance;
90+
uint8_t i;
8991
distanceSensor.setROICenter(center[zone]);
9092
distanceSensor.startContinuous(delay_between_measurements);
9193
distance = distanceSensor.read();
9294
distanceSensor.stopContinuous();
9395

94-
if (distance < DIST_THRESHOLD_MAX[zone] && distance > DIST_THRESHOLD_MIN[zone])
96+
if (DistancesTableSize[zone] < DISTANCES_ARRAY_SIZE)
97+
{
98+
Distances[zone][DistancesTableSize[zone]] = distance;
99+
DistancesTableSize[zone]++;
100+
}
101+
else
102+
{
103+
for (i = 1; i < DISTANCES_ARRAY_SIZE; i++)
104+
Distances[zone][i - 1] = Distances[zone][i];
105+
Distances[zone][DISTANCES_ARRAY_SIZE - 1] = distance;
106+
}
107+
108+
// pick up the min distance
109+
MinDistance = Distances[zone][0];
110+
if (DistancesTableSize[zone] >= 2)
111+
{
112+
for (i = 1; i < DistancesTableSize[zone]; i++)
113+
{
114+
if (Distances[zone][i] < MinDistance)
115+
MinDistance = Distances[zone][i];
116+
}
117+
}
118+
119+
if (MinDistance < DIST_THRESHOLD_MAX[zone] && MinDistance > DIST_THRESHOLD_MIN[zone])
95120
{
96121
// Someone is in the sensing area
97122
CurrentZoneStatus = SOMEONE;
@@ -176,10 +201,9 @@ namespace esphome
176201
sendCounter(peopleCounter);
177202
ESP_LOGD("Roode pathTracking", "Exit detected.");
178203
entry_exit_event_sensor->publish_state("Exit");
204+
DistancesTableSize[0] = 0;
205+
DistancesTableSize[1] = 0;
179206
}
180-
181-
right = 1;
182-
right = 0;
183207
}
184208
else if ((PathTrack[1] == 2) && (PathTrack[2] == 3) && (PathTrack[3] == 1))
185209
{
@@ -188,8 +212,14 @@ namespace esphome
188212
sendCounter(peopleCounter);
189213
ESP_LOGD("Roode pathTracking", "Entry detected.");
190214
entry_exit_event_sensor->publish_state("Entry");
191-
left = 1;
192-
left = 0;
215+
DistancesTableSize[0] = 0;
216+
DistancesTableSize[1] = 0;
217+
}
218+
else
219+
{
220+
// reset the table filling size also in case of unexpected path
221+
DistancesTableSize[0] = 0;
222+
DistancesTableSize[1] = 0;
193223
}
194224
}
195225

@@ -454,6 +484,6 @@ namespace esphome
454484

455485
delay(2000);
456486
}
457-
487+
458488
}
459489
}

components/roode/roode.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ namespace esphome
1515
{
1616
#define NOBODY 0
1717
#define SOMEONE 1
18-
#define VERSION "v1.3.2"
18+
#define VERSION "v1.3.3"
1919
#define EEPROM_SIZE 512
2020
static int LEFT = 0;
2121
static int RIGHT = 1;
22-
// MQTT Commands
23-
static int resetCounter = 0;
24-
static int forceSetValue = -1;
22+
static const uint16_t DISTANCES_ARRAY_SIZE = 10;
2523

2624
/*
2725
##### CALIBRATION #####
@@ -42,7 +40,7 @@ namespace esphome
4240

4341
// parameters which define the time between two different measurements in various modes (https://www.st.com/resource/en/datasheet/vl53l1x.pdf)
4442
static int time_budget_in_ms_short = 15; // 20ms with the full API but 15ms with the ULD API (https://www.st.com/resource/en/user_manual/um2510-a-guide-to-using-the-vl53l1x-ultra-lite-driver-stmicroelectronics.pdf)
45-
static int time_budget_in_ms_long = 33; // Works up to 3.1m increase to 140ms for 4m
43+
static int time_budget_in_ms_long = 33; // Works up to 3.1m increase to minimum of 140ms for 4m
4644
static int time_budget_in_ms_max_range = 200; // Works up to 4m in the dark on a white chart
4745
static int delay_between_measurements_short = 25;
4846
static int delay_between_measurements_long = 50;

0 commit comments

Comments
 (0)