flic 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae762531f46f32f4d88e0d006bf08c7c804e1a9f
4
- data.tar.gz: 470cd52b6b01ee89bb423df22d6847d6bfdfef9c
3
+ metadata.gz: 30e6a6023c2fe3f2a83299ce7358050ef07195c8
4
+ data.tar.gz: f1ac706e5cfca806615de68e6bf147893225662e
5
5
  SHA512:
6
- metadata.gz: bffa799520a877ab2924f84af76a1ae91acb5c860c1881c383ba7c8755c359d448ec0fdd7b02843dc44616e3cbc73778244da06253859ff8b32cdc7e8134ee2d
7
- data.tar.gz: 24481590f130a83cca420f172a0cf43d6832e45f2aa81bee9bea94d1b7d5dcc084915f4e072f991a05a37bd5ed43da2cc9cf5aaa77b7b554e73ff80bca849f1b
6
+ metadata.gz: a9bc7ad01daea014be21f5214cb15a5cd4d4a2cb0ae6a7cc69b8da408fed1153279475607d1267172f6f1a2bb6e13fe391829f596989189af3f449a3030b257b
7
+ data.tar.gz: a1263c875e8c918b4cd100d65d91964dda1a3d08c3ea613468556ac1eb6dcad6d25ec3c9e8a8fb074d445249358646dd4c1a2ca8b945712ea6065048fb9e84d0
@@ -1,27 +1,29 @@
1
1
  require 'flic/protocol/primitives'
2
2
 
3
3
  module Flic
4
- module Primitives
5
- class DisconnectTime < BinData::Primitive
6
- endian :little
4
+ module Protocol
5
+ module Primitives
6
+ class DisconnectTime < BinData::Primitive
7
+ endian :little
7
8
 
8
- uint16 :time, initial_value: 512
9
+ uint16 :time, initial_value: 512
9
10
 
10
- def get
11
- if time == 512
12
- nil
13
- else
14
- time
11
+ def get
12
+ if time == 512
13
+ nil
14
+ else
15
+ time
16
+ end
15
17
  end
16
- end
17
18
 
18
- def set(value)
19
- if value == 512
20
- raise RangeError, '512 is a special value that cannot be used for disconnect_time'
21
- elsif value
22
- self.time = value
23
- else
24
- self.time = 512
19
+ def set(value)
20
+ if value == 512
21
+ raise RangeError, '512 is a special value that cannot be used for disconnect_time'
22
+ elsif value
23
+ self.time = value
24
+ else
25
+ self.time = 512
26
+ end
25
27
  end
26
28
  end
27
29
  end
@@ -4,19 +4,21 @@ require 'bindata'
4
4
  require 'scanf'
5
5
 
6
6
  module Flic
7
- module Primitives
8
- class Uuid < BinData::Primitive
9
- PRINTF_FORMAT_STRING = '%.2X%.2X%.2X%.2X-%.2X%.2X-%.2X%.2X-%.2X%.2X-%.2X%.2X%.2X%.2X%.2X%.2X'.freeze
10
- SCANF_FORMAT_STRING = '%X%X%X%X-%X%X-%X%X-%X%X-%X%X%X%X%X%X'.freeze
7
+ module Protocol
8
+ module Primitives
9
+ class Uuid < BinData::Primitive
10
+ PRINTF_FORMAT_STRING = '%.2X%.2X%.2X%.2X-%.2X%.2X-%.2X%.2X-%.2X%.2X-%.2X%.2X%.2X%.2X%.2X%.2X'.freeze
11
+ SCANF_FORMAT_STRING = '%X%X%X%X-%X%X-%X%X-%X%X-%X%X%X%X%X%X'.freeze
11
12
 
12
- array :octets, type: :uint8, initial_length: 16
13
+ array :octets, type: :uint8, initial_length: 16
13
14
 
14
- def get
15
- sprintf(PRINTF_FORMAT_STRING, *octets)
16
- end
15
+ def get
16
+ sprintf(PRINTF_FORMAT_STRING, *octets)
17
+ end
17
18
 
18
- def set(value)
19
- self.octets = value.scanf(SCANF_FORMAT_STRING)
19
+ def set(value)
20
+ self.octets = value.scanf(SCANF_FORMAT_STRING)
21
+ end
20
22
  end
21
23
  end
22
24
  end
@@ -6,90 +6,100 @@ module Flic
6
6
  class SimpleClient
7
7
  class Error < StandardError; end
8
8
  class ConnectionChannelRemoved; end
9
-
9
+
10
10
  attr_reader :client
11
11
 
12
12
  def initialize(*client_args)
13
+ @semaphore = Mutex.new
13
14
  @client = Client.new(*client_args)
14
15
  end
