Now using the original time that the event was received instead of when
it is processed by bluetooth.
This commit is contained in:
parent
87ba3cdba7
commit
7644ab2e4d
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/google/gousb"
|
"github.com/google/gousb"
|
||||||
"github.com/half2me/antgo/ant"
|
"github.com/half2me/antgo/ant"
|
||||||
@ -77,6 +78,7 @@ func ListenForTrainer(vendorId uint16, productId uint16, deviceNumber uint32,
|
|||||||
case events <- Event{
|
case events <- Event{
|
||||||
Power: cur.InstantaneousPower(),
|
Power: cur.InstantaneousPower(),
|
||||||
Cadence: cur.InstantaneousCadence(),
|
Cadence: cur.InstantaneousCadence(),
|
||||||
|
Now: time.Now(),
|
||||||
}:
|
}:
|
||||||
default:
|
default:
|
||||||
logPrintf("ant: dropped event, buffer full\n")
|
logPrintf("ant: dropped event, buffer full\n")
|
||||||
|
|||||||
@ -56,7 +56,7 @@ func ExposeBluetooth(events <-chan Event) {
|
|||||||
lastUpdate := time.Now()
|
lastUpdate := time.Now()
|
||||||
var elapsedTicks float64
|
var elapsedTicks float64
|
||||||
for event := range events {
|
for event := range events {
|
||||||
now := time.Now()
|
now := event.Now
|
||||||
deltaT := now.Sub(lastUpdate).Seconds()
|
deltaT := now.Sub(lastUpdate).Seconds()
|
||||||
lastUpdate = now
|
lastUpdate = now
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ func ExposeBluetooth(events <-chan Event) {
|
|||||||
if _, err := powerChar.Write(payload); err != nil {
|
if _, err := powerChar.Write(payload); err != nil {
|
||||||
logPrintf("bt: failed to write power characteristic: %v\n", err)
|
logPrintf("bt: failed to write power characteristic: %v\n", err)
|
||||||
}
|
}
|
||||||
logPrintf("bt: watts: %d rpm: %.0f completedRevs: %.0f lastRevTime: %.0f processingTime: %v\n",
|
logPrintf("bt: watts: %d rpm: %.0f completedRevs: %.0f lastRevTime: %.0f processingDelay: %v\n",
|
||||||
watts, rpm, completedRevs, lastCompletedRev, time.Now().Sub(now))
|
watts, rpm, completedRevs, lastCompletedRev, time.Now().Sub(now))
|
||||||
}
|
}
|
||||||
logMsg("bt: BLE advertising stopped")
|
logMsg("bt: BLE advertising stopped")
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Power uint16
|
Power uint16
|
||||||
Cadence uint8
|
Cadence uint8
|
||||||
|
Now time.Time
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user