@@ -19,7 +19,7 @@ import (
19
19
"github.com/BitBoxSwiss/bitbox02-api-go/util/errp"
20
20
)
21
21
22
- // nonAtomicQueryBluetooth is like query , but nested one level deeper for Bluetooth.
22
+ // nonAtomicQueryBluetooth is like nonAtomicQuery , but nested one level deeper for Bluetooth.
23
23
func (device * Device ) nonAtomicQueryBluetooth (request * messages.BluetoothRequest ) (* messages.BluetoothResponse , error ) {
24
24
if ! device .SupportsBluetooth () {
25
25
return nil , errp .New ("this device does not support Bluetooth" )
@@ -39,6 +39,13 @@ func (device *Device) nonAtomicQueryBluetooth(request *messages.BluetoothRequest
39
39
return bluetoothResponse .Bluetooth , nil
40
40
}
41
41
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
+
42
49
// BluetoothUpgrade attempts an upgrade of the Bluetooth firmware.
43
50
func (device * Device ) BluetoothUpgrade (firmware []byte ) error {
44
51
return device .atomicQueries (func () error {
@@ -80,3 +87,20 @@ func (device *Device) BluetoothUpgrade(firmware []byte) error {
80
87
}
81
88
})
82
89
}
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
+ }
0 commit comments