Skip to content

Commit

Permalink
Merge pull request #53 from Lyr3x/v1.3.3
Browse files Browse the repository at this point in the history
V1.3.3
  • Loading branch information
Lyr3x authored Nov 23, 2021
2 parents 353f371 + 461d00d commit d946b95
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
48 changes: 39 additions & 9 deletions components/roode/roode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,42 @@ namespace esphome
static int PathTrackFillingSize = 1; // init this to 1 as we start from state where nobody is any of the zones
static int LeftPreviousStatus = NOBODY;
static int RightPreviousStatus = NOBODY;

static uint16_t Distances[2][DISTANCES_ARRAY_SIZE];
static uint8_t DistancesTableSize[2] = {0, 0};
int CurrentZoneStatus = NOBODY;
int AllZonesCurrentStatus = 0;
int AnEventHasOccured = 0;

uint16_t MinDistance;
uint8_t i;
distanceSensor.setROICenter(center[zone]);
distanceSensor.startContinuous(delay_between_measurements);
distance = distanceSensor.read();
distanceSensor.stopContinuous();

if (distance < DIST_THRESHOLD_MAX[zone] && distance > DIST_THRESHOLD_MIN[zone])
if (DistancesTableSize[zone] < DISTANCES_ARRAY_SIZE)
{
Distances[zone][DistancesTableSize[zone]] = distance;
DistancesTableSize[zone]++;
}
else
{
for (i = 1; i < DISTANCES_ARRAY_SIZE; i++)
Distances[zone][i - 1] = Distances[zone][i];
Distances[zone][DISTANCES_ARRAY_SIZE - 1] = distance;
}

// pick up the min distance
MinDistance = Distances[zone][0];
if (DistancesTableSize[zone] >= 2)
{
for (i = 1; i < DistancesTableSize[zone]; i++)
{
if (Distances[zone][i] < MinDistance)
MinDistance = Distances[zone][i];
}
}

if (MinDistance < DIST_THRESHOLD_MAX[zone] && MinDistance > DIST_THRESHOLD_MIN[zone])
{
// Someone is in the sensing area
CurrentZoneStatus = SOMEONE;
Expand Down Expand Up @@ -176,10 +201,9 @@ namespace esphome
sendCounter(peopleCounter);
ESP_LOGD("Roode pathTracking", "Exit detected.");
entry_exit_event_sensor->publish_state("Exit");
DistancesTableSize[0] = 0;
DistancesTableSize[1] = 0;
}

right = 1;
right = 0;
}
else if ((PathTrack[1] == 2) && (PathTrack[2] == 3) && (PathTrack[3] == 1))
{
Expand All @@ -188,8 +212,14 @@ namespace esphome
sendCounter(peopleCounter);
ESP_LOGD("Roode pathTracking", "Entry detected.");
entry_exit_event_sensor->publish_state("Entry");
left = 1;
left = 0;
DistancesTableSize[0] = 0;
DistancesTableSize[1] = 0;
}
else
{
// reset the table filling size also in case of unexpected path
DistancesTableSize[0] = 0;
DistancesTableSize[1] = 0;
}
}

Expand Down Expand Up @@ -454,6 +484,6 @@ namespace esphome

delay(2000);
}

}
}
8 changes: 3 additions & 5 deletions components/roode/roode.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ namespace esphome
{
#define NOBODY 0
#define SOMEONE 1
#define VERSION "v1.3.2"
#define VERSION "v1.3.3"
#define EEPROM_SIZE 512
static int LEFT = 0;
static int RIGHT = 1;
// MQTT Commands
static int resetCounter = 0;
static int forceSetValue = -1;
static const uint16_t DISTANCES_ARRAY_SIZE = 10;

/*
##### CALIBRATION #####
Expand All @@ -42,7 +40,7 @@ namespace esphome

// parameters which define the time between two different measurements in various modes (https://www.st.com/resource/en/datasheet/vl53l1x.pdf)
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)
static int time_budget_in_ms_long = 33; // Works up to 3.1m increase to 140ms for 4m
static int time_budget_in_ms_long = 33; // Works up to 3.1m increase to minimum of 140ms for 4m
static int time_budget_in_ms_max_range = 200; // Works up to 4m in the dark on a white chart
static int delay_between_measurements_short = 25;
static int delay_between_measurements_long = 50;
Expand Down

0 comments on commit d946b95

Please sign in to comment.