1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +01:00

l3gd20: reset the timer after reading gyro reading

This commit is contained in:
Karan Misra 2014-01-09 00:56:44 +05:30
parent 2218fba756
commit cce1943e34

View File

@ -338,7 +338,11 @@ func (d *L3GD20) Start() (err error) {
var orientations chan Orientation
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 {
select {
@ -355,6 +359,7 @@ func (d *L3GD20) Start() (err error) {
orientations = d.orientations
}
oldTime = currTime
resetTimer()
case orientations <- Orientation{x, y, z}:
orientations = nil
case waitc := <-d.closing:
@ -374,6 +379,7 @@ func (d *L3GD20) Stop() (err error) {
waitc := make(chan struct{})
d.closing <- waitc
<-waitc
d.closing = nil
}
if err = d.Bus.WriteByteToReg(address, ctrlReg1, ctrlReg1Finished); err != nil {
return