adam6050 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/bin/server +14 -0
- data/lib/adam6050/state.rb +15 -2
- data/lib/adam6050/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: 48b0537af2f984ebbf6664a99fb02f74436a2bb1
|
4
|
+
data.tar.gz: a4f39537371a137c2ecf474d777f7ab2bed58a55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f666d5c54f971b5f250894cec6813c0d2939d4feeb6c561800fdbcd978039096d705a5a4c0066363f82ba09d09e3ba1f7c604263af79023feb705a6a1bc25f34
|
7
|
+
data.tar.gz: e863e198371c9942dc50c8f222c60796c8bba4cc1c4b9df311151167799a3e78c46de0108fca51f12c6bc3243cf8ab3abecd2d3bb4ece9564856cd19d1154cc6
|
data/Gemfile.lock
CHANGED
data/bin/server
CHANGED
@@ -8,9 +8,23 @@ server = ADAM6050::Server.new
|
|
8
8
|
server.logger.level = Logger::INFO
|
9
9
|
|
10
10
|
begin
|
11
|
+
worker = Thread.new do
|
12
|
+
loop do
|
13
|
+
sleep 5
|
14
|
+
input_channel = rand 0...ADAM6050::State::NUM_INPUTS
|
15
|
+
|
16
|
+
server.update do |state|
|
17
|
+
value = !ADAM6050::State.input_set?(state, input_channel)
|
18
|
+
puts "Setting input #{input_channel} to #{value}"
|
19
|
+
ADAM6050::State.set_input state, input_channel, value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
11
24
|
server.run do |state|
|
12
25
|
puts ADAM6050::State.inspect(state)
|
13
26
|
end
|
14
27
|
rescue Interrupt
|
15
28
|
puts 'Exiting...'
|
29
|
+
worker.kill
|
16
30
|
end
|
data/lib/adam6050/state.rb
CHANGED
@@ -37,6 +37,19 @@ module ADAM6050
|
|
37
37
|
state & (1 << input_channel) != 0
|
38
38
|
end
|
39
39
|
|
40
|
+
# @raise [RangeError] if the given channel index exceeds the number of
|
41
|
+
# available input channels.
|
42
|
+
#
|
43
|
+
# @param state [Integer] the current state.
|
44
|
+
# @param input_channel [Integer] the input channel number.
|
45
|
+
# @return [true, false] the state of the specified input.
|
46
|
+
def set_input(state, input_channel, value)
|
47
|
+
raise RangeError if input_channel >= NUM_INPUTS
|
48
|
+
|
49
|
+
mask = (1 << input_channel)
|
50
|
+
value ? state | mask : state & ~mask
|
51
|
+
end
|
52
|
+
|
40
53
|
# @raise [RangeError] if the given channel index exceeds the number of
|
41
54
|
# available output channels.
|
42
55
|
#
|
@@ -83,7 +96,7 @@ module ADAM6050
|
|
83
96
|
format '%05X', (~state & MASK)
|
84
97
|
end
|
85
98
|
|
86
|
-
module_function :initial, :input_set?, :output_set?, :update,
|
87
|
-
:inspect, :to_bin
|
99
|
+
module_function :initial, :input_set?, :set_input, :output_set?, :update,
|
100
|
+
:update_all, :inspect, :to_bin
|
88
101
|
end
|
89
102
|
end
|
data/lib/adam6050/version.rb
CHANGED