Skip to content

Commit

Permalink
configurable hardware beep (#576)
Browse files Browse the repository at this point in the history
* configurable hardware beep

* fix engine_fsm.py

* fix control.py
  • Loading branch information
t0mpr1c3 authored Oct 17, 2023
1 parent df1111e commit c31efa5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/main/python/ayab/engine/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,15 @@ def req_test_API6(self):
self.__ser.write(data)

def req_start_API6(self, start_needle, stop_needle,
continuous_reporting):
continuous_reporting, disable_hardware_beep):
"""Send a start message to the device."""
data = bytearray()
data.append(Token.reqStart.value)
data.append(start_needle)
data.append(stop_needle)
data.append(continuous_reporting)
data.append(
1 * continuous_reporting +
2 * (not disable_hardware_beep))
hash = 0
hash = add_crc(hash, data)
data.append(hash)
Expand Down
2 changes: 1 addition & 1 deletion src/main/python/ayab/engine/communication_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def req_test_API6(self) -> None:
self.rx_msg_list.append(cnfTest)

def req_start_API6(self, start_needle, stop_needle,
continuous_reporting) -> None:
continuous_reporting, disable_hardware_beep) -> None:
"""Send a request to start knitting."""
self.__is_started = True
cnfStart = bytes([Token.cnfStart.value, 0])
Expand Down
1 change: 1 addition & 0 deletions src/main/python/ayab/engine/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def start(self, pattern, options, operation):
self.mode = options.mode
self.inf_repeat = options.inf_repeat
self.continuous_reporting = options.continuous_reporting
self.prefs = options.prefs
self.len_pat_expanded = self.pat_height * self.num_colors
self.passes_per_row = self.mode.row_multiplier(self.num_colors)
self.start_needle = max(0, self.pattern.pat_start_needle)
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/ayab/engine/engine_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ def _API6_request_start(control, operation):
# request start
control.com.req_start_API6(control.pattern.knit_start_needle,
control.pattern.knit_end_needle - 1,
control.continuous_reporting)
control.continuous_reporting,
control.prefs.value("disable_hardware_beep"))
control.state = State.CONFIRM_START
control.logger.debug("State CONFIRM_START")
else:
Expand Down
1 change: 1 addition & 0 deletions src/main/python/ayab/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Preferences(SignalSender):
'default_knit_side_image': bool,
# 'default_continuous_reporting': bool,
'quiet_mode': bool,
'disable_hardware_beep': bool,
'language': Language,
}

Expand Down
13 changes: 9 additions & 4 deletions src/main/python/ayab/tests/test_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,17 @@ def test_update_API6(self):
assert result == expected_result

def test_req_start_API6(self):
start_val, end_val, continuous_reporting, crc8 = 0, 10, True, 0x36
start_val, end_val, continuous_reporting, disable_hardware_beep, crc8 = 0, 10, True, False, 0x8A
self.comm_dummy.req_start_API6(start_val, end_val,
continuous_reporting)
continuous_reporting,
disable_hardware_beep)
byte_array = bytearray([
Token.slipFrameEnd.value, Token.reqStart.value,
start_val, end_val, continuous_reporting, crc8,
Token.slipFrameEnd.value,
Token.reqStart.value,
start_val,
end_val,
1 * continuous_reporting + 2 * (not disable_hardware_beep),
crc8,
Token.slipFrameEnd.value
])
bytes_read = self.dummy_serial.read(len(byte_array))
Expand Down
10 changes: 6 additions & 4 deletions src/main/python/ayab/tests/test_communication_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ def test_update_API6(self):
assert self.comm_dummy.update_API6() == (None, Token.none, 0)

def test_req_start_API6(self):
start_val, end_val, continuous_reporting, crc8 = 0, 10, True, 0xb9
start_val, end_val, continuous_reporting, disable_hardware_beep = 0, 10, True, False
expected_result = (bytes([Token.cnfStart.value, 0]), Token.cnfStart, 0)
self.comm_dummy.req_start_API6(start_val, end_val,
continuous_reporting)
continuous_reporting,
disable_hardware_beep)
bytes_read = self.comm_dummy.update_API6()
assert bytes_read == expected_result

Expand Down Expand Up @@ -86,9 +87,10 @@ def test_cnf_line_API6(self):

def test_req_line_API6(self):
self.comm_dummy.open_serial()
start_val, end_val, continuous_reporting = 0, 10, True
start_val, end_val, continuous_reporting, disable_hardware_beep = 0, 10, True, False
self.comm_dummy.req_start_API6(start_val, end_val,
continuous_reporting)
continuous_reporting,
disable_hardware_beep)
self.comm_dummy.update_API6() # cnfStart

for i in range(0, 256):
Expand Down

0 comments on commit c31efa5

Please sign in to comment.