Skip to content

Commit

Permalink
feat: add bluetooth battery
Browse files Browse the repository at this point in the history
add bluetooth battery for DBus org.deepin.dde.bluetooth1.GetDevices
  • Loading branch information
kt286 authored and deepin-bot[bot] committed Jul 26, 2023
1 parent 3049a76 commit 17285e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bluetooth1/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type DeviceInfo struct {
Icon string
RSSI int16
Address string

Battery byte
}

func unmarshalDeviceInfo(data string) (*DeviceInfo, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/gosexy/gettext v0.0.0-20160830220431-74466a0a0c4a
github.com/jouyouyun/hardware v0.1.8
github.com/linuxdeepin/dde-api v0.0.0-20230407015108-8b16b3779328
github.com/linuxdeepin/go-dbus-factory v0.0.0-20230407013947-6ff704a21ca7
github.com/linuxdeepin/go-dbus-factory v0.0.0-20230725071734-325d628cbf6e
github.com/linuxdeepin/go-gir v0.0.0-20230331033513-a8d7a9e89f9b
github.com/linuxdeepin/go-lib v0.0.0-20230406092403-b4b4282fc513
github.com/linuxdeepin/go-x11-client v0.0.0-20230329071904-56c906e1ab5d
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/linuxdeepin/dde-api v0.0.0-20230407015108-8b16b3779328 h1:X1TCNEJ1FcBXDqI10T9urw2lV4eQFJ1j6wb59MFxQvs=
github.com/linuxdeepin/dde-api v0.0.0-20230407015108-8b16b3779328/go.mod h1:plHSVHmj6Uvkp2QGQEnc+kZFV/AUZcA2LM5FU8CYvy4=
github.com/linuxdeepin/go-dbus-factory v0.0.0-20230407013947-6ff704a21ca7 h1:4C7KkjoO5Fb1XGmzsD5uym3ZDaeBgtwd710T4nxDcC8=
github.com/linuxdeepin/go-dbus-factory v0.0.0-20230407013947-6ff704a21ca7/go.mod h1:iIlTR50SA8MJ9ORPyMOpKWMF4g+AUorbER5AX0RD9Jk=
github.com/linuxdeepin/go-dbus-factory v0.0.0-20230725071734-325d628cbf6e h1:zBJiuS1i1Zz5mDWIjUMQNR3b5lIfKJXzPqx/6oDJjxI=
github.com/linuxdeepin/go-dbus-factory v0.0.0-20230725071734-325d628cbf6e/go.mod h1:iIlTR50SA8MJ9ORPyMOpKWMF4g+AUorbER5AX0RD9Jk=
github.com/linuxdeepin/go-gir v0.0.0-20230331033513-a8d7a9e89f9b h1:jQpiMVcWkn3iS1u5JGiUrEMgRe6fa+OwdAA5mW1AZtI=
github.com/linuxdeepin/go-gir v0.0.0-20230331033513-a8d7a9e89f9b/go.mod h1:a0tox5vepTQu5iO6rdKc4diGT+fkyXZlRROM8ULEvaI=
github.com/linuxdeepin/go-lib v0.0.0-20230406092403-b4b4282fc513 h1:4qux/rKQwaJSuEp9Vq2UN47cS9oM5JQZ84ajBv3m2uk=
Expand Down
15 changes: 15 additions & 0 deletions system/bluetooth1/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type device struct {
RSSI int16
Address string

Battery byte

connected bool
connectedTime time.Time
retryConnectCount int
Expand Down Expand Up @@ -114,6 +116,8 @@ type backupDevice struct {
Icon string
RSSI int16
Address string

Battery byte
}

type connectPhase uint32
Expand Down Expand Up @@ -229,6 +233,7 @@ func newDevice(systemSigLoop *dbusutil.SignalLoop, dpath dbus.ObjectPath) (d *de
d.Icon, _ = d.core.Icon().Get(0)
d.RSSI, _ = d.core.RSSI().Get(0)
d.blocked, _ = d.core.Blocked().Get(0)
d.Battery, _ = d.core.Percentage().Get(0)
d.needNotify = true
var err error
d.inputReconnectMode, err = d.getInputReconnectModeRaw()
Expand Down Expand Up @@ -491,6 +496,15 @@ func (d *device) connectProperties() {
logger.Debugf("%s Blocked: %v", d, value)
d.blocked = value
})

_ = d.core.Percentage().ConnectChanged(func(hasValue bool, value byte) {
if !hasValue {
return
}
d.Battery = value
logger.Debugf("%s Battery: %v", d, value)
d.notifyDevicePropertiesChanged()
})
}

func (d *device) notifyConnectedChanged() {
Expand Down Expand Up @@ -892,6 +906,7 @@ func newBackupDevice(d *device) (bd *backupDevice) {
bd.ServicesResolved = d.ServicesResolved
bd.Trusted = d.Trusted
bd.UUIDs = d.UUIDs
bd.Battery = d.Battery
return bd
}

Expand Down

0 comments on commit 17285e8

Please sign in to comment.