Skip to content

Commit 7fded36

Browse files
committed
updated
1 parent 712bfe7 commit 7fded36

8 files changed

Lines changed: 31 additions & 24 deletions

File tree

README.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ to Micro-Python / Python 3 for the [DumbDisplay Android app](https://play.google
66
For a video introduction, please watch the YouTube video: [Introducing DumbDisplay MicroPython Library --
77
with ESP32, Raspberry Pi Pico, and Raspberry Pi Zero](https://www.youtube.com/watch?v=KVU26FyXs5M)
88

9-
Although the porting is not complete, nevertheless, a large portion of DumbDisplay functionalities have been ported.
9+
Although the porting is work in progress, nevertheless, a large portion of DumbDisplay functionalities have been ported.
1010
Hopefully, this should already be helpful for friends that develop programs for microcontroller boards in Micro-Python.
1111

12-
As hinted previously, even it is originally targeted for MicroPython, it should be useful with regular Python 3, like in Raspberry Pi environment
12+
As hinted previously, even it is originally targeted for MicroPython, it should be useful with regular Python 3, like in Raspberry Pi environment
1313
or even with desktop / laptop.
14+
As a result, it can be an alternative way to prototype Android app driven remotely with Python 3 from desktop / laptop.
1415

1516

1617
Enjoy
@@ -27,9 +28,9 @@ Enjoy
2728
# Installation
2829

2930
For Micro-Python, please refer to the [above-mentioned YouTube video](https://www.youtube.com/watch?v=KVU26FyXs5M)
30-
for examples of using DumbDisplay MicroPython Library for microcontroller boards programming.
31+
for examples of using DumbDisplay MicroPython Library for microcontroller programming.
3132

32-
If your targeted is desktop / laptop, you can install the library by cloning the repository:
33+
If your targeted is desktop / laptop, you can install the package like:
3334
```
3435
pip install git+https://github.com/trevorwslee/MicroPython-DumbDisplay
3536
```
@@ -44,21 +45,23 @@ pip install --upgrade --force-reinstall git+https://github.com/trevorwslee/Micro
4445

4546
The basic script setup is:
4647
1. import core, for creating `DumbDisplay` object
47-
2. import IO mechanism, for creating IO object
48+
2. import IO mechanism, for creating IO object, like
49+
- `io4Inet`(the default) -- Python networking support (not available for Micro-Python)
50+
- `io4Wifi` -- Micro-Python WiFi support (for Raspberry Pi Pico W, ESP32, etc.)
4851
3. import layers, for creating layer objects
4952

50-
For example
53+
For example (using Python networking support with `io4Inet` as `io` )
5154
```
5255
from dumbdisplay.core import *
5356
from dumbdisplay.io_inet import *
5457
from dumbdisplay.layer_ledgrid import *
55-
dd = DumbDisplay(io4Inet())
58+
dd = DumbDisplay() # default io is io4Inet()
5659
l = LayerLedGrid(dd)
5760
l.turnOn()
5861
```
5962

6063

61-
A "very simple" sample that makes use of WiFi can be like
64+
A simple sample that explicitly makes use of WiFi `io4Wifi` as `io`, can be like
6265
```
6366
from dumbdisplay.core import *
6467
from dumbdisplay.io_wifi import *
@@ -81,7 +84,7 @@ A simple sample that polls for feedbacks, can be like
8184
from dumbdisplay.core import *
8285
from dumbdisplay.io_inet import *
8386
from dumbdisplay.layer_ledgrid import *
84-
dd = DumbDisplay(io4Inet())
87+
dd = DumbDisplay() # default io is io4Inet()
8588
l = LayerLedGrid(dd, 20, 20)
8689
l.enableFeedback("fa")
8790
l.offColor(RGB_COLOR(0xcc, 0xcc, 0xcc))
@@ -118,7 +121,7 @@ def feedback_handler(layer, type, x, y):
118121
_last_x = -1
119122
120123
121-
dd = DumbDisplay(io4Inet())
124+
dd = DumbDisplay() # default io is io4Inet()
122125
l_r = LayerLcd(dd)
123126
l_g = LayerLcd(dd)
124127
l_b = LayerLcd(dd)
@@ -134,7 +137,7 @@ l_b.enableFeedback("f", feedback_handler=feedback_handler)
134137
l.enableFeedback("fs:rpt50", feedback_handler=feedback_handler)
135138
AutoPin('V', AutoPin('H', l_r, l_g, l_b), l).pin(dd)
136139
while True:
137-
dd.sleep(1)
140+
dd.timeslice()
138141
```
139142

140143
Notes:

_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def run_melody():
2727
def test_very_simple():
2828
#import time
2929
from dumbdisplay.layer_ledgrid import LayerLedGrid
30-
dd = DumbDisplay(io4Inet())
30+
dd = DumbDisplay() # default io is io4Inet()
3131
l = LayerLedGrid(dd, 2, 1)
3232
l.offColor("green")
3333
l.turnOn()
@@ -40,7 +40,7 @@ def test_very_simple():
4040

4141
def test_plotter():
4242
from dumbdisplay.layer_plotter import LayerPlotter
43-
dd = DumbDisplay(io4Inet())
43+
dd = DumbDisplay() # default io is io4Inet()
4444
l = LayerPlotter(dd, 300, 100)
4545
l.label("X", sin="Sin")
4646
for x in range(1000):
@@ -51,7 +51,7 @@ def test_plotter():
5151

5252
def test_margin():
5353
from dumbdisplay.layer_ledgrid import LayerLedGrid
54-
dd = DumbDisplay(io4Inet())
54+
dd = DumbDisplay() # default io is io4Inet()
5555
l = LayerLedGrid(dd)
5656
dd.backgroundColor("yellow")
5757
l.backgroundColor("pink")
@@ -61,7 +61,7 @@ def test_margin():
6161
l.margin(0.4, 0.3, 0.2, 0.1)
6262
while True:
6363
print("... ", end="")
64-
dd.delay(1)
64+
dd.timeslice()
6565
print("...")
6666
if dd.isReconnecting():
6767
break # since haven't setup for reconnection (like with recordLayerSetupCommands) ... may as well break out of the loop
@@ -106,9 +106,9 @@ def test_find_packages():
106106
#run_graphical()
107107
#run_melody()
108108

109-
#test_margin()
109+
test_margin()
110110
#test_very_simple()
111111
#test_plotter()
112112

113-
test_read_readme()
113+
#test_read_readme()
114114
#test_find_packages()

dumbdisplay/_ddimpl.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,15 @@ def _Connect_Threaded(io: DDInputOutput):
162162

163163
class DumbDisplayImpl:
164164
def __init__(self, io: DDInputOutput):
165+
if io is None:
166+
# if not specific, default to DDIOInet
167+
from ._ddio_inet import DDIOInet
168+
io = DDIOInet()
165169
self._io: DDInputOutput = io
166170
self._connected = False
167171
self._compatibility = 0
168172
self._connected_iop: IOProxy = None
169-
self._layers: dict[DDLayer] = {}
173+
self._layers: dict[str, DDLayer] = {}
170174
self._tunnels: dict = {}
171175
self.last_validate_ms = 0
172176

@@ -175,7 +179,7 @@ def timeslice(self):
175179

176180
def delay(self, seconds: float = 0):
177181
'''
178-
use sleep() instead
182+
deprecated; use sleep() instead
179183
'''
180184
self.sleep_ms(seconds * 1000)
181185

dumbdisplay/_ddlayer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, type, x, y):
4747
self.y = y
4848

4949
class DDLayer:
50-
def __init__(self, dd, layer_id):
50+
def __init__(self, dd, layer_id: str):
5151
self.dd = dd
5252
self.layer_id = layer_id
5353
self._feedback_handler = None

dumbdisplay/_dumbdisplay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class DumbDisplay(DumbDisplayImpl):
5858
@staticmethod
5959
def runningWithMicropython():
6060
return hasattr(sys, 'implementation') and sys.implementation.name == 'micropython'
61-
def __init__(self, io: DDInputOutput, reset_machine_when_failed_to_send_command: bool = False, reset_machine_if_detected_disconnect_for_s: int = None):
61+
def __init__(self, io: DDInputOutput = None, reset_machine_when_failed_to_send_command: bool = False, reset_machine_if_detected_disconnect_for_s: int = None):
6262
super().__init__(io)
6363
#self.debug_led = None
6464
self.reset_machine_when_failed_to_send_command = reset_machine_when_failed_to_send_command

dumbdisplay_examples/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
def create_example_wifi_dd():
55
'''
6-
create example DumbDisplay with WiFi connection
6+
create example DumbDisplay ... if for Micro-Python WiFi connection, assumes _my_secret.py
77
'''
88
if DumbDisplay.runningWithMicropython():
99
# connect using WIFI:

experiments/testing/_debug.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ def loop(io: DDInputOutput):
7979
while True:
8080
dd = start(io)
8181
once(dd, True)
82-
dd.sleep(2)
82+
dd.sleep(2) # sleep for 2 seconds before restarting
8383
dd.release()
8484

samples/doodle/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def feedback_handler(layer, type, x, y):
7171

7272
# the main loop does nothing, but uses DumbDisplay's delay, so that DumbDisplay has a chance to do it's work
7373
while True:
74-
dd.delay(1)
74+
dd.timeslice()
7575

7676

7777

0 commit comments

Comments
 (0)