If "WithHCSR04UseEdgePolling()" is used, stopping the robot by CTRL-C hangs. This is only tested with gpiod driver, not sysfs.
This is caused by the reconfiguration of the pin with this call hierarchy:
DigitalPinsAdaptor.Finalize()
pin.Unexport()
digitalPinGpiodReconfigure()
digitalPinGpiodReconfigureLine()
startEdgePolling()
call of a go - function with a loop, like this
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
...
var firstLoopDone bool
for {
select {
case <-quitChan:
return
default:
... if !firstLoopDone {
wg.Done()
firstLoopDone = true
}
}
}
}()
wg.Wait()
The wait group ensures, that the first reading is done for the edge detection. But for the "Finalize()" call the quitChan will be closed immediately and the waitgroup is not done. This is more clean and will fix the problem:
for {
select {
case <-quitChan:
if !firstLoopDone {
wg.Done()
}
return
default:
If "WithHCSR04UseEdgePolling()" is used, stopping the robot by CTRL-C hangs. This is only tested with gpiod driver, not sysfs.
This is caused by the reconfiguration of the pin with this call hierarchy:
The wait group ensures, that the first reading is done for the edge detection. But for the "Finalize()" call the quitChan will be closed immediately and the waitgroup is not done. This is more clean and will fix the problem: