Skip to content

Commit dba834f

Browse files
committed
Merge branch 'bluetooth'
2 parents cdd4ce7 + f4c89d5 commit dba834f

File tree

7 files changed

+246
-109
lines changed

7 files changed

+246
-109
lines changed

api/firmware/bluetooth.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"github.com/BitBoxSwiss/bitbox02-api-go/util/errp"
2020
)
2121

22-
// nonAtomicQueryBluetooth is like query, but nested one level deeper for Bluetooth.
22+
// nonAtomicQueryBluetooth is like nonAtomicQuery, but nested one level deeper for Bluetooth.
2323
func (device *Device) nonAtomicQueryBluetooth(request *messages.BluetoothRequest) (*messages.BluetoothResponse, error) {
2424
if !device.SupportsBluetooth() {
2525
return nil, errp.New("this device does not support Bluetooth")
@@ -39,6 +39,13 @@ func (device *Device) nonAtomicQueryBluetooth(request *messages.BluetoothRequest
3939
return bluetoothResponse.Bluetooth, nil
4040
}
4141

42+
// queryBluetooth is like query, but nested one level deeper for Bluetooth.
43+
func (device *Device) queryBluetooth(request *messages.BluetoothRequest) (*messages.BluetoothResponse, error) {
44+
return atomicQueriesValue(device, func() (*messages.BluetoothResponse, error) {
45+
return device.nonAtomicQueryBluetooth(request)
46+
})
47+
}
48+
4249
// BluetoothUpgrade attempts an upgrade of the Bluetooth firmware.
4350
func (device *Device) BluetoothUpgrade(firmware []byte) error {
4451
return device.atomicQueries(func() error {
@@ -80,3 +87,20 @@ func (device *Device) BluetoothUpgrade(firmware []byte) error {
8087
}
8188
})
8289
}
90+
91+
// BluetoothToggleEnabled enables/disables Bluetooth.
92+
func (device *Device) BluetoothToggleEnabled() error {
93+
response, err := device.queryBluetooth(&messages.BluetoothRequest{
94+
Request: &messages.BluetoothRequest_ToggleEnabled{
95+
ToggleEnabled: &messages.BluetoothToggleEnabledRequest{},
96+
},
97+
})
98+
if err != nil {
99+
return err
100+
}
101+
_, ok := response.Response.(*messages.BluetoothResponse_Success)
102+
if !ok {
103+
return errp.New("unexpected response")
104+
}
105+
return nil
106+
}

api/firmware/device.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ type Device struct {
116116
type BluetoothInfo struct {
117117
// FirmwareHash is the hex-encoded 32 byte Bluetooth firmware hash.
118118
FirmwareHash string `json:"firmwareHash"`
119+
// FirmwareVersion is the Bluetooth firmware version, formated as "major.minor.patch".
120+
FirmwareVersion string `json:"firmwareVersion"`
121+
// Enabled is true if Bluetooth is enabled.
122+
Enabled bool `json:"enabled"`
119123
}
120124

121125
// DeviceInfo is the data returned from the device info api call.

api/firmware/messages/bitbox02_system.pb.go

Lines changed: 48 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/firmware/messages/bitbox02_system.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ message DeviceInfoResponse {
2929
message Bluetooth {
3030
// Hash of the currently active Bluetooth firmware on the device.
3131
bytes firmware_hash = 1;
32+
// Firmware version, formated as an unsigned integer "1", "2", etc.
33+
string firmware_version = 2;
34+
// True if Bluetooth is enabled
35+
bool enabled = 3;
3236
}
3337
string name = 1;
3438
bool initialized = 2;

0 commit comments

Comments
 (0)