Added Navigation service #5
@ -62,6 +62,41 @@ var charNames = map[string]string{
|
|||||||
NavProgressChar: "Navigation Progress",
|
NavProgressChar: "Navigation Progress",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var NavFlagNames = []string{
|
||||||
|
"arrive", "arrive-left", "arrive-right", "arrive-straight",
|
||||||
|
"close",
|
||||||
|
"continue", "continue-left", "continue-right", "continue-slight-left",
|
||||||
|
"continue-slight-right", "continue-straight", "continue-uturn",
|
||||||
|
"depart", "depart-left", "depart-right", "depart-straight",
|
||||||
|
"end-of-road-left", "end-of-road-right",
|
||||||
|
"ferry", "flag",
|
||||||
|
"fork", "fork-left", "fork-right", "fork-straight",
|
||||||
|
"fork-slight-left", "fork-slight-right",
|
||||||
|
"invalid", "invalid-left", "invalid-right",
|
||||||
|
"invalid-slight-left", "invalid-slight-right",
|
||||||
|
"invalid-straight", "invalid-uturn",
|
||||||
|
"merge-left", "merge-right", "merge-slight-left",
|
||||||
|
"merge-slight-right", "merge-straight",
|
||||||
|
"new-name-left", "new-name-right", "new-name-sharp-left", "new-name-sharp-right",
|
||||||
|
"new-name-slight-left", "new-name-slight-right", "new-name-straight",
|
||||||
|
"notification-left", "notification-right",
|
||||||
|
"notification-sharp-left", "notification-sharp-right",
|
||||||
|
"notification-slight-left", "notification-slight-right",
|
||||||
|
"notification-straight",
|
||||||
|
"off-ramp-left", "off-ramp-right", "off-ramp-sharp-left", "off-ramp-sharp-right",
|
||||||
|
"off-ramp-slight-left", "off-ramp-slight-right", "off-ramp-straight",
|
||||||
|
"on-ramp-left", "on-ramp-right", "on-ramp-sharp-left", "on-ramp-sharp-right",
|
||||||
|
"on-ramp-slight-left", "on-ramp-slight-right", "on-ramp-straight",
|
||||||
|
"rotary", "rotary-left", "rotary-right", "rotary-sharp-left", "rotary-sharp-right",
|
||||||
|
"rotary-slight-left", "rotary-slight-right", "rotary-straight",
|
||||||
|
"roundabout", "roundabout-left", "roundabout-right",
|
||||||
|
"roundabout-sharp-left", "roundabout-sharp-right",
|
||||||
|
"roundabout-slight-left", "roundabout-slight-right", "roundabout-straight",
|
||||||
|
"turn-left", "turn-right", "turn-sharp-left", "turn-sharp-right",
|
||||||
|
"turn-slight-left", "turn-slight-right", "turn-stright",
|
||||||
|
"updown", "uturn",
|
||||||
|
}
|
||||||
|
|
||||||
type NavigationEvent struct {
|
type NavigationEvent struct {
|
||||||
flag string
|
flag string
|
||||||
narrative string
|
narrative string
|
||||||
@ -99,6 +134,8 @@ var (
|
|||||||
ErrNotConnected = errors.New("not connected")
|
ErrNotConnected = errors.New("not connected")
|
||||||
ErrNoTimelineHeader = errors.New("events must contain the timeline header")
|
ErrNoTimelineHeader = errors.New("events must contain the timeline header")
|
||||||
ErrPairTimeout = errors.New("reached timeout while pairing")
|
ErrPairTimeout = errors.New("reached timeout while pairing")
|
||||||
|
ErrNavProgress = errors.New("progress needs to between 0 and 100")
|
||||||
|
ErrNavInvalidFlag = errors.New("this flag is invalid")
|
||||||
)
|
)
|
||||||
|
|
||||||
type ErrCharNotAvail struct {
|
type ErrCharNotAvail struct {
|
||||||
@ -751,8 +788,24 @@ func (i *Device) Notify(title, body string) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckValidNavFlag(flag string) error {
|
||||||
|
for _, v := range NavFlagNames {
|
||||||
|
if v == flag {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ErrNavInvalidFlag
|
||||||
|
}
|
||||||
|
|
||||||
// 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 progress > 100 {
|
||||||
|
return ErrNavProgress
|
||||||
|
}
|
||||||
|
if err := CheckValidNavFlag(flag); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if flag != i.navigationEv.flag {
|
if flag != i.navigationEv.flag {
|
||||||
log.Debug().Str("func", "Navigation").
|
log.Debug().Str("func", "Navigation").
|
||||||
Msg("Sending flag")
|
Msg("Sending flag")
|
||||||
|
Reference in New Issue
Block a user