From 368384481ca039b61e3ae2150a154edb465bf9d7 Mon Sep 17 00:00:00 2001 From: klonfish Date: Wed, 27 Dec 2017 14:36:25 +0100 Subject: [PATCH] Added grace period to player detection to allow for accidential stepping off a board --- wii-pair/daemon.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wii-pair/daemon.py b/wii-pair/daemon.py index 763c8fb..b47f20a 100755 --- a/wii-pair/daemon.py +++ b/wii-pair/daemon.py @@ -16,6 +16,7 @@ known_boards = {'niklas': '00:26:59:34:C8:69', } MIN_WEIGHT = 10 +PLAYER_TIMEOUT = 3 class StatusThread(Thread): def __init__(self, t1, t2): @@ -90,6 +91,7 @@ class WiiThread(Thread): self.pos_x = None self.pos_y = None self.weight = 0 + self.timeout = None def run(self): if self.addr != 'dummy': @@ -111,6 +113,7 @@ class WiiThread(Thread): while not self.stop and self.board.status == 'Connected': self.weight = self.board.mass.totalWeight if self.board.mass.totalWeight >= MIN_WEIGHT: + self.timeout = None m = self.board.mass x_balance = -(m.topLeft+m.bottomLeft) + (m.topRight+m.bottomRight) x_balance = x_balance/float(m.totalWeight) @@ -119,8 +122,12 @@ class WiiThread(Thread): self.pos_x = x_balance self.pos_y = y_balance else: - self.pos_x = None - self.pos_y = None + if self.timeout is None: + self.timeout = time.time()+PLAYER_TIMEOUT + else: + if time.time() >= self.timeout: + self.pos_x = None + self.pos_y = None time.sleep(0.1)