refactor: remove init() and package-level rootCmd, add error logging
- Move flag registration from init() to main() - Make rootCmd a local variable in main() instead of a package variable - Log errors from hciconfig down/up reset commands - Log errors from BLE power characteristic writes
This commit is contained in:
@@ -72,7 +72,9 @@ func ExposeBluetooth(events <-chan Event) {
|
||||
binary.LittleEndian.PutUint16(payload[4:], uint16(completedRevs))
|
||||
binary.LittleEndian.PutUint16(payload[6:], uint16(lastCompletedRev))
|
||||
|
||||
powerChar.Write(payload)
|
||||
if _, err := powerChar.Write(payload); err != nil {
|
||||
logPrintf("bt: failed to write power characteristic: %v\n", err)
|
||||
}
|
||||
logPrintf("bt: watts: %d rpm: %.0f completedRevs: %.0f lastRevTime: %.0f processingTime: %v\n",
|
||||
watts, rpm, completedRevs, lastCompletedRev, time.Now().Sub(now))
|
||||
}
|
||||
|
||||
+6
-2
@@ -66,8 +66,12 @@ This allows these trainers to be used with modern devices that don't support ANT
|
||||
logMsgf("product: 0x%04x/%d", productID, productID)
|
||||
logMsgf("device: 0x%03x/%d", deviceNumber, deviceNumber)
|
||||
|
||||
exec.Command("hciconfig", "hci0", "down").Run()
|
||||
exec.Command("hciconfig", "hci0", "up").Run()
|
||||
if err := exec.Command("hciconfig", "hci0", "down").Run(); err != nil {
|
||||
logPrintf("hciconfig down failed: %v\n", err)
|
||||
}
|
||||
if err := exec.Command("hciconfig", "hci0", "up").Run(); err != nil {
|
||||
logPrintf("hciconfig up failed: %v\n", err)
|
||||
}
|
||||
|
||||
events := make(chan Event)
|
||||
go ListenForTrainer(uint16(c.vendorID), uint16(c.productID), c.deviceNumber, events)
|
||||
|
||||
Reference in New Issue
Block a user