20
20
FWK_MAGIC = [0x32 , 0xAC ]
21
21
FWK_VID = 0x32AC
22
22
LED_MATRIX_PID = 0x20
23
- INPUTMODULE_PIDS = [LED_MATRIX_PID ]
23
+ QTPY_PID = 0x001F
24
+ INPUTMODULE_PIDS = [LED_MATRIX_PID , QTPY_PID ]
24
25
25
26
26
27
class CommandVals (IntEnum ):
@@ -614,12 +615,12 @@ def commit_cols(s):
614
615
send_serial (s , command )
615
616
616
617
617
- def get_color ():
618
+ def get_color (dev ):
618
619
res = send_command (dev , CommandVals .SetColor , with_response = True )
619
620
return (int (res [0 ]), int (res [1 ]), int (res [2 ]))
620
621
621
622
622
- def set_color (color ):
623
+ def set_color (dev , color ):
623
624
rgb = None
624
625
if color == 'white' :
625
626
rgb = [0xFF , 0xFF , 0xFF ]
@@ -825,7 +826,7 @@ def game_over(dev):
825
826
time .sleep (0.75 )
826
827
827
828
828
- def pong_embedded ():
829
+ def pong_embedded (dev ):
829
830
# Start game
830
831
send_command (dev , CommandVals .StartGame , [Game .Pong ])
831
832
@@ -849,14 +850,14 @@ def pong_embedded():
849
850
send_command (dev , CommandVals .GameControl , [key_arg ])
850
851
851
852
852
- def game_of_life_embedded (arg ):
853
+ def game_of_life_embedded (dev , arg ):
853
854
# Start game
854
855
# TODO: Add a way to stop it
855
856
print ("Game" , int (arg ))
856
857
send_command (dev , CommandVals .StartGame , [Game .GameOfLife , int (arg )])
857
858
858
859
859
- def snake_embedded ():
860
+ def snake_embedded (dev ):
860
861
# Start game
861
862
send_command (dev , CommandVals .StartGame , [Game .Snake ])
862
863
@@ -938,7 +939,7 @@ def snake(dev):
938
939
render_matrix (dev , matrix )
939
940
940
941
941
- def wpm_demo ():
942
+ def wpm_demo (dev ):
942
943
"""Capture keypresses and calculate the WPM of the last 10 seconds
943
944
TODO: I'm not sure my calculation is right."""
944
945
from getkey import getkey , keys
@@ -1363,92 +1364,92 @@ def gui(devices):
1363
1364
#sg.popup_error_with_traceback(f'An error happened. Here is the info:', e)
1364
1365
1365
1366
1366
- def display_string (disp_str ):
1367
+ def display_string (dev , disp_str ):
1367
1368
b = [ord (x ) for x in disp_str ]
1368
- send_command (CommandVals .SetText , [len (disp_str )] + b )
1369
+ send_command (dev , CommandVals .SetText , [len (disp_str )] + b )
1369
1370
1370
1371
1371
- def display_on_cmd (on ):
1372
- send_command (CommandVals .DisplayOn , [on ])
1372
+ def display_on_cmd (dev , on ):
1373
+ send_command (dev , CommandVals .DisplayOn , [on ])
1373
1374
1374
1375
1375
- def invert_screen_cmd (invert ):
1376
- send_command (CommandVals .InvertScreen , [invert ])
1376
+ def invert_screen_cmd (dev , invert ):
1377
+ send_command (dev , CommandVals .InvertScreen , [invert ])
1377
1378
1378
1379
1379
- def screen_saver_cmd (on ):
1380
- send_command (CommandVals .ScreenSaver , [on ])
1380
+ def screen_saver_cmd (dev , on ):
1381
+ send_command (dev , CommandVals .ScreenSaver , [on ])
1381
1382
1382
1383
1383
- def set_fps_cmd (mode ):
1384
- res = send_command (CommandVals .SetFps , with_response = True )
1384
+ def set_fps_cmd (dev , mode ):
1385
+ res = send_command (dev , CommandVals .SetFps , with_response = True )
1385
1386
current_fps = res [0 ]
1386
1387
1387
1388
if mode == 'quarter' :
1388
1389
fps = current_fps & ~ LOW_FPS_MASK
1389
1390
fps |= 0b000
1390
- send_command (CommandVals .SetFps , [fps ])
1391
+ send_command (dev , CommandVals .SetFps , [fps ])
1391
1392
set_power_mode_cmd ('low' )
1392
1393
elif mode == 'half' :
1393
1394
fps = current_fps & ~ LOW_FPS_MASK
1394
1395
fps |= 0b001
1395
- send_command (CommandVals .SetFps , [fps ])
1396
+ send_command (dev , CommandVals .SetFps , [fps ])
1396
1397
set_power_mode_cmd ('low' )
1397
1398
elif mode == 'one' :
1398
1399
fps = current_fps & ~ LOW_FPS_MASK
1399
1400
fps |= 0b010
1400
- send_command (CommandVals .SetFps , [fps ])
1401
+ send_command (dev , CommandVals .SetFps , [fps ])
1401
1402
set_power_mode_cmd ('low' )
1402
1403
elif mode == 'two' :
1403
1404
fps = current_fps & ~ LOW_FPS_MASK
1404
1405
fps |= 0b011
1405
- send_command (CommandVals .SetFps , [fps ])
1406
+ send_command (dev , CommandVals .SetFps , [fps ])
1406
1407
set_power_mode_cmd ('low' )
1407
1408
elif mode == 'four' :
1408
1409
fps = current_fps & ~ LOW_FPS_MASK
1409
1410
fps |= 0b100
1410
- send_command (CommandVals .SetFps , [fps ])
1411
+ send_command (dev , CommandVals .SetFps , [fps ])
1411
1412
set_power_mode_cmd ('low' )
1412
1413
elif mode == 'eight' :
1413
1414
fps = current_fps & ~ LOW_FPS_MASK
1414
1415
fps |= 0b101
1415
- send_command (CommandVals .SetFps , [fps ])
1416
+ send_command (dev , CommandVals .SetFps , [fps ])
1416
1417
set_power_mode_cmd ('low' )
1417
1418
elif mode == 'sixteen' :
1418
1419
fps = current_fps & ~ HIGH_FPS_MASK
1419
1420
fps |= 0b00000000
1420
- send_command (CommandVals .SetFps , [fps ])
1421
+ send_command (dev , CommandVals .SetFps , [fps ])
1421
1422
set_power_mode_cmd ('high' )
1422
1423
elif mode == 'thirtytwo' :
1423
1424
fps = current_fps & ~ HIGH_FPS_MASK
1424
1425
fps |= 0b00010000
1425
- send_command (CommandVals .SetFps , [fps ])
1426
+ send_command (dev , CommandVals .SetFps , [fps ])
1426
1427
set_power_mode_cmd ('high' )
1427
1428
1428
1429
1429
- def set_power_mode_cmd (mode ):
1430
+ def set_power_mode_cmd (dev , mode ):
1430
1431
if mode == 'low' :
1431
- send_command (CommandVals .SetPowerMode , [0 ])
1432
+ send_command (dev , CommandVals .SetPowerMode , [0 ])
1432
1433
elif mode == 'high' :
1433
- send_command (CommandVals .SetPowerMode , [1 ])
1434
+ send_command (dev , CommandVals .SetPowerMode , [1 ])
1434
1435
else :
1435
1436
print ("Unsupported power mode" )
1436
1437
sys .exit (1 )
1437
1438
1438
1439
1439
- def get_power_mode_cmd ():
1440
- res = send_command (CommandVals .SetPowerMode , with_response = True )
1440
+ def get_power_mode_cmd (dev ):
1441
+ res = send_command (dev , CommandVals .SetPowerMode , with_response = True )
1441
1442
current_mode = int (res [0 ])
1442
1443
if current_mode == 0 :
1443
1444
print (f"Current Power Mode: Low Power" )
1444
1445
elif current_mode == 1 :
1445
1446
print (f"Current Power Mode: High Power" )
1446
1447
1447
1448
1448
- def get_fps_cmd ():
1449
- res = send_command (CommandVals .SetFps , with_response = True )
1449
+ def get_fps_cmd (dev ):
1450
+ res = send_command (dev , CommandVals .SetFps , with_response = True )
1450
1451
current_fps = res [0 ]
1451
- res = send_command (CommandVals .SetPowerMode , with_response = True )
1452
+ res = send_command (dev , CommandVals .SetPowerMode , with_response = True )
1452
1453
current_mode = int (res [0 ])
1453
1454
1454
1455
if current_mode == 0 :
0 commit comments