lauschkiste-plugins-raspberry-pi 0.1.0a7__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.
Files changed (28) hide show
  1. lauschkiste_plugins_raspberry_pi-0.1.0a7/.gitignore +55 -0
  2. lauschkiste_plugins_raspberry_pi-0.1.0a7/LICENSE +22 -0
  3. lauschkiste_plugins_raspberry_pi-0.1.0a7/PKG-INFO +52 -0
  4. lauschkiste_plugins_raspberry_pi-0.1.0a7/README.md +20 -0
  5. lauschkiste_plugins_raspberry_pi-0.1.0a7/interfaces/battery.json +71 -0
  6. lauschkiste_plugins_raspberry_pi-0.1.0a7/interfaces/device_raspberry_pi.json +70 -0
  7. lauschkiste_plugins_raspberry_pi-0.1.0a7/interfaces/gpio_controls.json +14 -0
  8. lauschkiste_plugins_raspberry_pi-0.1.0a7/interfaces/phat_beat.json +16 -0
  9. lauschkiste_plugins_raspberry_pi-0.1.0a7/interfaces/power_button.json +15 -0
  10. lauschkiste_plugins_raspberry_pi-0.1.0a7/pyproject.toml +60 -0
  11. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/__init__.py +158 -0
  12. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/bootconfig.py +112 -0
  13. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/hat.py +45 -0
  14. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/health.py +68 -0
  15. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/pins.py +67 -0
  16. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/settings.py +24 -0
  17. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/setup.py +165 -0
  18. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/translations/de.json +41 -0
  19. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_device_raspberry_pi/translations/en.json +41 -0
  20. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/__init__.py +1 -0
  21. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/apa102.py +95 -0
  22. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/battery.py +236 -0
  23. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/gpio.py +45 -0
  24. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/gpio_controls.py +210 -0
  25. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/phat_beat.py +458 -0
  26. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/power_button.py +109 -0
  27. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/translations/de.json +157 -0
  28. lauschkiste_plugins_raspberry_pi-0.1.0a7/src/lauschkiste_plugin_peripherals/translations/en.json +157 -0
