Remove check for unchanged values and refactor code
This commit is contained in:
parent
0aa25353fd
commit
9e73961af9
@ -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,8 +1,6 @@
|
|||||||
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"
|
||||||
)
|
)
|
||||||
@ -14,7 +12,7 @@ const (
|
|||||||
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
|
||||||
@ -22,6 +20,7 @@ type NavigationCtrl struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user