logging with date time format.
This commit is contained in:
parent
29d7dc1632
commit
39b5a95eb4
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/google/gousb"
|
||||
@ -35,7 +34,7 @@ func ListenForTrainer(vendorId gousb.ID, productId gousb.ID, deviceNumber uint32
|
||||
}
|
||||
defer drv.Close()
|
||||
|
||||
fmt.Println("device opened")
|
||||
logMsg("device opened")
|
||||
|
||||
if err := resetAndWait(drv); err != nil {
|
||||
panic(err)
|
||||
@ -43,15 +42,15 @@ func ListenForTrainer(vendorId gousb.ID, productId gousb.ID, deviceNumber uint32
|
||||
if err := device.StartRxScanModeWait(drv); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println("scan mode started")
|
||||
logMsg("scan mode started")
|
||||
|
||||
msgs := make(chan ant.BroadcastMessage, 100)
|
||||
go device.DumpBroadcastMessages(context.Background(), drv, msgs)
|
||||
|
||||
fmt.Println("listening...")
|
||||
logMsg("listening...")
|
||||
for msg := range msgs {
|
||||
if msg.DeviceNumber() != deviceNumber {
|
||||
fmt.Printf("Received msg from ignored ant+ device %v\n", msg.DeviceNumber())
|
||||
logPrintf("Received msg from ignored ant+ device %v\n", msg.DeviceNumber())
|
||||
continue
|
||||
}
|
||||
//fmt.Printf("raw msg: device type=0x%02x device number=%d content=%x\n",
|
||||
@ -65,7 +64,7 @@ func ListenForTrainer(vendorId gousb.ID, productId gousb.ID, deviceNumber uint32
|
||||
continue
|
||||
}
|
||||
cur := ant.PowerMessage(msg)
|
||||
fmt.Printf("%v: power: %dW cadence: %d rpm\n",
|
||||
logPrintf("ant: %v: power: %dW cadence: %d rpm\n",
|
||||
msg.DeviceNumber(), cur.InstantaneousPower(), cur.InstantaneousCadence())
|
||||
events <- Event{
|
||||
Power: cur.InstantaneousPower(),
|
||||
|
||||
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
@ -43,7 +42,7 @@ func ExposeBluetooth(events <-chan Event) {
|
||||
ServiceUUIDs: []bluetooth.UUID{bluetooth.New16BitUUID(0x1818)},
|
||||
}))
|
||||
must(adapter.DefaultAdvertisement().Start())
|
||||
fmt.Println("BLE advertising...")
|
||||
logMsg("BLE advertising...")
|
||||
|
||||
var totalRevs float64
|
||||
var lastCompletedRev float64 // time in 1/1024s of last completed revolution
|
||||
@ -74,7 +73,7 @@ func ExposeBluetooth(events <-chan Event) {
|
||||
binary.LittleEndian.PutUint16(payload[6:], uint16(lastCompletedRev))
|
||||
|
||||
powerChar.Write(payload)
|
||||
fmt.Printf("watts: %d rpm: %.0f completedRevs: %.0f lastRevTime: %.0f\n",
|
||||
watts, rpm, completedRevs, lastCompletedRev)
|
||||
logPrintf("bt: watts: %d rpm: %.0f completedRevs: %.0f lastRevTime: %.0f processingTime: %v\n",
|
||||
watts, rpm, completedRevs, lastCompletedRev, time.Now().Sub(now))
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user