forked from Elara6331/infinitime
Compare commits
5 Commits
54fdd19bec
...
e6a1baa32b
Author | SHA1 | Date | |
---|---|---|---|
|
e6a1baa32b | ||
|
ba3169d1d0 | ||
|
912ccd14b3 | ||
|
62987fa31b | ||
|
2fbd8cb666 |
136
infinitime.go
136
infinitime.go
@ -38,6 +38,10 @@ const (
|
|||||||
FSTransferChar = "adaf0200-4669-6c65-5472-616e73666572"
|
FSTransferChar = "adaf0200-4669-6c65-5472-616e73666572"
|
||||||
FSVersionChar = "adaf0100-4669-6c65-5472-616e73666572"
|
FSVersionChar = "adaf0100-4669-6c65-5472-616e73666572"
|
||||||
WeatherDataChar = "00040001-78fc-48fe-8e23-433b3a1942d0"
|
WeatherDataChar = "00040001-78fc-48fe-8e23-433b3a1942d0"
|
||||||
|
NavFlagsChar = "00010001-78fc-48fe-8e23-433b3a1942d0"
|
||||||
|
NavNarrativeChar= "00010002-78fc-48fe-8e23-433b3a1942d0"
|
||||||
|
NavManDistChar = "00010003-78fc-48fe-8e23-433b3a1942d0"
|
||||||
|
NavProgressChar = "00010004-78fc-48fe-8e23-433b3a1942d0"
|
||||||
)
|
)
|
||||||
|
|
||||||
var charNames = map[string]string{
|
var charNames = map[string]string{
|
||||||
@ -52,10 +56,60 @@ var charNames = map[string]string{
|
|||||||
FSTransferChar: "Filesystem Transfer",
|
FSTransferChar: "Filesystem Transfer",
|
||||||
FSVersionChar: "Filesystem Version",
|
FSVersionChar: "Filesystem Version",
|
||||||
WeatherDataChar: "Weather Data",
|
WeatherDataChar: "Weather Data",
|
||||||
|
NavFlagsChar: "Navigation Icon",
|
||||||
|
NavNarrativeChar:"Navigation Instruction",
|
||||||
|
NavManDistChar: "Navigation Distance to next event",
|
||||||
|
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 {
|
||||||
|
flag string
|
||||||
|
narrative string
|
||||||
|
dist string
|
||||||
|
progress uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
device *device.Device1
|
device *device.Device1
|
||||||
|
navflagsChar *gatt.GattCharacteristic1
|
||||||
|
navnarrativeChar*gatt.GattCharacteristic1
|
||||||
|
navmandistChar *gatt.GattCharacteristic1
|
||||||
|
navprogressChar *gatt.GattCharacteristic1
|
||||||
newAlertChar *gatt.GattCharacteristic1
|
newAlertChar *gatt.GattCharacteristic1
|
||||||
notifEventChar *gatt.GattCharacteristic1
|
notifEventChar *gatt.GattCharacteristic1
|
||||||
stepCountChar *gatt.GattCharacteristic1
|
stepCountChar *gatt.GattCharacteristic1
|
||||||
@ -71,6 +125,7 @@ type Device struct {
|
|||||||
notifEventDone bool
|
notifEventDone bool
|
||||||
Music MusicCtrl
|
Music MusicCtrl
|
||||||
DFU DFU
|
DFU DFU
|
||||||
|
navigationEv NavigationEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -79,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 {
|
||||||
@ -394,6 +451,14 @@ func (i *Device) resolveChars() error {
|
|||||||
charResolved := true
|
charResolved := true
|
||||||
// Set correct characteristics
|
// Set correct characteristics
|
||||||
switch char.Properties.UUID {
|
switch char.Properties.UUID {
|
||||||
|
case NavFlagsChar:
|
||||||
|
i.navflagsChar = char
|
||||||
|
case NavNarrativeChar:
|
||||||
|
i.navnarrativeChar = char
|
||||||
|
case NavManDistChar:
|
||||||
|
i.navmandistChar = char
|
||||||
|
case NavProgressChar:
|
||||||
|
i.navprogressChar = char
|
||||||
case NewAlertChar:
|
case NewAlertChar:
|
||||||
i.newAlertChar = char
|
i.newAlertChar = char
|
||||||
case NotifEventChar:
|
case NotifEventChar:
|
||||||
@ -723,6 +788,77 @@ 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
|
||||||
|
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 {
|
||||||
|
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 {
|
||||||
|
log.Debug().Str("func", "Navigation").
|
||||||
|
Msg("Sending narrative")
|
||||||
|
if err := i.checkStatus(i.navnarrativeChar, NavNarrativeChar); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := i.navnarrativeChar.WriteValue([]byte(narrative), nil); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
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
|
||||||
|
}
|
||||||
|
i.navigationEv.progress = progress
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// These constants represent the possible call statuses selected by the user
|
// These constants represent the possible call statuses selected by the user
|
||||||
const (
|
const (
|
||||||
CallStatusDeclined uint8 = iota
|
CallStatusDeclined uint8 = iota
|
||||||
|
Loading…
Reference in New Issue
Block a user