Skip to content

Commit

Permalink
Add canceled state to engine FSM
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mpr1c3 committed Mar 9, 2024
1 parent 517fdf4 commit d2e24be
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/main/python/ayab/engine/communication_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ def req_start_API6(self, start_needle, stop_needle,
cnfStart = bytes([Token.cnfStart.value, 0])
self.rx_msg_list.append(cnfStart)

def quit_API6(self):
"""Send a quit message to the device."""
cnfQuit = bytes([Token.quitCmd.value, 0])
self.rx_msg_list.append(cnfQuit)

def cnf_line_API6(self, line_number, color, flags, line_data) -> bool:
"""Send a row of stitch data."""
return True
Expand Down
11 changes: 7 additions & 4 deletions src/main/python/ayab/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,25 @@ def run(self, operation):
if self.__canceled or self.control.state == State.FINISHED:
break

self.control.stop()

# TODO: provide translations for these messages
if operation == Operation.KNIT:
if self.__canceled:
self.control.state = State.CANCELED
self.emit_notification("Knitting canceled.")
self.__logger.info("Knitting canceled.")
self.control.operate(operation)
else:
# operation == Operation.TEST:
self.__logger.info("Finished knitting.")
# small delay to finish printing to knit progress window
# before "finish.wav" sound plays
sleep(1)
else:
# TODO: provide translations for these messages
# operation == Operation.TEST:
self.__logger.info("Finished testing.")

# stop serial communication
self.control.stop()

# send signal to finish operation
# "finish.wav" sound only plays if knitting was not canceled
self.emit_operation_finisher(operation, not self.__canceled)
Expand Down
7 changes: 7 additions & 0 deletions src/main/python/ayab/engine/engine_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class State(Enum):
REQUEST_TEST = auto()
CONFIRM_TEST = auto()
RUN_TEST = auto()
CANCELED = auto()
FINISHED = auto()


Expand Down Expand Up @@ -220,6 +221,12 @@ def _API6_run_test(control, operation):
control.logger.debug("Token " + token.name + ", param " + str(param))
return Output.NONE

def _API6_canceled(control, operation):
control.logger.debug("State CANCELED")
control.com.quit_API6()
control.state = State.FINISHED
return Output.NONE

def _API6_finished(control, operation):
control.logger.debug("State FINISHED")
try:
Expand Down
5 changes: 2 additions & 3 deletions src/main/python/ayab/hw_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ def output(self, msg):
def hideEvent(self, event):
self.__timer.stop()
self.__console.setPlainText("")
self.__control.state == State.FINISHED
self.__control.state = State.FINISHED
self.accept()

def reject(self):
# send quitCmd
# cancel operation
self.__control.com.quit_API6()
self.__control.state = State.FINISHED
# reset dialog
self._auto_button.setChecked(False)
self._test_button.setChecked(False)
Expand Down

0 comments on commit d2e24be

Please sign in to comment.