initial version.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/half2me/antgo/ant"
|
||||
"github.com/half2me/antgo/device"
|
||||
"github.com/half2me/antgo/driver/usb"
|
||||
)
|
||||
|
||||
func main() {
|
||||
drv, err := usb.GetDevice(0x0fcf, 0x1008)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer drv.Close()
|
||||
|
||||
fmt.Println("device opened")
|
||||
|
||||
if err := device.ResetWait(drv); err != nil {
|
||||
panic(fmt.Sprintf("reset failed: %v", err))
|
||||
}
|
||||
fmt.Println("reset ok")
|
||||
|
||||
if err := device.StartRxScanModeWait(drv); err != nil {
|
||||
panic(fmt.Sprintf("scan mode failed: %v", err))
|
||||
}
|
||||
fmt.Println("scan mode started")
|
||||
|
||||
msgs := make(chan ant.BroadcastMessage, 100)
|
||||
go device.DumpBroadcastMessages(context.Background(), drv, msgs)
|
||||
|
||||
fmt.Println("listening...")
|
||||
for msg := range msgs {
|
||||
//fmt.Printf("raw msg: device type=0x%02x device number=%d content=%x\n",
|
||||
// msg.DeviceType(), msg.DeviceNumber(), msg.Content())
|
||||
|
||||
switch msg.DeviceType() {
|
||||
case ant.DEVICE_TYPE_POWER:
|
||||
cur := ant.PowerMessage(msg)
|
||||
fmt.Printf("power: %dW cadence: %d rpm\n", cur.InstantaneousPower(), cur.InstantaneousCadence())
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println("channel closed")
|
||||
}
|
||||
Reference in New Issue
Block a user