From 8276c9cf82d62ac801e9f707d9267b36fc24205d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kundr=C3=A1t?= Date: Thu, 10 Aug 2023 19:52:05 +0200 Subject: [PATCH] tridonic: support sending 8-bit backward frames Bug: https://github.com/sde1000/python-dali/discussions/126 --- dali/driver/hid.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/dali/driver/hid.py b/dali/driver/hid.py index 37abb3a..4523012 100644 --- a/dali/driver/hid.py +++ b/dali/driver/hid.py @@ -404,6 +404,15 @@ async def _power_supply(self, supply_on): self.disconnect(reconnect=True) raise CommunicationError + @staticmethod + def _command_mode(frame): + if len(frame) == 8: + return tridonic._SEND_MODE_DALI8 + if len(frame) == 16: + return tridonic._SEND_MODE_DALI16 + if len(frame) == 24: + return tridonic._SEND_MODE_DALI24 + raise UnsupportedFrameTypeError async def _send_raw(self, command): frame = command.frame @@ -423,8 +432,7 @@ async def _send_raw(self, command): data = self._cmd( self._CMD_SEND, seq, ctrl=self._SEND_CTRL_SENDTWICE if command.sendtwice else 0, - mode=self._SEND_MODE_DALI16 if len(frame) == 16 - else self._SEND_MODE_DALI24, + mode=self._command_mode(frame), frame=frame.pack_len(4)) try: os.write(self._f, data)