mirror of
https://github.com/kidoman/embd
synced 2024-12-22 21:00:05 +01:00
l3gd20: reset the timer after reading gyro reading
This commit is contained in:
parent
2218fba756
commit
cce1943e34
@ -338,7 +338,11 @@ func (d *L3GD20) Start() (err error) {
|
|||||||
var orientations chan Orientation
|
var orientations chan Orientation
|
||||||
oldTime := time.Now()
|
oldTime := time.Now()
|
||||||
|
|
||||||
timer := time.Tick(time.Duration(d.Poll) * time.Millisecond)
|
var timer <-chan time.Time
|
||||||
|
resetTimer := func() {
|
||||||
|
timer = time.After(time.Duration(d.Poll) * time.Millisecond)
|
||||||
|
}
|
||||||
|
resetTimer()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
@ -355,6 +359,7 @@ func (d *L3GD20) Start() (err error) {
|
|||||||
orientations = d.orientations
|
orientations = d.orientations
|
||||||
}
|
}
|
||||||
oldTime = currTime
|
oldTime = currTime
|
||||||
|
resetTimer()
|
||||||
case orientations <- Orientation{x, y, z}:
|
case orientations <- Orientation{x, y, z}:
|
||||||
orientations = nil
|
orientations = nil
|
||||||
case waitc := <-d.closing:
|
case waitc := <-d.closing:
|
||||||
@ -374,6 +379,7 @@ func (d *L3GD20) Stop() (err error) {
|
|||||||
waitc := make(chan struct{})
|
waitc := make(chan struct{})
|
||||||
d.closing <- waitc
|
d.closing <- waitc
|
||||||
<-waitc
|
<-waitc
|
||||||
|
d.closing = nil
|
||||||
}
|
}
|
||||||
if err = d.Bus.WriteByteToReg(address, ctrlReg1, ctrlReg1Finished); err != nil {
|
if err = d.Bus.WriteByteToReg(address, ctrlReg1, ctrlReg1Finished); err != nil {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user