16
16
# import PySimpleGUI as sg
17
17
18
18
FWK_MAGIC = [0x32 , 0xAC ]
19
- PATTERNS = ['full' , 'lotus' , 'gradient' ,
20
- 'double-gradient' , 'zigzag' , 'panic' , 'lotus2' ]
19
+ PATTERNS = [
20
+ 'All LEDs on' ,
21
+ '"LOTUS" sideways' ,
22
+ 'Gradient (0-13% Brightness)' ,
23
+ 'Double Gradient (0-7-0% Brightness)' ,
24
+ 'Zigzag' ,
25
+ '"PANIC"' ,
26
+ '"LOTUS" Top Down' ,
27
+ 'All brightness levels (1 LED each)' ,
28
+ ]
21
29
DRAW_PATTERNS = ['off' , 'on' , 'foo' ]
22
30
GREYSCALE_DEPTH = 32
23
31
WIDTH = 9
24
32
HEIGHT = 34
25
33
26
34
SERIAL_DEV = None
27
35
36
+ STOP_THREAD = False
37
+
28
38
29
39
def main ():
30
40
parser = argparse .ArgumentParser ()
@@ -252,7 +262,11 @@ def countdown(seconds):
252
262
Until the timer runs out and every LED is lit"""
253
263
start = datetime .now ()
254
264
target = seconds * 1_000_000
265
+ global STOP_THREAD
255
266
while True :
267
+ if STOP_THREAD :
268
+ STOP_THREAD = False
269
+ return
256
270
now = datetime .now ()
257
271
passed_time = (now - start ) / timedelta (microseconds = 1 )
258
272
@@ -450,7 +464,11 @@ def wpm_demo():
450
464
def random_eq ():
451
465
"""Display an equlizer looking animation with random values.
452
466
"""
467
+ global STOP_THREAD
453
468
while True :
469
+ if STOP_THREAD :
470
+ STOP_THREAD = False
471
+ return
454
472
# Lower values more likely, makes it look nicer
455
473
weights = [i * i for i in range (33 , 0 , - 1 )]
456
474
population = list (range (1 , 34 ))
@@ -504,27 +522,29 @@ def light_leds(leds):
504
522
505
523
def pattern (p ):
506
524
"""Display a pattern that's already programmed into the firmware"""
507
- if p == 'full ' :
525
+ if p == 'All LEDs on ' :
508
526
command = FWK_MAGIC + [0x01 , 5 ]
509
527
send_command (command )
510
- elif p == 'gradient ' :
528
+ elif p == 'Gradient (0-13% Brightness) ' :
511
529
command = FWK_MAGIC + [0x01 , 1 ]
512
530
send_command (command )
513
- elif p == 'double-gradient ' :
531
+ elif p == 'Double Gradient (0-7-0% Brightness) ' :
514
532
command = FWK_MAGIC + [0x01 , 2 ]
515
533
send_command (command )
516
- elif p == 'lotus ' :
534
+ elif p == '"LOTUS" sideways ' :
517
535
command = FWK_MAGIC + [0x01 , 3 ]
518
536
send_command (command )
519
- elif p == 'zigzag ' :
537
+ elif p == 'Zigzag ' :
520
538
command = FWK_MAGIC + [0x01 , 4 ]
521
539
send_command (command )
522
- elif p == 'panic ' :
540
+ elif p == '"PANIC" ' :
523
541
command = FWK_MAGIC + [0x01 , 6 ]
524
542
send_command (command )
525
- elif p == 'lotus2 ' :
543
+ elif p == '"LOTUS" Top Down ' :
526
544
command = FWK_MAGIC + [0x01 , 7 ]
527
545
send_command (command )
546
+ elif p == 'All brightness levels (1 LED each)' :
547
+ all_brightnesses ()
528
548
else :
529
549
print ("Invalid pattern" )
530
550
@@ -567,7 +587,11 @@ def show_symbols(symbols):
567
587
def clock ():
568
588
"""Render the current time and display.
569
589
Loops forever, updating every second"""
590
+ global STOP_THREAD
570
591
while True :
592
+ if STOP_THREAD :
593
+ STOP_THREAD = False
594
+ return
571
595
now = datetime .now ()
572
596
current_time = now .strftime ("%H:%M" )
573
597
print ("Current Time =" , current_time )
@@ -599,25 +623,52 @@ def gui():
599
623
[sg .Button ("Bootloader" )],
600
624
601
625
[sg .Text ("Brightness" )],
602
- [sg .Slider ((0 , 255 ), orientation = 'h' ,
626
+ # TODO: Get default from device
627
+ [sg .Slider ((0 , 255 ), orientation = 'h' , default_value = 120 ,
603
628
k = '-BRIGHTNESS-' , enable_events = True )],
604
629
605
630
[sg .Text ("Animation" )],
606
631
[sg .Button ("Start Animation" ), sg .Button ("Stop Animation" )],
607
632
608
633
[sg .Text ("Pattern" )],
609
- [sg .Combo (PATTERNS , k = '-COMBO -' , enable_events = True )],
634
+ [sg .Combo (PATTERNS , k = '-PATTERN -' , enable_events = True )],
610
635
611
- [sg .Text ("Display Percentage " )],
636
+ [sg .Text ("Fill screen X% (could be volume indicator) " )],
612
637
[sg .Slider ((0 , 100 ), orientation = 'h' ,
613
638
k = '-PERCENTAGE-' , enable_events = True )],
614
639
615
- [sg .Text ("Countdown" )],
640
+ [sg .Text ("Countdown Timer " )],
616
641
[
617
642
sg .Spin ([i for i in range (1 , 60 )],
618
643
initial_value = 10 , k = '-COUNTDOWN-' ),
619
644
sg .Text ("Seconds" ),
620
- sg .Button ("Start" , k = '-START-COUNTDOWN-' )
645
+ sg .Button ("Start" , k = '-START-COUNTDOWN-' ),
646
+ sg .Button ("Stop" , k = '-STOP-COUNTDOWN-' ),
647
+ ],
648
+
649
+ [sg .Text ("Black&White Image" )],
650
+ [sg .Button ("Send stripe.gif" , k = '-SEND-BL-IMAGE-' )],
651
+
652
+ [sg .Text ("Greyscale Image" )],
653
+ [sg .Button ("Send greyscale.gif" , k = '-SEND-GREY-IMAGE-' )],
654
+
655
+ [sg .Text ("Display Current Time" )],
656
+ [
657
+ sg .Button ("Start" , k = '-START-TIME-' ),
658
+ sg .Button ("Stop" , k = '-STOP-TIME-' )
659
+ ],
660
+
661
+ [sg .Text ("Display Text with Symbols" )],
662
+ [sg .Button ("Send '2 5 degC thunder'" , k = '-SEND-TEXT-' )],
663
+
664
+ # TODO
665
+ #[sg.Text("Play Snake")],
666
+ #[sg.Button("Start Game", k='-PLAY-SNAKE-')],
667
+
668
+ [sg .Text ("Equalizer" )],
669
+ [
670
+ sg .Button ("Start random equalizer" , k = '-RANDOM-EQ-' ),
671
+ sg .Button ("Stop" , k = '-STOP-EQ-' )
621
672
],
622
673
623
674
[sg .Text ("Sleep" )],
@@ -627,6 +678,7 @@ def gui():
627
678
[sg .Button ("Quit" )]
628
679
]
629
680
window = sg .Window ("Lotus LED Matrix Control" , layout )
681
+ global STOP_THREAD
630
682
while True :
631
683
event , values = window .read ()
632
684
# print('Event', event)
@@ -638,8 +690,8 @@ def gui():
638
690
if event == "Bootloader" :
639
691
bootloader ()
640
692
641
- if event == '-COMBO -' :
642
- pattern (values ['-COMBO -' ])
693
+ if event == '-PATTERN -' :
694
+ pattern (values ['-PATTERN -' ])
643
695
644
696
if event == 'Start Animation' :
645
697
animate (True )
@@ -657,6 +709,32 @@ def gui():
657
709
thread = threading .Thread (target = countdown , args = (
658
710
int (values ['-COUNTDOWN-' ]),), daemon = True )
659
711
thread .start ()
712
+ if event == '-STOP-COUNTDOWN-' :
713
+ STOP_THREAD = True
714
+
715
+ if event == '-SEND-BL-IMAGE-' :
716
+ image_bl ('stripe.gif' )
717
+
718
+ if event == '-SEND-GREY-IMAGE-' :
719
+ image_greyscale ('greyscale.gif' )
720
+
721
+ if event == '-START-TIME-' :
722
+ thread = threading .Thread (target = clock , args = (), daemon = True )
723
+ thread .start ()
724
+ if event == '-STOP-TIME-' :
725
+ STOP_THREAD = True
726
+
727
+ if event == '-SEND-TEXT-' :
728
+ show_symbols (['2' , '5' , 'degC' , ' ' , 'thunder' ])
729
+
730
+ if event == '-PLAY-SNAKE-' :
731
+ snake ()
732
+
733
+ if event == '-RANDOM-EQ-' :
734
+ thread = threading .Thread (target = random_eq , args = (), daemon = True )
735
+ thread .start ()
736
+ if event == '-STOP-EQ-' :
737
+ STOP_THREAD = True
660
738
661
739
if event == 'Sleep' :
662
740
command = FWK_MAGIC + [0x03 , True ]
0 commit comments