Skip to content

Commit ac3213f

Browse files
committed
fixed parse FB bug
1 parent 6f43609 commit ac3213f

4 files changed

Lines changed: 19 additions & 11 deletions

File tree

dumbdisplay/ddimpl.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ def available(self):
8383
done = '\n' in s
8484
return done
8585
def read(self) -> str:
86-
#print(self.data)
86+
# if True: # TODO: disable printing of received data
87+
# data = self.data[:-1]
88+
# print(data)
8789
idx = self.data.index('\n')
8890
s = self.data[0:idx]
8991
self.data = self.data[idx + 1:]
@@ -461,7 +463,7 @@ def _checkForFeedback(self):
461463
pass
462464
#self._onFeedbackKeepAlive()
463465
else:
464-
#print(feedback)####
466+
#print(feedback) # TODO: disable debug
465467
if feedback.startswith('<lt.'):
466468
try:
467469
feedback = feedback[4:]
@@ -492,6 +494,7 @@ def _checkForFeedback(self):
492494
pass
493495
else:
494496
idx = feedback.find('.')
497+
#print("** FEEDBACK: " + feedback) # TODO: disable debug
495498
if idx != -1:
496499
try:
497500
lid = feedback[0:idx]
@@ -525,14 +528,13 @@ def _checkForFeedback(self):
525528
x_str = feedback[0:idx]
526529
if x_str != "":
527530
x = int(x_str)
528-
idx += 1
529531
else:
530532
x = 0
531533
if idx2 == -1:
532-
y_str = feedback[idx:]
534+
y_str = feedback[idx + 1:]
533535
text = None
534536
else:
535-
y_str = feedback[idx:idx2]
537+
y_str = feedback[idx + 1:idx2]
536538
text = feedback[idx2 + 1:]
537539
if y_str != "":
538540
y = int(y_str)
@@ -550,8 +552,10 @@ def _checkForFeedback(self):
550552
layer._handleAck(ack_seq, x, y, text)
551553
else:
552554
layer._handleFeedback(fb_type, x, y) # TODO: set text as feedback text
553-
except:
554-
pass
555+
except Exception as e:
556+
#print("** EXCEPT: " + feedback)
557+
if True:
558+
raise e
555559
def _readFeedback(self) -> str:
556560
validate_res = self._validateConnection()
557561
if validate_res is None:

dumbdisplay/ddlayer_multilevel.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,20 @@ def setLevelAnchor(self, x: float, y: float, reach_in_millis: int = 0):
7171
"""
7272
set the anchor of the level; note that level anchor is the top-left corner of the level "opening"
7373
"""
74+
command = "setlevelanchor" if self.dd._compatibility < 15 else "SLA"
7475
if reach_in_millis > 0:
75-
self.dd._sendCommand(self.layer_id, "setlevelanchor", _DD_FLOAT_ARG(x), _DD_FLOAT_ARG(y), _DD_INT_ARG(reach_in_millis))
76+
self.dd._sendCommand(self.layer_id, command, _DD_FLOAT_ARG(x), _DD_FLOAT_ARG(y), _DD_INT_ARG(reach_in_millis))
7677
else:
77-
self.dd._sendCommand(self.layer_id, "setlevelanchor", _DD_FLOAT_ARG(x), _DD_FLOAT_ARG(y))
78+
self.dd._sendCommand(self.layer_id, command, _DD_FLOAT_ARG(x), _DD_FLOAT_ARG(y))
7879
def moveLevelAnchorBy(self, by_x: float, by_y: float, reach_in_millis: int = 0):
7980
"""
8081
move the level anchor
8182
"""
83+
command = "movelevelanchorby" if self.dd._compatibility < 15 else "MLAB"
8284
if reach_in_millis > 0:
83-
self.dd._sendCommand(self.layer_id, "movelevelanchorby", _DD_FLOAT_ARG(by_x), _DD_FLOAT_ARG(by_y), _DD_INT_ARG(reach_in_millis));
85+
self.dd._sendCommand(self.layer_id, command, _DD_FLOAT_ARG(by_x), _DD_FLOAT_ARG(by_y), _DD_INT_ARG(reach_in_millis));
8486
else:
85-
self.dd._sendCommand(self.layer_id, "movelevelanchorby", _DD_FLOAT_ARG(by_x), _DD_FLOAT_ARG(by_y));
87+
self.dd._sendCommand(self.layer_id, command, _DD_FLOAT_ARG(by_x), _DD_FLOAT_ARG(by_y));
8688
def registerLevelBackground(self, background_id: str, background_image_name: str, draw_background_options: str = ""):
8789
"""
8890
register an image for setting as level's background

dumbdisplay_examples/tetris/tetris_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def move_left(self, grid: Grid) -> bool:
7070
if _check_block_grid_placement(self.block_grid, self.x - 1, self.y, grid=grid):
7171
return False
7272
self.x -= 1
73+
#print(f"* left ==> x={self.x}")
7374
self.sync_image()
7475
return True
7576

dumbdisplay_examples/tetris/tetris_two_block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ def moveBlockDown(self) -> bool:
277277
# return False
278278

279279
def moveBlockLeft(self) -> bool:
280+
#print("$ move left")
280281
if self.shape is None:
281282
self.startGame()
282283
return False

0 commit comments

Comments
 (0)