11import random
2- import time
3- import math
4-
5-
2+ from dumbdisplay .full import *
63from dumbdisplay_examples .utils import create_example_wifi_dd
74
85
@@ -25,6 +22,179 @@ def run_melody():
2522 import samples .melody .main
2623
2724
25+ def test_turtleTracked ():
26+ from dumbdisplay .layer_turtle import LayerTurtleTracked
27+ dd = create_example_wifi_dd ()
28+ l = LayerTurtleTracked (dd , 2000 , 2000 )
29+ l .backgroundColor ("ivory" )
30+ l .border (3 , "blue" )
31+ if True :
32+ sync = True
33+ distance = 1
34+ angle = 10
35+ for i in range (0 , 180 ):
36+ l .penColor ("red" )
37+ l .penSize (20 )
38+ l .forward (distance )
39+ l .rightTurn (angle )
40+ distance += 1
41+ coor = l .pos (sync = sync )
42+ if True :
43+ l .goTo (0 , 0 , with_pen = False )
44+ l .penColor ("blue" )
45+ l .penSize (10 )
46+ l .circle (15 * i , centered = True )
47+ l .goTo (coor [0 ], coor [1 ], with_pen = False )
48+ print (f"* LOOP[{ i } ] turtle pos: { coor } " )
49+ if not sync :
50+ dd .sleep (0.1 )
51+ else :
52+ l .forward (100 )
53+ coor = l .pos ()
54+ print (f"* INIT turtle pos: { coor } " )
55+ l .forward (100 )
56+ coor = l .pos ()
57+ print (f"* INIT 2 turtle pos: { coor } " )
58+ while True :
59+ coor = l .pos ()
60+ print (f"* turtle pos: { coor } " )
61+ dd .sleep (2 )
62+
63+ def test_passive_turtleTracked (sync : bool = True ):
64+ from dumbdisplay .layer_turtle import LayerTurtleTracked
65+ def _setup (dd : DumbDisplay ) -> LayerTurtleTracked :
66+ l = LayerTurtleTracked (dd , 2000 , 2000 )
67+ l .backgroundColor ("ivory" )
68+ l .border (3 , "blue" )
69+ return l
70+ def _loop (l : LayerTurtleTracked , i : int , distance : int ):
71+ l .penColor ("red" )
72+ l .penSize (20 )
73+ l .forward (distance )
74+ l .rightTurn (10 )
75+ if True :
76+ r = 50 + int (random .random () * 30 )
77+ r2 = r + 10 + int (random .random () * 20 )
78+ a = int (random .random () * 45 )
79+ a2 = a + 10 + int (random .random () * 45 )
80+ centered = random .random () < 0.5
81+ l .penColor ("green" )
82+ l .penSize (10 )
83+ shape = i % 7
84+ if shape == 0 :
85+ l .rectangle (r , r2 , centered = centered )
86+ elif shape == 1 :
87+ l .centeredPolygon (r , 5 , inside = centered )
88+ elif shape == 2 :
89+ l .polygon (r , 5 )
90+ elif shape == 3 :
91+ l .arc (r , r2 , a , a2 , centered = centered )
92+ elif shape == 4 :
93+ l .circle (r , centered = centered )
94+ elif shape == 5 :
95+ l .isoscelesTriangle (r , a )
96+ else :
97+ l .dot (r , color = "darkblue" )
98+ coor = l .pos (sync = sync )
99+ if i % 2 == 0 :
100+ l .goTo (0 , 0 , with_pen = False )
101+ l .penColor ("blue" )
102+ l .penSize (5 )
103+ r = 5 * i
104+ l .circle (r , centered = True )
105+ l .goTo (coor [0 ], coor [1 ], with_pen = False )
106+ print (f"* LOOP[{ i } ] turtle pos: { coor } " )
107+ # if not sync:
108+ # l.dd.sleep(0.2)
109+ dd = create_example_wifi_dd ()
110+ distance = 1
111+ i = 0
112+ l : LayerTurtleTracked = None
113+ freeze_for_steps = 10
114+ while True :
115+ (connected , reconnecting ) = dd .connectPassive ()
116+ if connected :
117+ if l is None :
118+ l = _setup (dd )
119+ # if freeze_for_steps > 0:
120+ # dd.freezeDrawing()
121+ distance = 1
122+ i = 0
123+ else :
124+ if reconnecting :
125+ dd .masterReset ()
126+ l = None
127+ else :
128+ if i <= 300 :
129+ if i < 300 :
130+ # if freeze_for_steps > 0 and i == 0:
131+ # dd.freezeDrawing()
132+ _loop (l , i = i , distance = distance )
133+ if freeze_for_steps > 0 :
134+ if (i + 1 ) % freeze_for_steps == 0 :
135+ dd .unfreezeDrawing (refreeze_after_draw = True )
136+ print (f" --- unfreeze" )
137+ else :
138+ if freeze_for_steps > 0 :
139+ dd .unfreezeDrawing ()
140+ print (f" --- FINAL[{ i } ] unfreeze" )
141+ else :
142+ coor = l .pos (sync = sync )
143+ print (f"* ENDED[{ i } ] turtle pos: { coor } " )
144+ l .dd .sleep (1 )
145+ if i > 305 :
146+ l .clear ()
147+ l .home (with_pen = False )
148+ distance = 0
149+ i = - 1
150+ distance = distance + 1
151+ i = i + 1
152+
153+
154+
155+ def test_auto_pin_remaining ():
156+ rooted = True
157+
158+ dd = create_example_wifi_dd ()
159+
160+ if rooted :
161+ root_layer = DDRootLayer (dd , 200 , 300 )
162+ root_layer .border (5 , "darkgreen" )
163+ root_layer .backgroundColor ("lightgreen" )
164+ status_layer = LayerGraphical (dd , 300 , 80 )
165+ dd .configPinFrame (100 , 100 )
166+ dd .pinLayer (status_layer , 0 , 0 , 100 , 35 )
167+
168+ test_remaining = True
169+
170+ ll = []
171+ if test_remaining :
172+ dd .pinAutoPinLayers (AutoPin ("H" ).build (), 0 , 35 , 100 , 65 )
173+ for i in range (3 ):
174+ l = LayerLedGrid (dd , i + 1 , i + 1 )
175+ l .offColor ("yellow" )
176+ ll .append (l )
177+ dd .addRemainingAutoPinConfig (AutoPin ("V" , ll [0 ], ll [1 ]).build ())
178+ else :
179+ l1 = LayerLedGrid (dd )
180+ l1 .offColor ("yellow" )
181+ l2 = LayerLedGrid (dd , 2 , 2 )
182+ l2 .offColor ("pink" )
183+ dd .pinAutoPinLayers (AutoPin ("H" , l1 , l2 ).build (), 0 , 35 , 100 , 65 )
184+ ll .append (l1 )
185+ ll .append (l2 )
186+
187+ while True :
188+ for l in ll :
189+ l .toggle ()
190+ print ("... " , end = "" )
191+ dd .sleep (1 )
192+ print ("..." )
193+ if dd .isReconnecting ():
194+ break # since haven't setup for reconnection (like with recordLayerSetupCommands) ... may as well break out of the loop
195+ print ("... ASSUME disconnected" )
196+
197+
28198def test_margin ():
29199 from dumbdisplay .layer_ledgrid import LayerLedGrid
30200 dd = create_example_wifi_dd ()
@@ -51,22 +221,6 @@ def run_passive_blink_app():
51221 app .run ()
52222
53223
54- def run_sliding_puzzle_app ():
55- from dumbdisplay_examples .sliding_puzzle .sliding_puzzle_app import SlidingPuzzleApp
56- print (f"*** SlidingPuzzleApp ***" )
57- suggest_move_from_dir_func = lambda board_manager : random .randint (0 , 3 )
58- app = SlidingPuzzleApp (dd = create_example_wifi_dd (), suggest_move_from_dir_func = suggest_move_from_dir_func )
59- app .run ()
60-
61- def run_mnist_app ():
62- from dumbdisplay_examples .mnist .mnist_app import MnistApp
63- print (f"*** MnistApp ***" )
64- inference_func = lambda board_manager : random .randint (0 , 9 )
65- app = MnistApp (dd = create_example_wifi_dd (), inference_func = inference_func )
66- app .run ()
67-
68-
69-
70224def test_read_readme ():
71225 from pathlib import Path
72226 this_directory = Path (__file__ ).parent
@@ -81,27 +235,20 @@ def test_find_packages():
81235
82236
83237if __name__ == "__main__" :
84- #test_LayerLedGrid(2, 2)
85- #test_LayerLcd()
86- #test_LayerGraphical()
87- #test_Layer7SegmentRow()
88- #test_LayerSelection()
89- #test_LayerPlotter()
90-
91- test_AutoPin ()
92-
93- #run_passive_blink_app()
94- #run_sliding_puzzle_app()
95- #run_mnist_app()
96238
97- #run_debug()
98- #run_doodle()
99- #run_graphical()
100- #run_melody()
239+ test_passive_turtleTracked (sync = True )
101240
102- #test_margin()
103241
104- #run_debugBlepriority("MyBLEDevice" )
242+ #test_auto_pin_remaining( )
105243
106- #test_read_readme()
107- #test_find_packages()
244+ # run_debug()
245+ # run_doodle()
246+ # run_graphical()
247+ # run_melody()
248+ #
249+ # test_margin()
250+ #
251+ # run_debugBlepriority("MyBLEDevice")
252+ #
253+ # test_read_readme()
254+ # test_find_packages()
0 commit comments