Skip to content

Commit 8c0b155

Browse files
committed
firmware: add BluetoothToggleEnabled
1 parent 23522dc commit 8c0b155

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
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(firmware []byte) 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/messages/bluetooth.pb.go

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

0 commit comments

Comments
 (0)