Skip to content

Commit a48868a

Browse files
authored
linux: Add Write method to write characteristic value with response (#389)
* linux: Add Write method to write characteristic value with response * Use short hand error check * Remove named returns
1 parent 04fbc0e commit a48868a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

gattc_linux.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,19 @@ func (s DeviceService) DiscoverCharacteristics(uuids []UUID) ([]DeviceCharacteri
221221
// call will return before all data has been written. A limited number of such
222222
// writes can be in flight at any given time. This call is also known as a
223223
// "write command" (as opposed to a write request).
224-
func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (n int, err error) {
225-
err = c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, map[string]dbus.Variant(nil)).Err
226-
if err != nil {
224+
func (c DeviceCharacteristic) WriteWithoutResponse(p []byte) (int, error) {
225+
args := map[string]any{"type": "command"}
226+
if err := c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err; err != nil {
227+
return 0, err
228+
}
229+
return len(p), nil
230+
}
231+
232+
// Write replaces the characteristic value with a new value. The
233+
// call will return after all data has been written.
234+
func (c DeviceCharacteristic) Write(p []byte) (int, error) {
235+
args := map[string]any{"type": "request"}
236+
if err := c.characteristic.Call("org.bluez.GattCharacteristic1.WriteValue", 0, p, args).Err; err != nil {
227237
return 0, err
228238
}
229239
return len(p), nil

0 commit comments

Comments
 (0)