class BLE::Characteristic
Build information about {developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicsHome.aspx Bluetooth Characteristics}
Constants
- FLAGS
Public Class Methods
new(desc)
click to toggle source
# File lib/ble/characteristic.rb, line 14 def initialize(desc) @dbus_obj= desc[:obj] @desc= CharDesc.new(desc) end
Public Instance Methods
async_read(raw: false)
click to toggle source
# File lib/ble/characteristic.rb, line 60 def async_read(raw: false) return Concurrent::Promise.execute do @dbus_obj[I_GATT_CHARACTERISTIC].ReadValue() do |result| val= result.first val= _deserialize_value(val, raw: raw) end end end
async_write(val, raw: false)
click to toggle source
# File lib/ble/characteristic.rb, line 46 def async_write(val, raw: false) val= _serialize_value(val, raw: raw) Concurrent::Promise.execute do @dbus_obj[I_GATT_CHARACTERISTIC].WriteValue(val, []) do |result| result end end end
notify!()
click to toggle source
Register to this characteristic for notifications when its value changes.
# File lib/ble/characteristic.rb, line 71 def notify! @dbus_obj[I_GATT_CHARACTERISTIC].StartNotify end
on_change(raw: false, &callback)
click to toggle source
# File lib/ble/characteristic.rb, line 75 def on_change(raw: false, &callback) @dbus_obj[I_PROPERTIES].on_signal('PropertiesChanged') do |intf, props| case intf when I_GATT_CHARACTERISTIC val= _deserialize_value(props['Value'], raw: raw) callback.call(val) end end end
read(raw: false)
click to toggle source
# File lib/ble/characteristic.rb, line 55 def read(raw: false) val= @dbus_obj[I_GATT_CHARACTERISTIC].ReadValue().first val= _deserialize_value(val, raw: raw) end
write(val, raw: false)
click to toggle source
++++++++++++++++++++++++++++
# File lib/ble/characteristic.rb, line 41 def write(val, raw: false) val= _serialize_value(val, raw: raw) @dbus_obj[I_GATT_CHARACTERISTIC].WriteValue(val, []) end
Private Instance Methods
_deserialize_value(val, raw: false)
click to toggle source
Convert Arrays of bytes returned by DBus to Strings of bytes.
# File lib/ble/characteristic.rb, line 97 def _deserialize_value(val, raw: false) val = val.pack('C*') val = @desc.post_process(val) if !raw && @desc.read_processors? val end
_serialize_value(val, raw: false)
click to toggle source
Convert Arrays of bytes returned by DBus to Strings of bytes.
# File lib/ble/characteristic.rb, line 89 def _serialize_value(val, raw: false) if !raw && @desc.write_processors? val= @desc.pre_process(val) end val.unpack('C*') end