flic 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flic/protocol/primitives/disconnect_time.rb +19 -17
- data/lib/flic/protocol/primitives/uuid.rb +12 -10
- data/lib/flic/simple_client.rb +58 -48
- data/lib/flic/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30e6a6023c2fe3f2a83299ce7358050ef07195c8
|
4
|
+
data.tar.gz: f1ac706e5cfca806615de68e6bf147893225662e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
5
|
-
|
6
|
-
|
4
|
+
module Protocol
|
5
|
+
module Primitives
|
6
|
+
class DisconnectTime < BinData::Primitive
|
7
|
+
endian :little
|
7
8
|
|
8
|
-
|
9
|
+
uint16 :time, initial_value: 512
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def get
|
12
|
+
if time == 512
|
13
|
+
nil
|
14
|
+
else
|
15
|
+
time
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
-
|
13
|
+
array :octets, type: :uint8, initial_length: 16
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def get
|
16
|
+
sprintf(PRINTF_FORMAT_STRING, *octets)
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
def set(value)
|
20
|
+
self.octets = value.scanf(SCANF_FORMAT_STRING)
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/lib/flic/simple_client.rb
CHANGED
@@ -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
|
-
|
18
|
+
@semaphore.synchronize do
|
19
|
+
client.shutdown
|
20
|
+
end
|
18
21
|
end
|
19
22
|
|
20
23
|
def buttons
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
@semaphore.synchronize do
|
25
|
+
server_info = process_events_until do |callback|
|
26
|
+
client.get_info(&callback)
|
27
|
+
end
|
24
28
|
|
25
|
-
|
29
|
+
server_info.verified_buttons_bluetooth_addresses
|
30
|
+
end
|
26
31
|
end
|
27
32
|
|
28
33
|
def connect_button
|
29
|
-
|
34
|
+
@semaphore.synchronize do
|
30
35
|
scan_wizard = Client::ScanWizard.new
|
31
36
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
62
|
+
@semaphore.synchronize do
|
63
|
+
connection_channels = []
|
64
|
+
button_events = []
|
65
|
+
broken = false
|
56
66
|
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
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
|
-
|
79
|
+
connection_channel.removed do
|
80
|
+
broken = true
|
81
|
+
end
|
74
82
|
|
75
|
-
|
76
|
-
end
|
83
|
+
connection_channels << connection_channel
|
77
84
|
|
85
|
+
client.add_connection_channel connection_channel
|
86
|
+
end
|
78
87
|
|
79
|
-
|
80
|
-
|
88
|
+
loop do
|
89
|
+
client.handle_next_event while !broken && button_events.empty?
|
81
90
|
|
82
|
-
|
83
|
-
|
84
|
-
|
91
|
+
button_events.each do |button_event|
|
92
|
+
yield *button_event
|
93
|
+
end
|
85
94
|
|
86
|
-
|
95
|
+
button_events.clear
|
87
96
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
data/lib/flic/version.rb
CHANGED