rpideck 0.1.0__tar.gz

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-0.1.0/ENV.md ADDED
@@ -0,0 +1,77 @@
1
+ # Environment
2
+
3
+ ## Platforms supported
4
+
5
+ ### Operating system
6
+
7
+ There are two non-directly-portable components used: USB and MCCS over DDC.
8
+
9
+ USB should work everywhere LibUSB and HIDAPI are supported, which includes Linux, macOS (Intel and ARM) and Windows. On the software level, DDC works best on Linux with excellent [ddcutil](https://www.ddcutil.com), it seems to work on Windows, and it's a nightmare on non-Intel macOS. macOS supports DDC properly, but no one made a competent ddcutil compatible (providing at least raw read-write to any VCP including multibyte values) utility yet.
10
+
11
+ ### Hardware
12
+
13
+ While any regular x86 PC with HDMI/DisplayPort and USB should work, I've chosen to run it on an external single-board computer connected to a monitor using a spare HDMI input. The main reason for that is the ability to leave such a small computer always on and make it wake up actual workstations (saving power, bypassing downtimes, not having to decide which workstation in KVM controls the device etc.)
14
+
15
+ Selected SBC must support both fast and modern USB host controller and proper DDC support in HDMI.
16
+
17
+ #### USB Host
18
+
19
+ Some USB hosts like DWC2 found in Raspberry Pi 3B or Zero 2W can't handle Stream Decks, despite tweaks applied. That host was cheap and widely used in Raspberry Pi clones. While it's not about the speed, it seems like the easiest way to determine whether DWC2 is *not* used is to look for an SBC with a USB 3.0 port.
20
+
21
+ While Stream Deck will technically work with a bad USB host for a while, it'll quickly crash a device, and you'll need to manually reconnect it. Some more context can be found [here](https://github.com/abcminiuser/python-elgato-streamdeck/issues/154).
22
+
23
+ There's no way to confirm that DWC2 is the only problematic USB host, but I'd run miles away from any platform which does not adhere to full interface speeds (things like 300Mbps on "Gigabit Ethernet").
24
+
25
+ #### DDC support
26
+
27
+ DDC is actually I2C added to various video connectors like HDMI, DisplayPort and even VGA. This means it must be properly exposed as an I2C bus to software. Moreover, an I2C controller onboard handling HDMI must support multibyte operations. Some controllers like DesignWare HDMI can't do that - while most basic MCCS operations should work on single-byte writes, the kernel driver just blacklists DDC over DesignWare HDMI completely (see [this discussion](https://github.com/rockowitz/ddcutil/issues/306) and [kernel patch](https://patchwork.kernel.org/project/dri-devel/patch/20190722181945.244395-1-mka@chromium.org/#22771979)).
28
+
29
+ It seems to be the case that most of Rockchip and Amlogic chipsets come withe DesignWare HDMI and thus are incompatible. Some boards may be able to bypass that by using a main I2C controller for GPIO, like [reported for Pine64](https://forum.pine64.org/showthread.php?tid=19462). That said, it looks like the safest options for DDC supporting SoCs are Allwiner and Broadcom.
30
+
31
+ #### Compatible boards
32
+
33
+ *Fun fact: both DWC and DesignWare HDMI are products of Synopsys*
34
+
35
+ Confirmed personally:
36
+
37
+ - Raspberry Pi 5
38
+
39
+ Should work:
40
+
41
+ - Raspberry Pi 4
42
+
43
+ Confirmed not to work:
44
+
45
+ - Raspberry Pi 3B (USB)
46
+ - Orange Pi 3B (DDC)
47
+ - Orange Pi 5+ (DDC)
48
+
49
+ ## Installation on Raspberry Pi 5
50
+
51
+ Sources:
52
+
53
+ - https://www.ddcutil.com/config_steps/
54
+ - https://www.ddcutil.com/raspberry/#raspberry-pi-4
55
+ - https://python-elgato-streamdeck.readthedocs.io/en/stable/pages/installation.html
56
+
57
+ Assuming Raspbian 64-bit (minimal or desktop) based on Debian Bookwork (default in 2025), install base OS dependencies and configure system so DDC and USB are available to regular users:
58
+
59
+ ```bash
60
+ apt update && apt dist-upgrade -y
61
+ apt install ddcutil libudev-dev libudev-dev libusb-1.0-0-dev libhidapi-libusb0 python3-dev
62
+
63
+ echo 'i2c-dev' >> /etc/modules
64
+ modprobe i2c-dev
65
+
66
+ echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="0fd9", GROUP="users", TAG+="uaccess"' > /etc/udev/rules.d/10-streamdeck.rules
67
+ udevadm control --reload-rules # reconnect USB cable after that
68
+ ```
69
+
70
+ Development tools:
71
+
72
+ ```bash
73
+ apt install git pipx
74
+ pipx install hatch
75
+ ```
76
+
77
+
rpideck-0.1.0/LICENSE ADDED
@@ -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.
rpideck-0.1.0/PKG-INFO ADDED
@@ -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,21 @@
1
+ # RPiDeck
2
+
3
+ ***At this stage, this is a personal project, so many things may be hardcoded***
4
+
5
+ Python agent enabling Elgato StreamDeck Neo connected to Raspberry Pi 5 running headless (server) system to control various devices including:
6
+
7
+ - Dell monitor over spare HDMI using MCCS over DDC - inputs, KVM, PBP modes
8
+ - Pioneer (Onkyo) AVR - HDMI matrix, audio amplifier source
9
+
10
+ Future devices to be supported:
11
+
12
+ - anything from Home Assistant
13
+ - multimedia devices connected to AVR using HDMI-CEC
14
+
15
+ [ENV.md](./ENV.md) contains critical information about the environment where this project can be installed.
16
+
17
+ ## CLI usage
18
+
19
+ Config and assets must be placed under `~/.config/rpideck`. See examples in [example_config](./example_config/).
20
+
21
+ For now, just run `rpideck` and it'll start main loop. Buttons on last row (next to screen) act as page selectors.
rpideck-0.1.0/TODO.md ADDED
@@ -0,0 +1 @@
1
+ - https://github.com/newAM/monitorcontrol/blob/main/monitorcontrol/vcp/vcp_linux.py
@@ -0,0 +1,8 @@
1
+ 2025-02-24 17:34:41 INFO Opened 'Stream Deck Neo' device (serial number: 'A7BSA429127EAV', fw: '1.00.013')
2
+ 2025-02-24 17:34:50 INFO Key 8 pressed => calling page:previous
3
+ 2025-02-24 17:34:51 INFO Key 8 pressed up
4
+ 2025-02-24 17:34:52 INFO Key 9 pressed => calling page:next
5
+ 2025-02-24 17:34:52 INFO Key 9 pressed up
6
+ 2025-02-24 17:34:53 INFO Key 9 pressed => calling page:next
7
+ 2025-02-24 17:34:53 INFO Key 9 pressed up
8
+ 2025-02-24 17:34:54 INFO SIGINT
@@ -0,0 +1,8 @@
1
+ <a target="_blank" href="https://icons8.com/icon/ofWDphz4az7r/mac-studio">Mac Studio</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
2
+ <a target="_blank" href="https://icons8.com/icon/2784/briefcase">Briefcase</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
3
+ <a target="_blank" href="https://icons8.com/icon/10342/hdmi-cable">HDMI Cable</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
4
+ <a target="_blank" href="https://icons8.com/icon/uI4k7cPiwxCJ/power-off-button">Power</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
5
+ <a target="_blank" href="https://icons8.com/icon/10861/apple-tv">Apple TV</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
6
+ <a target="_blank" href="https://icons8.com/icon/10330/rca">RCA</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
7
+ <a target="_blank" href="https://icons8.com/icon/12519/playstation">Playstation</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
8
+ <a target="_blank" href="https://icons8.com/icon/XaIQdSh4y3F9/nintendo-switch-logo">Nintendo Switch Logo</a> icon by <a target="_blank" href="https://icons8.com">Icons8</a>
@@ -0,0 +1,142 @@
1
+ ---
2
+ ddc: null
3
+ avr:
4
+ ip: 192.168.0.2
5
+ deck:
6
+ matchSerial: AAAAAAAAAAAAAA
7
+ brightness: 50
8
+ font: Roboto-Regular.ttf
9
+ highlightColour: "#2E7D32"
10
+ pages:
11
+ - keys:
12
+ ddc_nya:
13
+ position: 0
14
+ icon: ddc_nya.png
15
+ label: "KVM NYA"
16
+ steps:
17
+ - text: "DDC PBP OFF"
18
+ type: ddc
19
+ parameters:
20
+ vcp: 0xE9
21
+ value: 0x00
22
+ - text: "DDC input DisplayPort"
23
+ type: ddc
24
+ parameters:
25
+ vcp: 0x60
26
+ value: 0x0F
27
+ - text: "AVR MacStudio"
28
+ type: eiscp
29
+ parameters:
30
+ cmd: source
31
+ value: tv
32
+ ddc_corp:
33
+ position: 1
34
+ icon: ddc_corp.png
35
+ label: "KVM CORP"
36
+ steps:
37
+ - text: "DDC PBP OFF"
38
+ type: ddc
39
+ parameters:
40
+ vcp: 0xE9
41
+ value: 0x00
42
+ - text: "DDC input USB-C"
43
+ type: ddc
44
+ parameters:
45
+ vcp: 0x60
46
+ value: 0x19
47
+ ddc_game:
48
+ position: 2
49
+ icon: ddc_hdmi.png
50
+ label: "HDMI PBP"
51
+ steps:
52
+ - text: "AVR ON"
53
+ type: eiscp
54
+ parameters:
55
+ cmd: power
56
+ value: "on"
57
+ - text: "DDC PBP OFF"
58
+ type: ddc
59
+ parameters:
60
+ vcp: 0xE9
61
+ value: 0x00
62
+ - text: "DDC input HDMI-2"
63
+ type: ddc
64
+ parameters:
65
+ vcp: 0x60
66
+ value: 0x12
67
+ - text: "DDC PBP 75%-25%"
68
+ type: ddc
69
+ parameters:
70
+ vcp: 0xE9
71
+ value: 0x2A
72
+ - text: "DDC PBP-SUB DP"
73
+ type: ddc
74
+ parameters:
75
+ vcp: 0xE8
76
+ value: 0x0F
77
+ ddc_power:
78
+ position: 3
79
+ icon: ddc_power.png
80
+ label: "Monitor"
81
+ steps: []
82
+ avr_appletv:
83
+ position: 4
84
+ icon: avr_appletv.png
85
+ label: "AVR AppleTV"
86
+ steps:
87
+ - text: "AVR AppleTV"
88
+ type: eiscp
89
+ parameters:
90
+ cmd: source
91
+ value: strm-box
92
+ avr_nya:
93
+ position: 5
94
+ icon: avr_nya.png
95
+ label: "AVR MacStudio"
96
+ steps:
97
+ - text: "AVR MacStudio"
98
+ type: eiscp
99
+ parameters:
100
+ cmd: source
101
+ value: tv
102
+ avr_nintendo:
103
+ position: 6
104
+ icon: avr_nintendo.png
105
+ label: "AVR Nintendo"
106
+ steps:
107
+ - text: "AVR Nintendo"
108
+ type: eiscp
109
+ parameters:
110
+ cmd: source
111
+ value: game
112
+ avr_playstation:
113
+ position: 7
114
+ icon: avr_playstation.png
115
+ label: "AVR PlayStation"
116
+ steps:
117
+ - text: "AVR PlayStation"
118
+ type: eiscp
119
+ parameters:
120
+ cmd: source
121
+ value: dvd
122
+ - keys:
123
+ ddc_nya:
124
+ position: 0
125
+ icon: ddc_nya.png
126
+ label: "KVM NYA"
127
+ steps:
128
+ - text: "DDC PBP OFF"
129
+ type: ddc
130
+ parameters:
131
+ vcp: 0xE9
132
+ value: 0x00
133
+ - text: "DDC input DisplayPort"
134
+ type: ddc
135
+ parameters:
136
+ vcp: 0x60
137
+ value: 0x0F
138
+ - text: "AVR MacStudio"
139
+ type: eiscp
140
+ parameters:
141
+ cmd: source
142
+ value: tv
@@ -0,0 +1,72 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "rpideck"
7
+ dynamic = ["version"]
8
+ description = ''
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = "MIT"
12
+ keywords = []
13
+ authors = [
14
+ { name = "Daniel Skowroński", email = "daniel@skowron.ski" },
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 4 - Beta",
18
+ "Programming Language :: Python",
19
+ "Programming Language :: Python :: 3.8",
20
+ "Programming Language :: Python :: 3.9",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: Implementation :: CPython",
25
+ "Programming Language :: Python :: Implementation :: PyPy",
26
+ ]
27
+ dependencies = [
28
+ "pillow~=11.1.0",
29
+ "streamdeck~=0.9.6",
30
+ "onkyo-eiscp~=1.2.7",
31
+ "click~=8.1.8",
32
+ "coloredlogs~=15.0.1",
33
+ "schema~=0.7.7",
34
+ "PyYAML~=6.0.2"
35
+ ]
36
+
37
+ [project.urls]
38
+ Documentation = "https://github.com/danielskowronski/RPiDeck"
39
+ Issues = "https://github.com/danielskowronski/RPiDeck/issues"
40
+ Source = "https://github.com/danielskowronski/RPiDeck"
41
+
42
+ [tool.hatch.version]
43
+ path = "src/rpideck/__about__.py"
44
+
45
+ [tool.hatch.envs.types]
46
+ extra-dependencies = [
47
+ "mypy>=1.0.0",
48
+ ]
49
+ [tool.hatch.envs.types.scripts]
50
+ check = "mypy --install-types --non-interactive {args:src/rpideck tests}"
51
+
52
+ [tool.coverage.run]
53
+ source_pkgs = ["rpideck", "tests"]
54
+ branch = true
55
+ parallel = true
56
+ omit = [
57
+ "src/rpideck/__about__.py",
58
+ ]
59
+
60
+ [tool.coverage.paths]
61
+ rpideck = ["src/rpideck", "*/rpideck/src/rpideck"]
62
+ tests = ["tests", "*/rpideck/tests"]
63
+
64
+ [tool.coverage.report]
65
+ exclude_lines = [
66
+ "no cov",
67
+ "if __name__ == .__main__.:",
68
+ "if TYPE_CHECKING:",
69
+ ]
70
+
71
+ [project.scripts]
72
+ rpideck = "rpideck.cli:rpideck"
@@ -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"
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: Daniel Skowroński <daniel@skowron.ski>
2
+ #
3
+ # SPDX-License-Identifier: MIT
@@ -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())
@@ -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}")
@@ -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)
@@ -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,3 @@
1
+ # SPDX-FileCopyrightText: Daniel Skowroński <daniel@skowron.ski>
2
+ #
3
+ # SPDX-License-Identifier: MIT