forked from Elara6331/infinitime
Compare commits
No commits in common. "d20e8af00e0307c4cbd9923fe3671f06f7bb2ea3" and "5fb5cf4b928bb0962a4c17fd94ea63eb8a98139b" have entirely different histories.
d20e8af00e
...
5fb5cf4b92
@ -33,7 +33,6 @@ const (
|
|||||||
MotionValChar = "00030002-78fc-48fe-8e23-433b3a1942d0"
|
MotionValChar = "00030002-78fc-48fe-8e23-433b3a1942d0"
|
||||||
FirmwareVerChar = "00002a26-0000-1000-8000-00805f9b34fb"
|
FirmwareVerChar = "00002a26-0000-1000-8000-00805f9b34fb"
|
||||||
CurrentTimeChar = "00002a2b-0000-1000-8000-00805f9b34fb"
|
CurrentTimeChar = "00002a2b-0000-1000-8000-00805f9b34fb"
|
||||||
LocalTimeChar = "00002a0f-0000-1000-8000-00805f9b34fb"
|
|
||||||
BatteryLvlChar = "00002a19-0000-1000-8000-00805f9b34fb"
|
BatteryLvlChar = "00002a19-0000-1000-8000-00805f9b34fb"
|
||||||
HeartRateChar = "00002a37-0000-1000-8000-00805f9b34fb"
|
HeartRateChar = "00002a37-0000-1000-8000-00805f9b34fb"
|
||||||
FSTransferChar = "adaf0200-4669-6c65-5472-616e73666572"
|
FSTransferChar = "adaf0200-4669-6c65-5472-616e73666572"
|
||||||
@ -48,7 +47,6 @@ var charNames = map[string]string{
|
|||||||
MotionValChar: "Motion Values",
|
MotionValChar: "Motion Values",
|
||||||
FirmwareVerChar: "Firmware Version",
|
FirmwareVerChar: "Firmware Version",
|
||||||
CurrentTimeChar: "Current Time",
|
CurrentTimeChar: "Current Time",
|
||||||
LocalTimeChar: "Local Time",
|
|
||||||
BatteryLvlChar: "Battery Level",
|
BatteryLvlChar: "Battery Level",
|
||||||
HeartRateChar: "Heart Rate",
|
HeartRateChar: "Heart Rate",
|
||||||
FSTransferChar: "Filesystem Transfer",
|
FSTransferChar: "Filesystem Transfer",
|
||||||
@ -68,7 +66,6 @@ type Device struct {
|
|||||||
motionValChar *gatt.GattCharacteristic1
|
motionValChar *gatt.GattCharacteristic1
|
||||||
fwVersionChar *gatt.GattCharacteristic1
|
fwVersionChar *gatt.GattCharacteristic1
|
||||||
currentTimeChar *gatt.GattCharacteristic1
|
currentTimeChar *gatt.GattCharacteristic1
|
||||||
localTimeChar *gatt.GattCharacteristic1
|
|
||||||
battLevelChar *gatt.GattCharacteristic1
|
battLevelChar *gatt.GattCharacteristic1
|
||||||
heartRateChar *gatt.GattCharacteristic1
|
heartRateChar *gatt.GattCharacteristic1
|
||||||
fsVersionChar *gatt.GattCharacteristic1
|
fsVersionChar *gatt.GattCharacteristic1
|
||||||
@ -424,8 +421,6 @@ func (i *Device) resolveChars() error {
|
|||||||
i.fwVersionChar = char
|
i.fwVersionChar = char
|
||||||
case CurrentTimeChar:
|
case CurrentTimeChar:
|
||||||
i.currentTimeChar = char
|
i.currentTimeChar = char
|
||||||
case LocalTimeChar:
|
|
||||||
i.localTimeChar = char
|
|
||||||
case BatteryLvlChar:
|
case BatteryLvlChar:
|
||||||
i.battLevelChar = char
|
i.battLevelChar = char
|
||||||
case HeartRateChar:
|
case HeartRateChar:
|
||||||
@ -713,9 +708,7 @@ func (i *Device) WatchMotion(ctx context.Context) (<-chan MotionValues, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTime sets the watch's
|
// SetTime sets the watch's time using the Current Time Service
|
||||||
// * time using the Current Time Service's current time characteristic
|
|
||||||
// * timezone information using the CTS's local time characteristic
|
|
||||||
func (i *Device) SetTime(t time.Time) error {
|
func (i *Device) SetTime(t time.Time) error {
|
||||||
if err := i.checkStatus(i.currentTimeChar, CurrentTimeChar); err != nil {
|
if err := i.checkStatus(i.currentTimeChar, CurrentTimeChar); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -730,38 +723,7 @@ func (i *Device) SetTime(t time.Time) error {
|
|||||||
binary.Write(buf, binary.LittleEndian, uint8(t.Weekday()))
|
binary.Write(buf, binary.LittleEndian, uint8(t.Weekday()))
|
||||||
binary.Write(buf, binary.LittleEndian, uint8((t.Nanosecond()/1000)/1e6*256))
|
binary.Write(buf, binary.LittleEndian, uint8((t.Nanosecond()/1000)/1e6*256))
|
||||||
binary.Write(buf, binary.LittleEndian, uint8(0b0001))
|
binary.Write(buf, binary.LittleEndian, uint8(0b0001))
|
||||||
if err := i.currentTimeChar.WriteValue(buf.Bytes(), nil); err != nil {
|
return i.currentTimeChar.WriteValue(buf.Bytes(), nil)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := i.checkStatus(i.localTimeChar, LocalTimeChar); err != nil {
|
|
||||||
// If the characteristic is unavailable,
|
|
||||||
// fail silently, as many people may be on
|
|
||||||
// older InfiniTime versions. A warning
|
|
||||||
// may be added later.
|
|
||||||
if _, ok := err.(ErrCharNotAvail); ok {
|
|
||||||
return nil
|
|
||||||
} else {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_, offset := t.Zone()
|
|
||||||
dst := 0
|
|
||||||
|
|
||||||
// Local time expects two values: the timezone offset and the dst offset, both
|
|
||||||
// expressed in quarters of an hour.
|
|
||||||
// Timezone offset is to be constant over DST, with dst offset holding the offset != 0
|
|
||||||
// when DST is in effect.
|
|
||||||
// As there is no standard way in go to get the actual dst offset, we assume it to be 1h
|
|
||||||
// when DST is in effect
|
|
||||||
if t.IsDST() {
|
|
||||||
dst = 3600
|
|
||||||
offset -= 3600
|
|
||||||
}
|
|
||||||
bufTz := &bytes.Buffer{}
|
|
||||||
binary.Write(bufTz, binary.LittleEndian, uint8(offset / 3600 * 4))
|
|
||||||
binary.Write(bufTz, binary.LittleEndian, uint8(dst / 3600 * 4))
|
|
||||||
return i.localTimeChar.WriteValue(bufTz.Bytes(), nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify sends a notification to InfiniTime via
|
// Notify sends a notification to InfiniTime via
|
||||||
|
Loading…
Reference in New Issue
Block a user