wifly 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/wifly/calculations.rb +24 -0
- data/lib/wifly/control.rb +3 -23
- data/lib/wifly/version.rb +1 -1
- data/lib/wifly.rb +1 -0
- data/spec/control_spec.rb +3 -2
- metadata +5 -4
@@ -0,0 +1,24 @@
|
|
1
|
+
module Wifly
|
2
|
+
module Calculations
|
3
|
+
##
|
4
|
+
# Return an array containing the numbers of the pins that are in HIGH state
|
5
|
+
#
|
6
|
+
def high_pins(hex_str)
|
7
|
+
#"8d08" 36104 "1000110100001000" make it 16 bits
|
8
|
+
binary_string = hex_str .hex .to_s(2) .rjust(hex_str.size*4, '0')
|
9
|
+
binary_string.reverse.split("").each_with_index.map do |value, pin|
|
10
|
+
pin if value == "1"
|
11
|
+
end.compact
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Given a pin number, return the hex code that corresponds to it
|
16
|
+
#
|
17
|
+
def pin_to_hex(pin)
|
18
|
+
return "0x0" if pin == 0
|
19
|
+
binstr = "0b1" + ("0" * pin) # make a binary string with a 1 in `pin` position
|
20
|
+
base10 = binstr.to_i(2) # convert to base 10
|
21
|
+
"0x" + base10.to_s(16) # return hexadecimal string
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/wifly/control.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Wifly
|
2
2
|
class Control
|
3
|
+
include Calculations
|
4
|
+
|
3
5
|
attr_accessor :connection
|
4
6
|
|
5
7
|
##
|
@@ -20,18 +22,6 @@ module Wifly
|
|
20
22
|
connection.send_command("lites")
|
21
23
|
end
|
22
24
|
|
23
|
-
##
|
24
|
-
# Return an array containing the numbers of the pins that are in HIGH state
|
25
|
-
#
|
26
|
-
def high_pins
|
27
|
-
io=read_io
|
28
|
-
#"8d08" 36104 "1000110100001000" make it 16 bits
|
29
|
-
binary_string = io .hex .to_s(2) .rjust(io.size*4, '0')
|
30
|
-
binary_string.reverse.split("").each_with_index.map do |value, pin|
|
31
|
-
pin if value == "1"
|
32
|
-
end.compact
|
33
|
-
end
|
34
|
-
|
35
25
|
##
|
36
26
|
# set a pin high
|
37
27
|
#
|
@@ -52,17 +42,7 @@ module Wifly
|
|
52
42
|
# given a pin number, return 1 if high or 0 if low
|
53
43
|
#
|
54
44
|
def read_pin(pin)
|
55
|
-
high_pins.include?(pin) ? 1 : 0
|
56
|
-
end
|
57
|
-
|
58
|
-
##
|
59
|
-
# Given a pin number, return the hex code that corresponds to it
|
60
|
-
#
|
61
|
-
def pin_to_hex(pin)
|
62
|
-
return "0x0" if pin == 0
|
63
|
-
binstr = "0b1" + ("0" * pin) # make a binary string with a 1 in `pin` position
|
64
|
-
base10 = binstr.to_i(2) # convert to base 10
|
65
|
-
"0x" + base10.to_s(16) # return hexadecimal string
|
45
|
+
high_pins(read_io).include?(pin) ? 1 : 0
|
66
46
|
end
|
67
47
|
|
68
48
|
private
|
data/lib/wifly/version.rb
CHANGED
data/lib/wifly.rb
CHANGED
data/spec/control_spec.rb
CHANGED
@@ -8,9 +8,10 @@ describe Wifly::Control do
|
|
8
8
|
|
9
9
|
it 'should get high pins' do
|
10
10
|
connection = double('connection')
|
11
|
-
connection.should_receive(:send_command).exactly(
|
11
|
+
connection.should_receive(:send_command).exactly(2).times.and_return("show io\r\r\n8d08\r\n")
|
12
12
|
control = Wifly::Control.new('localhost', 2000, '1.2', connection)
|
13
|
-
|
13
|
+
|
14
|
+
result = control.high_pins('8d08')
|
14
15
|
result.should eq([3, 8, 10, 11, 15])
|
15
16
|
control.read_pin(8).should eq(1)
|
16
17
|
control.read_pin(7).should eq(0)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wifly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- README.md
|
90
90
|
- Rakefile
|
91
91
|
- lib/wifly.rb
|
92
|
+
- lib/wifly/calculations.rb
|
92
93
|
- lib/wifly/connection.rb
|
93
94
|
- lib/wifly/control.rb
|
94
95
|
- lib/wifly/version.rb
|
@@ -111,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
112
|
version: '0'
|
112
113
|
segments:
|
113
114
|
- 0
|
114
|
-
hash: -
|
115
|
+
hash: -499143373
|
115
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
117
|
none: false
|
117
118
|
requirements:
|
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
121
|
version: '0'
|
121
122
|
segments:
|
122
123
|
- 0
|
123
|
-
hash: -
|
124
|
+
hash: -499143373
|
124
125
|
requirements: []
|
125
126
|
rubyforge_project:
|
126
127
|
rubygems_version: 1.8.25
|