@@ -46,6 +46,7 @@ class CommandVals(IntEnum):
4646 ScreenSaver = 0x19
4747 SetFps = 0x1A
4848 SetPowerMode = 0x1B
49+ PwmFreq = 0x1E
4950 Version = 0x20
5051
5152
@@ -96,6 +97,12 @@ class GameControlVal(IntEnum):
9697 Right = 3
9798 Quit = 4
9899
100+ PWM_FREQUENCIES = [
101+ '29kHz' ,
102+ '3.6kHz' ,
103+ '1.8kHz' ,
104+ '900Hz' ,
105+ ]
99106
100107PATTERNS = [
101108 'All LEDs on' ,
@@ -166,6 +173,10 @@ def main():
166173 help = 'Start/stop vertical scrolling' )
167174 parser .add_argument ('--get-animate' , action = 'store_true' ,
168175 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" )
169180 parser .add_argument ("--pattern" , help = 'Display a pattern' ,
170181 type = str , choices = PATTERNS )
171182 parser .add_argument ("--image" , help = "Display a PNG or GIF image in black and white only)" ,
@@ -285,6 +296,18 @@ def main():
285296 elif args .get_brightness :
286297 br = get_brightness (dev )
287298 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" )
288311 elif args .percentage is not None :
289312 if args .percentage > 100 or args .percentage < 0 :
290313 print ("Percentage must be 0-100" )
@@ -414,6 +437,23 @@ def get_brightness(dev):
414437 return int (res [0 ])
415438
416439
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+
417457def get_version (dev ):
418458 """Get the device's firmware version"""
419459 res = send_command (dev , CommandVals .Version , with_response = True )
@@ -963,6 +1003,18 @@ def light_leds(dev, leds):
9631003 send_command (dev , CommandVals .Draw , vals )
9641004
9651005
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+
9661018def pattern (dev , p ):
9671019 """Display a pattern that's already programmed into the firmware"""
9681020 if p == 'All LEDs on' :
@@ -1177,6 +1229,9 @@ def gui(devices):
11771229 [sg .Button ("Send '2 5 degC thunder'" , k = '-SEND-TEXT-' )],
11781230 ])
11791231 ],
1232+ [sg .HorizontalSeparator ()],
1233+ [sg .Text ("PWM Frequency" )],
1234+ [sg .Combo (PWM_FREQUENCIES , k = '-PWM-FREQ-' , enable_events = True )],
11801235
11811236
11821237 # TODO
@@ -1245,6 +1300,9 @@ def gui(devices):
12451300 if event == '-PATTERN-' :
12461301 pattern (dev , values ['-PATTERN-' ])
12471302
1303+ if event == '-PWM-FREQ-' :
1304+ pwm_freq (dev , values ['-PWM-FREQ-' ])
1305+
12481306 if event == 'Start Animation' :
12491307 animate (dev , True )
12501308
0 commit comments