flic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +5 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +30 -0
  8. data/Rakefile +12 -0
  9. data/flic.gemspec +25 -0
  10. data/lib/flic.rb +7 -0
  11. data/lib/flic/client.rb +247 -0
  12. data/lib/flic/client/connection.rb +87 -0
  13. data/lib/flic/event_bus.rb +81 -0
  14. data/lib/flic/event_bus/driver.rb +23 -0
  15. data/lib/flic/event_bus/subscription.rb +66 -0
  16. data/lib/flic/protocol.rb +64 -0
  17. data/lib/flic/protocol/commands.rb +44 -0
  18. data/lib/flic/protocol/commands/cancel_scan_wizard.rb +15 -0
  19. data/lib/flic/protocol/commands/change_mode_parameters.rb +17 -0
  20. data/lib/flic/protocol/commands/command.rb +21 -0
  21. data/lib/flic/protocol/commands/create_connection_channel.rb +20 -0
  22. data/lib/flic/protocol/commands/create_scan_wizard.rb +15 -0
  23. data/lib/flic/protocol/commands/create_scanner.rb +14 -0
  24. data/lib/flic/protocol/commands/force_disconnect.rb +15 -0
  25. data/lib/flic/protocol/commands/get_button_uuid.rb +15 -0
  26. data/lib/flic/protocol/commands/get_info.rb +12 -0
  27. data/lib/flic/protocol/commands/ping.rb +14 -0
  28. data/lib/flic/protocol/commands/remove_connection_channel.rb +14 -0
  29. data/lib/flic/protocol/commands/remove_scanner.rb +14 -0
  30. data/lib/flic/protocol/events.rb +60 -0
  31. data/lib/flic/protocol/events/advertisement_packet.rb +25 -0
  32. data/lib/flic/protocol/events/bluetooth_controller_state_change.rb +15 -0
  33. data/lib/flic/protocol/events/button_click_or_hold.rb +19 -0
  34. data/lib/flic/protocol/events/button_single_or_double_click.rb +19 -0
  35. data/lib/flic/protocol/events/button_single_or_double_click_or_hold.rb +19 -0
  36. data/lib/flic/protocol/events/button_up_or_down.rb +19 -0
  37. data/lib/flic/protocol/events/connection_channel_removed.rb +16 -0
  38. data/lib/flic/protocol/events/connection_status_changed.rb +19 -0
  39. data/lib/flic/protocol/events/create_connection_channel_response.rb +18 -0
  40. data/lib/flic/protocol/events/event.rb +21 -0
  41. data/lib/flic/protocol/events/get_button_uuid_response.rb +17 -0
  42. data/lib/flic/protocol/events/get_info_response.rb +27 -0
  43. data/lib/flic/protocol/events/got_space_for_new_connection.rb +14 -0
  44. data/lib/flic/protocol/events/new_verified_button.rb +15 -0
  45. data/lib/flic/protocol/events/no_space_for_new_connection.rb +14 -0
  46. data/lib/flic/protocol/events/ping_response.rb +14 -0
  47. data/lib/flic/protocol/events/scan_wizard_button_connected.rb +14 -0
  48. data/lib/flic/protocol/events/scan_wizard_completed.rb +16 -0
  49. data/lib/flic/protocol/events/scan_wizard_found_private_button.rb +14 -0
  50. data/lib/flic/protocol/events/scan_wizard_found_public_button.rb +19 -0
  51. data/lib/flic/protocol/packet_header.rb +12 -0
  52. data/lib/flic/protocol/primitives.rb +22 -0
  53. data/lib/flic/protocol/primitives/bluetooth_address.rb +35 -0
  54. data/lib/flic/protocol/primitives/bluetooth_address_type.rb +13 -0
  55. data/lib/flic/protocol/primitives/bluetooth_controller_state.rb +14 -0
  56. data/lib/flic/protocol/primitives/boolean.rb +19 -0
  57. data/lib/flic/protocol/primitives/click_type.rb +17 -0
  58. data/lib/flic/protocol/primitives/connection_status.rb +14 -0
  59. data/lib/flic/protocol/primitives/create_connection_channel_error.rb +13 -0
  60. data/lib/flic/protocol/primitives/device_name.rb +44 -0
  61. data/lib/flic/protocol/primitives/disconnect_reason.rb +15 -0
  62. data/lib/flic/protocol/primitives/enum.rb +85 -0
  63. data/lib/flic/protocol/primitives/latency_mode.rb +14 -0
  64. data/lib/flic/protocol/primitives/removed_reason.rb +18 -0
  65. data/lib/flic/protocol/primitives/scan_wizard_result.rb +18 -0
  66. data/lib/flic/protocol/primitives/uuid.rb +23 -0
  67. data/lib/flic/version.rb +3 -0
  68. metadata +180 -0
