summaryrefslogtreecommitdiff
path: root/kvmd/plugins/ugpio
diff options
context:
space:
mode:
authorKenny Younger <[email protected]>2022-01-24 10:04:52 -0600
committerGitHub <[email protected]>2022-01-24 19:04:52 +0300
commita614be7d7687e755385886ac17686902c5d512a0 (patch)
tree9d4537c8f4da160f4c6440b7c4f999ca900f5363 /kvmd/plugins/ugpio
parent954ec769c62a6a24554bd6d3a8419bb1567db336 (diff)
PWAY plugin fix: Normalize pin/channel index to 0-based (#78)
* PWAY plugin fix: Normalize pin/channel index to 1-based * Normalize to 0-based instead
Diffstat (limited to 'kvmd/plugins/ugpio')
-rw-r--r--kvmd/plugins/ugpio/pway.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/kvmd/plugins/ugpio/pway.py b/kvmd/plugins/ugpio/pway.py
index 41d6f92b..3bd2a268 100644
--- a/kvmd/plugins/ugpio/pway.py
+++ b/kvmd/plugins/ugpio/pway.py
@@ -144,7 +144,7 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
# Switch and then recieve the state.
# FIXME: Get actual state without modifying the current.
# I'm lazy and like the idea of the KVM resetting to port 1 on reboot of the PiKVM.
- self.__send_channel(tty, 0)
+ self.__reset(tty)
while not self.__stop_event.is_set():
(channel, data) = self.__recv_channel(tty, data)
@@ -180,15 +180,17 @@ class Plugin(BaseUserGpioDriver): # pylint: disable=too-many-instance-attribute
def __send_channel(self, tty: serial.Serial, channel: int) -> None:
# Set a channel by sending PS [1-16]
+ # Note that the recv is 0-based index, while send is 1-based. We add 1 to the "channel" to
+ # normalize for the 1-based index on send
cmd = (b"PS")
- if channel == 0:
- # when it initializes this will push us to port 1 and set us back to defaults.
- tty.write(b"%s\r" % (cmd))
- tty.flush()
- else:
- # Basically send `PS [1-15]` that switches the port
- tty.write(b"%s %d\r" % (cmd, channel))
- tty.flush()
+ tty.write(b"%s %d\r" % (cmd, channel + 1))
+ tty.flush()
+
+ def __reset(self, tty: serial.Serial) -> None:
+ # Reset by sending PS without port number
+ cmd = (b"PS")
+ tty.write(b"%s\r" % (cmd))
+ tty.flush()
def __str__(self) -> str:
return f"PWAY({self._instance_name})"