You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I'd like to contribute again and implement functionality inspired by this bcm2835 lib example.
(In my eyes this has higher priority than software pwm duscussed in #20)
Reason
The use case is, when you want to detect short input signal, eg. fast button press (or something much much shorter), and you don't want to waste much CPU (prevent rapid pooling), but you don't mind waiting a bit to actually process the action.
Let's say the button accuation time when pressed may be as short as 10ms. In current stage, only way to reliably detect it is to sample input every 5ms, like in following example.
pin.Input()
for {
ifpin.Read() ==rpio.High {
println("button pressed")
}
time.Sleep(5*time.Millisecond) // wait time determines shortes detectable signal length
}
This is not much CPU effecient for long running instances.
Solution
I propose to use rise/fall edge event detection (without interruption handling like in github.com/brian-armstrong/gpio, but it would still be an improvement).
Two new pin method would be implemented. (Better naming ideas are welcomed).
func(pin) Detect(edge) - for enabling/disabling detection of rising and/or falling edge event
It would write to GPREN and GPFEN registers - this functionality scans pins using clock and detect 011 and/or 100 patterns.
The edge argument would be one of: NoEdge, RiseEdge, FallEdge, AnyEdge.
func(pin) EdgeDetected() bool - for checking if event has occured since last call
done by reading and cleaning bits of GPEDS register
Example of usage:
pin.Input()
pin.Detect(rpio.RiseEdge)
for {
ifpin.EdgeDetected() {
prinln("button pressed")
}
time.Sleep(500*time.Millisecond)
// wait time only affect user experience; signal length may be as short as two CLK ticks
}
In the future this functionaluty might be extended over intteruption handling using blocking channel, which would avoid the neccessity to use any sleeps.
I will create pull request soon, if there are no objections.
The text was updated successfully, but these errors were encountered:
Hi, I'd like to contribute again and implement functionality inspired by this bcm2835 lib example.
(In my eyes this has higher priority than software pwm duscussed in #20)
Reason
The use case is, when you want to detect short input signal, eg. fast button press (or something much much shorter), and you don't want to waste much CPU (prevent rapid pooling), but you don't mind waiting a bit to actually process the action.
Let's say the button accuation time when pressed may be as short as 10ms. In current stage, only way to reliably detect it is to sample input every 5ms, like in following example.
This is not much CPU effecient for long running instances.
Solution
I propose to use rise/fall edge event detection (without interruption handling like in github.com/brian-armstrong/gpio, but it would still be an improvement).
Two new pin method would be implemented. (Better naming ideas are welcomed).
func(pin) Detect(edge)
- for enabling/disabling detection of rising and/or falling edge eventGPREN
andGPFEN
registers - this functionality scans pins using clock and detect011
and/or100
patterns.edge
argument would be one of:NoEdge
,RiseEdge
,FallEdge
,AnyEdge
.func(pin) EdgeDetected() bool
- for checking if event has occured since last callGPEDS
registerExample of usage:
It would (partially) solve issues #18.
In the future this functionaluty might be extended over intteruption handling using blocking channel, which would avoid the neccessity to use any sleeps.
I will create pull request soon, if there are no objections.
The text was updated successfully, but these errors were encountered: