82 Commits

Author SHA1 Message Date
Elara6331 33c126f166 Add unmaintained warning 2024-04-14 13:44:56 +00:00
Elara6331 bd2aa32354 Remove all references to old domain 2024-04-01 21:53:29 -07:00
Elara6331 8961780053 Remove btmgmt 2024-04-01 20:33:33 -07:00
Elara6331 a73cfb3da5 Update logger dependency 2024-04-01 20:33:02 -07:00
Elara6331 f5546ca32e Add the ability to set a custom time in weather timeline headers 2023-06-28 22:14:35 -07:00
Elara6331 f2640203e9 Update domain 2023-04-20 19:53:34 -07:00
Elara6331 4ff1be5b02 Update go.mod domain 2023-04-20 19:49:05 -07:00
Elara6331 492242bd54 Switch from zerolog to go.arsenm.dev/logger 2023-01-04 15:00:15 -08:00
FloralExMachina 8c5eca51f9 Remove MPRIS controls (#7)
This is the follow up PR for moving Mpris controls to itd

Co-authored-by: razorkitty <razorkitty@null.net>
Reviewed-on: https://gitea.arsenm.dev/Arsen6331/infinitime/pulls/7
Co-authored-by: FloralExMachina <william@null.org.uk>
Co-committed-by: FloralExMachina <william@null.org.uk>
2022-11-22 22:53:35 +00:00
cybuzuma 02444f2b66 Add local time characteristic (#4)
Co-authored-by: cybuzuma <cybuzuma@vnxs.de>
Co-committed-by: cybuzuma <cybuzuma@vnxs.de>
2022-11-21 16:51:49 +00:00
Elara6331 1f15572063 Merge pull request 'replace pactl based volume control with mpris based volume control' (#6) from FloralExMachina/infinitime:master into master
Reviewed-on: https://gitea.arsenm.dev/Arsen6331/infinitime/pulls/6
2022-11-19 22:46:12 +00:00
razorkitty 19402624bb removed pulseaudio-utils and libpulse dependencies 2022-11-19 22:43:03 +00:00
razorkitty fbc1110d8f replace pactl based volume control with mpris based volume control
methods
2022-11-19 21:30:54 +00:00
Elara6331 0f12aee5e9 Use NavFlag type in SetFlag() 2022-11-06 20:20:15 -08:00
Elara6331 4479cad6f9 Improve navigation API 2022-11-06 20:08:13 -08:00
Elara6331 70ab2e9f03 Fix typo 2022-11-05 20:54:45 -07:00
Elara6331 9e73961af9 Remove check for unchanged values and refactor code 2022-11-05 20:33:30 -07:00
yannickulrich 0aa25353fd Added Navigation service (#5)
InfiniTime implements a [Navigation Service](https://github.com/InfiniTimeOrg/InfiniTime/blob/develop/doc/NavigationService.md). This pull request will add it to the go library by defining a function
```go
func (i *Device) Navigation(flag string, narrative string, dist string, progress uint8) error {
  ...
}
```
From the InfiniTime manual
 * `flag`: the graphic instruction as provided by [Pure Maps](https://github.com/rinigus/pure-maps/tree/master/qml/icons/navigation). A list of valid instruction icons can be found [here](https://github.com/rinigus/pure-maps/tree/master/qml/icons/navigation)
 * `narrative`: the instruction in words, eg. "At the roundabout take the first exit".
 * `dist`: a short string describing the distance to the upcoming instruction such as "50 m".
 * `progress`: the percent complete in a `uint8`

Adding this to the `itd` daemon is straightforward
```patch
diff --git a/api/types.go b/api/types.go
index 281a85b..14c84de 100644
--- a/api/types.go
+++ b/api/types.go
@@ -22,6 +22,13 @@ type FwUpgradeData struct {
        Files []string
 }

+type NavigationData struct {
+       Flag         string
+       Narrative    string
+       Dist         string
+       Progress     uint8
+}
+
 type NotifyData struct {
        Title string
        Body  string
diff --git a/socket.go b/socket.go
index 6fcba5c..91b37c0 100644
--- a/socket.go
+++ b/socket.go
@@ -204,6 +204,10 @@ func (i *ITD) Address(_ *server.Context) string {
        return i.dev.Address()
 }

+func (i *ITD) Navigation(_ *server.Context, data api.NavigationData) error {
+       return i.dev.Navigation(data.Flag, data.Narrative, data.Dist, data.Progress)
+}
+
 func (i *ITD) Notify(_ *server.Context, data api.NotifyData) error {
        return i.dev.Notify(data.Title, data.Body)
 }
```

Co-authored-by: Yannick Ulrich <yannick.ulrich@durham.ac.uk>
Reviewed-on: https://gitea.arsenm.dev/Arsen6331/infinitime/pulls/5
Co-authored-by: yannickulrich <yannick.ulrich@protonmail.com>
Co-committed-by: yannickulrich <yannick.ulrich@protonmail.com>
2022-11-03 19:09:06 +00:00
Elara6331 24206c05f3 Assume MTU if not available from BlueZ 2022-10-25 12:36:34 -07:00
Elara6331 062757b314 Use timestamp with timezone offset to (finally) fix weather issue 2022-10-20 01:41:15 -07:00
Elara6331 1a95637439 Close files properly when returning an error (Arsen6331/itd#29) 2022-10-17 12:49:49 -07:00
Elara6331 e124e1ccbd Stop DBus errors from causing panics by checking error type (Arsen6331/itd#29) 2022-10-17 12:19:23 -07:00
Elara6331 5f6b0205da Add debug logging to resource loading 2022-10-16 12:39:42 -07:00
Elara6331 0c2c2592c7 Fix RemoveAll() and MkdirAll() functions 2022-10-16 12:39:11 -07:00
Elara6331 986513750f Implement resource loading feature 2022-08-29 14:43:16 -07:00
Elara6331 4845a33a25 Remove debug code 2022-08-29 14:23:10 -07:00
Elara6331 12d92afa0a Add RemoveAll() and MkdirAll() to the filesystem implementation 2022-08-29 14:22:02 -07:00
Elara6331 03aadaa01b Add Stat() to filesystem implementation 2022-08-29 14:06:56 -07:00
Elara6331 1bf8ee4e7a Fix bug where the filesystem implementation misreports the amount of bytes written, causing functions such as io.Copy() to return an error 2022-08-29 14:05:33 -07:00
Elara6331 a1a289efc9 Update go-bluetooth library for 5.65 support 2022-08-19 14:02:52 -07:00
Elara6331 91a47acb50 Add contexts and improve error handling 2022-05-11 13:22:57 -07:00
Elara6331 e3a6bd308d Fix error handling in (*FS).Remove() 2022-05-05 12:39:16 -07:00
Elara6331 2c2d854929 Use adapter ID in btmgmt as well 2022-05-02 20:20:16 -07:00
Elara6331 5e7a110cdc Ask for adapter ID in Init() 2022-05-02 20:14:46 -07:00
Elara6331 9f0ee67c0f Clarify DFU debug logs 2022-04-23 20:08:49 -07:00
Elara6331 a832c16d69 Add debug logging 2022-04-23 19:58:00 -07:00
Elara6331 c5d938ce99 Use log level provided in options 2022-04-23 19:07:41 -07:00
Elara6331 8ff29b0ca9 Ensure that done signals for Watch functions are handled properly and restart notifications if they stop unexpectedly 2022-04-23 18:40:25 -07:00
Elara6331 165db63deb Log when too many disconnects occur rather than removing the device (Arsen6331/itd#10) 2022-04-16 04:24:21 -07:00
Elara6331 36aee2e1fe Handle case where artists value is a single string rather than a slice. Fixes Arsen6331/itd#9. 2022-03-04 12:04:37 -08:00
Elara6331 b6ba971d50 Rewrite connect/reconnect code 2022-02-21 02:46:20 -08:00
Elara6331 2342b0d82a Create custom BlueZ agent 2021-12-16 21:30:29 -08:00
Elara6331 2f23dd3348 Restrict to one open file of each type at a time 2021-12-13 09:56:34 -08:00
Elara6331 60a0daa82e Add file transfer progress 2021-12-12 13:25:40 -08:00
Elara6331 db8f03dee7 Add weather service 2021-12-12 12:43:43 -08:00
Elara6331 90936d8900 Set connected property to true in all connecting functions 2021-11-25 20:33:06 -08:00
Elara6331 a5c90c3b7d Fix checkStatus call in (*Device).FS() 2021-11-25 13:35:58 -08:00
Elara6331 0a3ed67ede Allow multiple call notification responses and improve error handling 2021-11-25 12:39:43 -08:00
Elara6331 d96dae1f13 Only allow OnChange() to be called once 2021-11-24 17:21:12 -08:00
Elara6331 388f48b260 Fix README errors 2021-11-24 16:51:42 -08:00
Elara6331 e5c4279346 Remove playerctl from dependencies and add pactl providers 2021-11-24 16:50:35 -08:00
Elara6331 2a3df6bcf8 Buffer message channel for music 2021-11-24 16:41:56 -08:00
Elara6331 b2b0ecebdd Switch player to MPRIS interface 2021-11-24 16:31:18 -08:00
Elara6331 4e88b4b7f8 Remove BLE docs as they have been merged into InfiniTime 2021-11-22 21:20:01 -08:00
Elara6331 60a4ad91f4 Implement BLE filesystem (experimental and will change in the future) 2021-11-22 21:19:30 -08:00
Elara6331 96ffb87c86 Update go-bluetooth to fix BlueZ 5.62 compatibility 2021-11-22 01:14:16 -08:00
Elara6331 cf4688f393 Upgrade go-bluetooth version 2021-11-01 11:20:10 -07:00
Elara6331 52b05385a3 Create Init() rather than using init() 2021-11-01 09:19:12 -07:00
Elara6331 a19fedf763 Add whitelist to pair() and make case insensitive 2021-10-26 21:42:41 -07:00
Elara6331 651270051e Add cancel functions to battery level and heart rate 2021-10-22 21:26:33 -07:00
Elara6331 4fa0ce1801 Implement Motion Service 2021-10-22 12:59:51 -07:00
Elara6331 d3f48d6339 Fix issue where DFU responses are missed causing DFU to time out intermittently 2021-10-21 20:17:44 -07:00
Elara6331 88f15c6aa1 Fix Alert Notification Service Client link 2021-10-15 20:13:09 -07:00
Elara6331 07ca733a9b Fix typo 2021-10-15 20:11:34 -07:00
Elara6331 2e019e7589 Add name to Notification Event UUID 2021-10-15 20:10:59 -07:00
Elara6331 f5f0efb55e Add docs for InfiniTime BLE 2021-10-15 19:58:57 -07:00
Elara6331 6b602169a0 Add call notification support 2021-10-15 00:23:54 -07:00
Elara6331 ce95ce259c Prevent sending of extra zero bytes during DFU 2021-10-06 17:08:21 -07:00
Elara6331 fa5072b1b0 Power on bluetooth as part of setup 2021-09-09 08:34:56 -07:00
Elara6331 df067d2c56 Return intial values in watch functions 2021-08-24 22:17:34 -07:00
Elara6331 367032ec7e Add watch function for battery level 2021-08-24 21:55:03 -07:00
Elara6331 18dec0d2b5 Improve current music status functions 2021-08-23 10:16:03 -07:00
Elara6331 032147ae61 Add functions for current status and metadata 2021-08-23 10:07:11 -07:00
Elara6331 cd3daa5848 Remove pair timeout entirely 2021-08-22 13:12:16 -07:00
Elara6331 613a7cb044 Fix bug where Connect blocked forever after 10 seconds 2021-08-22 13:09:56 -07:00
Elara6331 8f4bb3e226 Fix segfault due to using wrong opts struct 2021-08-21 20:27:31 -07:00
Elara6331 d5c893b9d1 Add error handling to connect call 2021-08-21 20:25:09 -07:00
Elara6331 d5f83f4643 Allow configuration of pair timeout 2021-08-21 20:24:56 -07:00
Elara6331 213fe39b21 Add progress to DFU 2021-08-21 00:04:29 -07:00
Elara6331 fd9d97629a Mention import path in README.md 2021-08-19 18:04:23 -07:00
Elara6331 12925caa84 Add go reference badge 2021-08-19 17:59:38 -07:00
Elara6331 1b10eba464 Initial Commit 2021-08-19 17:41:09 -07:00
14 changed files with 315 additions and 530 deletions
+8 -6
View File
@@ -1,38 +1,40 @@
# InfiniTime # InfiniTime
> **Warning** This library is no longer maintained. A rewrite has been merged into the ITD repo in [the infinitime subpackage](https://gitea.elara.ws/Elara6331/itd/src/branch/master/infinitime)
This is a go library for interfacing with InfiniTime firmware This is a go library for interfacing with InfiniTime firmware
over BLE on Linux. over BLE on Linux.
[![Go Reference](https://pkg.go.dev/badge/go.arsenm.dev/infinitime.svg)](https://pkg.go.dev/go.arsenm.dev/infinitime) [![Go Reference](https://pkg.go.dev/badge/go.elara.ws/infinitime.svg)](https://pkg.go.dev/go.elara.ws/infinitime)
--- ---
### Importing ### Importing
This library's import path is `go.arsenm.dev/infinitime`. This library's import path is `go.elara.ws/infinitime`.
--- ---
### Dependencies ### Dependencies
This library requires `dbus`, `bluez`, and `pactl` to function. These allow the library to use bluetooth, control media, control volume, etc. This library requires `dbus`, and `bluez` to function. These allow the library to use bluetooth, control media, control volume, etc.
#### Arch #### Arch
```shell ```shell
sudo pacman -S dbus bluez libpulse --needed sudo pacman -S dbus bluez --needed
``` ```
#### Debian/Ubuntu #### Debian/Ubuntu
```shell ```shell
sudo apt install dbus bluez pulseaudio-utils sudo apt install dbus bluez
``` ```
#### Fedora #### Fedora
```shell ```shell
sudo dnf install dbus bluez pulseaudio-utils sudo dnf install dbus bluez
``` ```
--- ---
+7 -1
View File
@@ -199,7 +199,13 @@ func decode(data []byte, vals ...interface{}) error {
// to send in a packet. Subtracting 20 ensures that the MTU // to send in a packet. Subtracting 20 ensures that the MTU
// is never exceeded. // is never exceeded.
func (blefs *FS) maxData() uint16 { func (blefs *FS) maxData() uint16 {
return blefs.transferChar.Properties.MTU - 20 mtu := blefs.transferChar.Properties.MTU
// If MTU is zero, the current version of BlueZ likely
// doesn't support the MTU property, so assume 256.
if mtu == 0 {
mtu = 256
}
return mtu - 20
} }
// padding returns a slice of len amount of 0x00. // padding returns a slice of len amount of 0x00.
+3 -7
View File
@@ -5,7 +5,6 @@ import (
bt "github.com/muka/go-bluetooth/api" bt "github.com/muka/go-bluetooth/api"
"github.com/muka/go-bluetooth/bluez/profile/adapter" "github.com/muka/go-bluetooth/bluez/profile/adapter"
"github.com/muka/go-bluetooth/bluez/profile/agent" "github.com/muka/go-bluetooth/bluez/profile/agent"
"github.com/muka/go-bluetooth/hw/linux/btmgmt"
) )
var defaultAdapter *adapter.Adapter1 var defaultAdapter *adapter.Adapter1
@@ -33,9 +32,6 @@ func Init(adapterID string) {
panic(err) panic(err)
} }
daMgmt := btmgmt.NewBtMgmt(adapterID)
daMgmt.SetPowered(true)
defaultAdapter = da defaultAdapter = da
itdAgent = ag itdAgent = ag
} }
@@ -77,7 +73,7 @@ func (a *Agent) RequestPasskey(device dbus.ObjectPath) (uint32, *dbus.Error) {
if a.ReqPasskey == nil { if a.ReqPasskey == nil {
return 0, errAuthFailed return 0, errAuthFailed
} }
log.Debug().Msg("Passkey requested, calling onReqPasskey callback") log.Debug("Passkey requested, calling onReqPasskey callback").Send()
passkey, err := a.ReqPasskey() passkey, err := a.ReqPasskey()
if err != nil { if err != nil {
return 0, errAuthFailed return 0, errAuthFailed
@@ -110,9 +106,9 @@ func (*Agent) Cancel() *dbus.Error {
return nil return nil
} }
// Path returns "/dev/arsenm/infinitime/Agent" // Path returns "/ws/elara/infinitime/Agent"
func (*Agent) Path() dbus.ObjectPath { func (*Agent) Path() dbus.ObjectPath {
return "/dev/arsenm/infinitime/Agent" return "/ws/elara/infinitime/Agent"
} }
// Interface returns "org.bluez.Agent1" // Interface returns "org.bluez.Agent1"
+8 -8
View File
@@ -313,7 +313,7 @@ func (dfu *DFU) Reset() {
// on waits for the given command to be received on // on waits for the given command to be received on
// the control point characteristic, then runs the callback. // the control point characteristic, then runs the callback.
func (dfu *DFU) on(cmd []byte, onCmdCb func(data []byte) error) error { func (dfu *DFU) on(cmd []byte, onCmdCb func(data []byte) error) error {
log.Debug().Hex("expecting", cmd).Msg("Waiting for DFU command") log.Debug("Waiting for DFU command").Bytes("expecting", cmd).Send()
// Use for loop in case of invalid property // Use for loop in case of invalid property
for { for {
select { select {
@@ -325,10 +325,10 @@ func (dfu *DFU) on(cmd []byte, onCmdCb func(data []byte) error) error {
} }
// Assert propery value as byte slice // Assert propery value as byte slice
data := propChanged.Value.([]byte) data := propChanged.Value.([]byte)
log.Debug(). log.Debug("Received DFU command").
Hex("expecting", cmd). Bytes("expecting", cmd).
Hex("received", data). Bytes("received", data).
Msg("Received DFU command") Send()
// If command has prefix of given command // If command has prefix of given command
if bytes.HasPrefix(data, cmd) { if bytes.HasPrefix(data, cmd) {
// Return callback with data after command // Return callback with data after command
@@ -413,7 +413,7 @@ func (dfu *DFU) stepSeven() error {
if err != nil { if err != nil {
return err return err
} }
log.Debug().Msg("Sent firmware image segment") log.Debug("Sent firmware image segment").Send()
// Increment bytes sent by amount read // Increment bytes sent by amount read
dfu.bytesSent += len(segment) dfu.bytesSent += len(segment)
} }
@@ -421,10 +421,10 @@ func (dfu *DFU) stepSeven() error {
err := dfu.on(DFUNotifPktRecvd, func(data []byte) error { err := dfu.on(DFUNotifPktRecvd, func(data []byte) error {
// Set bytes received to data returned by InfiniTime // Set bytes received to data returned by InfiniTime
dfu.bytesRecvd = int(binary.LittleEndian.Uint32(data)) dfu.bytesRecvd = int(binary.LittleEndian.Uint32(data))
log.Debug(). log.Debug("Received packet receipt notification").
Int("sent", dfu.bytesSent). Int("sent", dfu.bytesSent).
Int("rcvd", dfu.bytesRecvd). Int("rcvd", dfu.bytesRecvd).
Msg("Received packet receipt notification") Send()
if dfu.bytesRecvd != dfu.bytesSent { if dfu.bytesRecvd != dfu.bytesSent {
return ErrDFUSizeMismatch return ErrDFUSizeMismatch
} }
+2 -2
View File
@@ -1,4 +1,4 @@
module go.arsenm.dev/infinitime module go.elara.ws/infinitime
go 1.16 go 1.16
@@ -6,6 +6,6 @@ require (
github.com/fxamacker/cbor/v2 v2.4.0 github.com/fxamacker/cbor/v2 v2.4.0
github.com/godbus/dbus/v5 v5.0.6 github.com/godbus/dbus/v5 v5.0.6
github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268 github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268
github.com/rs/zerolog v1.26.1 go.elara.ws/logger v0.0.0-20230928062203-85e135cf02ae
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
) )
+18 -21
View File
@@ -1,4 +1,3 @@
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -7,14 +6,17 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga
github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88= github.com/fxamacker/cbor/v2 v2.4.0 h1:ri0ArlOR+5XunOP8CRUowT0pSJOwhW098ZCUyskZD88=
github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo= github.com/fxamacker/cbor/v2 v2.4.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro= github.com/godbus/dbus/v5 v5.0.6 h1:mkgN1ofwASrYnJ5W6U/BxG15eXXXjirgZc7CLqkcaro=
github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.0.6/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8= github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268 h1:kOnq7TfaAO2Vc/MHxPqFIXe00y1qBxJAvhctXdko6vo= github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268 h1:kOnq7TfaAO2Vc/MHxPqFIXe00y1qBxJAvhctXdko6vo=
github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0= github.com/muka/go-bluetooth v0.0.0-20220819140550-1d8857e3b268/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
@@ -22,56 +24,51 @@ github.com/paypal/gatt v0.0.0-20151011220935-4ae819d591cf/go.mod h1:+AwQL2mK3Pd3
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/suapapa/go_eddystone v1.3.1/go.mod h1:bXC11TfJOS+3g3q/Uzd7FKd5g62STQEfeEIhcKe4Qy8= github.com/suapapa/go_eddystone v1.3.1/go.mod h1:bXC11TfJOS+3g3q/Uzd7FKd5g62STQEfeEIhcKe4Qy8=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.elara.ws/logger v0.0.0-20230928062203-85e135cf02ae h1:d+gJUhEWSrOjrrfgeydYWEr8TTnx0DLvcVhghaOsFeE=
go.elara.ws/logger v0.0.0-20230928062203-85e135cf02ae/go.mod h1:qng49owViqsW5Aey93lwBXONw20oGbJIoLVscB16mPM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c= golang.org/x/sys v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+84 -167
View File
@@ -15,14 +15,14 @@ import (
"github.com/muka/go-bluetooth/bluez/profile/adapter" "github.com/muka/go-bluetooth/bluez/profile/adapter"
"github.com/muka/go-bluetooth/bluez/profile/device" "github.com/muka/go-bluetooth/bluez/profile/device"
"github.com/muka/go-bluetooth/bluez/profile/gatt" "github.com/muka/go-bluetooth/bluez/profile/gatt"
"github.com/rs/zerolog" "go.elara.ws/infinitime/blefs"
"go.arsenm.dev/infinitime/blefs" "go.elara.ws/logger"
) )
// This global is used to store the logger. // This global is used to store the logger.
// log.Logger is not used as it would interfere // log.Logger is not used as it would interfere
// with the package importing the library // with the package importing the library
var log zerolog.Logger var log logger.Logger
const BTName = "InfiniTime" const BTName = "InfiniTime"
@@ -33,15 +33,12 @@ const (
MotionValChar = "00030002-78fc-48fe-8e23-433b3a1942d0" MotionValChar = "00030002-78fc-48fe-8e23-433b3a1942d0"
FirmwareVerChar = "00002a26-0000-1000-8000-00805f9b34fb" FirmwareVerChar = "00002a26-0000-1000-8000-00805f9b34fb"
CurrentTimeChar = "00002a2b-0000-1000-8000-00805f9b34fb" CurrentTimeChar = "00002a2b-0000-1000-8000-00805f9b34fb"
LocalTimeChar = "00002a0f-0000-1000-8000-00805f9b34fb"
BatteryLvlChar = "00002a19-0000-1000-8000-00805f9b34fb" BatteryLvlChar = "00002a19-0000-1000-8000-00805f9b34fb"
HeartRateChar = "00002a37-0000-1000-8000-00805f9b34fb" HeartRateChar = "00002a37-0000-1000-8000-00805f9b34fb"
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{
@@ -51,6 +48,7 @@ var charNames = map[string]string{
MotionValChar: "Motion Values", MotionValChar: "Motion Values",
FirmwareVerChar: "Firmware Version", FirmwareVerChar: "Firmware Version",
CurrentTimeChar: "Current Time", CurrentTimeChar: "Current Time",
LocalTimeChar: "Local Time",
BatteryLvlChar: "Battery Level", BatteryLvlChar: "Battery Level",
HeartRateChar: "Heart Rate", HeartRateChar: "Heart Rate",
FSTransferChar: "Filesystem Transfer", FSTransferChar: "Filesystem Transfer",
@@ -62,70 +60,26 @@ 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 {
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
motionValChar *gatt.GattCharacteristic1 motionValChar *gatt.GattCharacteristic1
fwVersionChar *gatt.GattCharacteristic1 fwVersionChar *gatt.GattCharacteristic1
currentTimeChar *gatt.GattCharacteristic1 currentTimeChar *gatt.GattCharacteristic1
localTimeChar *gatt.GattCharacteristic1
battLevelChar *gatt.GattCharacteristic1 battLevelChar *gatt.GattCharacteristic1
heartRateChar *gatt.GattCharacteristic1 heartRateChar *gatt.GattCharacteristic1
fsVersionChar *gatt.GattCharacteristic1 fsVersionChar *gatt.GattCharacteristic1
fsTransferChar *gatt.GattCharacteristic1 fsTransferChar *gatt.GattCharacteristic1
weatherDataChar *gatt.GattCharacteristic1 weatherDataChar *gatt.GattCharacteristic1
weatherdataChar *gatt.GattCharacteristic1
notifEventCh chan uint8 notifEventCh chan uint8
notifEventDone bool notifEventDone bool
Music MusicCtrl Music MusicCtrl
Navigation NavigationService
DFU DFU DFU DFU
navigationEv NavigationEvent
} }
var ( var (
@@ -134,8 +88,6 @@ 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 {
@@ -152,15 +104,14 @@ type Options struct {
Whitelist []string Whitelist []string
OnReqPasskey func() (uint32, error) OnReqPasskey func() (uint32, error)
OnReconnect func() OnReconnect func()
Logger zerolog.Logger Logger logger.Logger
LogLevel zerolog.Level LogLevel logger.LogLevel
} }
var DefaultOptions = &Options{ var DefaultOptions = &Options{
AttemptReconnect: true, AttemptReconnect: true,
WhitelistEnabled: false, WhitelistEnabled: false,
Logger: zerolog.Nop(), Logger: logger.NewNop(),
LogLevel: zerolog.Disabled,
} }
// Connect will attempt to connect to a // Connect will attempt to connect to a
@@ -174,7 +125,8 @@ func Connect(ctx context.Context, opts *Options) (*Device, error) {
opts = DefaultOptions opts = DefaultOptions
} }
log = opts.Logger.Level(opts.LogLevel) log = opts.Logger
opts.Logger.SetLevel(opts.LogLevel)
// Set passkey request callback // Set passkey request callback
setOnPasskeyReq(opts.OnReqPasskey) setOnPasskeyReq(opts.OnReqPasskey)
@@ -187,6 +139,7 @@ func Connect(ctx context.Context, opts *Options) (*Device, error) {
// Create new device // Create new device
out := &Device{device: btDev} out := &Device{device: btDev}
out.Navigation = NavigationService{dev: out}
// Resolve characteristics // Resolve characteristics
err = out.resolveChars() err = out.resolveChars()
@@ -215,25 +168,25 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// device, skip // device, skip
if opts.WhitelistEnabled && if opts.WhitelistEnabled &&
!contains(opts.Whitelist, listDev.Properties.Address) { !contains(opts.Whitelist, listDev.Properties.Address) {
log.Debug(). log.Debug("InfiniTime device skipped as it is not in whitelist").
Str("mac", listDev.Properties.Address). Str("mac", listDev.Properties.Address).
Msg("InfiniTime device skipped as it is not in whitelist") Send()
continue continue
} }
// Set device // Set device
dev = listDev dev = listDev
log.Debug(). log.Debug("InfiniTime device found in list").
Str("mac", dev.Properties.Address). Str("mac", dev.Properties.Address).
Msg("InfiniTime device found in list") Send()
break break
} }
// If device not set // If device not set
if dev == nil { if dev == nil {
log.Debug().Msg("No device found in list, attempting to discover") log.Debug("No device found in list, attempting to discover").Send()
// Discover devices on adapter // Discover devices on adapter
discoverCh, cancel, err := bt.Discover(defaultAdapter, &adapter.DiscoveryFilter{Transport: "le"}) discoverCh, cancel, err := bt.Discover(defaultAdapter, &adapter.DiscoveryFilter{Transport: "le"})
if err != nil { if err != nil {
@@ -263,18 +216,18 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// device, skip // device, skip
if opts.WhitelistEnabled && if opts.WhitelistEnabled &&
!contains(opts.Whitelist, discovered.Properties.Address) { !contains(opts.Whitelist, discovered.Properties.Address) {
log.Debug(). log.Debug("Discovered InfiniTime device skipped as it is not in whitelist").
Str("mac", discovered.Properties.Address). Str("mac", discovered.Properties.Address).
Msg("Discovered InfiniTime device skipped as it is not in whitelist") Send()
continue continue
} }
// Set device // Set device
dev = discovered dev = discovered
log.Debug(). log.Debug("InfiniTime device discovered").
Str("mac", dev.Properties.Address). Str("mac", dev.Properties.Address).
Msg("InfiniTime device discovered") Send()
break discoverLoop break discoverLoop
case <-ctx.Done(): case <-ctx.Done():
break discoverLoop break discoverLoop
@@ -296,7 +249,7 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
reconnRequired := false reconnRequired := false
// If device is not connected // If device is not connected
if !dev.Properties.Connected { if !dev.Properties.Connected {
log.Debug().Msg("Device not connected, connecting") log.Debug("Device not connected, connecting").Send()
// Connect to device // Connect to device
err = dev.Connect() err = dev.Connect()
if err != nil { if err != nil {
@@ -308,7 +261,7 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// If device is not paired // If device is not paired
if !dev.Properties.Paired { if !dev.Properties.Paired {
log.Debug().Msg("Device not paired, pairing") log.Debug("Device not paired, pairing").Send()
// Pair device // Pair device
err = dev.Pair() err = dev.Pair()
if err != nil { if err != nil {
@@ -326,7 +279,7 @@ func connect(ctx context.Context, opts *Options, first bool) (dev *device.Device
// was required, and the OnReconnect callback exists, // was required, and the OnReconnect callback exists,
// run it // run it
if !first && reconnRequired && opts.OnReconnect != nil { if !first && reconnRequired && opts.OnReconnect != nil {
log.Debug().Msg("Reconnected to device, running OnReconnect callback") log.Debug("Reconnected to device, running OnReconnect callback").Send()
opts.OnReconnect() opts.OnReconnect()
} }
@@ -359,7 +312,7 @@ func reconnect(ctx context.Context, opts *Options, dev *device.Device1) {
// If less than 3 seconds have passed and more than 6 // If less than 3 seconds have passed and more than 6
// disconnects have occurred, remove the device and reset // disconnects have occurred, remove the device and reset
if secsSince <= 3 && amtDisconnects >= 6 { if secsSince <= 3 && amtDisconnects >= 6 {
opts.Logger.Warn().Msg("At least 6 disconnects have occurred in the last three seconds. If this continues, try removing the InfiniTime device from bluetooth.") opts.Logger.Warn("At least 6 disconnects have occurred in the last three seconds. If this continues, try removing the InfiniTime device from bluetooth.").Send()
lastDisconnect = time.Unix(0, 0) lastDisconnect = time.Unix(0, 0)
amtDisconnects = 0 amtDisconnects = 0
} }
@@ -371,7 +324,7 @@ func reconnect(ctx context.Context, opts *Options, dev *device.Device1) {
for i := 0; i < 6; i++ { for i := 0; i < 6; i++ {
// If three tries failed, remove device // If three tries failed, remove device
if i == 3 { if i == 3 {
opts.Logger.Warn().Msg("Multiple connection attempts have failed. If this continues, try removing the InfiniTime device from bluetooth.") opts.Logger.Warn("Multiple connection attempts have failed. If this continues, try removing the InfiniTime device from bluetooth.").Send()
} }
// Connect to device // Connect to device
newDev, err := connect(ctx, opts, false) newDev, err := connect(ctx, opts, false)
@@ -452,13 +405,13 @@ func (i *Device) resolveChars() error {
// Set correct characteristics // Set correct characteristics
switch char.Properties.UUID { switch char.Properties.UUID {
case NavFlagsChar: case NavFlagsChar:
i.navflagsChar = char i.Navigation.flagsChar = char
case NavNarrativeChar: case NavNarrativeChar:
i.navnarrativeChar = char i.Navigation.narrativeChar = char
case NavManDistChar: case NavManDistChar:
i.navmandistChar = char i.Navigation.mandistChar = char
case NavProgressChar: case NavProgressChar:
i.navprogressChar = char i.Navigation.progressChar = char
case NewAlertChar: case NewAlertChar:
i.newAlertChar = char i.newAlertChar = char
case NotifEventChar: case NotifEventChar:
@@ -471,6 +424,8 @@ func (i *Device) resolveChars() error {
i.fwVersionChar = char i.fwVersionChar = char
case CurrentTimeChar: case CurrentTimeChar:
i.currentTimeChar = char i.currentTimeChar = char
case LocalTimeChar:
i.localTimeChar = char
case BatteryLvlChar: case BatteryLvlChar:
i.battLevelChar = char i.battLevelChar = char
case HeartRateChar: case HeartRateChar:
@@ -499,10 +454,10 @@ func (i *Device) resolveChars() error {
charResolved = false charResolved = false
} }
if charResolved { if charResolved {
log.Debug(). log.Debug("Resolved characteristic").
Str("uuid", char.Properties.UUID). Str("uuid", char.Properties.UUID).
Str("name", charNames[char.Properties.UUID]). Str("name", charNames[char.Properties.UUID]).
Msg("Resolved characteristic") Send()
} }
} }
return nil return nil
@@ -604,7 +559,7 @@ func (i *Device) WatchHeartRate(ctx context.Context) (<-chan uint8, error) {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal") log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out) close(out)
i.heartRateChar.StopNotify() i.heartRateChar.StopNotify()
return return
@@ -614,7 +569,7 @@ func (i *Device) WatchHeartRate(ctx context.Context) (<-chan uint8, error) {
// Send heart rate to channel // Send heart rate to channel
out <- uint8(event.Value.([]byte)[1]) out <- uint8(event.Value.([]byte)[1])
} else if event.Name == "Notifying" && !event.Value.(bool) { } else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting") log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.heartRateChar.StartNotify() i.heartRateChar.StartNotify()
} }
} }
@@ -648,7 +603,7 @@ func (i *Device) WatchBatteryLevel(ctx context.Context) (<-chan uint8, error) {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal") log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out) close(out)
i.battLevelChar.StopNotify() i.battLevelChar.StopNotify()
return return
@@ -658,7 +613,7 @@ func (i *Device) WatchBatteryLevel(ctx context.Context) (<-chan uint8, error) {
// Send heart rate to channel // Send heart rate to channel
out <- uint8(event.Value.([]byte)[0]) out <- uint8(event.Value.([]byte)[0])
} else if event.Name == "Notifying" && !event.Value.(bool) { } else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting") log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.battLevelChar.StartNotify() i.battLevelChar.StartNotify()
} }
} }
@@ -692,7 +647,7 @@ func (i *Device) WatchStepCount(ctx context.Context) (<-chan uint32, error) {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal") log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out) close(out)
i.stepCountChar.StopNotify() i.stepCountChar.StopNotify()
return return
@@ -702,7 +657,7 @@ func (i *Device) WatchStepCount(ctx context.Context) (<-chan uint32, error) {
// Send step count to channel // Send step count to channel
out <- binary.LittleEndian.Uint32(event.Value.([]byte)) out <- binary.LittleEndian.Uint32(event.Value.([]byte))
} else if event.Name == "Notifying" && !event.Value.(bool) { } else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting") log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.stepCountChar.StartNotify() i.stepCountChar.StartNotify()
} }
} }
@@ -736,7 +691,7 @@ func (i *Device) WatchMotion(ctx context.Context) (<-chan MotionValues, error) {
for { for {
select { select {
case <-ctx.Done(): case <-ctx.Done():
log.Debug().Str("func", "WatchMotion").Msg("Received done signal") log.Debug("Received done signal").Str("func", "WatchMotion").Send()
close(out) close(out)
i.motionValChar.StopNotify() i.motionValChar.StopNotify()
return return
@@ -748,7 +703,7 @@ func (i *Device) WatchMotion(ctx context.Context) (<-chan MotionValues, error) {
// Send step count to channel // Send step count to channel
out <- motionVals out <- motionVals
} else if event.Name == "Notifying" && !event.Value.(bool) { } else if event.Name == "Notifying" && !event.Value.(bool) {
log.Debug().Str("func", "WatchMotion").Msg("Notifications stopped, restarting") log.Debug("Notifications stopped, restarting").Str("func", "WatchMotion").Send()
i.motionValChar.StartNotify() i.motionValChar.StartNotify()
} }
} }
@@ -758,7 +713,9 @@ func (i *Device) WatchMotion(ctx context.Context) (<-chan MotionValues, error) {
return out, nil return out, nil
} }
// SetTime sets the watch's time using the Current Time Service // SetTime sets the watch's
// * time using the Current Time Service's current time characteristic
// * timezone information using the CTS's local time characteristic
func (i *Device) SetTime(t time.Time) error { func (i *Device) SetTime(t time.Time) error {
if err := i.checkStatus(i.currentTimeChar, CurrentTimeChar); err != nil { if err := i.checkStatus(i.currentTimeChar, CurrentTimeChar); err != nil {
return err return err
@@ -773,7 +730,38 @@ func (i *Device) SetTime(t time.Time) error {
binary.Write(buf, binary.LittleEndian, uint8(t.Weekday())) binary.Write(buf, binary.LittleEndian, uint8(t.Weekday()))
binary.Write(buf, binary.LittleEndian, uint8((t.Nanosecond()/1000)/1e6*256)) binary.Write(buf, binary.LittleEndian, uint8((t.Nanosecond()/1000)/1e6*256))
binary.Write(buf, binary.LittleEndian, uint8(0b0001)) binary.Write(buf, binary.LittleEndian, uint8(0b0001))
return i.currentTimeChar.WriteValue(buf.Bytes(), nil) if err := i.currentTimeChar.WriteValue(buf.Bytes(), nil); err != nil {
return err
}
if err := i.checkStatus(i.localTimeChar, LocalTimeChar); err != nil {
// If the characteristic is unavailable,
// fail silently, as many people may be on
// older InfiniTime versions. A warning
// may be added later.
if _, ok := err.(ErrCharNotAvail); ok {
return nil
} else {
return err
}
}
_, offset := t.Zone()
dst := 0
// Local time expects two values: the timezone offset and the dst offset, both
// expressed in quarters of an hour.
// Timezone offset is to be constant over DST, with dst offset holding the offset != 0
// when DST is in effect.
// As there is no standard way in go to get the actual dst offset, we assume it to be 1h
// when DST is in effect
if t.IsDST() {
dst = 3600
offset -= 3600
}
bufTz := &bytes.Buffer{}
binary.Write(bufTz, binary.LittleEndian, uint8(offset/3600*4))
binary.Write(bufTz, binary.LittleEndian, uint8(dst/3600*4))
return i.localTimeChar.WriteValue(bufTz.Bytes(), nil)
} }
// Notify sends a notification to InfiniTime via // Notify sends a notification to InfiniTime via
@@ -788,77 +776,6 @@ 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
@@ -949,13 +866,13 @@ func (i *Device) AddWeatherEvent(event interface{}) error {
return err return err
} }
log.Debug().Interface("event", event).Msg("Adding weather event") log.Debug("Adding weather event").Any("event", event).Send()
// Write data to weather data characteristic // Write data to weather data characteristic
return i.weatherDataChar.WriteValue(data, nil) return i.weatherDataChar.WriteValue(data, nil)
} }
func (i *Device) checkStatus(char *gatt.GattCharacteristic1, uuid string) error { func (i *Device) checkStatus(char *gatt.GattCharacteristic1, uuid string) error {
log.Debug().Msg("Checking characteristic status") log.Debug("Checking characteristic status").Send()
connected, err := i.device.GetConnected() connected, err := i.device.GetConnected()
if err != nil { if err != nil {
return err return err
@@ -964,12 +881,12 @@ func (i *Device) checkStatus(char *gatt.GattCharacteristic1, uuid string) error
return ErrNotConnected return ErrNotConnected
} }
if char == nil { if char == nil {
log.Debug().Msg("Characteristic not available (nil)") log.Debug("Characteristic not available (nil)").Send()
return ErrCharNotAvail{uuid} return ErrCharNotAvail{uuid}
} }
log.Debug(). log.Debug("Characteristic available").
Str("uuid", char.Properties.UUID). Str("uuid", char.Properties.UUID).
Str("name", charNames[char.Properties.UUID]). Str("name", charNames[char.Properties.UUID]).
Msg("Characteristic available") Send()
return nil return nil
} }
-37
View File
@@ -1,37 +0,0 @@
package utils
import "github.com/godbus/dbus/v5"
func NewSystemBusConn() (*dbus.Conn, error) {
// Connect to dbus session bus
conn, err := dbus.SystemBusPrivate()
if err != nil {
return nil, err
}
err = conn.Auth(nil)
if err != nil {
return nil, err
}
err = conn.Hello()
if err != nil {
return nil, err
}
return conn, nil
}
func NewSessionBusConn() (*dbus.Conn, error) {
// Connect to dbus session bus
conn, err := dbus.SessionBusPrivate()
if err != nil {
return nil, err
}
err = conn.Auth(nil)
if err != nil {
return nil, err
}
err = conn.Hello()
if err != nil {
return nil, err
}
return conn, nil
}
+1 -1
View File
@@ -72,7 +72,7 @@ func (mc MusicCtrl) WatchEvents() (<-chan MusicEvent, error) {
for event := range ch { for event := range ch {
// If value changes // If value changes
if event.Name == "Value" { if event.Name == "Value" {
log.Debug().Bytes("value", event.Value.([]byte)).Msg("Received music event from watch") log.Debug("Received music event from watch").Bytes("value", event.Value.([]byte)).Send()
// Send music event to channel // Send music event to channel
musicEventCh <- MusicEvent(event.Value.([]byte)[0]) musicEventCh <- MusicEvent(event.Value.([]byte)[0])
} }
+152
View File
@@ -0,0 +1,152 @@
package infinitime
import (
"errors"
"github.com/muka/go-bluetooth/bluez/profile/gatt"
)
var ErrNavProgress = errors.New("progress needs to be between 0 and 100")
const (
NavFlagsChar = "00010001-78fc-48fe-8e23-433b3a1942d0"
NavNarrativeChar = "00010002-78fc-48fe-8e23-433b3a1942d0"
NavManDistChar = "00010003-78fc-48fe-8e23-433b3a1942d0"
NavProgressChar = "00010004-78fc-48fe-8e23-433b3a1942d0"
)
type NavigationService struct {
dev *Device
flagsChar *gatt.GattCharacteristic1
narrativeChar *gatt.GattCharacteristic1
mandistChar *gatt.GattCharacteristic1
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"
)
func (n *NavigationService) SetFlag(flag NavFlag) error {
log.Debug("Sending flag").Str("func", "SetFlag").Send()
if err := n.dev.checkStatus(n.flagsChar, NavFlagsChar); err != nil {
return err
}
return n.flagsChar.WriteValue([]byte(flag), nil)
}
func (n *NavigationService) SetNarrative(narrative string) error {
log.Debug("Sending narrative").Str("func", "SetNarrative").Send()
if err := n.dev.checkStatus(n.narrativeChar, NavNarrativeChar); err != nil {
return err
}
return n.narrativeChar.WriteValue([]byte(narrative), nil)
}
func (n *NavigationService) SetManDist(manDist string) error {
log.Debug("Sending maneuver distance").Str("func", "SetNarrative").Send()
if err := n.dev.checkStatus(n.mandistChar, NavManDistChar); err != nil {
return err
}
return n.mandistChar.WriteValue([]byte(manDist), nil)
}
func (n *NavigationService) SetProgress(progress uint8) error {
log.Debug("Sending progress").Str("func", "SetNarrative").Send()
if err := n.dev.checkStatus(n.progressChar, NavProgressChar); err != nil {
return err
}
return n.progressChar.WriteValue([]byte{progress}, nil)
}
-16
View File
@@ -1,16 +0,0 @@
package player
import (
"fmt"
"os/exec"
)
// VolUp uses pactl to increase the volume of the default sink
func VolUp(percent uint) error {
return exec.Command("pactl", "set-sink-volume", "@DEFAULT_SINK@", fmt.Sprintf("+%d%%", percent)).Run()
}
// VolDown uses pactl to decrease the volume of the default sink
func VolDown(percent uint) error {
return exec.Command("pactl", "set-sink-volume", "@DEFAULT_SINK@", fmt.Sprintf("-%d%%", percent)).Run()
}
-231
View File
@@ -1,231 +0,0 @@
package player
import (
"strings"
"sync"
"github.com/godbus/dbus/v5"
"go.arsenm.dev/infinitime/internal/utils"
)
var (
method, monitor *dbus.Conn
monitorCh chan *dbus.Message
onChangeOnce sync.Once
)
// Init makes required connections to DBis and
// initializes change monitoring channel
func Init() error {
// Connect to session bus for monitoring
monitorConn, err := utils.NewSessionBusConn()
if err != nil {
return err
}
// Add match rule for PropertiesChanged on media player
monitorConn.AddMatchSignal(
dbus.WithMatchObjectPath("/org/mpris/MediaPlayer2"),
dbus.WithMatchInterface("org.freedesktop.DBus.Properties"),
dbus.WithMatchMember("PropertiesChanged"),
)
monitorCh = make(chan *dbus.Message, 10)
monitorConn.Eavesdrop(monitorCh)
// Connect to session bus for method calls
methodConn, err := utils.NewSessionBusConn()
if err != nil {
return err
}
method, monitor = methodConn, monitorConn
return nil
}
// Exit closes all connections and channels
func Exit() {
close(monitorCh)
method.Close()
monitor.Close()
}
// Play uses MPRIS to play media
func Play() error {
player, err := getPlayerObj()
if err != nil {
return err
}
if player != nil {
call := player.Call("org.mpris.MediaPlayer2.Player.Play", 0)
if call.Err != nil {
return call.Err
}
}
return nil
}
// Pause uses MPRIS to pause media
func Pause() error {
player, err := getPlayerObj()
if err != nil {
return err
}
if player != nil {
call := player.Call("org.mpris.MediaPlayer2.Player.Pause", 0)
if call.Err != nil {
return call.Err
}
}
return nil
}
// Next uses MPRIS to skip to next media
func Next() error {
player, err := getPlayerObj()
if err != nil {
return err
}
if player != nil {
call := player.Call("org.mpris.MediaPlayer2.Player.Next", 0)
if call.Err != nil {
return call.Err
}
}
return nil
}
// Prev uses MPRIS to skip to previous media
func Prev() error {
player, err := getPlayerObj()
if err != nil {
return err
}
if player != nil {
call := player.Call("org.mpris.MediaPlayer2.Player.Previous", 0)
if call.Err != nil {
return call.Err
}
}
return nil
}
type ChangeType int
const (
ChangeTypeTitle ChangeType = iota
ChangeTypeArtist
ChangeTypeAlbum
ChangeTypeStatus
)
func (ct ChangeType) String() string {
switch ct {
case ChangeTypeTitle:
return "Title"
case ChangeTypeAlbum:
return "Album"
case ChangeTypeArtist:
return "Artist"
case ChangeTypeStatus:
return "Status"
}
return ""
}
// OnChange runs cb when a value changes
func OnChange(cb func(ChangeType, string)) {
go onChangeOnce.Do(func() {
// For every message on channel
for msg := range monitorCh {
// Parse PropertiesChanged
iface, changed, ok := parsePropertiesChanged(msg)
if !ok || iface != "org.mpris.MediaPlayer2.Player" {
continue
}
// For every property changed
for name, val := range changed {
// If metadata changed
if name == "Metadata" {
// Get fields
fields := val.Value().(map[string]dbus.Variant)
// For every field
for name, val := range fields {
// Handle each field appropriately
if strings.HasSuffix(name, "title") {
title := val.Value().(string)
if title == "" {
title = "Unknown " + ChangeTypeTitle.String()
}
cb(ChangeTypeTitle, title)
} else if strings.HasSuffix(name, "album") {
album := val.Value().(string)
if album == "" {
album = "Unknown " + ChangeTypeAlbum.String()
}
cb(ChangeTypeAlbum, album)
} else if strings.HasSuffix(name, "artist") {
var artists string
switch artistVal := val.Value().(type) {
case string:
artists = artistVal
case []string:
artists = strings.Join(artistVal, ", ")
}
if artists == "" {
artists = "Unknown " + ChangeTypeArtist.String()
}
cb(ChangeTypeArtist, artists)
}
}
} else if name == "PlaybackStatus" {
// Handle status change
cb(ChangeTypeStatus, val.Value().(string))
}
}
}
})
}
// getPlayerNames gets all DBus MPRIS player bus names
func getPlayerNames(conn *dbus.Conn) ([]string, error) {
var names []string
err := conn.BusObject().Call("org.freedesktop.DBus.ListNames", 0).Store(&names)
if err != nil {
return nil, err
}
var players []string
for _, name := range names {
if strings.HasPrefix(name, "org.mpris.MediaPlayer2") {
players = append(players, name)
}
}
return players, nil
}
// GetPlayerObj gets the object corresponding to the first
// bus name found in DBus
func getPlayerObj() (dbus.BusObject, error) {
players, err := getPlayerNames(method)
if err != nil {
return nil, err
}
if len(players) == 0 {
return nil, nil
}
return method.Object(players[0], "/org/mpris/MediaPlayer2"), nil
}
// parsePropertiesChanged parses a DBus PropertiesChanged signal
func parsePropertiesChanged(msg *dbus.Message) (iface string, changed map[string]dbus.Variant, ok bool) {
if len(msg.Body) != 3 {
return "", nil, false
}
iface, ok = msg.Body[0].(string)
if !ok {
return
}
changed, ok = msg.Body[1].(map[string]dbus.Variant)
if !ok {
return
}
return
}
+12 -12
View File
@@ -7,7 +7,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"go.arsenm.dev/infinitime/blefs" "go.elara.ws/infinitime/blefs"
) )
// ResourceOperation represents an operation performed during // ResourceOperation represents an operation performed during
@@ -80,7 +80,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
m.Close() m.Close()
log.Debug().Msg("Decoded manifest file") log.Debug("Decoded manifest file").Send()
go func() { go func() {
defer close(out) defer close(out)
@@ -88,7 +88,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
for _, file := range manifest.Obsolete { for _, file := range manifest.Obsolete {
name := filepath.Base(file.Path) name := filepath.Base(file.Path)
log.Debug().Str("file", file.Path).Msg("Removing file") log.Debug("Removing file").Str("file", file.Path).Send()
err := fs.RemoveAll(file.Path) err := fs.RemoveAll(file.Path)
if err != nil { if err != nil {
@@ -100,7 +100,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return return
} }
log.Debug().Str("file", file.Path).Msg("Removed file") log.Debug("Removed file").Str("file", file.Path).Send()
out <- ResourceLoadProgress{ out <- ResourceLoadProgress{
Name: name, Name: name,
@@ -131,11 +131,11 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return return
} }
log.Debug().Str("file", file.Path).Msg("Making directories") log.Debug("Making directories").Str("file", file.Path).Send()
err = fs.MkdirAll(filepath.Dir(file.Path)) err = fs.MkdirAll(filepath.Dir(file.Path))
if err != nil { if err != nil {
log.Debug().Err(err).Msg("Error making directories") log.Debug("Error making directories").Err(err).Send()
out <- ResourceLoadProgress{ out <- ResourceLoadProgress{
Name: file.Name, Name: file.Name,
Operation: ResourceOperationUpload, Operation: ResourceOperationUpload,
@@ -146,14 +146,14 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
return return
} }
log.Debug(). log.Debug("Creating file").
Str("file", file.Path). Str("file", file.Path).
Int64("size", srcFi.Size()). Int64("size", srcFi.Size()).
Msg("Creating file") Send()
dst, err := fs.Create(file.Path, uint32(srcFi.Size())) dst, err := fs.Create(file.Path, uint32(srcFi.Size()))
if err != nil { if err != nil {
log.Debug().Err(err).Msg("Error creating file") log.Debug("Error creating file").Err(err).Send()
out <- ResourceLoadProgress{ out <- ResourceLoadProgress{
Name: file.Name, Name: file.Name,
Operation: ResourceOperationUpload, Operation: ResourceOperationUpload,
@@ -167,10 +167,10 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
progCh := dst.Progress() progCh := dst.Progress()
go func() { go func() {
for sent := range progCh { for sent := range progCh {
log.Debug(). log.Debug("Progress event sent").
Int64("total", srcFi.Size()). Int64("total", srcFi.Size()).
Uint32("sent", sent). Uint32("sent", sent).
Msg("Progress event sent") Send()
out <- ResourceLoadProgress{ out <- ResourceLoadProgress{
Name: file.Name, Name: file.Name,
@@ -187,7 +187,7 @@ func LoadResources(file *os.File, fs *blefs.FS) (<-chan ResourceLoadProgress, er
n, err := io.Copy(dst, src) n, err := io.Copy(dst, src)
if err != nil { if err != nil {
log.Debug().Err(err).Msg("Error writing to file") log.Debug("Error writing to file").Err(err).Send()
out <- ResourceLoadProgress{ out <- ResourceLoadProgress{
Name: file.Name, Name: file.Name,
Operation: ResourceOperationUpload, Operation: ResourceOperationUpload,
+4 -5
View File
@@ -81,13 +81,12 @@ type TimelineHeader struct {
// NewHeader creates and populates a new timeline header // NewHeader creates and populates a new timeline header
// and returns it // and returns it
func NewHeader(evtType EventType, expires time.Duration) TimelineHeader { func NewHeader(t time.Time, evtType EventType, expires time.Duration) TimelineHeader {
now := time.Now() _, offset := t.Zone()
_, offset := now.Zone() t = t.Add(time.Duration(offset) * time.Second)
now = now.Add(time.Duration(offset) * time.Second)
return TimelineHeader{ return TimelineHeader{
Timestamp: uint64(now.Unix()), Timestamp: uint64(t.Unix()),
Expires: uint32(expires.Seconds()), Expires: uint32(expires.Seconds()),
EventType: evtType, EventType: evtType,
} }