-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathbattery.go
More file actions
38 lines (32 loc) · 798 Bytes
/
Copy pathbattery.go
File metadata and controls
38 lines (32 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package medtronic
import (
"fmt"
)
// Voltage represents the battery voltage in milliVolts.
type Voltage int
func (r Voltage) String() string {
return fmt.Sprintf("%g", float64(r)/1000)
}
// BatteryInfo represents the pump's battery voltage and low-battery state.
type BatteryInfo struct {
Voltage Voltage
LowBattery bool
}
func decodeBatteryInfo(data []byte) BatteryInfo {
return BatteryInfo{
LowBattery: data[1] != 0,
Voltage: Voltage(twoByteInt(data[2:4]) * 10),
}
}
// Battery returns the pump's battery information.
func (pump *Pump) Battery() BatteryInfo {
data := pump.Execute(battery)
if pump.Error() != nil {
return BatteryInfo{}
}
if len(data) < 4 || data[0] != 3 {
pump.BadResponse(battery, data)
return BatteryInfo{}
}
return decodeBatteryInfo(data)
}