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 13
def initialize(desc)
  @dbus_obj= desc[:obj]
  @desc= CharDesc.new(desc)
end

Public Instance Methods

notify!() click to toggle source

Register to this characteristic for notifications when its value changes.

# File lib/ble/characteristic.rb, line 52
def notify!
  @dbus_obj[I_GATT_CHARACTERISTIC].StartNotify
end
on_change(raw: false, &callback) click to toggle source
# File lib/ble/characteristic.rb, line 56
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 45
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 40
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 78
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 70
def _serialize_value(val, raw: false)
  if !raw && @desc.write_processors?
    val= @desc.pre_process(val)
  end
  val.unpack('C*')
end