@@ -170,7 +170,7 @@ type Device struct {
170170// Connect starts a connection attempt to the given peripheral device address.
171171//
172172// On Linux and Windows, the IsRandom part of the address is ignored.
173- func (a * Adapter ) Connect (address Address , params ConnectionParams ) (* Device , error ) {
173+ func (a * Adapter ) Connect (address Address , params ConnectionParams ) (Device , error ) {
174174 var winAddr uint64
175175 for i := range address .MAC {
176176 winAddr += uint64 (address .MAC [i ]) << (8 * i )
@@ -179,23 +179,23 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (*Device, er
179179 // IAsyncOperation<BluetoothLEDevice>
180180 bleDeviceOp , err := bluetooth .FromBluetoothAddressAsync (winAddr )
181181 if err != nil {
182- return nil , err
182+ return Device {} , err
183183 }
184184
185185 // We need to pass the signature of the parameter returned by the async operation:
186186 // IAsyncOperation<BluetoothLEDevice>
187187 if err := awaitAsyncOperation (bleDeviceOp , bluetooth .SignatureBluetoothLEDevice ); err != nil {
188- return nil , fmt .Errorf ("error connecting to device: %w" , err )
188+ return Device {} , fmt .Errorf ("error connecting to device: %w" , err )
189189 }
190190
191191 res , err := bleDeviceOp .GetResults ()
192192 if err != nil {
193- return nil , err
193+ return Device {} , err
194194 }
195195
196196 // The returned BluetoothLEDevice is set to null if FromBluetoothAddressAsync can't find the device identified by bluetoothAddress
197197 if uintptr (res ) == 0x0 {
198- return nil , fmt .Errorf ("device with the given address was not found" )
198+ return Device {} , fmt .Errorf ("device with the given address was not found" )
199199 }
200200
201201 bleDevice := (* bluetooth .BluetoothLEDevice )(res )
@@ -204,37 +204,37 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (*Device, er
204204 // To initiate a connection, we need to set GattSession.MaintainConnection to true.
205205 dID , err := bleDevice .GetBluetoothDeviceId ()
206206 if err != nil {
207- return nil , err
207+ return Device {} , err
208208 }
209209
210210 // Windows does not support explicitly connecting to a device.
211211 // Instead it has the concept of a GATT session that is owned
212212 // by the calling program.
213213 gattSessionOp , err := genericattributeprofile .FromDeviceIdAsync (dID ) // IAsyncOperation<GattSession>
214214 if err != nil {
215- return nil , err
215+ return Device {} , err
216216 }
217217
218218 if err := awaitAsyncOperation (gattSessionOp , genericattributeprofile .SignatureGattSession ); err != nil {
219- return nil , fmt .Errorf ("error getting gatt session: %w" , err )
219+ return Device {} , fmt .Errorf ("error getting gatt session: %w" , err )
220220 }
221221
222222 gattRes , err := gattSessionOp .GetResults ()
223223 if err != nil {
224- return nil , err
224+ return Device {} , err
225225 }
226226 newSession := (* genericattributeprofile .GattSession )(gattRes )
227227 // This keeps the device connected until we set maintain_connection = False.
228228 if err := newSession .SetMaintainConnection (true ); err != nil {
229- return nil , err
229+ return Device {} , err
230230 }
231231
232- return & Device {bleDevice , newSession }, nil
232+ return Device {bleDevice , newSession }, nil
233233}
234234
235235// Disconnect from the BLE device. This method is non-blocking and does not
236236// wait until the connection is fully gone.
237- func (d * Device ) Disconnect () error {
237+ func (d Device ) Disconnect () error {
238238 defer d .device .Release ()
239239 defer d .session .Release ()
240240
0 commit comments