@@ -0,0 +1,14 @@
1
+ require 'flic/protocol/commands'
2
+ require 'flic/protocol/commands/command'
3
+
4
+ module Flic
5
+ module Protocol
6
+ module Commands
7
+ class Ping < Command
8
+ endian :little
9
+
10
+ uint32 :ping_id
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'flic/protocol/commands'
2
+ require 'flic/protocol/commands/command'
3
+
4
+ module Flic
5
+ module Protocol
6
+ module Commands
7
+ class RemoveConnectionChannel < Command
8
+ endian :little
9
+
10
+ uint32 :connection_id
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'flic/protocol/commands'
2
+ require 'flic/protocol/commands/command'
3
+
4
+ module Flic
5
+ module Protocol
6
+ module Commands
7
+ class RemoveScanner < Command
8
+ endian :little
9
+
10
+ uint32 :scan_id
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,60 @@
1
+ require 'flic/protocol'
2
+
3
+ module Flic
4
+ module Protocol
5
+ module Events
6
+ autoload :AdvertisementPacket, 'flic/protocol/events/advertisement_packet'
7
+ autoload :BluetoothControllerStateChange, 'flic/protocol/events/bluetooth_controller_state_change'
8
+ autoload :ButtonClickOrHold, 'flic/protocol/events/button_click_or_hold'
9
+ autoload :ButtonSingleOrDoubleClick, 'flic/protocol/events/button_single_or_double_click'
10
+ autoload :ButtonSingleOrDoubleClickOrHold, 'flic/protocol/events/button_single_or_double_click_or_hold'
11
+ autoload :ButtonUpOrDown, 'flic/protocol/events/button_up_or_down'
12
+ autoload :ConnectionChannelRemoved, 'flic/protocol/events/connection_channel_removed'
13
+ autoload :ConnectionStatusChanged, 'flic/protocol/events/connection_status_changed'
14
+ autoload :CreateConnectionChannelResponse, 'flic/protocol/events/create_connection_channel_response'
15
+ autoload :Event, 'flic/protocol/events/event'
16
+ autoload :GetButtonUuidResponse, 'flic/protocol/events/get_button_uuid_response'
17
+ autoload :GetInfoResponse, 'flic/protocol/events/get_info_response'
18
+ autoload :GotSpaceForNewConnection, 'flic/protocol/events/got_space_for_new_connection'
19
+ autoload :NewVerifiedButton, 'flic/protocol/events/new_verified_button'
20
+ autoload :NoSpaceForNewConnection, 'flic/protocol/events/no_space_for_new_connection'
21
+ autoload :PingResponse, 'flic/protocol/events/ping_response'
22
+ autoload :ScanWizardButtonConnected, 'flic/protocol/events/scan_wizard_button_connected'
23
+ autoload :ScanWizardCompleted, 'flic/protocol/events/scan_wizard_completed'
24
+ autoload :ScanWizardFoundPrivateButton, 'flic/protocol/events/scan_wizard_found_private_button'
25
+ autoload :ScanWizardFoundPublicButton, 'flic/protocol/events/scan_wizard_found_public_button'
26
+
27
+ EVENT_CLASS_OPCODE = {
28
+ Events::AdvertisementPacket => 0x00,
29
+ Events::CreateConnectionChannelResponse => 0x01,
30
+ Events::ConnectionStatusChanged => 0x02,
31
+ Events::ConnectionChannelRemoved => 0x03,
32
+ Events::ButtonUpOrDown => 0x04,
33
+ Events::ButtonClickOrHold => 0x05,
34
+ Events::ButtonSingleOrDoubleClick => 0x06,
35
+ Events::ButtonSingleOrDoubleClickOrHold => 0x07,
36
+ Events::NewVerifiedButton => 0x08,
37
+ Events::GetInfoResponse => 0x09,
38
+ Events::NoSpaceForNewConnection => 0x0A,
39
+ Events::GotSpaceForNewConnection => 0x0B,
40
+ Events::BluetoothControllerStateChange => 0x0C,
41
+ Events::PingResponse => 0x0D,
42
+ Events::GetButtonUuidResponse => 0x0E,
43
+ Events::ScanWizardFoundPrivateButton => 0x0F,
44
+ Events::ScanWizardFoundPublicButton => 0x10,
45
+ Events::ScanWizardButtonConnected => 0x11,
46
+ Events::ScanWizardCompleted => 0x12
47
+ }.freeze
48
+
49
+ OPCODE_EVENT_CLASS = EVENT_CLASS_OPCODE.invert.freeze
50
+
51
+ def self.event_class_for_opcode(opcode)
52
+ OPCODE_EVENT_CLASS[opcode]
53
+ end
54
+
55
+ def self.opcode_for_event_class(event_class)
56
+ EVENT_CLASS_OPCODE[event_class]
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,25 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/bluetooth_address'
4
+ require 'flic/protocol/primitives/device_name'
5
+ require 'flic/protocol/primitives/boolean'
6
+
7
+ module Flic
8
+ module Protocol
9
+ module Events
10
+ class AdvertisementPacket < Event
11
+ endian :little
12
+
13
+ uint32 :scan_id
14
+ bluetooth_address :bluetooth_address
15
+
16
+ device_name :name
17
+
18
+ int8 :rssi
19
+
20
+ boolean :is_private
21
+ boolean :is_already_verified
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/bluetooth_controller_state'
4
+
5
+ module Flic
6
+ module Protocol
7
+ module Events
8
+ class BluetoothControllerStateChange < Event
9
+ endian :little
10
+
11
+ bluetooth_controller_state :bluetooth_controller_state
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/click_type'
4
+ require 'flic/protocol/primitives/boolean'
5
+
6
+ module Flic
7
+ module Protocol
8
+ module Events
9
+ class ButtonClickOrHold < Event
10
+ endian :little
11
+
12
+ uint32 :connection_id
13
+ click_type :click_type
14
+ boolean :was_queued
15
+ uint32 :time_difference
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/click_type'
4
+ require 'flic/protocol/primitives/boolean'
5
+
6
+ module Flic
7
+ module Protocol
8
+ module Events
9
+ class ButtonSingleOrDoubleClick < Event
10
+ endian :little
11
+
12
+ uint32 :connection_id
13
+ click_type :click_type
14
+ boolean :was_queued
15
+ uint32 :time_difference
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/click_type'
4
+ require 'flic/protocol/primitives/boolean'
5
+
6
+ module Flic
7
+ module Protocol
8
+ module Events
9
+ class ButtonSingleOrDoubleClickOrHold < Event
10
+ endian :little
11
+
12
+ uint32 :connection_id
13
+ click_type :click_type
14
+ boolean :was_queued
15
+ uint32 :time_difference
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/click_type'
4
+ require 'flic/protocol/primitives/boolean'
5
+
6
+ module Flic
7
+ module Protocol
8
+ module Events
9
+ class ButtonUpOrDown < Event
10
+ endian :little
11
+
12
+ uint32 :connection_id
13
+ click_type :click_type
14
+ boolean :was_queued
15
+ uint32 :time_difference
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/removed_reason'
4
+
5
+ module Flic
6
+ module Protocol
7
+ module Events
8
+ class ConnectionChannelRemoved < Event
9
+ endian :little
10
+
11
+ uint32 :connection_id
12
+ removed_reason :removed_reason
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/connection_status'
4
+ require 'flic/protocol/primitives/disconnect_reason'
5
+
6
+ module Flic
7
+ module Protocol
8
+ module Events
9
+ class ConnectionStatusChanged < Event
10
+ endian :little
11
+
12
+ uint32 :connection_id
13
+ connection_status :connection_status
14
+
15
+ disconnect_reason :disconnect_reason # only relevant when connection_status is :disconnected
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/create_connection_channel_error'
4
+ require 'flic/protocol/primitives/connection_status'
5
+
6
+ module Flic
7
+ module Protocol
8
+ module Events
9
+ class CreateConnectionChannelResponse < Event
10
+ endian :little
11
+
12
+ uint32 :connection_id
13
+ create_connection_channel_error :error
14
+ connection_status :connection_status
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'flic/protocol/events'
2
+
3
+ require 'bindata'
4
+
5
+ module Flic
6
+ module Protocol
7
+ module Events
8
+ class Event < BinData::Record
9
+ endian :little
10
+
11
+ uint8 :opcode, initial_value: -> { init_opcode }
12
+
13
+ private
14
+
15
+ def init_opcode
16
+ Event.opcode_for_event_class(self.class)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/bluetooth_address'
4
+ require 'flic/protocol/primitives/uuid'
5
+
6
+ module Flic
7
+ module Protocol
8
+ module Events
9
+ class GetButtonUuidResponse < Event
10
+ endian :little
11
+
12
+ bluetooth_address :bluetooth_address
13
+ uuid :uuid
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/bluetooth_controller_state'
4
+ require 'flic/protocol/primitives/bluetooth_address'
5
+ require 'flic/protocol/primitives/bluetooth_address_type'
6
+
7
+ module Flic
8
+ module Protocol
9
+ module Events
10
+ class GetInfoResponse < Event
11
+ endian :little
12
+
13
+ bluetooth_controller_state :bluetooth_controller_state
14
+ bluetooth_address :bluetooth_address
15
+ bluetooth_address_type :bluetooth_address_type
16
+
17
+ uint8 :maximum_pending_connections
18
+ int16 :maximum_concurrently_connected_buttons
19
+ uint8 :current_pending_connections
20
+ boolean :currently_no_space_for_new_connection
21
+
22
+ uint16 :verified_buttons_length
23
+ array :verified_buttons, type: :bluetooth_address, initial_length: :verified_buttons_length
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+
4
+ module Flic
5
+ module Protocol
6
+ module Events
7
+ class GotSpaceForNewConnection < Event
8
+ endian :little
9
+
10
+ uint8 :maximum_concurrently_connected_buttons
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+ require 'flic/protocol/primitives/bluetooth_address'
4
+
5
+ module Flic
6
+ module Protocol
7
+ module Events
8
+ class NewVerifiedButton < Event
9
+ endian :little
10
+
11
+ bluetooth_address :bluetooth_address
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+
4
+ module Flic
5
+ module Protocol
6
+ module Events
7
+ class NoSpaceForNewConnection < Event
8
+ endian :little
9
+
10
+ uint8 :maximum_concurrently_connected_buttons
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+
4
+ module Flic
5
+ module Protocol
6
+ module Events
7
+ class PingResponse < Event
8
+ endian :little
9
+
10
+ uint32 :ping_id
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ require 'flic/protocol/events'
2
+ require 'flic/protocol/events/event'
3
+
4
+ module Flic
5
+ module Protocol
6
+ module Events
7
+ class ScanWizardButtonConnected < Event
8
+ endian :little
9
+
10
+ uint32 :scan_wizard_id
11
+ end
12
+ end
13
+ end
14
+ end