ble 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,44 @@
1
+ module BLE
2
+ module Notifications
3
+
4
+ # Registers current device for notifications of the given _characteristic_.
5
+ # Synonym for 'subscribe' or 'activate'.
6
+ # This step is required in order to later receive notifications.
7
+ # @param service [String, Symbol]
8
+ # @param characteristic [String, Symbol]
9
+ #
10
+ def start_notify!(service, characteristic)
11
+ char= _find_characteristic(service, characteristic)
12
+ if char.flag?('notify')
13
+ char.notify!
14
+ else
15
+ raise OperationNotSupportedError.new("No notifications available for characteristic #{characteristic}")
16
+ end
17
+ end
18
+
19
+ #
20
+ # Registers the callback to be invoked when a notification from the given _characteristic_ is received.
21
+ #
22
+ # NOTE: Requires the device to be subscribed to _characteristic_ notifications.
23
+ # @param service [String, Symbol]
24
+ # @param characteristic [String, Symbol]
25
+ # @param raw [Boolean] When raw is true the value (set/get) is a binary string, instead of an object corresponding to the decoded characteristic (float, integer, array, ...)
26
+ # @param callback [Proc] This callback will have the notified value as argument.
27
+ #
28
+ def on_notification(service, characteristic, raw: false, &callback)
29
+ _require_connection!
30
+ char= _find_characteristic(service, characteristic)
31
+ if char.flag?('notify')
32
+ char.on_change(raw: raw) { |val|
33
+ callback.call(val)
34
+ }
35
+ elsif char.flag?('encrypt-read') ||
36
+ char.flag?('encrypt-authenticated-read')
37
+ raise NotYetImplemented
38
+ else
39
+ raise AccessUnavailable
40
+ end
41
+ end
42
+
43
+ end
44
+ end
@@ -1,9 +1,15 @@
1
1
  module BLE
2
- # Library version
2
+ # = Library version =
3
+ # Major version zero (0.y.z) is for initial development.
4
+ # Anything may change at any time.
5
+ # The public API should not be considered stable.
6
+
7
+ # 0.1.0 MINOR
8
+ # - [FEATURE] BLE notifications functionality.
9
+ # - [REFACTOR] Breaks Characteristic API
3
10
 
4
- #
5
11
  # 0.0.3 PATCH
6
12
  # - [FIX] NotSupported exeption was not declared.
7
13
  #
8
- VERSION = '0.0.3'
14
+ VERSION = '0.1.0'
9
15
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ble
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephane D'Alu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-05 00:00:00.000000000 Z
11
+ date: 2016-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-dbus
@@ -93,12 +93,15 @@ files:
93
93
  - lib/ble.rb
94
94
  - lib/ble/adapter.rb
95
95
  - lib/ble/agent.rb
96
+ - lib/ble/char_desc.rb
97
+ - lib/ble/char_registry.rb
96
98
  - lib/ble/characteristic.rb
97
99
  - lib/ble/db_eddystone.rb
98
100
  - lib/ble/db_nordic.rb
99
101
  - lib/ble/db_sig_characteristic.rb
100
102
  - lib/ble/db_sig_service.rb
101
103
  - lib/ble/device.rb
104
+ - lib/ble/notifications.rb
102
105
  - lib/ble/service.rb
103
106
  - lib/ble/uuid.rb
104
107
  - lib/ble/version.rb