Skip to content

Commit 69a016e

Browse files
committed
going for v0.3
1 parent 119ccd6 commit 69a016e

12 files changed

Lines changed: 182 additions & 13 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
.idea
2+
.vscode
23
venv
34
__pycache__
45
/u_dumbdisplay.iml
56
MicroPythonDumbDisplay.iml
67

8+
dumbdisplay_experimental
9+
710
/_my_secret.py
811
/_test.py
912
/_dd.py

dumbdisplay/_ddlayer.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
def DD_RGB_COLOR(r, g, b):
33
return r * 0x10000 + g * 0x100 + b
44

5+
def _DD_INT_ARG(val):
6+
return str(int(val))
57

68
def _DD_BOOL_ARG(b):
79
if b:
@@ -16,6 +18,7 @@ def _DD_COLOR_ARG(c):
1618
return str(c)
1719

1820

21+
1922
class DDFeedback:
2023
def __init__(self, type, x, y):
2124
self.type = type
@@ -28,6 +31,7 @@ def __init__(self, dd, layer_id):
2831
self.layer_id = layer_id
2932
self._feedback_handler = None
3033
self._feedbacks = []
34+
self.customData = ""
3135
dd._onCreatedLayer(self)
3236
def visibility(self, visible):
3337
'''set layer visibility'''
@@ -55,9 +59,18 @@ def border(self, size, color, shape: str = "flat", extra_size = 0):
5559
self.dd._sendCommand(self.layer_id, "border", str(size), _DD_COLOR_ARG(color), shape, str(extra_size))
5660
def noBorder(self):
5761
self.dd._sendCommand(self.layer_id, "border")
58-
def padding(self, left, top, right, bottom):
62+
def padding(self, left, top = None, right = None, bottom = None):
5963
'''see border() for size unit'''
60-
self.dd._sendCommand(self.layer_id, "padding", str(left), str(top), str(right), str(bottom))
64+
if top == None and right == None and bottom == None:
65+
self.dd._sendCommand(self.layer_id, "padding", str(left))
66+
else:
67+
if top == None:
68+
top = left
69+
if right == None:
70+
right = left
71+
if bottom == None:
72+
bottom = top
73+
self.dd._sendCommand(self.layer_id, "padding", str(left), str(top), str(right), str(bottom))
6174
def noPadding(self):
6275
self.dd._sendCommand(self.layer_id, "padding")
6376
def margin(self, left, top, right, bottom):
@@ -125,6 +138,8 @@ def release(self):
125138
self.dd._deleteLayer(self.layer_id)
126139
self.dd._onDeletedLayer(self.layer_id)
127140
self.dd = None
141+
def pinLayer(self, uLeft: int, uTop: int, uWidth: int, uHeight: int, align: str = ""):
142+
self.dd._pinLayer(self.layer_id, uLeft, uTop, uWidth, uHeight, align)
128143

129144

130145
def _handleFeedback(self, type, x, y):

dumbdisplay/_ddlayer_graphical.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from ._ddlayer import DDLayer
2-
from ._ddlayer import _DD_COLOR_ARG
3-
from ._ddlayer import _DD_BOOL_ARG
2+
from ._ddlayer import _DD_COLOR_ARG, _DD_BOOL_ARG, _DD_INT_ARG
43

54
class DDLayerGraphical(DDLayer):
65
'''Graphical LCD'''
@@ -10,7 +9,7 @@ def __init__(self, dd, width, height):
109
:param width: width
1110
:param height: height
1211
'''
13-
layer_id = dd._createLayer(str("graphical"), str(width), str(height))
12+
layer_id = dd._createLayer(str("graphical"), _DD_INT_ARG(width), _DD_INT_ARG(height))
1413
super().__init__(dd, layer_id)
1514
def setCursor(self, x, y):
1615
self.dd._sendCommand(self.layer_id, "setcursor", str(x), str(y))

dumbdisplay/_dumbdisplay.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from dumbdisplay._ddimpl import DumbDisplayImpl
22
from dumbdisplay._ddiobase import DDInputOutput
3+
from ._ddlayer import _DD_INT_ARG, _DD_BOOL_ARG
34

45

56
import sys
@@ -19,6 +20,8 @@ def __init__(self, orientation, *layers):
1920
'''
2021
self.orientation = orientation
2122
self.layers = layers
23+
def build(self):
24+
return self._build_layout()
2225
def pin(self, dd):
2326
layout_spec = self._build_layout()
2427
if layout_spec != None:
@@ -40,6 +43,9 @@ def _build_layout(self):
4043

4144

