Added Navigation service #5
@ -117,10 +117,10 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NavigationEvent struct {
|
type NavigationEvent struct {
|
||||||
flag NavFlag
|
Flag NavFlag
|
||||||
narrative string
|
Narrative string
|
||||||
dist string
|
Dist string
|
||||||
progress uint8
|
Progress uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -129,59 +129,59 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Navigation sends a NavigationEvent to the watch
|
// Navigation sends a NavigationEvent to the watch
|
||||||
func (i *Device) SetNavigation(flag NavFlag, narrative string, dist string, progress uint8) error {
|
func (i *Device) SetNavigation(ev NavigationEvent) error {
|
||||||
if progress > 100 {
|
if ev.Progress > 100 {
|
||||||
return ErrNavProgress
|
return ErrNavProgress
|
||||||
}
|
}
|
||||||
|
|
||||||
if flag != i.navigationEv.flag {
|
if ev.Flag != i.navigationEv.Flag {
|
||||||
log.Debug().Str("func", "Navigation").
|
log.Debug().Str("func", "Navigation").
|
||||||
Msg("Sending flag")
|
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(flag), nil); err != nil {
|
if err := i.Navigation.flagsChar.WriteValue([]byte(ev.Flag), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.flag = flag
|
i.navigationEv.Flag = ev.Flag
|
||||||
}
|
}
|
||||||
|
|
||||||
if narrative != i.navigationEv.narrative {
|
if ev.Narrative != i.navigationEv.Narrative {
|
||||||
log.Debug().Str("func", "Navigation").
|
log.Debug().Str("func", "Navigation").
|
||||||
Msg("Sending narrative")
|
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(narrative), nil); err != nil {
|
if err := i.Navigation.narrativeChar.WriteValue([]byte(ev.Narrative), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.narrative = narrative
|
i.navigationEv.Narrative = ev.Narrative
|
||||||
}
|
}
|
||||||
|
|
||||||
if dist != i.navigationEv.dist {
|
if ev.Dist != i.navigationEv.Dist {
|
||||||
log.Debug().Str("func", "Navigation").
|
log.Debug().Str("func", "Navigation").
|
||||||
Msg("Sending mandist")
|
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(dist), nil); err != nil {
|
if err := i.Navigation.mandistChar.WriteValue([]byte(ev.Dist), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.dist = dist
|
i.navigationEv.Dist = ev.Dist
|
||||||
}
|
}
|
||||||
|
|
||||||
if progress != i.navigationEv.progress {
|
if ev.Progress != i.navigationEv.Progress {
|
||||||
log.Debug().Str("func", "Navigation").
|
log.Debug().Str("func", "Navigation").
|
||||||
Msg("Sending progress")
|
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{}
|
buf := &bytes.Buffer{}
|
||||||
binary.Write(buf, binary.LittleEndian, progress)
|
binary.Write(buf, binary.LittleEndian, ev.Progress)
|
||||||
if err := i.Navigation.progressChar.WriteValue(buf.Bytes(), nil); err != nil {
|
if err := i.Navigation.progressChar.WriteValue(buf.Bytes(), nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
i.navigationEv.progress = progress
|
i.navigationEv.Progress = ev.Progress
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user