15
16
 
16
17
  def shutdown
17
- client.shutdown
18
+ @semaphore.synchronize do
19
+ client.shutdown
20
+ end
18
21
  end
19
22
 
20
23
  def buttons
21
- server_info = process_events_until do |callback|
22
- client.get_info(&callback)
23
- end
24
+ @semaphore.synchronize do
25
+ server_info = process_events_until do |callback|
26
+ client.get_info(&callback)
27
+ end
24
28
 
25
- server_info.verified_buttons_bluetooth_addresses
29
+ server_info.verified_buttons_bluetooth_addresses
30
+ end
26
31
  end
27
32
 
28
33
  def connect_button
29
- begin
34
+ @semaphore.synchronize do
30
35
  scan_wizard = Client::ScanWizard.new
31
36
 
32
- process_events_until do |callback|
33
- scan_wizard.removed do |result, bluetooth_address, *|
34
- if result == :success
35
- callback.call(bluetooth_address)
36
- else
37
- callback.call(nil)
37
+ begin
38
+ process_events_until do |callback|
39
+ scan_wizard.removed do |result, bluetooth_address, *|
40
+ if result == :success
41
+ callback.call(bluetooth_address)
42
+ else
43
+ callback.call(nil)
44
+ end
38
45
  end
39
- end
40
46
 
41
- client.add_scan_wizard(scan_wizard)
47
+ client.add_scan_wizard(scan_wizard)
48
+ end
49
+ ensure
50
+ client.remove_scan_wizard(scan_wizard)
42
51
  end
43
- ensure
44
- client.remove_scan_wizard(scan_wizard)
45
52
  end
46
53
  end
47
54
 
48
55
  def disconnect_button(button_bluetooth_address)
49
- client.force_disconnect(button_bluetooth_address)
56
+ @semaphore.synchronize do
57
+ client.force_disconnect(button_bluetooth_address)
58
+ end
50
59
  end
51
60
 
52
61
  def listen(latency_mode, *button_bluetooth_addresses)
53
- connection_channels = []
54
- button_events = []
55
- broken = false
62
+ @semaphore.synchronize do
63
+ connection_channels = []
64
+ button_events = []
65
+ broken = false
56
66
 
57
- begin
58
- button_bluetooth_addresses.each do |button_bluetooth_addresses|
59
- connection_channel = Client::ConnectionChannel.new(button_bluetooth_addresses, latency_mode)
67
+ begin
68
+ button_bluetooth_addresses.each do |button_bluetooth_addresses|
69
+ connection_channel = Client::ConnectionChannel.new(button_bluetooth_addresses, latency_mode)
60
70
 
61
- connection_channel.button_up_or_down do |click_type, latency|
62
- button_events << [button_bluetooth_addresses, click_type, latency]
63
- end
64
-
65
- connection_channel.button_single_click_or_double_click_or_hold do |click_type, latency|
66
- button_events << [button_bluetooth_addresses, click_type, latency]
67
- end
71
+ connection_channel.button_up_or_down do |click_type, latency|
72
+ button_events << [button_bluetooth_addresses, click_type, latency]
73
+ end
68
74
 
69
- connection_channel.removed do
70
- broken = true
71
- end
75
+ connection_channel.button_single_click_or_double_click_or_hold do |click_type, latency|
76
+ button_events << [button_bluetooth_addresses, click_type, latency]
77
+ end
72
78
 
73
- connection_channels << connection_channel
79
+ connection_channel.removed do
80
+ broken = true
81
+ end
74
82
 
75
- client.add_connection_channel connection_channel
76
- end
83
+ connection_channels << connection_channel
77
84
 
85
+ client.add_connection_channel connection_channel
86
+ end
78
87
 
79
- loop do
80
- client.handle_next_event while !broken && button_events.empty?
88
+ loop do
89
+ client.handle_next_event while !broken && button_events.empty?
81
90
 
82
- button_events.each do |button_event|
83
- yield *button_event
84
- end
91
+ button_events.each do |button_event|
92
+ yield *button_event
93
+ end
85
94
 
86
- button_events.clear
95
+ button_events.clear
87
96
 
88
- raise ConnectionChannelRemoved, 'A connection channel was removed' if broken
89
- end
90
- ensure
91
- connection_channels.each do |connection_channel|
92
- client.remove_connection_channel connection_channel
97
+ raise ConnectionChannelRemoved, 'A connection channel was removed' if broken
98
+ end
99
+ ensure
100
+ connection_channels.each do |connection_channel|
101
+ client.remove_connection_channel connection_channel
102
+ end
93
103
  end
94
104
  end
95
105
  end
@@ -1,3 +1,3 @@
1
1
  module Flic
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alec Larsen