Skip to content

Commit a262ed2

Browse files
authored
Merge pull request #15 from trevorwslee/develop
Develop
2 parents 77240ea + 479c40f commit a262ed2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3899
-374
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/.vscode
33
/venv
44

5+
__pycache__
6+
57
/MicroPythonDumbDisplay.iml
68
/MicroPythonDumbDisplay.code-workspace
79

@@ -17,3 +19,4 @@
1719

1820
uDumbDisplay.code-workspace
1921
/OLD.md
22+
/setup_OLD.py

README.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
# DumbDisplay MicroPython Library (v0.5.0)
2+
# DumbDisplay MicroPython Library (v0.6.0)
33

44
DumbDisplay MicroPython Library -- workable with Python 3 -- is a port of the [DumbDisplay Arduino Library](https://github.com/trevorwslee/Arduino-DumbDisplay)
55
to MicroPython / Python 3 for the [DumbDisplay Android app](https://play.google.com/store/apps/details?id=nobody.trevorlee.dumbdisplay)
@@ -135,7 +135,7 @@ Other then the `DumbDisplay` object, you will need to create one or more layer o
135135
|:--:|
136136
|<img style="width: 300px; height: 300px;" src="screenshots/layer_lcd.png"></img>|
137137
138-
- `LayerGraphical` -- a graphical LCD that you can draw to with common drawing directives
138+
- `LayerGraphical` -- a graphical LCD that you can draw to with common TFT LCD drawing directives
139139
```
140140
from dumbdisplay.core import *
141141
from dumbdisplay.layer_graphical import *
@@ -148,31 +148,46 @@ Other then the `DumbDisplay` object, you will need to create one or more layer o
148148
|:--:|
149149
|<img style="width: 300px; height: 300px;" src="screenshots/layer_graphical.png"></img>|
150150
151-
- `LayerSelection` -- a row / column / grid of TEXT based LCDs mostly for showing selection choices
151+
- `Layer7SegmentRow` -- a single 7-segment digit, or a row of **n** 7-segments digits
152152
```
153153
from dumbdisplay.core import *
154-
from dumbdisplay.layer_selection import *
154+
from dumbdisplay.layer_7segrow import *
155155
dd = DumbDisplay()
156-
l = LayerSelection(dd)
156+
l = Layer7SegmentRow(dd)
157+
```
158+
159+
example:
160+
|[`demo_Layer7SegmentRow()` in `dd_demo.py`](dd_demo.py)|
161+
|:--:|
162+
|<img style="width: 300px; height: 300px;" src="screenshots/layer_7segment_3d.png"></img>|
163+
-
164+
- `LayerTurtle` -- a Python Turtle like canvas that you can draw to using Python Turtle like commands
165+
```
166+
from dumbdisplay.core import *
167+
from dumbdisplay.layer_turtle import *
168+
dd = DumbDisplay()
169+
l = LayerTurtle(dd)
157170
```
158171
159172
example:
160-
|[`demo_LayerSelection()` in `dd_demo.py`](dd_demo.py)|
173+
|[`demo_LayerTurtle()` in `dd_demo.py`](dd_demo.py)|
161174
|:--:|
162-
|<img style="width: 300px; height: 300px;" src="screenshots/layer_selection_1x3.png"></img>|
175+
|<img style="width: 300px; height: 300px;" src="screenshots/layer_turtle.png"></img>|
163176
164-
- `Layer7SegmentRow` -- a single 7-segment digit, or a row of **n** 7-segments digits
177+
178+
- `LayerSelection` -- a row / column / grid of TEXT based LCDs mostly for showing selection choices
165179
```
166180
from dumbdisplay.core import *
167-
from dumbdisplay.layer_7segrow import *
181+
from dumbdisplay.layer_selection import *
168182
dd = DumbDisplay()
169-
l = Layer7SegmentRow(dd)
183+
l = LayerSelection(dd)
170184
```
171-
185+
172186
example:
173-
|[`demo_Layer7SegmentRow()` in `dd_demo.py`](dd_demo.py)|
187+
|[`demo_LayerSelection()` in `dd_demo.py`](dd_demo.py)|
174188
|:--:|
175-
|<img style="width: 300px; height: 300px;" src="screenshots/layer_7segment_3d.png"></img>|
189+
|<img style="width: 300px; height: 300px;" src="screenshots/layer_selection_1x3.png"></img>|
190+
176191
177192
- `LayerPlotter` -- a "plotter" for plotting real-time data
178193
```
@@ -213,7 +228,7 @@ Other then the `DumbDisplay` object, you will need to create one or more layer o
213228
214229
as shown in the example
215230
* you can configure the joystick to be a horizontal or vertical slider by changing the `directions` parameter to `LayerJoystick`
216-
- param `maxStickValue`: the max value of the stick; e.g. 255 or 1023 (the default); min is 15
231+
- param `max_stick_value`: the max value of the stick; e.g. 255 or 1023 (the default); min is 15
217232
- param `directions`: "lr" or "hori": left-to-right; "tb" or "vert": top-to-bottom; "rl": right-to-left; "bt": bottom-to-top;
218233
use "+" combines the above like "lr+tb" to mean both directions; "" the same as "lr+tb"
219234
* feedback -- to be talked about later -- is enabled by default, and you can poll for feedback like
@@ -334,6 +349,12 @@ MIT
334349
335350
# Change History
336351
352+
v0.6.0
353+
- added DDRootLayer
354+
- added LayerTurtle
355+
- added more examples
356+
- bug fixes
357+
337358
v0.5.0
338359
- ported "level options" for LayerGraphical
339360
- ported LayerSelection

_dev_test.py

Lines changed: 187 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import random
2-
import time
3-
import math
4-
5-
2+
from dumbdisplay.full import *
63
from 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+
28198
def 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-
70224
def test_read_readme():
71225
from pathlib import Path
72226
this_directory = Path(__file__).parent
@@ -81,27 +235,20 @@ def test_find_packages():
81235

82236

83237
if __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

Comments
 (0)