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)
|
countChange: int = self.getCountChange(self.directionState)
|
||||||
|
|
||||||
# Hooks
|
# Hooks
|
||||||
self.handleChangeCallbacks(countChange)
|
th = threading.Thread(target=self.handleCallbacks, args=(self,countChange))
|
||||||
self.handleCountingCallbacks(countChange)
|
th.start()
|
||||||
self.handleTriggerCallbacks()
|
|
||||||
|
|
||||||
# Reset records
|
# Reset records
|
||||||
if countChange != 0:
|
if countChange != 0:
|
||||||
|
@ -131,6 +130,11 @@ class PeopleCounter ():
|
||||||
def isTriggerDistance(self, distance: float) -> bool:
|
def isTriggerDistance(self, distance: float) -> bool:
|
||||||
#! TODO: Should be based on the distance from the ground, not them the sensor
|
#! TODO: Should be based on the distance from the ground, not them the sensor
|
||||||
return distance <= self.maxTriggerDistance
|
return distance <= self.maxTriggerDistance
|
||||||
|
|
||||||
|
def handleCallbacks(self, countChange: int):
|
||||||
|
self.handleChangeCallbacks(countChange)
|
||||||
|
self.handleCountingCallbacks(countChange)
|
||||||
|
self.handleTriggerCallbacks()
|
||||||
|
|
||||||
def handleCountingCallbacks(self, countChange: int) -> None:
|
def handleCountingCallbacks(self, countChange: int) -> None:
|
||||||
# Only notify counting on actual count change
|
# Only notify counting on actual count change
|
||||||
|
@ -138,8 +142,7 @@ class PeopleCounter ():
|
||||||
return
|
return
|
||||||
|
|
||||||
for cb in self.callbacks[COUNTING_CB]:
|
for cb in self.callbacks[COUNTING_CB]:
|
||||||
th = threading.Thread(target=cb, args=(countChange,))
|
cb(countChange)
|
||||||
th.start()
|
|
||||||
|
|
||||||
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
|
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]:
|
for cb in self.callbacks[TRIGGER_CB]:
|
||||||
th = threading.Thread(target=cb, args=(triggerState,))
|
cb(triggerState)
|
||||||
th.start()
|
|
||||||
|
|
||||||
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]:
|
||||||
th = threading.Thread(target=cb, args=(countChange, self.directionState))
|
cb(countChange, self.directionState)
|
||||||
th.start()
|
|
||||||
|
|
||||||
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