4245
class DumbDisplay(DumbDisplayImpl):
46+
@staticmethod
47+
def runningWithMicropython():
48+
return hasattr(sys, 'implementation') and sys.implementation.name == 'micropython'
4349
def __init__(self, io: DDInputOutput):
4450
super().__init__(io)
4551
self.debug_led = None
@@ -69,6 +75,19 @@ def configAutoPin(self, layout_spec):
6975
'''
7076
self._connect()
7177
self._sendCommand(None, "CFGAP", layout_spec)
78+
def configPinFrame(self, xUnitCount: int, yUnitCount: int):
79+
self._connect()
80+
self._sendCommand(None, "CFGPF", _DD_INT_ARG(xUnitCount), _DD_INT_ARG(yUnitCount))
81+
def _pinLayer(self, layer_id: str, uLeft: int, uTop: int, uWidth: int, uHeight: int, align: str = ""):
82+
self._sendCommand(layer_id, "PIN", _DD_INT_ARG(uLeft), _DD_INT_ARG(uTop), _DD_INT_ARG(uWidth), _DD_INT_ARG(uHeight), align)
83+
def pinAutoPinLayers(self, layout_spec: str, uLeft: int, uTop: int, uWidth: int, uHeight: int, align: str = ""):
84+
self._sendCommand(None, "PINAP", layout_spec, _DD_INT_ARG(uLeft), _DD_INT_ARG(uTop), _DD_INT_ARG(uWidth), _DD_INT_ARG(uHeight), align)
85+
def recordLayerSetupCommands(self):
86+
self._connect()
87+
self._sendCommand(None, "RECC")
88+
def playbackLayerSetupCommands(self, layerSetupPersistId: str):
89+
self._sendCommand(None, "SAVEC", layerSetupPersistId, _DD_BOOL_ARG(True))
90+
self._sendCommand(None, "PLAYC")
7291
def backgroundColor(self, color: str):
7392
'''set DD background color with common "color name"'''
7493
self._connect()

samples/doodle/_my_secret.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
WIFI_SSID="your wifi router ssid"
3+
WIFI_PWD="your wifi router password"

samples/doodle/main.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
from dumbdisplay.core import *
3-
from dumbdisplay.io_inet import *
43
from dumbdisplay.layer_lcd import *
54
from dumbdisplay.layer_graphical import *
65

@@ -28,7 +27,18 @@ def feedback_handler(layer, type, x, y):
2827

2928

3029
# create DumbDisplay connected using Inet (Python Internet connection)
31-
dd = DumbDisplay(io4Inet())
30+
if DumbDisplay.runningWithMicropython():
31+
# connect using WIFI:
32+
# assume a _my_secret.py Python script containing
33+
# WIFI_SSID="SSID"
34+
# WIFI_PWD="PASSWORD"
35+
from _my_secret import *
36+
from dumbdisplay.io_wifi import *
37+
dd = DumbDisplay(io4Wifi(WIFI_SSID, WIFI_PWD))
38+
else:
39+
# connect using Inet (Python Internet connection)
40+
from dumbdisplay.io_inet import *
41+
dd = DumbDisplay(io4Inet())
3242

3343
# create 3 LCD layer as 3 tabs for changing color
3444
l_r = LayerLcd(dd)

samples/graphical/_my_secret.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
WIFI_SSID="your wifi router ssid"
3+
WIFI_PWD="your wifi router password"

samples/graphical/main.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11

22
from dumbdisplay.core import *
3-
from dumbdisplay.io_inet import *
43
from dumbdisplay.layer_graphical import LayerGraphical
54

6-
# create DumbDisplay connected using Inet (Python Internet connection)
7-
dd = DumbDisplay(io4Inet())
5+
# create DumbDisplay
6+
if DumbDisplay.runningWithMicropython():
7+
# connect using WIFI:
8+
# assume a _my_secret.py Python script containing
9+
# WIFI_SSID="SSID"
10+
# WIFI_PWD="PASSWORD"
11+
from _my_secret import *
12+
from dumbdisplay.io_wifi import *
13+
dd = DumbDisplay(io4Wifi(WIFI_SSID, WIFI_PWD))
14+
else:
15+
# connect using Inet (Python Internet connection)
16+
from dumbdisplay.io_inet import *
17+
dd = DumbDisplay(io4Inet())
18+
19+
import time
820

921
# create 4 graphical [LCD] layers
1022
l1 = LayerGraphical(dd, 150, 101)
@@ -17,13 +29,15 @@
1729

1830

1931
while True:
20-
dd.writeComment("start")
32+
dd.writeComment("start ...")
2133

2234
# set fill screen with color
2335
l1.fillScreen("azure")
2436
l2.fillScreen("azure")
2537
l3.fillScreen("azure")
2638
l4.fillScreen("azure")
39+
40+
start_ms = time.ticks_ms()
2741

2842
# draw triangles
2943
left = 0
@@ -79,7 +93,11 @@
7993
l4.drawCircle(x, y, r, "teal")
8094
l4.drawCircle(x + r, y + r, r, "gold", True)
8195

82-
dd.writeComment("done ... will repeat in 5 second")
96+
taken_s = (time.ticks_ms() - start_ms) / 1000.0
97+
dd.writeComment(f"done ... in {taken_s:.2}s")
98+
99+
100+
dd.writeComment("will repeat in 5 second")
83101
dd.delay(5)
84102
l1.clear()
85103
l2.clear()

samples/melody/_my_secret.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
WIFI_SSID="your wifi router ssid"
3+
WIFI_PWD="your wifi router password"

samples/melody/main.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
2+
from dumbdisplay.core import *
3+
from dumbdisplay.layer_graphical import LayerGraphical
4+
from dumbdisplay.layer_lcd import LayerLcd
5+
6+
7+
TOP_HEIGHT = 30
8+
WIDTH = 14
9+
HEIGHT = 80
10+
BORDER = 1
11+
12+
13+
14+
# create DumbDisplay
15+
if DumbDisplay.runningWithMicropython():
16+
# connect using WIFI:
17+
# assume a _my_secret.py Python script containing
18+
# WIFI_SSID="SSID"
19+
# WIFI_PWD="PASSWORD"
20+
from _my_secret import *
21+
from dumbdisplay.io_wifi import *
22+
dd = DumbDisplay(io4Wifi(WIFI_SSID, WIFI_PWD))
23+
else:
24+
# connect using Inet (Python Internet connection)
25+
from dumbdisplay.io_inet import *
26+
dd = DumbDisplay(io4Inet())
27+
28+
29+
def SetupKey(octiveOffset: int, noteIdx: int) -> LayerGraphical:
30+
width = WIDTH - 2 * BORDER
31+
xOffset = noteIdx * WIDTH / 2
32+
#height
33+
#bgColor
34+
isSemi = False
35+
if noteIdx == 1 or noteIdx == 3 or noteIdx == 6 or noteIdx == 8 or noteIdx == 10:
36+
height = HEIGHT / 2 + 10
37+
bgColor = "black"
38+
isSemi = True
39+
else:
40+
height = HEIGHT
41+
bgColor = "white"
42+
if noteIdx > 4:
43+
xOffset += WIDTH / 2
44+
customData = chr(ord(" ") + octiveOffset) + chr(ord(" ") + noteIdx)
45+
#customData[0] = '0' + octiveOffset;
46+
#customData[1] = '0' + noteIdx;
47+
#customData[2] = 0;
48+
keyLayer = LayerGraphical(dd, width, height)
49+
keyLayer.customData = customData
50+
keyLayer.backgroundColor(bgColor)
51+
keyLayer.border(BORDER, "gray")
52+
keyLayer.padding(0)
53+
#keyLayer->setFeedbackHandler(FeedbackHandler, "f");
54+
if isSemi:
55+
#dumbdisplay.reorderLayer(keyLayer, "T");
56+
pass
57+
else:
58+
if noteIdx == 0:
59+
keyLayer.drawStr(2, HEIGHT - 15, "C", "blue")
60+
l = WIDTH + octiveOffset * 7 * WIDTH + xOffset
61+
t = TOP_HEIGHT
62+
w = width + 2 * BORDER
63+
h = height + 2 * BORDER
64+
keyLayer.pinLayer(l, t, w, h)
65+
return keyLayer
66+
67+
def SetupButton(label: str) -> LayerLcd:
68+
buttonLayer = LayerLcd(dd, 4, 1)
69+
buttonLayer.writeLine(label, 0, "C")
70+
buttonLayer.border(1, "darkgray", "round")
71+
buttonLayer.noBackgroundColor()
72+
#buttonLayer.setFeedbackHandler(FeedbackHandler, "f");
73+
return buttonLayer
74+
75+
dd.recordLayerSetupCommands()
76+
77+
dd.configPinFrame(9 * WIDTH, TOP_HEIGHT + HEIGHT)
78+
79+
SetupKey(-1, 11)
80+
for i in range(0, 12):
81+
SetupKey(0, i)
82+
SetupKey(1, 0)
83+
84+
playLayer = SetupButton("⏯");
85+
restartLayer = SetupButton("⏮");
86+
targetLayer = SetupButton("📱");
87+
88+
dd.pinAutoPinLayers(AutoPin("H", playLayer, restartLayer, targetLayer).build(), 0, 0, 9 * WIDTH, TOP_HEIGHT)
89+
90+
dd.playbackLayerSetupCommands("ddmelody")

0 commit comments

Comments
 (0)