rpideck 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
rpideck/__about__.py ADDED
@@ -0,0 +1,4 @@
1
+ # SPDX-FileCopyrightText: 2025-present Daniel Skowroński <daniel@skowron.ski>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ __version__ = "0.1.0"
rpideck/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: Daniel Skowroński <daniel@skowron.ski>
2
+ #
3
+ # SPDX-License-Identifier: MIT
rpideck/__main__.py ADDED
@@ -0,0 +1,9 @@
1
+ # SPDX-FileCopyrightText: Daniel Skowroński <daniel@skowron.ski>
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ import sys
5
+
6
+ if __name__ == "__main__":
7
+ from rpideck.cli import rpideck
8
+
9
+ sys.exit(rpideck())
rpideck/cli/AVR.py ADDED
@@ -0,0 +1,14 @@
1
+ # SPDX-FileCopyrightText: 2025-present Daniel Skowroński <daniel@skowron.ski>
2
+ # base on https://github.com/abcminiuser/python-elgato-streamdeck/blob/master/src/example_neo.py by abcminiuser
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+ import eiscp
6
+
7
+
8
+ class AVR:
9
+ def __init__(self, ip):
10
+ self.ip = ip
11
+
12
+ def cmd(self, cmd, value):
13
+ with eiscp.eISCP(self.ip) as receiver:
14
+ receiver.command(f"{cmd} {value}")
rpideck/cli/DDC.py ADDED
@@ -0,0 +1,42 @@
1
+ # SPDX-FileCopyrightText: 2025-present Daniel Skowroński <daniel@skowron.ski>
2
+ # base on https://github.com/abcminiuser/python-elgato-streamdeck/blob/master/src/example_neo.py by abcminiuser
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+ import subprocess
6
+
7
+
8
+ class DDCLinux:
9
+ def readVCP(self, vcp):
10
+ current = subprocess.run(
11
+ ["/usr/bin/ddcutil", "getvcp", "--brief", "0x{:02X}".format(vcp)],
12
+ capture_output=True,
13
+ text=True,
14
+ )
15
+ if current.returncode != 0:
16
+ logger.warn(f"getvcp for {vcp} exited with {current.returncode}")
17
+ return None
18
+ current_out = str(current.stdout).split("\n")[0].split(" ")
19
+ current_value = int(f"0{current_out[3]}", 16) # FIXME: multibyte values
20
+ return current_value
21
+
22
+ def setVCP(self, vcp, new_value, force=False):
23
+ if not force:
24
+ current_value = self.readVCP(vcp)
25
+ if current_value is None:
26
+ return
27
+ if current_value == new_value:
28
+ return
29
+ action = subprocess.run(
30
+ [
31
+ "/usr/bin/ddcutil",
32
+ "setvcp",
33
+ "--sleep-multiplier",
34
+ "10",
35
+ "--brief",
36
+ "0x{:02X}".format(vcp),
37
+ "0x{:02X}".format(new_value),
38
+ ],
39
+ capture_output=True,
40
+ text=True,
41
+ )
42
+ # logger.info(action)
rpideck/cli/RPiDeck.py ADDED
@@ -0,0 +1,193 @@
1
+ # SPDX-FileCopyrightText: 2025-present Daniel Skowroński <daniel@skowron.ski>
2
+ # base on https://github.com/abcminiuser/python-elgato-streamdeck/blob/master/src/example_neo.py by abcminiuser
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+ from PIL import Image, ImageDraw, ImageFont
6
+ from StreamDeck.DeviceManager import DeviceManager
7
+ from StreamDeck.ImageHelpers import PILHelper
8
+
9
+ from threading import Thread, Lock
10
+ import sched
11
+ import time
12
+ import datetime
13
+ import sys
14
+ import signal
15
+ from functools import partial
16
+ import traceback
17
+
18
+ import logging
19
+
20
+ from rpideck.cli.RPiDeckConfig import RPiDeckConfig
21
+ from rpideck.cli.DDC import DDCLinux
22
+ from rpideck.cli.AVR import AVR
23
+
24
+
25
+ class RPiDeck:
26
+ def __init__(self, config_path="~/.config/rpideck", logger_name=__name__):
27
+ self.logger = logging.getLogger(logger_name)
28
+ print(logger_name)
29
+ self.config = RPiDeckConfig(config_path, logger_name)
30
+ self.display_lock = Lock()
31
+ self.deck = None
32
+ self.page = 0
33
+ self.ddcController = DDCLinux()
34
+ self.avrController = AVR(self.config.avr["ip"])
35
+ sys.excepthook = self.exceptionHandler
36
+ self.clock_scheduler = sched.scheduler(time.time, time.sleep)
37
+
38
+ def openDeck(self, matchSerial=""):
39
+ streamdecks = DeviceManager().enumerate()
40
+ signal.signal(signal.SIGINT, partial(self.sigintHandler))
41
+ for deck in streamdecks:
42
+ deck.open()
43
+ self.logger.debug(deck.get_serial_number())
44
+ if matchSerial in deck.get_serial_number():
45
+ self.deck = deck
46
+ deck.close()
47
+ if self.deck is None:
48
+ raise Exception(f"didn't find working deck matching {matchSerial}")
49
+ self.deck.open()
50
+ self.logger.info(
51
+ "Opened '{}' device (serial number: '{}', fw: '{}')".format(
52
+ self.deck.deck_type(),
53
+ self.deck.get_serial_number(),
54
+ self.deck.get_firmware_version(),
55
+ )
56
+ ) # FIXME
57
+
58
+ def initializeDeck(self):
59
+ self.deck.reset()
60
+ self.deck.set_poll_frequency(100)
61
+ self.deck.set_brightness(self.config.deck["brightness"])
62
+ self.loadPage(0)
63
+ self.deck.set_key_callback(self.keyChangeCallback)
64
+ self.updateScreenText("RPiDeck started")
65
+ self.clock_scheduler.enter(0.25, 1, self.updateClock)
66
+ self.clock_scheduler.run()
67
+
68
+ def loadPage(self, page=0):
69
+ self.page = page
70
+ for key in range(self.deck.key_count()):
71
+ self.updateKeyImage(key, page, False)
72
+
73
+ def updateKeyImage(self, position, isPressedDown, page, background="black"):
74
+ try:
75
+ keyInfo = self.config.getKeyInfo(position, self.page, isPressedDown)
76
+ keyImage = self.renderKeyImage(
77
+ keyInfo["icon"], keyInfo["font"], keyInfo["label"], background
78
+ )
79
+ with self.deck:
80
+ self.deck.set_key_image(position, keyImage)
81
+ except Exception:
82
+ with self.deck:
83
+ self.deck.set_key_color(position, 0, 0, 0)
84
+
85
+ def renderKeyImage(
86
+ self, icon_filename, font_filename, label_text, background="black"
87
+ ):
88
+ icon = Image.open(icon_filename)
89
+ image = PILHelper.create_scaled_key_image(
90
+ self.deck, icon, margins=[0, 0, 20, 0], background=background
91
+ )
92
+ draw = ImageDraw.Draw(image)
93
+ font = ImageFont.truetype(font_filename, 14)
94
+ draw.text(
95
+ (image.width / 2, image.height - 5),
96
+ text=label_text,
97
+ font=font,
98
+ anchor="ms",
99
+ fill="white",
100
+ )
101
+ return PILHelper.to_native_key_format(self.deck, image)
102
+
103
+ def updateScreenText(self, text):
104
+ screenImage = self.renderScreenImage(text, self.config.getFont())
105
+ with self.deck:
106
+ self.deck.set_screen_image(screenImage)
107
+
108
+ def renderScreenImage(self, text, font_filename):
109
+ image = PILHelper.create_screen_image(self.deck)
110
+ draw = ImageDraw.Draw(image)
111
+ font = ImageFont.truetype(font_filename, 22)
112
+ draw.text(
113
+ (image.width / 2, image.height - 25),
114
+ text=text,
115
+ font=font,
116
+ anchor="ms",
117
+ fill="white",
118
+ )
119
+ return PILHelper.to_native_screen_format(self.deck, image)
120
+
121
+ def executeKeyAction(self, position, page):
122
+ pass
123
+ # TODO: implement logic separation from keyChangeCallback
124
+
125
+ def keyChangeCallback(self, deck, position, isPressedDown):
126
+ if position >= self.config.BUTTONS:
127
+ if isPressedDown:
128
+ delta = 0
129
+ if position == self.config.BUTTONS:
130
+ self.logger.info(f"Key {position} pressed => calling page:previous")
131
+ delta = -1
132
+ if position == self.config.BUTTONS + 1:
133
+ self.logger.info(f"Key {position} pressed => calling page:next")
134
+ delta = +1
135
+ self.page = (self.page + delta) % self.getPageCount()
136
+ self.loadPage(self.page)
137
+ else:
138
+ self.logger.info(f"Key {position} pressed up")
139
+ else:
140
+ keyInfo = self.config.getKeyInfo(position, self.page, isPressedDown)
141
+ actionInfo = f"down => calling {keyInfo['name']}" if isPressedDown else "up"
142
+ self.logger.info(f"Key {position} on page {self.page} pressed {actionInfo}")
143
+
144
+ if isPressedDown:
145
+ with self.deck:
146
+ self.updateKeyImage(
147
+ position,
148
+ isPressedDown,
149
+ self.page,
150
+ background=self.config.deck["highlightColour"],
151
+ )
152
+ with self.display_lock:
153
+ for step in keyInfo["steps"]:
154
+ self.updateScreenText(step["text"])
155
+ params = step["parameters"]
156
+ if step["type"] == "ddc":
157
+ self.ddcController.setVCP(
158
+ params["vcp"],
159
+ params["value"],
160
+ params.get("force", False),
161
+ )
162
+ elif step["type"] == "eiscp":
163
+ self.avrController.cmd(params["cmd"], params["value"])
164
+ self.updateScreenText("callback finished")
165
+ self.updateKeyImage(position, isPressedDown, self.page)
166
+
167
+ def getPageCount(self):
168
+ return len(self.config.deck["pages"])
169
+
170
+ def updateClock(self):
171
+ now = datetime.datetime.now()
172
+ if self.getPageCount() == 1:
173
+ text = "{:04d}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}".format(
174
+ now.year, now.month, now.day, now.hour, now.minute, now.second
175
+ )
176
+ else:
177
+ text = "page {:01d}/{:01d} | {:02d}:{:02d}:{:02d}".format(
178
+ self.page + 1, self.getPageCount(), now.hour, now.minute, now.second
179
+ )
180
+ with self.display_lock:
181
+ self.updateScreenText(text)
182
+ self.clock_scheduler.enter(0.25, 1, self.updateClock)
183
+
184
+ def exceptionHandler(self, exctype, value, tb):
185
+ self.logger.exception("".join(traceback.format_exception(exctype, value, tb)))
186
+ self.logger.exception("Uncaught exception: {0}".format(str(value)))
187
+
188
+ def sigintHandler(self, sig, frame):
189
+ self.logger.info("SIGINT")
190
+ with self.deck:
191
+ self.deck.reset()
192
+ self.deck.close()
193
+ sys.exit(0)
@@ -0,0 +1,108 @@
1
+ # SPDX-FileCopyrightText: 2025-present Daniel Skowroński <daniel@skowron.ski>
2
+ # base on https://github.com/abcminiuser/python-elgato-streamdeck/blob/master/src/example_neo.py by abcminiuser
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+ from schema import Schema, And, Or, Use, Optional, SchemaError
6
+ import yaml
7
+ import io
8
+ import os
9
+ import logging
10
+
11
+
12
+ class RPiDeckConfig:
13
+ BUTTONS = 8
14
+
15
+ def _build_schema(self):
16
+ PARAMETERS_DDC = Schema(
17
+ {
18
+ "vcp": lambda n: 0x00 <= n <= 0xFF,
19
+ "value": lambda n: 0x00 <= n <= 0xFFFF,
20
+ Optional("force"): bool,
21
+ }
22
+ )
23
+ PARAMETERS_EISCP = Schema(
24
+ {
25
+ "cmd": str,
26
+ "value": str,
27
+ }
28
+ )
29
+
30
+ def validate_step(step):
31
+ base_schema = Schema(
32
+ {
33
+ "text": str,
34
+ "type": And(str, lambda t: t in ["ddc", "eiscp"]),
35
+ "parameters": dict,
36
+ }
37
+ )
38
+ base_schema.validate(step)
39
+
40
+ if step["type"] == "ddc":
41
+ PARAMETERS_DDC.validate(step["parameters"])
42
+ elif step["type"] == "eiscp":
43
+ PARAMETERS_EISCP.validate(step["parameters"])
44
+ return step
45
+
46
+ KEY_SCHEMA = Schema(
47
+ {
48
+ "position": lambda n: 0 <= n <= self.BUTTONS,
49
+ "icon": str,
50
+ "label": str,
51
+ "steps": [validate_step],
52
+ }
53
+ )
54
+ PAGE_SCHEMA = Schema({"keys": {str: KEY_SCHEMA}})
55
+ return Schema(
56
+ {
57
+ "ddc": object,
58
+ "avr": {
59
+ "ip": str,
60
+ },
61
+ "deck": {
62
+ "brightness": lambda n: 0 <= n <= 100,
63
+ "matchSerial": str,
64
+ "font": str,
65
+ "highlightColour": str,
66
+ "pages": [PAGE_SCHEMA],
67
+ },
68
+ }
69
+ )
70
+
71
+ def __init__(self, path, logger_name=__name__):
72
+ logger = logging.getLogger(logger_name)
73
+ cfg_path = os.path.join(os.path.expanduser(path), "rpideck.yml")
74
+ self.assets_path = os.path.join(os.path.expanduser(path), "assets")
75
+
76
+ with open(cfg_path) as stream:
77
+ self.raw_config = yaml.safe_load(stream)
78
+
79
+ self.schema = self._build_schema()
80
+ validated = self.schema.validate(self.raw_config)
81
+ self.ddc = validated["ddc"]
82
+ self.avr = validated["avr"]
83
+ self.deck = validated["deck"]
84
+
85
+ def getKeyInfo(self, position, page=0, isPresssedDown=False):
86
+ key_name = None
87
+ key_cfg = None
88
+ page = self.deck["pages"][page]
89
+ if page is None:
90
+ raise Exception(f"no such page {page}")
91
+ for k, v in page["keys"].items():
92
+ if v["position"] == position:
93
+ key_name = k
94
+ key_cfg = v
95
+ break
96
+ if key_cfg is None:
97
+ raise Exception(f"no such key position {position} on page {page}")
98
+
99
+ return {
100
+ "name": key_name,
101
+ "icon": os.path.join(self.assets_path, key_cfg["icon"]),
102
+ "font": self.getFont(),
103
+ "label": key_cfg["label"],
104
+ "steps": key_cfg["steps"],
105
+ }
106
+
107
+ def getFont(self):
108
+ return os.path.join(self.assets_path, self.deck["font"])
@@ -0,0 +1,38 @@
1
+ # SPDX-FileCopyrightText: 2025-present Daniel Skowroński <daniel@skowron.ski>
2
+ # base on https://github.com/abcminiuser/python-elgato-streamdeck/blob/master/src/example_neo.py by abcminiuser
3
+ #
4
+ # SPDX-License-Identifier: MIT
5
+ import click
6
+ import threading
7
+ import logging
8
+ import coloredlogs
9
+ from StreamDeck.Transport.Transport import TransportError
10
+ from rpideck.__about__ import __version__
11
+ from rpideck.cli.RPiDeck import RPiDeck
12
+
13
+
14
+ @click.group(
15
+ context_settings={"help_option_names": ["-h", "--help"]},
16
+ invoke_without_command=True,
17
+ )
18
+ @click.version_option(version=__version__, prog_name="rpideck")
19
+ def rpideck():
20
+ logger = logging.getLogger(__name__)
21
+ logging.basicConfig(
22
+ format="%(asctime)s %(levelname)-8s %(message)s",
23
+ level=logging.INFO,
24
+ datefmt="%Y-%m-%d %H:%M:%S",
25
+ handlers=[logging.FileHandler("debug.log", mode="a"), logging.StreamHandler()],
26
+ )
27
+ coloredlogs.install()
28
+
29
+ rd = RPiDeck(
30
+ "~/.config/rpideck"
31
+ ) # FIXME: paramatrize this and split to config and assets path
32
+ rd.openDeck()
33
+ rd.initializeDeck()
34
+ for t in threading.enumerate():
35
+ try:
36
+ t.join()
37
+ except (TransportError, RuntimeError):
38
+ pass
@@ -0,0 +1,49 @@
1
+ Metadata-Version: 2.4
2
+ Name: rpideck
3
+ Version: 0.1.0
4
+ Project-URL: Documentation, https://github.com/danielskowronski/RPiDeck
5
+ Project-URL: Issues, https://github.com/danielskowronski/RPiDeck/issues
6
+ Project-URL: Source, https://github.com/danielskowronski/RPiDeck
7
+ Author-email: Daniel Skowroński <daniel@skowron.ski>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Programming Language :: Python
12
+ Classifier: Programming Language :: Python :: 3.8
13
+ Classifier: Programming Language :: Python :: 3.9
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: Implementation :: CPython
18
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
19
+ Requires-Python: >=3.8
20
+ Requires-Dist: click~=8.1.8
21
+ Requires-Dist: coloredlogs~=15.0.1
22
+ Requires-Dist: onkyo-eiscp~=1.2.7
23
+ Requires-Dist: pillow~=11.1.0
24
+ Requires-Dist: pyyaml~=6.0.2
25
+ Requires-Dist: schema~=0.7.7
26
+ Requires-Dist: streamdeck~=0.9.6
27
+ Description-Content-Type: text/markdown
28
+
29
+ # RPiDeck
30
+
31
+ ***At this stage, this is a personal project, so many things may be hardcoded***
32
+
33
+ Python agent enabling Elgato StreamDeck Neo connected to Raspberry Pi 5 running headless (server) system to control various devices including:
34
+
35
+ - Dell monitor over spare HDMI using MCCS over DDC - inputs, KVM, PBP modes
36
+ - Pioneer (Onkyo) AVR - HDMI matrix, audio amplifier source
37
+
38
+ Future devices to be supported:
39
+
40
+ - anything from Home Assistant
41
+ - multimedia devices connected to AVR using HDMI-CEC
42
+
43
+ [ENV.md](./ENV.md) contains critical information about the environment where this project can be installed.
44
+
45
+ ## CLI usage
46
+
47
+ Config and assets must be placed under `~/.config/rpideck`. See examples in [example_config](./example_config/).
48
+
49
+ For now, just run `rpideck` and it'll start main loop. Buttons on last row (next to screen) act as page selectors.
@@ -0,0 +1,13 @@
1
+ rpideck/__about__.py,sha256=dX_VI_STbZ1nO9TfKBULQX3rsBEYQDyfcYuE8unVZi4,134
2
+ rpideck/__init__.py,sha256=J6u1uVlzjtQvDZoxKKRSPc-cPgglStUCY_aJ9e2OoeA,99
3
+ rpideck/__main__.py,sha256=mAA08RvLrmZyd1lb-cLXtW6zfRZov-MK-BR9QUuLBvI,199
4
+ rpideck/cli/AVR.py,sha256=H_Ke8S2hIPK3aYqsb9UT6F0TGzFN_SbhvWZQhcWfrbg,425
5
+ rpideck/cli/DDC.py,sha256=jMKdRhKhc2UA47tQTGJt29JFUhLnMD2dQbsMhYRdShc,1423
6
+ rpideck/cli/RPiDeck.py,sha256=qS8FB4Ztfj8ZIWTBvJWM58fStdQPmXSTmqlbqj-gAhs,7579
7
+ rpideck/cli/RPiDeckConfig.py,sha256=8_-C5hZTNsMQqziB40iROZrpg07jRK9LzEhBecB0wPo,3389
8
+ rpideck/cli/__init__.py,sha256=TLMrumlu_AqVh1IIiZyDcW5XcszhTCCTs3ke1rVdFaA,1221
9
+ rpideck-0.1.0.dist-info/METADATA,sha256=9WmMq2vkPPO0i4pu8eMFTLInJ0v4nHZQcLZxYKswbfQ,1966
10
+ rpideck-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
11
+ rpideck-0.1.0.dist-info/entry_points.txt,sha256=MXSieDLyZ6iC1SzK4SbPUR_ilGvKHzZttt9NHLJCQl8,48
12
+ rpideck-0.1.0.dist-info/licenses/LICENSE,sha256=v_37-NuZKbIMflg4UEyOe47AMvMQkZqBSdDw0BDxDMM,1492
13
+ rpideck-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ rpideck = rpideck.cli:rpideck
@@ -0,0 +1,19 @@
1
+ Copyright 2025 Daniel Skowroński <daniel@skowron.ski>
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
4
+ are met:
5
+
6
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in
9
+ the documentation and/or other materials provided with the distribution.
10
+
11
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from
12
+ this software without specific prior written permission.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
16
+ COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
19
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.