1
- # clue-multi-rpsgame v1.19
1
+ # clue-multi-rpsgame v1.20
2
2
# CircuitPython massively multiplayer rock paper scissors game over Bluetooth LE
3
3
4
4
# Tested with CLUE and Circuit Playground Bluefruit Alpha with TFT Gizmo
@@ -138,16 +138,15 @@ def tftGizmoPresent():
138
138
_button_b = digitalio .DigitalInOut (board .BUTTON_B )
139
139
_button_b .switch_to_input (pull = digitalio .Pull .DOWN )
140
140
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
146
145
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
151
150
152
151
else :
153
152
# CLUE with builtin screen (240x240)
@@ -166,10 +165,11 @@ def tftGizmoPresent():
166
165
_button_a .switch_to_input (pull = digitalio .Pull .UP )
167
166
_button_b = digitalio .DigitalInOut (board .BUTTON_B )
168
167
_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
+
173
173
174
174
blankScreen (display , pixels )
175
175
@@ -296,6 +296,20 @@ def addPlayer(name, addr_text, address, ad):
296
296
rps_display .fadeUpDown ("down" )
297
297
addPlayer (my_name , addrToText (ble .address_bytes ), None , None )
298
298
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
+
299
313
# Join Game
300
314
gc .collect ()
301
315
d_print (2 , "GC before JG" , gc .mem_free ())
@@ -307,11 +321,10 @@ def addPlayer(name, addr_text, address, ad):
307
321
jg_msg ,
308
322
scan_time = JG_MSG_TIME_S ,
309
323
scan_response_request = True ,
310
- ad_cb = ((lambda _a , _b , _c :
311
- rps_display .flashBLE ())
324
+ ad_cb = (jgAdCallbackFlashBLE
312
325
if JG_FLASH
313
326
else None ),
314
- endscan_cb = lambda _a , _b , _c : button_left () ,
327
+ endscan_cb = jgEndscanCallback ,
315
328
name_cb = addPlayer )
316
329
del _ # To clean-up with GC below
317
330
sample .stop ()
0 commit comments