@@ -46,6 +46,7 @@ class CommandVals(IntEnum):
46
46
ScreenSaver = 0x19
47
47
SetFps = 0x1A
48
48
SetPowerMode = 0x1B
49
+ PwmFreq = 0x1E
49
50
Version = 0x20
50
51
51
52
@@ -96,6 +97,12 @@ class GameControlVal(IntEnum):
96
97
Right = 3
97
98
Quit = 4
98
99
100
+ PWM_FREQUENCIES = [
101
+ '29kHz' ,
102
+ '3.6kHz' ,
103
+ '1.8kHz' ,
104
+ '900Hz' ,
105
+ ]
99
106
100
107
PATTERNS = [
101
108
'All LEDs on' ,
@@ -166,6 +173,10 @@ def main():
166
173
help = 'Start/stop vertical scrolling' )
167
174
parser .add_argument ('--get-animate' , action = 'store_true' ,
168
175
help = 'Check if currently animating' )
176
+ parser .add_argument ("--pwm" , help = "Adjust the PWM frequency. Value 0-255" ,
177
+ type = int , choices = [29000 , 3600 , 1800 , 900 ])
178
+ parser .add_argument ("--get-pwm" , help = "Get current PWM Frequency" ,
179
+ action = "store_true" )
169
180
parser .add_argument ("--pattern" , help = 'Display a pattern' ,
170
181
type = str , choices = PATTERNS )
171
182
parser .add_argument ("--image" , help = "Display a PNG or GIF image in black and white only)" ,
@@ -285,6 +296,18 @@ def main():
285
296
elif args .get_brightness :
286
297
br = get_brightness (dev )
287
298
print (f"Current brightness: { br } " )
299
+ elif args .pwm is not None :
300
+ if args .pwm == 29000 :
301
+ pwm_freq (dev , '29kHz' )
302
+ elif args .pwm == 3600 :
303
+ pwm_freq (dev , '3.6kHz' )
304
+ elif args .pwm == 1800 :
305
+ pwm_freq (dev , '1.8kHz' )
306
+ elif args .pwm == 900 :
307
+ pwm_freq (dev , '900Hz' )
308
+ elif args .get_pwm :
309
+ p = get_pwm_freq (dev )
310
+ print (f"Current PWM Frequency: { p } Hz" )
288
311
elif args .percentage is not None :
289
312
if args .percentage > 100 or args .percentage < 0 :
290
313
print ("Percentage must be 0-100" )
@@ -414,6 +437,23 @@ def get_brightness(dev):
414
437
return int (res [0 ])
415
438
416
439
440
+ def get_pwm_freq (dev ):
441
+ """Adjust the brightness scaling of the entire screen.
442
+ """
443
+ res = send_command (dev , CommandVals .PwmFreq , with_response = True )
444
+ freq = int (res [0 ])
445
+ if freq == 0 :
446
+ return 29000
447
+ elif freq == 1 :
448
+ return 3600
449
+ elif freq == 2 :
450
+ return 1800
451
+ elif freq == 3 :
452
+ return 900
453
+ else :
454
+ return None
455
+
456
+
417
457
def get_version (dev ):
418
458
"""Get the device's firmware version"""
419
459
res = send_command (dev , CommandVals .Version , with_response = True )
@@ -963,6 +1003,18 @@ def light_leds(dev, leds):
963
1003
send_command (dev , CommandVals .Draw , vals )
964
1004
965
1005
1006
+ def pwm_freq (dev , freq ):
1007
+ """Display a pattern that's already programmed into the firmware"""
1008
+ if freq == '29kHz' :
1009
+ send_command (dev , CommandVals .PwmFreq , [0 ])
1010
+ elif freq == '3.6kHz' :
1011
+ send_command (dev , CommandVals .PwmFreq , [1 ])
1012
+ elif freq == '1.8kHz' :
1013
+ send_command (dev , CommandVals .PwmFreq , [2 ])
1014
+ elif freq == '900Hz' :
1015
+ send_command (dev , CommandVals .PwmFreq , [3 ])
1016
+
1017
+
966
1018
def pattern (dev , p ):
967
1019
"""Display a pattern that's already programmed into the firmware"""
968
1020
if p == 'All LEDs on' :
@@ -1177,6 +1229,9 @@ def gui(devices):
1177
1229
[sg .Button ("Send '2 5 degC thunder'" , k = '-SEND-TEXT-' )],
1178
1230
])
1179
1231
],
1232
+ [sg .HorizontalSeparator ()],
1233
+ [sg .Text ("PWM Frequency" )],
1234
+ [sg .Combo (PWM_FREQUENCIES , k = '-PWM-FREQ-' , enable_events = True )],
1180
1235
1181
1236
1182
1237
# TODO
@@ -1245,6 +1300,9 @@ def gui(devices):
1245
1300
if event == '-PATTERN-' :
1246
1301
pattern (dev , values ['-PATTERN-' ])
1247
1302
1303
+ if event == '-PWM-FREQ-' :
1304
+ pwm_freq (dev , values ['-PWM-FREQ-' ])
1305
+
1248
1306
if event == 'Start Animation' :
1249
1307
animate (dev , True )
1250
1308
0 commit comments