Skip to content

Commit

Permalink
Merge pull request #3 from sworisbreathing/battery-endianness
Browse files Browse the repository at this point in the history
Process battery levels as big-endian values instead of little-endian.
  • Loading branch information
sworisbreathing authored May 11, 2019
2 parents dde41cf + d8ab7f3 commit 1d7c8c3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions ibbq/ibbq.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ func (ibbq *Ibbq) settingResultReceived() ble.NotificationHandler {
switch data[0] {
case 0x24:
// battery
currentVoltage := int(binary.LittleEndian.Uint16(data[1:3]))
maxVoltage := int(binary.LittleEndian.Uint16(data[3:5]))
currentVoltage := int(binary.BigEndian.Uint16(data[1:3]))
maxVoltage := int(binary.BigEndian.Uint16(data[3:5]))
if maxVoltage == 0 {
maxVoltage = 6550
maxVoltage = 65535
}
batteryPct := 100 * currentVoltage / maxVoltage
go ibbq.batteryLevelReceivedHandler(batteryPct)
Expand Down

0 comments on commit 1d7c8c3

Please # to comment.