forked from Elara6331/infinitime
Remove check for unchanged values and refactor code
This commit is contained in:
parent
0aa25353fd
commit
9e73961af9
@ -53,7 +53,7 @@ var charNames = map[string]string{
|
|||||||
FSVersionChar: "Filesystem Version",
|
FSVersionChar: "Filesystem Version",
|
||||||
WeatherDataChar: "Weather Data",
|
WeatherDataChar: "Weather Data",
|
||||||
NavFlagsChar: "Navigation Icon",
|
NavFlagsChar: "Navigation Icon",
|
||||||
NavNarrativeChar:"Navigation Instruction",
|
NavNarrativeChar: "Navigation Instruction",
|
||||||
NavManDistChar: "Navigation Distance to next event",
|
NavManDistChar: "Navigation Distance to next event",
|
||||||
NavProgressChar: "Navigation Progress",
|
NavProgressChar: "Navigation Progress",
|
||||||
}
|
}
|
||||||
@ -75,9 +75,8 @@ type Device struct {
|
|||||||
notifEventCh chan uint8
|
notifEventCh chan uint8
|
||||||
notifEventDone bool
|
notifEventDone bool
|
||||||
Music MusicCtrl
|
Music MusicCtrl
|
||||||
Navigation NavigationCtrl
|
Navigation NavigationService
|
||||||
DFU DFU
|
DFU DFU
|
||||||
navigationEv NavigationEvent
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -738,7 +737,6 @@ func (i *Device) Notify(title, body string) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// These constants represent the possible call statuses selected by the user
|
// These constants represent the possible call statuses selected by the user
|
||||||
const (
|
const (
|
||||||
CallStatusDeclined uint8 = iota
|
CallStatusDeclined uint8 = iota
|
||||||
|
@ -1,27 +1,26 @@
|
|||||||
package infinitime
|
package infinitime
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/binary"
|
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/muka/go-bluetooth/bluez/profile/gatt"
|
"github.com/muka/go-bluetooth/bluez/profile/gatt"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NavFlagsChar = "00010001-78fc-48fe-8e23-433b3a1942d0"
|
NavFlagsChar = "00010001-78fc-48fe-8e23-433b3a1942d0"
|
||||||
NavNarrativeChar= "00010002-78fc-48fe-8e23-433b3a1942d0"
|
NavNarrativeChar = "00010002-78fc-48fe-8e23-433b3a1942d0"
|
||||||
NavManDistChar = "00010003-78fc-48fe-8e23-433b3a1942d0"
|
NavManDistChar = "00010003-78fc-48fe-8e23-433b3a1942d0"
|
||||||
NavProgressChar = "00010004-78fc-48fe-8e23-433b3a1942d0"
|
NavProgressChar = "00010004-78fc-48fe-8e23-433b3a1942d0"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NavigationCtrl struct {
|
type NavigationService struct {
|
||||||
flagsChar *gatt.GattCharacteristic1
|
flagsChar *gatt.GattCharacteristic1
|
||||||
narrativeChar*gatt.GattCharacteristic1
|
narrativeChar *gatt.GattCharacteristic1
|
||||||
mandistChar *gatt.GattCharacteristic1
|
mandistChar *gatt.GattCharacteristic1
|
||||||
progressChar *gatt.GattCharacteristic1
|
progressChar *gatt.GattCharacteristic1
|
||||||
}
|
}
|
||||||
|
|
||||||
type NavFlag string
|
type NavFlag string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NavFlagArrive NavFlag = "arrive"
|
NavFlagArrive NavFlag = "arrive"
|
||||||
NavFlagArriveLeft NavFlag = "arrive-left"
|
NavFlagArriveLeft NavFlag = "arrive-left"
|
||||||
@ -123,10 +122,7 @@ type NavigationEvent struct {
|
|||||||
Progress uint8
|
Progress uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var ErrNavProgress = errors.New("progress needs to between 0 and 100")
|
||||||
ErrNavProgress = errors.New("progress needs to between 0 and 100")
|
|
||||||
ErrNavInvalidFlag = errors.New("this flag is invalid")
|
|
||||||
)
|
|
||||||
|
|
||||||
// Navigation sends a NavigationEvent to the watch
|
// Navigation sends a NavigationEvent to the watch
|
||||||
func (i *Device) SetNavigation(ev NavigationEvent) error {
|
func (i *Device) SetNavigation(ev NavigationEvent) error {
|
||||||
@ -134,55 +130,37 @@ func (i *Device) SetNavigation(ev NavigationEvent) error {
|
|||||||
return ErrNavProgress
|
return ErrNavProgress
|
||||||
}
|
}
|
||||||
|
|
||||||
if ev.Flag != i.navigationEv.Flag {
|
log.Debug().Str("func", "SetNavigation").Msg("Sending flag")
|
||||||
log.Debug().Str("func", "Navigation").
|
|
||||||
Msg("Sending flag")
|
|
||||||
if err := i.checkStatus(i.Navigation.flagsChar, NavFlagsChar); err != nil {
|
if err := i.checkStatus(i.Navigation.flagsChar, NavFlagsChar); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := i.Navigation.flagsChar.WriteValue([]byte(ev.Flag), nil); err != nil {
|
if err := i.Navigation.flagsChar.WriteValue([]byte(ev.Flag), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.Flag = ev.Flag
|
|
||||||
}
|
|
||||||
|
|
||||||
if ev.Narrative != i.navigationEv.Narrative {
|
log.Debug().Str("func", "SetNavigation").Msg("Sending narrative")
|
||||||
log.Debug().Str("func", "Navigation").
|
|
||||||
Msg("Sending narrative")
|
|
||||||
if err := i.checkStatus(i.Navigation.narrativeChar, NavNarrativeChar); err != nil {
|
if err := i.checkStatus(i.Navigation.narrativeChar, NavNarrativeChar); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := i.Navigation.narrativeChar.WriteValue([]byte(ev.Narrative), nil); err != nil {
|
if err := i.Navigation.narrativeChar.WriteValue([]byte(ev.Narrative), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.Narrative = ev.Narrative
|
|
||||||
}
|
|
||||||
|
|
||||||
if ev.Dist != i.navigationEv.Dist {
|
log.Debug().Str("func", "SetNavigation").Msg("Sending mandist")
|
||||||
log.Debug().Str("func", "Navigation").
|
|
||||||
Msg("Sending mandist")
|
|
||||||
if err := i.checkStatus(i.Navigation.mandistChar, NavManDistChar); err != nil {
|
if err := i.checkStatus(i.Navigation.mandistChar, NavManDistChar); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := i.Navigation.mandistChar.WriteValue([]byte(ev.Dist), nil); err != nil {
|
if err := i.Navigation.mandistChar.WriteValue([]byte(ev.Dist), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.Dist = ev.Dist
|
|
||||||
}
|
|
||||||
|
|
||||||
if ev.Progress != i.navigationEv.Progress {
|
log.Debug().Str("func", "SetNavigation").Msg("Sending progress")
|
||||||
log.Debug().Str("func", "Navigation").
|
|
||||||
Msg("Sending progress")
|
|
||||||
if err := i.checkStatus(i.Navigation.progressChar, NavProgressChar); err != nil {
|
if err := i.checkStatus(i.Navigation.progressChar, NavProgressChar); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
buf := &bytes.Buffer{}
|
if err := i.Navigation.progressChar.WriteValue([]byte{ev.Progress}, nil); err != nil {
|
||||||
binary.Write(buf, binary.LittleEndian, ev.Progress)
|
|
||||||
if err := i.Navigation.progressChar.WriteValue(buf.Bytes(), nil); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.Progress = ev.Progress
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user