1
0
mirror of https://github.com/cmur2/miflorad.git synced 2026-04-02 16:18:34 +02:00
This commit is contained in:
cn
2018-12-12 07:26:18 +01:00
parent 1fff831652
commit 11971e9274
8 changed files with 86 additions and 184 deletions

View File

@@ -3,6 +3,9 @@ package common
import (
"encoding/binary"
"errors"
"math"
"strconv"
"strings"
"github.com/currantlabs/gatt"
)
@@ -107,3 +110,16 @@ func MifloraRequstSensorData(p gatt.Peripheral) (SensorDataResponse, error) {
Conductivity: binary.LittleEndian.Uint16(bytes[8:10]),
}, nil
}
func (res VersionBatteryResponse) NumericFirmwareVersion() int {
// turns "2.3.4" into 20304
version := 0
parts := strings.Split(res.FirmwareVersion, ".")
for i, part := range parts {
partNumber, err := strconv.Atoi(part)
if err != nil {
version += int(math.Pow10((len(parts)-(i+1))*2)) * partNumber
}
}
return version
}