1- # clue-multi-rpsgame v1.19
1+ # clue-multi-rpsgame v1.20
22# CircuitPython massively multiplayer rock paper scissors game over Bluetooth LE
33
44# Tested with CLUE and Circuit Playground Bluefruit Alpha with TFT Gizmo
@@ -138,16 +138,15 @@ def tftGizmoPresent():
138138 _button_b = digitalio .DigitalInOut (board .BUTTON_B )
139139 _button_b .switch_to_input (pull = digitalio .Pull .DOWN )
140140 if display is None :
141- button_left = lambda : _button_a .value
142- button_right = lambda : _button_b .value
143- ##button_left = lambda: cp.button_a
144- ##button_right = lambda: cp.button_b
145-
141+ def button_left ():
142+ return _button_a .value
143+ def button_right ():
144+ return _button_b .value
146145 else :
147- button_left = lambda : _button_b . value
148- button_right = lambda : _button_a .value
149- ##button_left = lambda: cp.button_b
150- ##button_right = lambda: cp.button_a
146+ def button_left ():
147+ return _button_b .value
148+ def button_right ():
149+ return _button_a . value
151150
152151else :
153152 # CLUE with builtin screen (240x240)
@@ -166,10 +165,11 @@ def tftGizmoPresent():
166165 _button_a .switch_to_input (pull = digitalio .Pull .UP )
167166 _button_b = digitalio .DigitalInOut (board .BUTTON_B )
168167 _button_b .switch_to_input (pull = digitalio .Pull .UP )
169- button_left = lambda : not _button_a .value
170- button_right = lambda : not _button_b .value
171- ##button_left = lambda: clue.button_a
172- ##button_right = lambda: clue.button_b
168+ def button_left ():
169+ return not _button_a .value
170+ def button_right ():
171+ return not _button_b .value
172+
173173
174174blankScreen (display , pixels )
175175
@@ -296,6 +296,20 @@ def addPlayer(name, addr_text, address, ad):
296296rps_display .fadeUpDown ("down" )
297297addPlayer (my_name , addrToText (ble .address_bytes ), None , None )
298298
299+
300+ # These two functions mainly serve to adapt the call back arguments
301+ # to the called functions which do not use them
302+ def jgAdCallbackFlashBLE (_a , _b , _c ):
303+ """Used in broadcastAndReceive to flash the NeoPixels
304+ when advertising messages are received."""
305+ return rps_display .flashBLE ()
306+
307+ def jgEndscanCallback (_a , _b , _c ):
308+ """Used in broadcastAndReceive to allow early termination of the scanning
309+ when the left button is pressed.
310+ Button may need to be held down for a second."""
311+ return button_left ()
312+
299313# Join Game
300314gc .collect ()
301315d_print (2 , "GC before JG" , gc .mem_free ())
@@ -307,11 +321,10 @@ def addPlayer(name, addr_text, address, ad):
307321 jg_msg ,
308322 scan_time = JG_MSG_TIME_S ,
309323 scan_response_request = True ,
310- ad_cb = ((lambda _a , _b , _c :
311- rps_display .flashBLE ())
324+ ad_cb = (jgAdCallbackFlashBLE
312325 if JG_FLASH
313326 else None ),
314- endscan_cb = lambda _a , _b , _c : button_left () ,
327+ endscan_cb = jgEndscanCallback ,
315328 name_cb = addPlayer )
316329del _ # To clean-up with GC below
317330sample .stop ()
0 commit comments