Openwb-native: fix gpio open/close (#25358)
This commit is contained in:
parent
c96077104d
commit
4cf35d224f
1 changed files with 14 additions and 6 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue