summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-06-28 06:03:51 +0300
committerDevaev Maxim <[email protected]>2018-06-28 06:03:51 +0300
commitcac56cd92f91c631ccf1f58d459e9c203e611de2 (patch)
tree1aed120aab088021faac24f375040afedcf04214 /kvmd
parent0a3ab57639c403fc50eacdc0bb9ad59ee5942c58 (diff)
cleanup script and refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/kvmd/atx.py8
-rw-r--r--kvmd/kvmd/extra/cleanup/__init__.py23
-rw-r--r--kvmd/kvmd/extra/cleanup/__main__.py2
-rw-r--r--kvmd/kvmd/extra/wscli/__init__.py (renamed from kvmd/kvmd/extra/wscli.py)4
-rw-r--r--kvmd/kvmd/extra/wscli/__main__.py2
5 files changed, 33 insertions, 6 deletions
diff --git a/kvmd/kvmd/atx.py b/kvmd/kvmd/atx.py
index ff596a87..a3d07fc4 100644
--- a/kvmd/kvmd/atx.py
+++ b/kvmd/kvmd/atx.py
@@ -21,8 +21,8 @@ class Atx:
long_click_delay: float,
) -> None:
- self.__power_led = self.__set_output_pin(power_led)
- self.__hdd_led = self.__set_output_pin(hdd_led)
+ self.__power_led = self.__set_input_pin(power_led)
+ self.__hdd_led = self.__set_input_pin(hdd_led)
self.__power_switch = self.__set_output_pin(power_switch)
self.__reset_switch = self.__set_output_pin(reset_switch)
@@ -31,6 +31,10 @@ class Atx:
self.__lock = asyncio.Lock()
+ def __set_input_pin(self, pin: int) -> int:
+ GPIO.setup(pin, GPIO.IN)
+ return pin
+
def __set_output_pin(self, pin: int) -> int:
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin, False)
diff --git a/kvmd/kvmd/extra/cleanup/__init__.py b/kvmd/kvmd/extra/cleanup/__init__.py
new file mode 100644
index 00000000..d8ae866c
--- /dev/null
+++ b/kvmd/kvmd/extra/cleanup/__init__.py
@@ -0,0 +1,23 @@
+import logging
+
+from RPi import GPIO
+
+from ...application import init
+
+
+# =====
+_logger = logging.getLogger(__name__)
+
+
+def main() -> None:
+ config = init()
+ _logger.info("Cleaning up ...")
+ GPIO.setmode(GPIO.BCM)
+ for (key, pin) in [
+ *config["atx"]["switches"]["pinout"].items(),
+ *config["video"]["pinout"].items(),
+ ]:
+ _logger.info("Writing value=0 to pin=%d (%s)", pin, key)
+ GPIO.output(pin, False)
+ GPIO.cleanup()
+ _logger.info("Done!")
diff --git a/kvmd/kvmd/extra/cleanup/__main__.py b/kvmd/kvmd/extra/cleanup/__main__.py
new file mode 100644
index 00000000..031df43e
--- /dev/null
+++ b/kvmd/kvmd/extra/cleanup/__main__.py
@@ -0,0 +1,2 @@
+from . import main
+main()
diff --git a/kvmd/kvmd/extra/wscli.py b/kvmd/kvmd/extra/wscli/__init__.py
index f4b261a7..3812871d 100644
--- a/kvmd/kvmd/extra/wscli.py
+++ b/kvmd/kvmd/extra/wscli/__init__.py
@@ -47,7 +47,3 @@ def main() -> None:
loop.add_signal_handler(signal.SIGINT, loop.stop)
loop.create_task(_run_client(loop, options.url))
loop.run_forever()
-
-
-if __name__ == "__main__":
- main()
diff --git a/kvmd/kvmd/extra/wscli/__main__.py b/kvmd/kvmd/extra/wscli/__main__.py
new file mode 100644
index 00000000..031df43e
--- /dev/null
+++ b/kvmd/kvmd/extra/wscli/__main__.py
@@ -0,0 +1,2 @@
+from . import main
+main()