forked from Elara6331/infinitime
2. Defined NavFlag type
This commit is contained in:
parent
e00a4fce70
commit
d46f5453f6
146
navigation.go
146
navigation.go
@ -21,8 +21,103 @@ type NavigationCtrl struct {
|
||||
progressChar *gatt.GattCharacteristic1
|
||||
}
|
||||
|
||||
type NavFlag string
|
||||
const (
|
||||
NavFlagArrive NavFlag = "arrive"
|
||||
NavFlagArriveLeft NavFlag = "arrive-left"
|
||||
NavFlagArriveRight NavFlag = "arrive-right"
|
||||
NavFlagArriveStraight NavFlag = "arrive-straight"
|
||||
NavFlagClose NavFlag = "close"
|
||||
NavFlagContinue NavFlag = "continue"
|
||||
NavFlagContinueLeft NavFlag = "continue-left"
|
||||
NavFlagContinueRight NavFlag = "continue-right"
|
||||
NavFlagContinueSlightLeft NavFlag = "continue-slight-left"
|
||||
NavFlagContinueSlightRight NavFlag = "continue-slight-right"
|
||||
NavFlagContinueStraight NavFlag = "continue-straight"
|
||||
NavFlagContinueUturn NavFlag = "continue-uturn"
|
||||
NavFlagDepart NavFlag = "depart"
|
||||
NavFlagDepartLeft NavFlag = "depart-left"
|
||||
NavFlagDepartRight NavFlag = "depart-right"
|
||||
NavFlagDepartStraight NavFlag = "depart-straight"
|
||||
NavFlagEndOfRoadLeft NavFlag = "end-of-road-left"
|
||||
NavFlagEndOfRoadRight NavFlag = "end-of-road-right"
|
||||
NavFlagFerry NavFlag = "ferry"
|
||||
NavFlagFlag NavFlag = "flag"
|
||||
NavFlagFork NavFlag = "fork"
|
||||
NavFlagForkLeft NavFlag = "fork-left"
|
||||
NavFlagForkRight NavFlag = "fork-right"
|
||||
NavFlagForkSlightLeft NavFlag = "fork-slight-left"
|
||||
NavFlagForkSlightRight NavFlag = "fork-slight-right"
|
||||
NavFlagForkStraight NavFlag = "fork-straight"
|
||||
NavFlagInvalid NavFlag = "invalid"
|
||||
NavFlagInvalidLeft NavFlag = "invalid-left"
|
||||
NavFlagInvalidRight NavFlag = "invalid-right"
|
||||
NavFlagInvalidSlightLeft NavFlag = "invalid-slight-left"
|
||||
NavFlagInvalidSlightRight NavFlag = "invalid-slight-right"
|
||||
NavFlagInvalidStraight NavFlag = "invalid-straight"
|
||||
NavFlagInvalidUturn NavFlag = "invalid-uturn"
|
||||
NavFlagMergeLeft NavFlag = "merge-left"
|
||||
NavFlagMergeRight NavFlag = "merge-right"
|
||||
NavFlagMergeSlightLeft NavFlag = "merge-slight-left"
|
||||
NavFlagMergeSlightRight NavFlag = "merge-slight-right"
|
||||
NavFlagMergeStraight NavFlag = "merge-straight"
|
||||
NavFlagNewNameLeft NavFlag = "new-name-left"
|
||||
NavFlagNewNameRight NavFlag = "new-name-right"
|
||||
NavFlagNewNameSharpLeft NavFlag = "new-name-sharp-left"
|
||||
NavFlagNewNameSharpRight NavFlag = "new-name-sharp-right"
|
||||
NavFlagNewNameSlightLeft NavFlag = "new-name-slight-left"
|
||||
NavFlagNewNameSlightRight NavFlag = "new-name-slight-right"
|
||||
NavFlagNewNameStraight NavFlag = "new-name-straight"
|
||||
NavFlagNotificationLeft NavFlag = "notification-left"
|
||||
NavFlagNotificationRight NavFlag = "notification-right"
|
||||
NavFlagNotificationSharpLeft NavFlag = "notification-sharp-left"
|
||||
NavFlagNotificationSharpRight NavFlag = "notification-sharp-right"
|
||||
NavFlagNotificationSlightLeft NavFlag = "notification-slight-left"
|
||||
NavFlagNotificationSlightRight NavFlag = "notification-slight-right"
|
||||
NavFlagNotificationStraight NavFlag = "notification-straight"
|
||||
NavFlagOffRampLeft NavFlag = "off-ramp-left"
|
||||
NavFlagOffRampRight NavFlag = "off-ramp-right"
|
||||
NavFlagOffRampSharpLeft NavFlag = "off-ramp-sharp-left"
|
||||
NavFlagOffRampSharpRight NavFlag = "off-ramp-sharp-right"
|
||||
NavFlagOffRampSlightLeft NavFlag = "off-ramp-slight-left"
|
||||
NavFlagOffRampSlightRight NavFlag = "off-ramp-slight-right"
|
||||
NavFlagOffRampStraight NavFlag = "off-ramp-straight"
|
||||
NavFlagOnRampLeft NavFlag = "on-ramp-left"
|
||||
NavFlagOnRampRight NavFlag = "on-ramp-right"
|
||||
NavFlagOnRampSharpLeft NavFlag = "on-ramp-sharp-left"
|
||||
NavFlagOnRampSharpRight NavFlag = "on-ramp-sharp-right"
|
||||
NavFlagOnRampSlightLeft NavFlag = "on-ramp-slight-left"
|
||||
NavFlagOnRampSlightRight NavFlag = "on-ramp-slight-right"
|
||||
NavFlagOnRampStraight NavFlag = "on-ramp-straight"
|
||||
NavFlagRotary NavFlag = "rotary"
|
||||
NavFlagRotaryLeft NavFlag = "rotary-left"
|
||||
NavFlagRotaryRight NavFlag = "rotary-right"
|
||||
NavFlagRotarySharpLeft NavFlag = "rotary-sharp-left"
|
||||
NavFlagRotarySharpRight NavFlag = "rotary-sharp-right"
|
||||
NavFlagRotarySlightLeft NavFlag = "rotary-slight-left"
|
||||
NavFlagRotarySlightRight NavFlag = "rotary-slight-right"
|
||||
NavFlagRotaryStraight NavFlag = "rotary-straight"
|
||||
NavFlagRoundabout NavFlag = "roundabout"
|
||||
NavFlagRoundaboutLeft NavFlag = "roundabout-left"
|
||||
NavFlagRoundaboutRight NavFlag = "roundabout-right"
|
||||
NavFlagRoundaboutSharpLeft NavFlag = "roundabout-sharp-left"
|
||||
NavFlagRoundaboutSharpRight NavFlag = "roundabout-sharp-right"
|
||||
NavFlagRoundaboutSlightLeft NavFlag = "roundabout-slight-left"
|
||||
NavFlagRoundaboutSlightRight NavFlag = "roundabout-slight-right"
|
||||
NavFlagRoundaboutStraight NavFlag = "roundabout-straight"
|
||||
NavFlagTurnLeft NavFlag = "turn-left"
|
||||
NavFlagTurnRight NavFlag = "turn-right"
|
||||
NavFlagTurnSharpLeft NavFlag = "turn-sharp-left"
|
||||
NavFlagTurnSharpRight NavFlag = "turn-sharp-right"
|
||||
NavFlagTurnSlightLeft NavFlag = "turn-slight-left"
|
||||
NavFlagTurnSlightRight NavFlag = "turn-slight-right"
|
||||
NavFlagTurnStright NavFlag = "turn-stright"
|
||||
NavFlagUpdown NavFlag = "updown"
|
||||
NavFlagUturn NavFlag = "uturn"
|
||||
)
|
||||
|
||||
type NavigationEvent struct {
|
||||
flag string
|
||||
flag NavFlag
|
||||
narrative string
|
||||
dist string
|
||||
progress uint8
|
||||
@ -33,58 +128,11 @@ var (
|
||||
ErrNavInvalidFlag = errors.New("this flag is invalid")
|
||||
)
|
||||
|
||||
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",
|
||||
}
|
||||
|
||||
func CheckValidNavFlag(flag string) error {
|
||||
for _, v := range NavFlagNames {
|
||||
if v == flag {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return ErrNavInvalidFlag
|
||||
}
|
||||
|
||||
// Navigation sends a NavigationEvent to the watch
|
||||
func (i *Device) SetNavigation(flag string, narrative string, dist string, progress uint8) error {
|
||||
func (i *Device) SetNavigation(flag NavFlag, 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 {
|
||||
log.Debug().Str("func", "Navigation").
|
||||
|
Loading…
Reference in New Issue
Block a user