Skip to content

Commit ae56dea

Browse files
authored
Merge pull request #5 from trevorwslee/develop
Develop
2 parents 90d3f91 + 676ad9e commit ae56dea

35 files changed

+511
-130
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ dumbdisplay_experimental
1111
/_dd.py
1212
/_test.ipynb
1313
/.micropico
14+
/experiments/pyclock

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# DumbDisplay MicroPython Library (v0.3.0)
1+
# DumbDisplay MicroPython Library (v0.3.1)
22

33
DumbDisplay MicroPython Library is a port of the [DumbDisplay Arduino Library](https://github.com/trevorwslee/Arduino-DumbDisplay)
44
for the [DumbDisplay Android app](https://play.google.com/store/apps/details?id=nobody.trevorlee.dumbdisplay)
@@ -58,7 +58,7 @@ l.enableFeedback("fa")
5858
l.offColor(RGB_COLOR(0xcc, 0xcc, 0xcc))
5959
while True:
6060
feedback = l.getFeedback()
61-
if feedback != None:
61+
if feedback is not None:
6262
print("l FB: {}: {},{}".format(feedback.type, feedback.x, feedback.y))
6363
l.toggle(feedback.x, feedback.y)
6464
```
@@ -126,6 +126,9 @@ Notes:
126126
127127
# Change History
128128
129+
v0.3.1
130+
- added LayerJoystick
131+
129132
v0.3.0
130133
- checked Raspberry Pi Pico W WIFI support
131134
- ported more options from Arduino DumbDisplay library

dumbdisplay/_ddimpl.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def release(self):
146146
tunnels = set(self._tunnels)
147147
for tunnel in tunnels:
148148
tunnel.release()
149-
if self._io != None:
149+
if self._io is not None:
150150
self._io.close()
151151
self._io = None
152152
self._connected = False
@@ -243,19 +243,19 @@ def _sendSpecial(self, special_type: str, special_id: str, special_command: str,
243243
self._io.print(special_type)
244244
self._io.print('.')
245245
self._io.print(special_id)
246-
if special_command != None:
246+
if special_command is not None:
247247
self._io.print(':')
248248
self._io.print(special_command)
249249
self._io.print('>')
250-
if special_data != None:
250+
if special_data is not None:
251251
self._io.print(special_data)
252252
self._io.print('\n')
253253
#self.switchDebugLed(False)
254254
def _sendCommand(self, layer_id: str, command: str, *params):
255255
self._checkForFeedback()
256256
#self.switchDebugLed(True)
257257
try:
258-
if layer_id != None:
258+
if layer_id is not None:
259259
self._io.print(layer_id)
260260
self._io.print('.')
261261
self._io.print(command)
@@ -276,10 +276,11 @@ def _sendCommand(self, layer_id: str, command: str, *params):
276276

277277
def _checkForFeedback(self):
278278
feedback = self._readFeedback()
279-
if feedback != None:
279+
if feedback is not None:
280280
if len(feedback) > 0:
281+
self._onFeedbackSignal()
281282
if feedback[0:1] == '<':
282-
self._onFeedbackKeepAlive()
283+
#self._onFeedbackKeepAlive()
283284
if len(feedback) == 1:
284285
pass
285286
#self._onFeedbackKeepAlive()
@@ -309,7 +310,7 @@ def _checkForFeedback(self):
309310
data = "???" + command + "???"
310311
#print("##" + str(final) + "/" + str(command) + "/" + str(data))####
311312
tunnel = self._tunnels.get(tid)
312-
if tunnel != None:
313+
if tunnel is not None:
313314
tunnel._handleInput(data, final)
314315
except:
315316
pass
@@ -326,7 +327,7 @@ def _checkForFeedback(self):
326327
x = int(feedback[0:idx])
327328
y = int(feedback[idx + 1:])
328329
layer = self._layers.get(lid)
329-
if layer != None:
330+
if layer is not None:
330331
layer._handleFeedback(type, x, y)
331332
except:
332333
pass
@@ -339,7 +340,7 @@ def _readFeedback(self) -> str:
339340
feedback = self._connected_iop.read()
340341
#self._connected_iop.clear()
341342
return feedback
342-
def _onFeedbackKeepAlive(self):
343+
def _onFeedbackSignal(self):
343344
if self._connected_iop:
344345
self._connected_iop.keepAlive()
345346
def _validateConnection(self):

dumbdisplay/_ddio.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from ._ddiobase import DD_DEF_PORT, DDInputOutput
22
from ._ddio_inet import DDIOInet
33

4+
# e.g.
5+
# from dumbdisplay.io_wifi import *
6+
# dd = DumbDisplay(io4Wifi(WIFI_SSID, WIFI_PWD))
7+
48
try:
59
from ._ddio_wifi import DDIOWifi
610
except:
@@ -9,7 +13,7 @@
913
def io4Inet(port: int = DD_DEF_PORT) -> DDInputOutput:
1014
return DDIOInet(port)
1115

12-
def io4Wifi(ssid: str, password: str, port: int = DD_DEF_PORT) -> DDInputOutput:
16+
def io4Wifi(ssid: str = None, password: str = None, port: int = DD_DEF_PORT) -> DDInputOutput:
1317
return DDIOWifi(ssid, password, port)
1418

1519
def io4WifiOrInet(ssid: str, password: str, port: int = DD_DEF_PORT) -> DDInputOutput:

dumbdisplay/_ddio_ble.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def preconnect(self):
1919
self._register()
2020
self._advertiser()
2121
while True:
22-
if self._data != None:
22+
if self._data is not None:
2323
break
2424
time.sleep_ms(500)
2525
print('... BLE connected')
2626
def available(self):
27-
return self._data != None and len(self._data) > 0
27+
return self._data is not None and len(self._data) > 0
2828
def read(self):
2929
return self._data.pop(0)
3030
def print(self, s):
@@ -37,7 +37,7 @@ def print(self, s):
3737
self.ble.gatts_notify(0, self._tx, b)
3838
#print(b)
3939
def close(self):
40-
if self._conn_handle != None:
40+
if self._conn_handle is not None:
4141
self.ble.gap_disconnect(self._conn_handle)
4242
self._conn_handle = None
4343
self._data = None
@@ -91,7 +91,7 @@ def _ble_irq(self, event, data):
9191
#message = buffer.decode('UTF-8')[:-1]
9292
message = buffer.decode('UTF-8').strip()
9393
#print(message)
94-
if (self._data != None):
94+
if (self._data is not None):
9595
self._data.append(message + '\n')
9696
#print(str(len(self._data)))
9797

dumbdisplay/_ddio_socket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def print(self, s):
5353
# raise e
5454
#self.conn.sendall(data)
5555
def close(self):
56-
if self.conn != None:
56+
if self.conn is not None:
5757
self.conn.close()
5858
self.sock.close()
5959
self.conn = None

dumbdisplay/_ddio_uart.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@
55
from machine import UART, Pin
66

77

8+
# e.g.
9+
# from dumbdisplay.io_uart import *
10+
# dd = DumbDisplay(io4Uart(id=1, baudrate=115200, rx=9, tx=8))
11+
812
class DDIOUart(DDInputOutput):
9-
# def __init__(self, id, baudrate = 115200, tx = None, rx = None):
10-
# '''if specify tx, must also specify rx'''
11-
# super().__init__()
12-
# self.uart = UART(id, baudrate)
13-
# if tx != None:
14-
# self.uart.init(baudrate, tx = tx, rx = rx)
15-
def __init__(self, uart):
13+
def __init__(self, uart, desc):
1614
super().__init__()
1715
self.uart = uart
16+
self.desc = desc
17+
def preconnect(self):
18+
print(f"connect with UART ({self.desc})")
1819
def available(self):
1920
return self.uart.any() > 0
2021
def read(self):
@@ -30,18 +31,10 @@ def io4Uart(id, baudrate, rx, tx):
3031
uart = UART(id, baudrate)
3132
uart.init(baudrate, rx=rx, tx=tx)
3233
except:
33-
uart = UART(id=id, baudrate=baudrate, rx=Pin(rx), tx=Pin(tx))
34-
return DDIOUart(uart)
35-
def io4DefUart(id, baudrate, rx):
34+
uart = UART(id, baudrate=baudrate, rx=Pin(rx), tx=Pin(tx))
35+
return DDIOUart(uart, {"id": id, "baudrate": baudrate, "rx": rx, "tx": tx})
36+
def io4DefUart(id, baudrate):
3637
uart = UART(id, baudrate)
37-
return DDIOUart(uart)
38-
39-
# def io4Uart(id, baudrate = 115200, tx = None, rx = None):
40-
# '''if specify tx, must also specify rx'''
41-
# uart = UART(id, baudrate)
42-
# if tx != None:
43-
# uart.init(baudrate, tx = tx, rx = rx)
44-
# return DDIOUart(id, baudrate, tx, rx)
45-
# def io4IpcoUart(uart):
46-
# return DDIOUart(uart)
38+
return DDIOUart(uart, "default")
39+
4740

dumbdisplay/_ddio_wifi.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
class DDIOWifi(DDIOSocket):
77
def __init__(self, ssid, password, port = DD_DEF_PORT):
88
super().__init__(port)
9-
print('connecting WIFI ... {} ...'.format(ssid))
109
station = network.WLAN(network.STA_IF)
1110
if not station.isconnected():
11+
print('connecting WIFI ... {} ...'.format(ssid))
12+
if ssid is None:
13+
raise Exception('SSID not provided')
1214
station.active(True)
1315
station.connect(ssid, password)
1416
while not station.isconnected():

dumbdisplay/_ddlayer.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ def DD_RGB_COLOR(r, g, b):
55
def _DD_INT_ARG(val):
66
return str(int(val))
77

8+
def _DD_FLOAT_ARG(val):
9+
return str(float(val))
10+
811
def _DD_BOOL_ARG(b):
912
if b:
1013
return "1"
@@ -64,34 +67,41 @@ def noBorder(self):
6467
self.dd._sendCommand(self.layer_id, "border")
6568
def padding(self, left, top = None, right = None, bottom = None):
6669
'''see border() for size unit'''
67-
if top == None and right == None and bottom == None:
70+
if top is None and right is None and bottom is None:
6871
self.dd._sendCommand(self.layer_id, "padding", str(left))
6972
else:
70-
if top == None:
73+
if top is None:
7174
top = left
72-
if right == None:
75+
if right is None:
7376
right = left
74-
if bottom == None:
77+
if bottom is None:
7578
bottom = top
7679
self.dd._sendCommand(self.layer_id, "padding", str(left), str(top), str(right), str(bottom))
7780
def noPadding(self):
7881
self.dd._sendCommand(self.layer_id, "padding")
7982
def margin(self, left, top = None, right = None, bottom = None):
8083
'''see border() for size unit'''
81-
if top == None and right == None and bottom == None:
84+
if top is None and right is None and bottom is None:
8285
self.dd._sendCommand(self.layer_id, "margin", str(left))
8386
else:
84-
if top == None:
87+
if top is None:
8588
top = left
86-
if right == None:
89+
if right is None:
8790
right = left
88-
if bottom == None:
91+
if bottom is None:
8992
bottom = top
9093
self.dd._sendCommand(self.layer_id, "margin", str(left), str(top), str(right), str(bottom))
9194
def noMargin(self):
9295
self.dd._sendCommand(self.layer_id, "margin")
93-
def backgroundColor(self, color):
94-
self.dd._sendCommand(self.layer_id, "bgcolor", _DD_COLOR_ARG(color))
96+
def backgroundColor(self, color, opacity = 100):
97+
'''
98+
:param opacity: background opacity (0 - 100)
99+
:return:
100+
'''
101+
if opacity < 100:
102+
self.dd._sendCommand(self.layer_id, "bgcolor", _DD_COLOR_ARG(color), str(opacity))
103+
else:
104+
self.dd._sendCommand(self.layer_id, "bgcolor", _DD_COLOR_ARG(color))
95105
def noBackgroundColor(self):
96106
self.dd._sendCommand(self.layer_id, "nobgcolor")
97107
def clear(self):
@@ -103,7 +113,7 @@ def flashArea(self, x, y):
103113
self.dd._sendCommand(self.layer_id, "flasharea", str(x), str(y))
104114
# def writeComment(self, comment):
105115
# self.dd.writeComment(comment)
106-
def enableFeedback(self, auto_feedback_method = "fa", feedback_handler = None):
116+
def enableFeedback(self, auto_feedback_method, feedback_handler = None):
107117
'''
108118
rely on getFeedback() being called */
109119
:param auto_feedback_method:
@@ -125,7 +135,7 @@ def disableFeedback(self):
125135
'''disable feedback'''
126136
self.dd._sendCommand(self.layer_id, "feedback", _DD_BOOL_ARG(False))
127137
self._feedback_handler = None
128-
def getFeedback(self):
138+
def getFeedback(self) -> DDFeedback:
129139
'''
130140
get any feedback as the structure {type, x, y}
131141
:return: None if none (or when "handler" set)
@@ -158,20 +168,11 @@ def reorderLayer(self, how: str):
158168

159169
def _handleFeedback(self, type, x, y):
160170
#print("RAW FB: " + self.layer_id + '.' + type + ':' + str(x) + ',' + str(y))
161-
if self._feedback_handler != None:
171+
if self._feedback_handler is not None:
162172
self._feedback_handler(self, type, x, y)
163173
else:
164174
self._feedbacks.append((type, x, y))
165175
# self._shipFeedbacks()
166-
# def _shipFeedbacks(self):
167-
# if self._feedback_handler != None:
168-
# feedbacks = self._feedbacks.copy()
169-
# self._feedbacks.clear()
170-
# for (type, x, y) in feedbacks:
171-
# self._feedback_handler.handleFeedback(type, x, y)
172-
# # else:
173-
# # for (type, x, y) in self.feedbacks:
174-
# # print("unhandled FB: " + self.layer_id + '.' + type + ':' + str(x) + ',' + str(y))
175176

176177

177178

dumbdisplay/_ddlayer_7segrow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def __init__(self, dd, digit_count = 1):
88
:param dd: DumbDisplay object
99
:param digit_count: number of digits / # rows
1010
'''
11-
layer_id = dd._createLayer(str("7segrow"), str(digit_count))
11+
layer_id = dd._createLayer("7segrow", str(digit_count))
1212
super().__init__(dd, layer_id)
1313
def segmentColor(self, color):
1414
'''set segment color'''

0 commit comments

Comments
 (0)