Added Navigation service #5

Merged
Elara6331 merged 9 commits from yannickulrich/infinitime:navigation-service into master 2022-11-03 19:09:07 +00:00
Showing only changes of commit c3a87278a6 - Show all commits

View File

@ -117,10 +117,10 @@ const (
)
type NavigationEvent struct {
flag NavFlag
narrative string
dist string
progress uint8
Flag NavFlag
Narrative string
Dist string
Progress uint8
}
var (
@ -129,59 +129,59 @@ var (
)
// Navigation sends a NavigationEvent to the watch
func (i *Device) SetNavigation(flag NavFlag, narrative string, dist string, progress uint8) error {
if progress > 100 {
func (i *Device) SetNavigation(ev NavigationEvent) error {
if ev.Progress > 100 {
return ErrNavProgress
}
if flag != i.navigationEv.flag {
if ev.Flag != i.navigationEv.Flag {
log.Debug().Str("func", "Navigation").
Msg("Sending flag")
if err := i.checkStatus(i.Navigation.flagsChar, NavFlagsChar); err != nil {
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
}
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").
Msg("Sending narrative")
if err := i.checkStatus(i.Navigation.narrativeChar, NavNarrativeChar); err != nil {
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
}
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").
Msg("Sending mandist")
if err := i.checkStatus(i.Navigation.mandistChar, NavManDistChar); err != nil {
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
}
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").
Msg("Sending progress")
if err := i.checkStatus(i.Navigation.progressChar, NavProgressChar); err != nil {
return err
}
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 {
return err
}
i.navigationEv.progress = progress
i.navigationEv.Progress = ev.Progress
}
return nil