Browse Source

Added grace period to player detection to allow for accidential stepping off a board

master
klonfish 7 years ago
parent
commit
368384481c
  1. 7
      wii-pair/daemon.py

7
wii-pair/daemon.py

@ -16,6 +16,7 @@ known_boards = {'niklas': '00:26:59:34:C8:69', @@ -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): @@ -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): @@ -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,6 +122,10 @@ class WiiThread(Thread): @@ -119,6 +122,10 @@ class WiiThread(Thread):
self.pos_x = x_balance
self.pos_y = y_balance
else:
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

Loading…
Cancel
Save