Skip to content

Commit

Permalink
fixed turn off turn on bug
Browse files Browse the repository at this point in the history
  • Loading branch information
adangert committed Jan 14, 2019
1 parent b4ebc6f commit a675a0b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions controller_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
def main_track_move(menu, restart, move_serial, move_num, move_opts, force_color, battery, dead_count, game_mode, \
team, team_color_enum, dead_move, music_speed, werewolf_reveal, show_team_colors, red_on_kill, zombie_opt,\
commander_intro, commander_move_opt, commander_powers, commander_overdrive,five_controller_opt, swapper_team_colors,\
invincibility, fight_club_color, num_teams,bomb_color,game_start,false_color, faked, rumble):
invincibility, fight_club_color, num_teams,bomb_color,game_start,false_color, faked, rumble, kill_proc):
print("starting Controller Process")

move = common.get_move(move_serial, move_num)
while(True):
while(not kill_proc.value):
move.set_rumble(0)
if(restart.value == 1):
pass
elif (menu.value == 1):
piparty.track_move(move_serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu)
piparty.track_move(move_serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu, kill_proc)
elif(game_mode.value == common.Games.Zombies.value):
zombie.track_controller(move, zombie_opt, restart, menu)
elif(game_mode.value == common.Games.Commander.value):
Expand Down
25 changes: 21 additions & 4 deletions piparty.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ class Sensitivity(Enum):
mid = 1
fast = 2

def track_move(serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu):
def track_move(serial, move_num, move, move_opts, force_color, battery, dead_count, restart, menu, kill_proc):
move.set_leds(0,0,0)
move.update_leds()
random_color = random.random()


while True:
if(restart.value ==1 or menu.value == 0):
if(restart.value ==1 or menu.value == 0 or kill_proc.value):
return
time.sleep(0.01)
if move.poll():
Expand Down Expand Up @@ -288,6 +288,7 @@ def __init__(self):
self.false_colors = {}
self.was_faked = {}
self.rumble = {}
self.kill_controller_proc = {}

self.i = 0
#load audio now so it converts before the game begins
Expand Down Expand Up @@ -345,6 +346,7 @@ def pair_usb_move(self, move):
self.pair_one_move = False

def pair_move(self, move, move_num):
print("NOW PAIRING MOVE")
move_serial = move.get_serial()
if move_serial not in self.tracked_moves:
color = Array('i', [0] * 3)
Expand Down Expand Up @@ -376,14 +378,15 @@ def pair_move(self, move, move_num):
false_color = Value('i', 0)
faked = Value('i', 0)
rumble = Value('i', 0)
kill_proc = Value('b', False)


proc = Process(target= controller_process.main_track_move, args=(self.menu, self.restart, move_serial, move_num, opts, color, self.show_battery, \
self.dead_count, self.controller_game_mode, team, team_color_enum, dead_move, \
self.music_speed, self.werewolf_reveal, self.show_team_colors, self.red_on_kill,zombie_opt,\
self.commander_intro, commander_move_opt, self.commander_powers, self.commander_overdrive,\
five_controller_opt, self.swapper_team_colors, invincibility, fight_club_color, self.num_teams,\
self.bomb_color,self.game_start,false_color, faked, rumble))
self.bomb_color,self.game_start,false_color, faked, rumble, kill_proc))


proc.start()
Expand All @@ -401,6 +404,7 @@ def pair_move(self, move, move_num):
self.false_colors[move_serial] = false_color
self.was_faked[move_serial] = faked
self.rumble[move_serial] = rumble
self.kill_controller_proc[move_serial] = kill_proc



Expand Down Expand Up @@ -489,12 +493,25 @@ def game_loop(self):
self.pair_one_move = True
self.paired_moves = []
if self.pair_one_move:
if psmove.count_connected() != len(self.tracked_moves):
if psmove.count_connected() > len(self.tracked_moves):
for move_num, move in enumerate(self.moves):
if move.connection_type == psmove.Conn_USB and self.pair_one_move:
self.pair_usb_move(move)
elif move.connection_type != psmove.Conn_USB:
self.pair_move(move, move_num)
elif(len(self.tracked_moves) > len(self.moves)):
connected_serials = [x.get_serial() for x in self.moves]
tracked_serials = self.tracked_moves.keys()
keys_to_kill = []
for serial in tracked_serials:
if serial not in connected_serials:
self.kill_controller_proc[serial].value = True
self.tracked_moves[serial].join()
self.tracked_moves[serial].terminate()
keys_to_kill.append(serial)
for key in keys_to_kill:
del self.tracked_moves[key]

self.check_for_new_moves()
if len(self.tracked_moves) > 0:
self.check_change_mode()
Expand Down

0 comments on commit a675a0b

Please sign in to comment.