summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-14 01:34:15 +0300
committerDevaev Maxim <[email protected]>2020-09-14 01:34:23 +0300
commitee10435b818e0bf8ebf749a209969166502d78d4 (patch)
tree02db1948ed4a956d0cd2f6c5fd0b12d03804d3b2
parent91eb257f3df32487d00ca457f9d78eabd354ce54 (diff)
common gpio path variable
-rw-r--r--Makefile1
-rw-r--r--kvmd/aiogp.py7
-rw-r--r--kvmd/plugins/atx/gpio.py4
-rw-r--r--kvmd/plugins/hid/serial.py2
-rw-r--r--kvmd/plugins/msd/relay.py2
-rw-r--r--kvmd/plugins/ugpio/gpio.py4
6 files changed, 14 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index a134acac..e8467361 100644
--- a/Makefile
+++ b/Makefile
@@ -89,6 +89,7 @@ run: testenv $(TESTENV_GPIO)
--volume `pwd`/contrib/keymaps:/usr/share/kvmd/keymaps:ro \
--device $(TESTENV_VIDEO):$(TESTENV_VIDEO) \
--device $(TESTENV_GPIO):$(TESTENV_GPIO) \
+ --env KVMD_GPIO_DEVICE_PATH=$(TESTENV_GPIO) \
$(if $(TESTENV_RELAY),--device $(TESTENV_RELAY):$(TESTENV_RELAY),) \
--publish 8080:80/tcp \
-it $(TESTENV_IMAGE) /bin/bash -c " \
diff --git a/kvmd/aiogp.py b/kvmd/aiogp.py
index 100bcd4c..2f988e67 100644
--- a/kvmd/aiogp.py
+++ b/kvmd/aiogp.py
@@ -20,6 +20,7 @@
# ========================================================================== #
+import os
import asyncio
import threading
@@ -32,6 +33,12 @@ from . import aiotools
# =====
+# XXX: Do not use this variable for any purpose other than testing.
+# It can be removed at any time.
+DEVICE_PATH = os.getenv("KVMD_GPIO_DEVICE_PATH", "/dev/gpiochip0")
+
+
+# =====
async def pulse(line: gpiod.Line, delay: float, final: float) -> None:
try:
line.set_value(1)
diff --git a/kvmd/plugins/atx/gpio.py b/kvmd/plugins/atx/gpio.py
index 5ca611ef..851e4ab4 100644
--- a/kvmd/plugins/atx/gpio.py
+++ b/kvmd/plugins/atx/gpio.py
@@ -73,7 +73,7 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
self.__reset_switch_line: Optional[gpiod.Line] = None
self.__reader = aiogp.AioPinsReader(
- path="/dev/gpiochip0",
+ path=aiogp.DEVICE_PATH,
consumer="kvmd/atx-gpio/leds",
pins={
power_led_pin: power_led_inverted,
@@ -101,7 +101,7 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes
assert self.__power_switch_line is None
assert self.__reset_switch_line is None
- self.__chip = gpiod.Chip("/dev/gpiochip0")
+ self.__chip = gpiod.Chip(aiogp.DEVICE_PATH)
self.__power_switch_line = self.__chip.get_line(self.__power_switch_pin)
self.__power_switch_line.request("kvmd/atx-gpio/power_switch", gpiod.LINE_REQ_DIR_OUT, default_val=0)
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index 27218323..c07ea45c 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -170,7 +170,7 @@ class _Gpio:
if self.__reset_pin >= 0:
assert self.__chip is None
assert self.__reset_line is None
- self.__chip = gpiod.Chip("/dev/gpiochip0")
+ self.__chip = gpiod.Chip(aiogp.DEVICE_PATH)
self.__reset_line = self.__chip.get_line(self.__reset_pin)
self.__reset_line.request("kvmd/hid-serial/reset", gpiod.LINE_REQ_DIR_OUT, default_val=0)
diff --git a/kvmd/plugins/msd/relay.py b/kvmd/plugins/msd/relay.py
index 227dff46..cec03377 100644
--- a/kvmd/plugins/msd/relay.py
+++ b/kvmd/plugins/msd/relay.py
@@ -174,7 +174,7 @@ class _Gpio:
assert self.__target_line is None
assert self.__reset_line is None
- self.__chip = gpiod.Chip("/dev/gpiochip0")
+ self.__chip = gpiod.Chip(aiogp.DEVICE_PATH)
self.__target_line = self.__chip.get_line(self.__target_pin)
self.__target_line.request("kvmd/msd-relay/target", gpiod.LINE_REQ_DIR_OUT, default_val=0)
diff --git a/kvmd/plugins/ugpio/gpio.py b/kvmd/plugins/ugpio/gpio.py
index aa43caf1..16e0b516 100644
--- a/kvmd/plugins/ugpio/gpio.py
+++ b/kvmd/plugins/ugpio/gpio.py
@@ -59,13 +59,13 @@ class Plugin(BaseUserGpioDriver):
def prepare(self) -> None:
assert self.__reader is None
self.__reader = aiogp.AioPinsReader(
- path="/dev/gpiochip0",
+ path=aiogp.DEVICE_PATH,
consumer="kvmd/ugpio-gpio/inputs",
pins=dict.fromkeys(self.__input_pins, False),
notifier=self._notifier,
)
- self.__chip = gpiod.Chip("/dev/gpiochip0")
+ self.__chip = gpiod.Chip(aiogp.DEVICE_PATH)
for (pin, initial) in self.__output_pins.items():
line = self.__chip.get_line(pin)
line.request("kvmd/ugpio-gpio/outputs", gpiod.LINE_REQ_DIR_OUT, default_val=int(initial or False))