Class: BLE::Characteristic

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
CharRegistry
Defined in:
lib/ble/characteristic.rb,
lib/ble/db_nordic.rb,
lib/ble/db_eddystone.rb,
lib/ble/db_sig_characteristic.rb

Overview

Build information about Bluetooth Characteristics

Defined Under Namespace

Classes: NotFound

Instance Method Summary collapse

Methods included from CharRegistry

included

Constructor Details

#initialize(desc) ⇒ Characteristic

Returns a new instance of Characteristic.



13
14
15
16
# File 'lib/ble/characteristic.rb', line 13

def initialize(desc)
  @dbus_obj= desc[:obj]
  @desc= CharDesc.new(desc)
end

Instance Method Details

#notify!Object

Register to this characteristic for notifications when its value changes.



52
53
54
# File 'lib/ble/characteristic.rb', line 52

def notify!
  @dbus_obj[I_GATT_CHARACTERISTIC].StartNotify
end

#on_change(raw: false, &callback) ⇒ Object



56
57
58
59
60
61
62
63
64
# 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) ⇒ Object



45
46
47
48
# 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) ⇒ Object

++++++++++++++++++++++++++++



40
41
42
43
# 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