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 ba3169d1d0 - Show all commits

View File

@ -753,6 +753,17 @@ func (i *Device) Notify(title, body string) error {
// Navigation sends a NavigationEvent to the watch // Navigation sends a NavigationEvent to the watch
func (i *Device) Navigation(flag string, narrative string, dist string, progress uint8) error { func (i *Device) Navigation(flag string, narrative string, dist string, progress uint8) error {
if flag != i.navigationEv.flag {
log.Debug().Str("func", "Navigation").
Msg("Sending flag")
if err := i.checkStatus(i.navflagsChar, NavFlagsChar); err != nil {
return err
}
if err := i.navflagsChar.WriteValue([]byte(flag), nil); err != nil {
return err
}
i.navigationEv.flag = flag
}
if narrative != i.navigationEv.narrative { if narrative != i.navigationEv.narrative {
log.Debug().Str("func", "Navigation"). log.Debug().Str("func", "Navigation").
@ -766,6 +777,32 @@ func (i *Device) Navigation(flag string, narrative string, dist string, progress
i.navigationEv.narrative = narrative i.navigationEv.narrative = narrative
} }
if dist != i.navigationEv.dist {
log.Debug().Str("func", "Navigation").
Msg("Sending mandist")
if err := i.checkStatus(i.navmandistChar, NavManDistChar); err != nil {
return err
}
if err := i.navmandistChar.WriteValue([]byte(dist), nil); err != nil {
return err
}
i.navigationEv.dist = dist
}
if progress != i.navigationEv.progress {
log.Debug().Str("func", "Navigation").
Msg("Sending progress")
if err := i.checkStatus(i.navprogressChar, NavProgressChar); err != nil {
return err
}
buf := &bytes.Buffer{}
binary.Write(buf, binary.LittleEndian, progress)
if err := i.navprogressChar.WriteValue(buf.Bytes(), nil); err != nil {
return err
yannickulrich marked this conversation as resolved Outdated

I'd prefer if this accepted a NavigationEvent rather than individual arguments. That also means all the fields in NavigationEvent should be capitalized to export them.

I'd prefer if this accepted a `NavigationEvent` rather than individual arguments. That also means all the fields in `NavigationEvent` should be capitalized to export them.

Sure! See c3a8727 but also my comment above

Sure! See c3a8727 but also my comment [above](https://gitea.arsenm.dev/Arsen6331/infinitime/pulls/5#issuecomment-322)
}
i.navigationEv.progress = progress
}
return nil return nil
} }