Skip to content

Commit d57c3c6

Browse files
committed
atx: independent power/reset regions
1 parent 49638ed commit d57c3c6

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

kvmd/plugins/atx/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ async def trigger_state(self) -> None:
5454
async def poll_state(self) -> AsyncGenerator[dict, None]:
5555
# ==== Granularity table ====
5656
# - enabled -- Full
57-
# - busy -- Partial
57+
# - busy -- Partial, follows with acts
58+
# - acts -- Partial, follows with busy
5859
# - leds -- Partial
5960
# ===========================
6061

kvmd/plugins/atx/disabled.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ async def get_state(self) -> dict:
4343
return {
4444
"enabled": False,
4545
"busy": False,
46+
"acts": {
47+
"power": False,
48+
"reset": False,
49+
},
4650
"leds": {
4751
"power": False,
4852
"hdd": False,

kvmd/plugins/atx/gpio.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ def __init__( # pylint: disable=too-many-arguments,super-init-not-called
7575
self.__long_click_delay = long_click_delay
7676

7777
self.__notifier = aiotools.AioNotifier()
78-
self.__region = aiotools.AioExclusiveRegion(AtxIsBusyError, self.__notifier)
78+
self.__power_region = aiotools.AioExclusiveRegion(AtxIsBusyError, self.__notifier)
79+
self.__reset_region = aiotools.AioExclusiveRegion(AtxIsBusyError, self.__notifier)
7980

8081
self.__line_req: (gpiod.LineRequest | None) = None
8182

@@ -122,9 +123,15 @@ def sysprep(self) -> None:
122123
)
123124

124125
async def get_state(self) -> dict:
126+
power_busy = self.__power_region.is_busy()
127+
reset_busy = self.__reset_region.is_busy()
125128
return {
126129
"enabled": True,
127-
"busy": self.__region.is_busy(),
130+
"busy": (power_busy or reset_busy),
131+
"acts": {
132+
"power": power_busy,
133+
"reset": reset_busy,
134+
},
128135
"leds": {
129136
"power": self.__reader.get(self.__power_led_pin),
130137
"hdd": self.__reader.get(self.__hdd_led_pin),
@@ -175,28 +182,28 @@ async def power_reset_hard(self, wait: bool) -> None:
175182
# =====
176183

177184
async def click_power(self, wait: bool) -> None:
178-
await self.__click("power", self.__power_switch_pin, self.__click_delay, wait)
185+
await self.__click("power", self.__power_region, self.__power_switch_pin, self.__click_delay, wait)
179186

180187
async def click_power_long(self, wait: bool) -> None:
181-
await self.__click("power_long", self.__power_switch_pin, self.__long_click_delay, wait)
188+
await self.__click("power_long", self.__power_region, self.__power_switch_pin, self.__long_click_delay, wait)
182189

183190
async def click_reset(self, wait: bool) -> None:
184-
await self.__click("reset", self.__reset_switch_pin, self.__click_delay, wait)
191+
await self.__click("reset", self.__reset_region, self.__reset_switch_pin, self.__click_delay, wait)
185192

186193
# =====
187194

188195
async def __get_power(self) -> bool:
189196
return (await self.get_state())["leds"]["power"]
190197

191198
@aiotools.atomic_fg
192-
async def __click(self, name: str, pin: int, delay: float, wait: bool) -> None:
199+
async def __click(self, name: str, region: aiotools.AioExclusiveRegion, pin: int, delay: float, wait: bool) -> None:
193200
if wait:
194-
with self.__region:
201+
with region:
195202
await self.__inner_click(name, pin, delay)
196203
else:
197204
await aiotools.run_region_task(
198205
f"Can't perform ATX {name} click or operation was not completed",
199-
self.__region, self.__inner_click, name, pin, delay,
206+
region, self.__inner_click, name, pin, delay,
200207
)
201208

202209
@aiotools.atomic_fg

0 commit comments

Comments
 (0)