From 4cf35d224ffb2486189e38ebc74fc3731c0739ab Mon Sep 17 00:00:00 2001 From: premultiply <4681172+premultiply@users.noreply.github.com> Date: Mon, 17 Nov 2025 07:26:18 +0100 Subject: [PATCH] Openwb-native: fix gpio open/close (#25358) --- charger/openwb-native_linux.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/charger/openwb-native_linux.go b/charger/openwb-native_linux.go index d14a32c44..0bc215e54 100644 --- a/charger/openwb-native_linux.go +++ b/charger/openwb-native_linux.go @@ -104,11 +104,24 @@ func NewOpenWbNative(ctx context.Context, uri, device, comset string, baudrate i identify = wb.identify } - // set pins to output + // initialize GPIO and set pins to output + if err := rpio.Open(); err != nil { + return nil, fmt.Errorf("failed to open GPIO: %w", err) + } + for _, pin := range structs.Fields(native.ChargePoints[connector-1]) { rpio.Pin(pin.Value().(int)).Output() } + // close GPIO when context is cancelled + go func() { + <-ctx.Done() + log.DEBUG.Println("context canceled, closing GPIO") + if err := rpio.Close(); err != nil { + log.ERROR.Printf("error closing GPIO: %v", err) + } + }() + return decorateOpenWbNative(wb, phases1p3p, identify), nil } @@ -151,11 +164,6 @@ func (wb *OpenWbNative) runGpioSequence(seq []gpioAction) error { return err } - if err := rpio.Open(); err != nil { - return err - } - defer rpio.Close() - for _, a := range seq { a.pin() if a.delay > 0 {