Skip to content

Commit d90c637

Browse files
committed
Add support for continuous reporting
Log the contents of the indState message to the console Continuous reporting remains disabled by default and can be enabled by setting the AYAB_DEBUG environment variable
1 parent 6c62a69 commit d90c637

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/main/python/main/ayab/engine/control.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
from .pattern import Pattern
4040
from ..preferences import Preferences
4141

42+
import struct
43+
4244

4345
class Control(SignalSender):
4446
"""
@@ -168,11 +170,41 @@ def check_serial_API6(self) -> tuple[Token, int]:
168170
self.__log_cnfInfo(msg)
169171
elif token == Token.indState:
170172
self.status.parse_device_state_API6(param, msg)
173+
self.__log_indState(msg)
171174
elif token == Token.testRes:
172175
if len(msg) > 0:
173176
self.emit_hw_test_writer(msg[1:].decode())
174177
return token, param
175178

179+
def __log_indState(self, msg: bytes) -> None:
180+
directionMap = {0x00: "Left ", 0x01: "Right", 0xFF: "?"}
181+
machineSideMap = {0x00: "? ", 0x01: "Left", 2: "Right"}
182+
beltShiftMap = {0x00: "?", 0x01: "Regular", 0x02: "Shifted"}
183+
carriageMap = {0x00: "K", 0x01: "L", 0x02: "G", 0x03: "K270", 0xFF: "None"}
184+
185+
error = msg[1]
186+
state = msg[2]
187+
hallLeft = struct.unpack(">H", msg[3:5])[0]
188+
hallRight = struct.unpack(">H", msg[5:7])[0]
189+
carriage = carriageMap[msg[7]]
190+
position = msg[8]
191+
direction = directionMap[msg[9]]
192+
193+
try: # AyabAsync supplies additional parameters
194+
hallActive = machineSideMap[msg[10]]
195+
beltShift = beltShiftMap[msg[11]]
196+
self.logger.info(
197+
f"IndState: {error:1d} {state:1d} {position:3d}"
198+
f" {carriage:5s} ({beltShift:11s},{direction:5s})"
199+
f" Hall:{hallActive:5s} ({hallLeft:5d}, {hallRight:5d})"
200+
)
201+
except IndexError:
202+
self.logger.info(
203+
f"IndState: {error:1d} {state:1d} {position:3d}"
204+
f" {carriage:5s} ({direction:5s})"
205+
f" Hall:({hallLeft:5d}, {hallRight:5d})"
206+
)
207+
176208
def __log_cnfInfo(self, msg: bytes) -> None:
177209
api = msg[1]
178210
log = "API v" + str(api)

src/main/python/main/ayab/engine/engine_fsm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from .output import Output
3232
from typing import TYPE_CHECKING, Callable, Any
3333

34+
import os
3435
import time
3536

3637
if TYPE_CHECKING:
@@ -171,7 +172,7 @@ def _API6_request_start(control: Control, operation: Operation) -> Output:
171172
control.com.req_start_API6(
172173
control.pattern.knit_start_needle,
173174
control.pattern.knit_end_needle - 1,
174-
control.continuous_reporting,
175+
True if os.getenv("AYAB_DEBUG") else control.continuous_reporting,
175176
control.prefs.value("disable_hardware_beep"),
176177
)
177178
control.state = State.CONFIRM_START

0 commit comments

Comments
 (0)