From ea6df41f05a11622f4377bf26a09a08edb773378 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Wed, 10 Jan 2024 05:59:21 -0500 Subject: [PATCH] gpio: fix initial state for inverted gpios The python-periphery library XORs the initial value based on whether or not its inverted. This requires consumers to set the direction to "high" for inverted pins that are off, and "low" otherwise. Signed-off-by: Eric Callahan --- moonraker/components/gpio.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/moonraker/components/gpio.py b/moonraker/components/gpio.py index 33dbb09..bd52f64 100644 --- a/moonraker/components/gpio.py +++ b/moonraker/components/gpio.py @@ -121,6 +121,7 @@ class GpioFactory: "documentation for details on the pin format." ) bias_flag: Optional[str] = pin_match.group("bias") + params["inverted"] = pin_match.group("inverted") is not None if req_type == "event": params["direction"] = "in" params["edge"] = "both" @@ -131,8 +132,8 @@ class GpioFactory: f"Invalid pin format {pin_desc}. Bias flag {bias_flag} " "not available for output pins." ) - params["direction"] = "out" if not initial_value else "high" - params["inverted"] = pin_match.group("inverted") is not None + initial_state = bool(initial_value) ^ params["inverted"] + params["direction"] = "low" if not initial_state else "high" chip_id: str = pin_match.group("chip_id") or "gpiochip0" pin_name: str = pin_match.group("pin_name") params["pin_id"] = int(pin_match.group("pin_id"))