@@ -0,0 +1,55 @@
1
+ # Shared folder
2
+ /shared/library/*
3
+ /shared/logs/*
4
+ /shared/playlists/*
5
+ /shared/settings/*
6
+ /shared/logs/*.log*
7
+ /shared/*.*
8
+ /shared/*
9
+ /packages/webapp/public/cover-cache/*.*
10
+ /packages/webapp/test-results/
11
+ /packages/lauschkiste/src/lauschkiste/webapp/
12
+ /dist/
13
+ /packages/webapp/playwright-report/
14
+
15
+ # Byte-compiled / optimized / DLL files
16
+ __pycache__/
17
+ *.py[cod]
18
+
19
+ .git
20
+ .venv
21
+ *~
22
+ *.*~
23
+ *.pyc
24
+ *.idea
25
+ *.vscode
26
+ .DS_Store
27
+ **/.mypy_cache
28
+
29
+ # Keep folders with .gitkeep
30
+ !/**/.gitkeep
31
+
32
+ # Development Scratchpads
33
+ /**/scratch
34
+ /**/scratch_*
35
+
36
+ # Local debug/build artifacts
37
+ /app.log
38
+ /*.tar.gz
39
+
40
+ # bam local cache and test reports
41
+ /.bam/
42
+ /.reports/
43
+ /.coverage
44
+ /coverage.xml
45
+
46
+ # Local secrets for tests and scripts (never committed)
47
+ .env
48
+ .env.local
49
+
50
+ # Documentation site (generated from documentation/ by site/scripts/sync-docs.mjs)
51
+ /site/node_modules/
52
+ /site/dist/
53
+ /site/.astro/
54
+ /site/src/content/docs/
55
+ /site/public/screenshots/
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Micz Flor
4
+ Copyright (c) 2026 the Lauschkiste contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.5
2
+ Name: lauschkiste-plugins-raspberry-pi
3
+ Version: 0.1.0a7
4
+ Summary: Lauschkiste plugins for the Raspberry Pi: the device and its peripherals (buttons, LEDs, battery, power button, pHAT BEAT)
5
+ Project-URL: Homepage, https://github.com/ladidadida/lauschkiste
6
+ Project-URL: Documentation, https://github.com/ladidadida/lauschkiste/tree/main/documentation
7
+ Project-URL: Issues, https://github.com/ladidadida/lauschkiste/issues
8
+ Project-URL: Changelog, https://github.com/ladidadida/lauschkiste/releases
9
+ Author: the Lauschkiste contributors
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: lauschkiste,plugin,raspberry pi
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: End Users/Desktop
15
+ Classifier: Operating System :: POSIX :: Linux
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Home Automation
22
+ Classifier: Topic :: System :: Hardware
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: lauschkiste-core==0.1.0a7
25
+ Provides-Extra: battery
26
+ Requires-Dist: pi-ina219; extra == 'battery'
27
+ Requires-Dist: smbus2; extra == 'battery'
28
+ Provides-Extra: gpio
29
+ Requires-Dist: gpiozero; extra == 'gpio'
30
+ Requires-Dist: lgpio; (platform_machine == 'armv6l' or platform_machine == 'armv7l' or platform_machine == 'aarch64') and extra == 'gpio'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # lauschkiste-plugins-raspberry-pi
34
+
35
+ The Raspberry Pi plugins of [Lauschkiste](https://github.com/ladidadida/lauschkiste), an open-source RFID audio player for kids:
36
+
37
+ - `device_raspberry_pi`: the Pi as the device: pin map, interfaces (I²C, SPI, I²S), sound cards, boot configuration,
38
+ shutdown and reboot, firmware health, and its steps in `lauschctl setup`
39
+ - the peripherals: `gpio_controls` (buttons, rotary encoders, a status LED), `battery` (MAX17048, INA219),
40
+ `power_button` (Pimoroni OnOff SHIM) and `phat_beat` (Pimoroni pHAT BEAT)
41
+
42
+ Install it next to [`lauschkiste`](https://pypi.org/project/lauschkiste/) (same version; `install.sh` does). Installing does not
43
+ switch anything on: `lauschctl setup` proposes what fits, and a plugin is switched on in the web app (Settings → Plugins)
44
+ or with:
45
+
46
+ ```bash
47
+ lauschctl plugin enable gpio_controls # or battery, power_button, phat_beat, device_raspberry_pi
48
+ ```
49
+
50
+ The GPIO libraries come with the `gpio` extra: `lauschkiste-plugins-raspberry-pi[gpio]` (the web app offers to install them).
51
+
52
+ Documentation: [guide](https://github.com/ladidadida/lauschkiste/blob/main/documentation/en/README.md). MIT license.
@@ -0,0 +1,20 @@
1
+ # lauschkiste-plugins-raspberry-pi
2
+
3
+ The Raspberry Pi plugins of [Lauschkiste](https://github.com/ladidadida/lauschkiste), an open-source RFID audio player for kids:
4
+
5
+ - `device_raspberry_pi`: the Pi as the device: pin map, interfaces (I²C, SPI, I²S), sound cards, boot configuration,
6
+ shutdown and reboot, firmware health, and its steps in `lauschctl setup`
7
+ - the peripherals: `gpio_controls` (buttons, rotary encoders, a status LED), `battery` (MAX17048, INA219),
8
+ `power_button` (Pimoroni OnOff SHIM) and `phat_beat` (Pimoroni pHAT BEAT)
9
+
10
+ Install it next to [`lauschkiste`](https://pypi.org/project/lauschkiste/) (same version; `install.sh` does). Installing does not
11
+ switch anything on: `lauschctl setup` proposes what fits, and a plugin is switched on in the web app (Settings → Plugins)
12
+ or with:
13
+
14
+ ```bash
15
+ lauschctl plugin enable gpio_controls # or battery, power_button, phat_beat, device_raspberry_pi
16
+ ```
17
+
18
+ The GPIO libraries come with the `gpio` extra: `lauschkiste-plugins-raspberry-pi[gpio]` (the web app offers to install them).
19
+
20
+ Documentation: [guide](https://github.com/ladidadida/lauschkiste/blob/main/documentation/en/README.md). MIT license.
@@ -0,0 +1,71 @@
1
+ {
2
+ "events": {
3
+ "state": {
4
+ "properties": {
5
+ "soc": {
6
+ "type": "integer"
7
+ },
8
+ "voltage_mv": {
9
+ "type": "integer"
10
+ },
11
+ "warning": {
12
+ "type": "boolean"
13
+ }
14
+ },
15
+ "required": [
16
+ "voltage_mv",
17
+ "soc",
18
+ "warning"
19
+ ],
20
+ "type": "object"
21
+ }
22
+ },
23
+ "extension_points": {},
24
+ "interface_version": "1.1",
25
+ "kind": "plugin",
26
+ "name": "battery",
27
+ "needs": [
28
+ "i2c"
29
+ ],
30
+ "operations": {
31
+ "get_battery": {
32
+ "args": {
33
+ "additionalProperties": false,
34
+ "properties": {},
35
+ "type": "object"
36
+ },
37
+ "kind": "query",
38
+ "method": "GET",
39
+ "path": "/api/v1/battery",
40
+ "returns": {
41
+ "anyOf": [
42
+ {
43
+ "properties": {
44
+ "soc": {
45
+ "type": "integer"
46
+ },
47
+ "voltage_mv": {
48
+ "type": "integer"
49
+ },
50
+ "warning": {
51
+ "type": "boolean"
52
+ }
53
+ },
54
+ "required": [
55
+ "voltage_mv",
56
+ "soc",
57
+ "warning"
58
+ ],
59
+ "type": "object"
60
+ },
61
+ {
62
+ "type": "null"
63
+ }
64
+ ]
65
+ }
66
+ }
67
+ },
68
+ "requires": {
69
+ "hardware": ">=2.0,<3"
70
+ }
71
+ }
@@ -0,0 +1,70 @@
1
+ {
2
+ "events": {},
3
+ "extension_points": {},
4
+ "interface_version": "1.2",
5
+ "kind": "plugin",
6
+ "name": "device_raspberry_pi",
7
+ "operations": {
8
+ "get_throttled": {
9
+ "args": {
10
+ "additionalProperties": false,
11
+ "properties": {},
12
+ "type": "object"
13
+ },
14
+ "kind": "query",
15
+ "method": "GET",
16
+ "path": "/api/v1/device_raspberry_pi/throttled",
17
+ "returns": {
18
+ "properties": {
19
+ "frequency_capped_now": {
20
+ "type": "boolean"
21
+ },
22
+ "frequency_capped_occurred": {
23
+ "type": "boolean"
24
+ },
25
+ "raw": {
26
+ "type": "string"
27
+ },
28
+ "throttled_now": {
29
+ "type": "boolean"
30
+ },
31
+ "throttled_occurred": {
32
+ "type": "boolean"
33
+ },
34
+ "under_voltage_now": {
35
+ "type": "boolean"
36
+ },
37
+ "under_voltage_occurred": {
38
+ "type": "boolean"
39
+ }
40
+ },
41
+ "required": [
42
+ "raw",
43
+ "under_voltage_now",
44
+ "frequency_capped_now",
45
+ "throttled_now",
46
+ "under_voltage_occurred",
47
+ "frequency_capped_occurred",
48
+ "throttled_occurred"
49
+ ],
50
+ "type": "object"
51
+ }
52
+ }
53
+ },
54
+ "provides": [
55
+ "autologin",
56
+ "boot_config",
57
+ "device",
58
+ "gpio",
59
+ "i2c",
60
+ "i2s",
61
+ "poweroff",
62
+ "screen",
63
+ "spi",
64
+ "system_setup",
65
+ "uart"
66
+ ],
67
+ "requires": {
68
+ "hardware": ">=2.0,<3"
69
+ }
70
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "events": {},
3
+ "extension_points": {},
4
+ "interface_version": "1.1",
5
+ "kind": "plugin",
6
+ "name": "gpio_controls",
7
+ "needs": [
8
+ "gpio"
9
+ ],
10
+ "operations": {},
11
+ "requires": {
12
+ "hardware": ">=2.0,<3"
13
+ }
14
+ }
@@ -0,0 +1,16 @@
1
+ {
2
+ "events": {},
3
+ "extension_points": {},
4
+ "interface_version": "1.3",
5
+ "kind": "plugin",
6
+ "name": "phat_beat",
7
+ "needs": [
8
+ "gpio",
9
+ "i2s"
10
+ ],
11
+ "operations": {},
12
+ "requires": {
13
+ "hardware": ">=2.0,<3",
14
+ "player": ">=7.0,<8"
15
+ }
16
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "events": {},
3
+ "extension_points": {},
4
+ "interface_version": "1.1",
5
+ "kind": "plugin",
6
+ "name": "power_button",
7
+ "needs": [
8
+ "gpio",
9
+ "poweroff"
10
+ ],
11
+ "operations": {},
12
+ "requires": {
13
+ "hardware": ">=2.0,<3"
14
+ }
15
+ }
@@ -0,0 +1,60 @@
1
+ [project]
2
+ name = "lauschkiste-plugins-raspberry-pi"
3
+ version = "0.1.0a7"
4
+ description = "Lauschkiste plugins for the Raspberry Pi: the device and its peripherals (buttons, LEDs, battery, power button, pHAT BEAT)"
5
+ license = "MIT"
6
+ requires-python = ">=3.11"
7
+ readme = "README.md"
8
+ authors = [{ name = "the Lauschkiste contributors" }]
9
+ keywords = [
10
+ "lauschkiste",
11
+ "plugin",
12
+ "raspberry pi",
13
+ ]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Intended Audience :: End Users/Desktop",
17
+ "Operating System :: POSIX :: Linux",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: 3.14",
23
+ "Topic :: System :: Hardware",
24
+ "Topic :: Home Automation",
25
+ ]
26
+ license-files = ["LICENSE"]
27
+ dependencies = [
28
+ "lauschkiste-core==0.1.0a7",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/ladidadida/lauschkiste"
33
+ Documentation = "https://github.com/ladidadida/lauschkiste/tree/main/documentation"
34
+ Issues = "https://github.com/ladidadida/lauschkiste/issues"
35
+ Changelog = "https://github.com/ladidadida/lauschkiste/releases"
36
+
37
+ [project.optional-dependencies]
38
+ gpio = [
39
+ "gpiozero",
40
+ # gpiozero's backend for Linux GPIO chips (any board, Raspberry Pi kernels >= 6.6)
41
+ "lgpio; platform_machine == 'armv6l' or platform_machine == 'armv7l' or platform_machine == 'aarch64'",
42
+ ]
43
+ battery = ["pi-ina219", "smbus2"]
44
+
45
+ [project.entry-points."lauschkiste.plugins"]
46
+ device_raspberry_pi = "lauschkiste_plugin_device_raspberry_pi:DeviceRaspberryPi"
47
+ gpio_controls = "lauschkiste_plugin_peripherals.gpio_controls:GpioControls"
48
+ battery = "lauschkiste_plugin_peripherals.battery:Battery"
49
+ power_button = "lauschkiste_plugin_peripherals.power_button:PowerButton"
50
+ phat_beat = "lauschkiste_plugin_peripherals.phat_beat:PhatBeat"
51
+
52
+ [tool.uv.sources]
53
+ lauschkiste-core = { workspace = true }
54
+
55
+ [build-system]
56
+ requires = ["hatchling"]
57
+ build-backend = "hatchling.build"
58
+
59
+ [tool.hatch.build.targets.wheel]
60
+ packages = ["src/lauschkiste_plugin_device_raspberry_pi", "src/lauschkiste_plugin_peripherals"]
@@ -0,0 +1,158 @@
1
+ """The Raspberry Pi as a device: 40-pin header, I²C/SPI/I²S, sound cards, power, firmware health.
2
+
3
+ Registers the device at the core ``hardware`` module. Changes of the boot configuration (sound card,
4
+ I²C, SPI, power-off pin) are written by ``lauschctl setup raspi``; the plugin reports them as pending
5
+ until then. See documentation/developers/hardware.md.
6
+ """
7
+
8
+ import logging
9
+ import subprocess
10
+ from pathlib import Path
11
+ from typing import Any, List, Optional
12
+
13
+ import lauschkiste.common.cfghandler
14
+ from lauschkiste.contract import OperationError, Plugin, query
15
+ from lauschkiste.box.hardware import Claim
16
+
17
+ from lauschkiste_plugin_device_raspberry_pi import bootconfig, hat, health, pins
18
+ from lauschkiste_plugin_device_raspberry_pi.settings import DeviceSettings
19
+
20
+ logger = logging.getLogger('lauschkiste.device_raspberry_pi')
21
+
22
+ BOOT_CONFIG = ('/boot/firmware/config.txt', '/boot/config.txt')
23
+
24
+
25
+ class RaspberryPiDevice:
26
+ """What the hardware module asks a device."""
27
+
28
+ def __init__(self, plugin: 'DeviceRaspberryPi'):
29
+ self._plugin = plugin
30
+ self._model = pins.model()
31
+ self._chip = pins.gpio_chip(self._model)
32
+
33
+ def describe(self):
34
+ return {'name': 'raspberry_pi', 'model': self._model or 'Raspberry Pi', 'pins': pins.pins(),
35
+ 'interfaces': pins.INTERFACES}
36
+
37
+ def pin_id(self, value) -> Optional[str]:
38
+ return pins.pin_id(value)
39
+
40
+ def gpio_line(self, pin: str):
41
+ return self._chip, int(pin[4:])
42
+
43
+ def shutdown(self) -> None:
44
+ self._plugin.power(['sudo', 'shutdown', '-h', 'now'], 'Shutting down')
45
+
46
+ def reboot(self) -> None:
47
+ self._plugin.power(['sudo', 'reboot'], 'Rebooting')
48
+
49
+ def boot_pending(self) -> List[str]:
50
+ return self._plugin.boot_pending()
51
+
52
+ def notes(self) -> List[dict]:
53
+ return self._plugin.notes()
54
+
55
+
56
+ class DeviceClaims:
57
+ def __init__(self, plugin: 'DeviceRaspberryPi'):
58
+ self._plugin = plugin
59
+
60
+ def claims(self) -> List[Claim]:
61
+ card = self._plugin.setting('sound_card', 'none')
62
+ return [Claim(resource='i2s', owner='device_raspberry_pi', purpose=f'sound card {card}')] \
63
+ if card != 'none' else []
64
+
65
+
66
+ class DeviceRaspberryPi(Plugin):
67
+ """Raspberry Pi: pins, interfaces, sound cards, boot configuration, shutdown/reboot and firmware health."""
68
+
69
+ name = 'device_raspberry_pi'
70
+ title = 'Raspberry Pi'
71
+ interface_version = '1.2'
72
+ requires = {'hardware': '>=2.0,<3'}
73
+ provides = ('device', 'gpio', 'i2c', 'spi', 'i2s', 'uart', 'poweroff', 'boot_config', 'system_setup', 'autologin',
74
+ 'screen')
75
+ settings = DeviceSettings
76
+
77
+ @classmethod
78
+ def detect(cls, read):
79
+ model = (read('/proc/device-tree/model') or '').strip('\x00\n ')
80
+ return model if 'Raspberry Pi' in model else None
81
+
82
+ @classmethod
83
+ def setup_steps(cls):
84
+ from lauschkiste_plugin_device_raspberry_pi import setup
85
+ return setup.steps()
86
+
87
+ def __init__(self):
88
+ self._ctx: Any = None
89
+
90
+ def setting(self, key, default=None):
91
+ return self._ctx.config.get(key, default=default)
92
+
93
+ def start(self, ctx) -> None:
94
+ self._ctx = ctx
95
+ if self.setting('hdmi_power_down', False):
96
+ health.hdmi_power_down()
97
+ if self.setting('wlan_power_save', None) is False:
98
+ health.disable_wlan_power_save(self.setting('wlan_interface', 'wlan0'))
99
+ hardware = ctx.modules.hardware
100
+ hardware.devices.register('raspberry_pi', RaspberryPiDevice(self))
101
+ hardware.claims.register('device_raspberry_pi', DeviceClaims(self))
102
+
103
+ def settings_changed(self, changed):
104
+ return set(changed) <= {'debug_mode', 'sound_card', 'onboard_audio', 'i2c', 'spi'}
105
+
106
+ def power(self, command: List[str], what: str) -> None:
107
+ if self.setting('debug_mode', False):
108
+ logger.info(f"debug_mode: not running '{' '.join(command)}' ({what})")
109
+ return
110
+ logger.info(what)
111
+ try:
112
+ subprocess.Popen(command)
113
+ except OSError as error:
114
+ raise OperationError(501, 'not_supported', f"{what} failed: {error}") from None
115
+
116
+ def boot_pending(self) -> List[str]:
117
+ path = next((Path(p) for p in BOOT_CONFIG if Path(p).exists()), None)
118
+ if path is None:
119
+ return []
120
+ main = lauschkiste.common.cfghandler.get_handler('lauschkiste')
121
+ rfid = lauschkiste.common.cfghandler.get_handler('rfid')
122
+ want = bootconfig.wanted({'plugins': main.getn('plugins', default=None) or {}},
123
+ {'rfid': rfid.getn('rfid', default=None) or {}})
124
+ return bootconfig.pending(path.read_text(), want)
125
+
126
+ def notes(self, read=hat.read_text) -> List[dict]:
127
+ """What is set up and what the user may want to check, for the hardware overview."""
128
+ found = hat.read_hat(read)
129
+ main = lauschkiste.common.cfghandler.get_handler('lauschkiste')
130
+ configured = bootconfig.wanted({'plugins': main.getn('plugins', default=None) or {}}, {}).sound_card
131
+ notes: List[dict] = []
132
+ if found is not None and found.sound_card is not None:
133
+ if configured == found.sound_card:
134
+ notes.append({'id': 'sound_card', 'level': 'ok', 'text': f'Sound card {found.label} is set up'})
135
+ elif configured == 'none':
136
+ notes.append({'id': 'sound_card', 'level': 'todo', 'hint': 'lauschctl setup hardware',
137
+ 'text': f'{found.label} was found, but no sound card is set up: the sound of the Pi '
138
+ 'itself is used'})
139
+ else:
140
+ notes.append({'id': 'sound_card', 'level': 'info',
141
+ 'text': f'{found.label} was found, the sound card setting is {configured}'})
142
+ elif found is not None:
143
+ notes.append({'id': 'hat', 'level': 'info', 'text': f'A board on the header reports itself as {found.label}'})
144
+ elif configured != 'none':
145
+ notes.append({'id': 'sound_card', 'level': 'ok', 'text': f'Sound card {configured} is set up'})
146
+ pending = self.boot_pending()
147
+ if pending:
148
+ notes.append({'id': 'boot', 'level': 'todo', 'hint': 'lauschctl setup raspi, then reboot',
149
+ 'text': 'The boot configuration lacks: ' + ', '.join(pending)})
150
+ return notes
151
+
152
+ @query(path='/throttled')
153
+ def get_throttled(self) -> health.Throttled:
154
+ """Under-voltage and throttling flags of the firmware (``vcgencmd get_throttled``)."""
155
+ state = health.read_throttled()
156
+ if state is None:
157
+ raise OperationError(501, 'not_supported', 'vcgencmd is not available')
158
+ return state
@@ -0,0 +1,112 @@
1
+ """What config.txt needs for the hardware Lauschkiste is set up with; used by the device plugin
2
+ (to report pending changes) and by ``lauschctl setup raspi`` (to write them)."""
3
+
4
+ import re
5
+ from dataclasses import dataclass
6
+ from typing import Any, Dict, List, Mapping, Optional
7
+
8
+ from lauschkiste_plugin_device_raspberry_pi.pins import pin_id
9
+
10
+ SOUND_CARDS = {
11
+ 'max98357a': 'MAX98357A I²S amplifier',
12
+ 'hifiberry-dac': 'HiFiBerry DAC / MiniAmp (PCM5102A)',
13
+ 'hifiberry-dacplus': 'HiFiBerry DAC+ Standard/Pro/Amp2',
14
+ 'hifiberry-dacplushd': 'HiFiBerry DAC2 HD',
15
+ 'hifiberry-dacplusadc': 'HiFiBerry DAC+ ADC',
16
+ 'hifiberry-dacplusadcpro': 'HiFiBerry DAC+ ADC Pro',
17
+ 'hifiberry-digi': 'HiFiBerry Digi+',
18
+ 'hifiberry-digi-pro': 'HiFiBerry Digi+ Pro',
19
+ 'hifiberry-amp': 'HiFiBerry Amp+',
20
+ }
21
+ SOUND_OVERLAY = re.compile(r'^dtoverlay=(max98357a|hifiberry-[\w-]+)\s*$', re.MULTILINE)
22
+ AUDIO_ON = re.compile(r'^(dtparam=([^,\n]*,)*)audio=(on|true|yes|1)(.*)$', re.MULTILINE)
23
+ I2C_ON = re.compile(r'^dtparam=([^\n]*,)?i2c(_arm)?=on', re.MULTILINE)
24
+ SPI_ON = re.compile(r'^dtparam=([^\n]*,)?spi=on', re.MULTILINE)
25
+ POWEROFF = re.compile(r'^dtoverlay=gpio-poweroff[^\n]*$', re.MULTILINE)
26
+
27
+ I2C_BATTERY_DRIVERS = ('ina219', 'max17048')
28
+ SPI_READERS = ('rc522_spi',)
29
+ #: Device plugins of HATs with a DAC: the sound card they need
30
+ HAT_SOUND_CARDS = {'phat_beat': 'hifiberry-dac'}
31
+
32
+
33
+ @dataclass
34
+ class Wanted:
35
+ sound_card: str = 'none'
36
+ onboard_audio: bool = True
37
+ i2c: bool = False
38
+ spi: bool = False
39
+ poweroff_pin: Optional[int] = None
40
+
41
+ def poweroff_line(self) -> Optional[str]:
42
+ if self.poweroff_pin is None:
43
+ return None
44
+ return f'dtoverlay=gpio-poweroff,gpiopin={self.poweroff_pin},active_low=1'
45
+
46
+
47
+ def _bcm(value: Any) -> Optional[int]:
48
+ pin = pin_id(value) if value is not None else None
49
+ return int(pin[4:]) if pin else None
50
+
51
+
52
+ def wanted(config: Mapping[str, Any], rfid: Optional[Mapping[str, Any]] = None) -> Wanted:
53
+ """From the main config (and rfid.yaml): what the boot configuration should switch on."""
54
+ plugins = config.get('plugins') or {}
55
+ board = plugins.get('device_raspberry_pi') or {}
56
+ battery = plugins.get('battery') or {}
57
+ power = plugins.get('power_button') or {}
58
+ readers = ((rfid or {}).get('rfid') or {}).get('readers') or {}
59
+ card = str(board.get('sound_card') or 'none')
60
+ if card == 'none':
61
+ card = next((sound for hat, sound in HAT_SOUND_CARDS.items() if hat in plugins), 'none')
62
+ return Wanted(
63
+ sound_card=card if card in SOUND_CARDS else 'none',
64
+ onboard_audio=card not in SOUND_CARDS and board.get('onboard_audio', True) is not False,
65
+ i2c=bool(board.get('i2c')) or ('battery' in plugins
66
+ and battery.get('driver', 'max17048') in I2C_BATTERY_DRIVERS),
67
+ spi=bool(board.get('spi')) or any(str(r.get('module')) in SPI_READERS for r in readers.values()
68
+ if isinstance(r, dict)),
69
+ poweroff_pin=_bcm(power.get('poweroff_pin')) if 'power_button' in plugins else None,
70
+ )
71
+
72
+
73
+ def pending(text: str, want: Wanted) -> List[str]:
74
+ """What config.txt lacks."""
75
+ problems = []
76
+ if want.sound_card != 'none' and SOUND_OVERLAY.findall(text) != [want.sound_card]:
77
+ problems.append(f'sound card {want.sound_card}')
78
+ if not want.onboard_audio and AUDIO_ON.search(text):
79
+ problems.append('on-chip audio off')
80
+ if want.i2c and not I2C_ON.search(text):
81
+ problems.append('I²C on')
82
+ if want.spi and not SPI_ON.search(text):
83
+ problems.append('SPI on')
84
+ line = want.poweroff_line()
85
+ if line and POWEROFF.findall(text) != [line]:
86
+ problems.append(f'power-off pin GPIO{want.poweroff_pin}')
87
+ return problems
88
+
89
+
90
+ def render(text: str, want: Wanted) -> str:
91
+ """config.txt with what ``pending`` reports added; other lines stay."""
92
+ if not want.onboard_audio:
93
+ text = AUDIO_ON.sub(r'\1audio=off\4', text)
94
+ additions: List[str] = []
95
+ if want.sound_card != 'none' and SOUND_OVERLAY.findall(text) != [want.sound_card]:
96
+ text = SOUND_OVERLAY.sub('', text)
97
+ additions.append(f'dtoverlay={want.sound_card}')
98
+ if want.i2c and not I2C_ON.search(text):
99
+ additions.append('dtparam=i2c_arm=on')
100
+ if want.spi and not SPI_ON.search(text):
101
+ additions.append('dtparam=spi=on')
102
+ line = want.poweroff_line()
103
+ if line and POWEROFF.findall(text) != [line]:
104
+ text = POWEROFF.sub('', text)
105
+ additions.append(line)
106
+ if additions:
107
+ text = text.rstrip('\n') + '\n' + '\n'.join(additions) + '\n'
108
+ return re.sub(r'\n{3,}', '\n\n', text)
109
+
110
+
111
+ def describe_cards() -> Dict[str, str]:
112
+ return dict(SOUND_CARDS)