Made hook execution predictable
This commit is contained in:
parent
8b28cd0f7c
commit
f2a77fae2b
1 changed files with 10 additions and 9 deletions
|
@ -61,9 +61,8 @@ class PeopleCounter ():
|
|||
countChange: int = self.getCountChange(self.directionState)
|
||||
|
||||
# Hooks
|
||||
self.handleChangeCallbacks(countChange)
|
||||
self.handleCountingCallbacks(countChange)
|
||||
self.handleTriggerCallbacks()
|
||||
th = threading.Thread(target=self.handleCallbacks, args=(self,countChange))
|
||||
th.start()
|
||||
|
||||
# Reset records
|
||||
if countChange != 0:
|
||||
|
@ -132,14 +131,18 @@ class PeopleCounter ():
|
|||
#! TODO: Should be based on the distance from the ground, not them the sensor
|
||||
return distance <= self.maxTriggerDistance
|
||||
|
||||
def handleCallbacks(self, countChange: int):
|
||||
self.handleChangeCallbacks(countChange)
|
||||
self.handleCountingCallbacks(countChange)
|
||||
self.handleTriggerCallbacks()
|
||||
|
||||
def handleCountingCallbacks(self, countChange: int) -> None:
|
||||
# Only notify counting on actual count change
|
||||
if countChange == 0:
|
||||
return
|
||||
|
||||
for cb in self.callbacks[COUNTING_CB]:
|
||||
th = threading.Thread(target=cb, args=(countChange,))
|
||||
th.start()
|
||||
cb(countChange)
|
||||
|
||||
def handleTriggerCallbacks(self) -> None:
|
||||
insideTrigger = len(self.directionState[Directions.INSIDE]) > 0 and self.directionState[Directions.INSIDE][-1][END_TIME] is None
|
||||
|
@ -151,13 +154,11 @@ class PeopleCounter ():
|
|||
}
|
||||
|
||||
for cb in self.callbacks[TRIGGER_CB]:
|
||||
th = threading.Thread(target=cb, args=(triggerState,))
|
||||
th.start()
|
||||
cb(triggerState)
|
||||
|
||||
def handleChangeCallbacks(self, countChange: int) -> None:
|
||||
for cb in self.callbacks[CHANGE_CB]:
|
||||
th = threading.Thread(target=cb, args=(countChange, self.directionState))
|
||||
th.start()
|
||||
cb(countChange, self.directionState)
|
||||
|
||||
def updateState(self, direction: Directions, triggered: bool) -> bool:
|
||||
previouslyTriggered = False
|
||||
|
|
Loading…
Reference in a new issue