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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9c3de0d21135c18d897b449946af5dc6b75f107
4
- data.tar.gz: dfbf368bced9fc2cbc3043d604a5ce64c698b1da
3
+ metadata.gz: 48b0537af2f984ebbf6664a99fb02f74436a2bb1
4
+ data.tar.gz: a4f39537371a137c2ecf474d777f7ab2bed58a55
5
5
  SHA512:
6
- metadata.gz: cbdf99dc764f984fce276fbccb2890ef0d2fc7320be13651b99075a25009ca953d327f755fc00ee8cfd676c35ab783d75eac04baa2215da56fbb5e9b47722e04
7
- data.tar.gz: b30126d49a258e1f7e35117f3e1caba5ffef9cd90c0f0680b55e1c6e1daaa2da74567f035c01daa096ecc62baa401df04731454e337688ce2587da089fe390e1
6
+ metadata.gz: f666d5c54f971b5f250894cec6813c0d2939d4feeb6c561800fdbcd978039096d705a5a4c0066363f82ba09d09e3ba1f7c604263af79023feb705a6a1bc25f34
7
+ data.tar.gz: e863e198371c9942dc50c8f222c60796c8bba4cc1c4b9df311151167799a3e78c46de0108fca51f12c6bc3243cf8ab3abecd2d3bb4ece9564856cd19d1154cc6
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- adam6050 (0.1.1)
4
+ adam6050 (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -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, :update_all,
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  module ADAM6050
4
4
  # @return [String] the ADAM6050 library version number.
5
- VERSION = '0.1.1'
5
+ VERSION = '0.1.2'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adam6050
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Lindberg