Skip to content

Commit 03c671f

Browse files
committed
going for v0.3.0
1 parent bef6622 commit 03c671f

3 files changed

Lines changed: 43 additions & 24 deletions

File tree

dumbdisplay/_ddimpl.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def setReconnectRCId(self, rc_id: str):
5656
self.reconnect_RC_id = rc_id
5757
self.reconnect_enabled = True
5858
self.reconnect_keep_alive_ms = 0
59-
def validateConnection(self):
59+
def validateConnection(self) -> bool:
6060
#print("validateConnection")
6161
need_reconnect = False
6262
if self.last_keep_alive_ms > 0:
@@ -87,6 +87,7 @@ def validateConnection(self):
8787
#_ConnectVersion = _ConnectVersion + 1;
8888
self.reconnect_keep_alive_ms = 0
8989
self.last_keep_alive_ms = time.ticks_ms()
90+
return not need_reconnect
9091
def isReconnecting(self) -> bool:
9192
return self.reconnecting;
9293

@@ -146,9 +147,11 @@ def release(self):
146147
self._connected = False
147148
self._connected_iop = None
148149

149-
def toggleDebugLed(self):
150-
pass
151-
def switchDebugLed(self, on):
150+
# def toggleDebugLed(self):
151+
# pass
152+
# def switchDebugLed(self, on):
153+
# pass
154+
def onDetectedDisconnect(self):
152155
pass
153156
def onSendCommandException(self, error):
154157
pass
@@ -184,7 +187,7 @@ def _connect(self):
184187
if self._connected:
185188
return
186189

187-
self.switchDebugLed(True)
190+
#self.switchDebugLed(True)
188191
self._io.preconnect()
189192

190193
# > ddhello and < ddhello
@@ -194,7 +197,7 @@ def _connect(self):
194197
now = time.ticks_ms()
195198
if now > next_time:
196199
iop.print('ddhello\n')
197-
self.toggleDebugLed()
200+
#self.toggleDebugLed()
198201
next_time = now + _HS_GAP
199202
if iop.available():
200203
data = iop.read()
@@ -211,7 +214,7 @@ def _connect(self):
211214
now = time.ticks_ms()
212215
if now > next_time:
213216
iop.print('>init>:' + _DD_SID + '\n')
214-
self.toggleDebugLed()
217+
#self.toggleDebugLed()
215218
next_time = now + _HS_GAP
216219
if iop.available():
217220
data = iop.read()
@@ -225,12 +228,12 @@ def _connect(self):
225228

226229
self._connected = True
227230
self._compatibility = compatibility
228-
self.switchDebugLed(False)
231+
#self.switchDebugLed(False)
229232
#print('connected:' + str(compatibility))
230233

231234
def _sendSpecial(self, special_type: str, special_id: str, special_command: str, special_data: str):
232235
##print("lt:" + str(special_command) + ":" + str(special_data))#####
233-
self.switchDebugLed(True)
236+
#self.switchDebugLed(True)
234237
self._io.print('%%>')
235238
self._io.print(special_type)
236239
self._io.print('.')
@@ -242,10 +245,10 @@ def _sendSpecial(self, special_type: str, special_id: str, special_command: str,
242245
if special_data != None:
243246
self._io.print(special_data)
244247
self._io.print('\n')
245-
self.switchDebugLed(False)
248+
#self.switchDebugLed(False)
246249
def _sendCommand(self, layer_id: str, command: str, *params):
247250
self._checkForFeedback()
248-
self.switchDebugLed(True)
251+
#self.switchDebugLed(True)
249252
try:
250253
if layer_id != None:
251254
self._io.print(layer_id)
@@ -323,7 +326,8 @@ def _checkForFeedback(self):
323326
except:
324327
pass
325328
def _readFeedback(self) -> str:
326-
self._validateConnection()
329+
if not self._validateConnection():
330+
self.onDetectedDisconnect()
327331
if not self._connected_iop.available():
328332
return None
329333
feedback = self._connected_iop.read()
@@ -338,8 +342,11 @@ def _validateConnection(self):
338342
now = time.ticks_ms()
339343
diff_ms = now - self.last_validate_ms
340344
if diff_ms >= validate_gap:
341-
self._connected_iop.validateConnection()
345+
res = self._connected_iop.validateConnection()
342346
self.last_validate_ms = now
347+
else:
348+
res = True
349+
return res
343350
def _setReconnectRCId(self, rc_id: str):
344351
if self._connected_iop:
345352
self._connected_iop.setReconnectRCId(rc_id)

dumbdisplay/_dumbdisplay.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class DumbDisplay(DumbDisplayImpl):
4646
@staticmethod
4747
def runningWithMicropython():
4848
return hasattr(sys, 'implementation') and sys.implementation.name == 'micropython'
49-
def __init__(self, io: DDInputOutput, reset_machine_on_connection_error: bool = True):
49+
def __init__(self, io: DDInputOutput, reset_machine_if_detected_disconnect: bool = True):
5050
super().__init__(io)
5151
#self.debug_led = None
52-
self.reset_machine_on_connection_error = reset_machine_on_connection_error # _DD_HAS_LED and len(sys.argv) != 0
52+
self.reset_machine_if_detected_disconnect = reset_machine_if_detected_disconnect # _DD_HAS_LED and len(sys.argv) != 0
5353

5454
# def debugSetup(self, debug_led_pin):
5555
# '''setup debug use flashing LED pin number'''
@@ -127,20 +127,30 @@ def notone(self):
127127
# self.debug_led.on()
128128
# else:
129129
# self.debug_led.off()
130-
def onSendCommandException(self, error):
131-
if False:
132-
print("xxxxxxxxx")
133-
print("xxx Error (send command) -- " + str(error) )
134-
print("xxxxxxxxx")
135-
if self.reset_machine_on_connection_error:
136-
print("xxxxxxxxx")
137-
print("xxx Error (send command) -- {}".format(error))
130+
def onDetectedDisconnect(self):
131+
if self.reset_machine_if_detected_disconnect:
138132
print("xxxxxxxxx")
133+
print("xxx detected disconnection ==>")
139134
try:
135+
print("xxx x reset machine")
140136
import machine
141137
machine.reset()
142138
except:
139+
print("xxx x exit system")
143140
sys.exit()
141+
def onSendCommandException(self, error):
142+
print("xxx Error (send command) -- " + str(error) )
143+
# if self.reset_machine_on_connection_error:
144+
# print("xxxxxxxxx")
145+
# print("xxx Error (send command) -- {}".format(error))
146+
# print("xxxxxxxxx")
147+
# try:
148+
# print("xxx reset machine")
149+
# import machine
150+
# machine.reset()
151+
# except:
152+
# print("xxx exit system")
153+
# sys.exit()
144154
# if _DD_HAS_LED and self.reset_machine_on_connection_error:
145155
# import machine
146156
# machine.reset()

samples/melody/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
try:
77
# https://docs.micropython.org/en/latest/library/rp2.html
8-
SPEAKER_PIN = 5
8+
import machine
9+
if machine.unique_id() == b'\xe6aA\x04\x03,D+': # unique_id() is unique to my board
10+
SPEAKER_PIN = 5
911
import time
1012
import rp2
1113
from machine import Pin

0 commit comments

Comments
 (0)