Fixed insufficient state reset
This commit is contained in:
parent
9799e1405b
commit
5e1e3241cb
1 changed files with 7 additions and 7 deletions
|
@ -64,8 +64,8 @@ class PeopleCounter ():
|
||||||
th = threading.Thread(target=self.handleCallbacks, args=(countChange,))
|
th = threading.Thread(target=self.handleCallbacks, args=(countChange,))
|
||||||
th.start()
|
th.start()
|
||||||
|
|
||||||
# Reset records
|
# Reset state if state is finalised
|
||||||
if countChange != 0:
|
if not self.isDirectionTriggered(Directions.INSIDE) and not self.isDirectionTriggered(Directions.OUTSIDE):
|
||||||
self.directionState = self.getInitialDirectionState()
|
self.directionState = self.getInitialDirectionState()
|
||||||
|
|
||||||
self.sensor.close()
|
self.sensor.close()
|
||||||
|
@ -145,12 +145,9 @@ class PeopleCounter ():
|
||||||
cb(countChange)
|
cb(countChange)
|
||||||
|
|
||||||
def handleTriggerCallbacks(self) -> None:
|
def handleTriggerCallbacks(self) -> None:
|
||||||
insideTrigger = len(self.directionState[Directions.INSIDE]) > 0 and self.directionState[Directions.INSIDE][-1][END_TIME] is None
|
|
||||||
outsideTrigger = len(self.directionState[Directions.OUTSIDE]) > 0 and self.directionState[Directions.OUTSIDE][-1][END_TIME] is None
|
|
||||||
|
|
||||||
triggerState = {
|
triggerState = {
|
||||||
Directions.INSIDE: insideTrigger,
|
Directions.INSIDE: self.isDirectionTriggered(Directions.INSIDE),
|
||||||
Directions.OUTSIDE: outsideTrigger
|
Directions.OUTSIDE: self.isDirectionTriggered(Directions.OUTSIDE)
|
||||||
}
|
}
|
||||||
|
|
||||||
for cb in self.callbacks[TRIGGER_CB]:
|
for cb in self.callbacks[TRIGGER_CB]:
|
||||||
|
@ -159,6 +156,9 @@ class PeopleCounter ():
|
||||||
def handleChangeCallbacks(self, countChange: int) -> None:
|
def handleChangeCallbacks(self, countChange: int) -> None:
|
||||||
for cb in self.callbacks[CHANGE_CB]:
|
for cb in self.callbacks[CHANGE_CB]:
|
||||||
cb(countChange, self.directionState)
|
cb(countChange, self.directionState)
|
||||||
|
|
||||||
|
def isDirectionTriggered(self, direction: Directions) -> bool:
|
||||||
|
return len(self.directionState[direction]]) > 0 and self.directionState[direction][-1][END_TIME] is None
|
||||||
|
|
||||||
def updateState(self, direction: Directions, triggered: bool) -> bool:
|
def updateState(self, direction: Directions, triggered: bool) -> bool:
|
||||||
previouslyTriggered = False
|
previouslyTriggered = False
|
||||||
|
|
Loading…
Reference in a new issue