wifly 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -16,3 +16,5 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  .rvmrc
19
+ .ruby-version
20
+ .ruby-gemset
@@ -1,9 +1,10 @@
1
1
  module Wifly
2
2
  module Calculations
3
3
  ##
4
- # Return an array containing the numbers of the pins that are in HIGH state
4
+ # Parse the hexadecimal string returned from the show_io command
5
+ # into an array of pins that are high
5
6
  #
6
- def high_pins(hex_str)
7
+ def parse_io(hex_str)
7
8
  #"8d08" 36104 "1000110100001000" make it 16 bits
8
9
  binary_string = hex_str .hex .to_s(2) .rjust(hex_str.size*4, '0')
9
10
  binary_string.reverse.split("").each_with_index.map do |value, pin|
data/lib/wifly/control.rb CHANGED
@@ -42,7 +42,14 @@ module Wifly
42
42
  # given a pin number, return 1 if high or 0 if low
43
43
  #
44
44
  def read_pin(pin)
45
- high_pins(read_io).include?(pin) ? 1 : 0
45
+ high_pins.include?(pin) ? 1 : 0
46
+ end
47
+
48
+ ##
49
+ # Return an array of all the pins which are currently high
50
+ #
51
+ def high_pins
52
+ parse_io(read_io)
46
53
  end
47
54
 
48
55
  private
data/lib/wifly/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Wifly
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ class WiflyControlShim
4
+ include Wifly::Calculations
5
+ end
6
+
7
+ describe Wifly::Calculations do
8
+ it 'should convert pin to hex' do
9
+ control = WiflyControlShim.new
10
+ control.pin_to_hex(5).should eq("0x20")
11
+ control.pin_to_hex(0).should eq("0x0")
12
+ end
13
+
14
+ it 'should get high pins' do
15
+ control = WiflyControlShim.new
16
+ result = control.parse_io('8d08')
17
+ result.should eq([3, 8, 10, 11, 15])
18
+ end
19
+ end
@@ -1,4 +1,4 @@
1
- require 'wifly'
1
+ require 'spec_helper'
2
2
  class Wifly::TestServer
3
3
  attr_accessor :input
4
4
 
data/spec/control_spec.rb CHANGED
@@ -1,28 +1,20 @@
1
- require 'wifly'
1
+ require 'spec_helper'
2
2
  describe Wifly::Control do
3
- it 'should convert pin to hex' do
4
- control = Wifly::Control.new('localhost', 2000, '1.2', {})
5
- control.pin_to_hex(5).should eq("0x20")
6
- control.pin_to_hex(0).should eq("0x0")
7
- end
3
+ it 'should set high and low' do
4
+ connection = double('connection')
5
+ connection.should_receive(:send_command).with("set sys output 0x20 0x20", Wifly::AOK.length)
6
+ connection.should_receive(:send_command).with("set sys output 0x00 0x20", Wifly::AOK.length)
7
+ control = Wifly::Control.new('localhost', 2000, '1.2', connection)
8
+ control.set_high(5)
9
+ control.set_low(5)
10
+ end
8
11
 
9
12
  it 'should get high pins' do
10
13
  connection = double('connection')
11
14
  connection.should_receive(:send_command).exactly(2).times.and_return("show io\r\r\n8d08\r\n")
12
15
  control = Wifly::Control.new('localhost', 2000, '1.2', connection)
13
16
 
14
- result = control.high_pins('8d08')
15
- result.should eq([3, 8, 10, 11, 15])
16
17
  control.read_pin(8).should eq(1)
17
18
  control.read_pin(7).should eq(0)
18
19
  end
19
-
20
- it 'should set high and low' do
21
- connection = double('connection')
22
- connection.should_receive(:send_command).with("set sys output 0x20 0x20", Wifly::AOK.length)
23
- connection.should_receive(:send_command).with("set sys output 0x00 0x20", Wifly::AOK.length)
24
- control = Wifly::Control.new('localhost', 2000, '1.2', connection)
25
- control.set_high(5)
26
- control.set_low(5)
27
- end
28
20
  end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,8 @@
4
4
  # loaded once.
5
5
  #
6
6
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ require 'wifly'
8
+
7
9
  RSpec.configure do |config|
8
10
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
11
  config.run_all_when_everything_filtered = true
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
4
+ version: 0.0.5
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-07-14 00:00:00.000000000 Z
12
+ date: 2013-11-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -93,6 +93,7 @@ files:
93
93
  - lib/wifly/connection.rb
94
94
  - lib/wifly/control.rb
95
95
  - lib/wifly/version.rb
96
+ - spec/calculations_spec.rb
96
97
  - spec/connection_spec.rb
97
98
  - spec/control_spec.rb
98
99
  - spec/spec_helper.rb
@@ -110,12 +111,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
111
  - - ! '>='
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0'
114
+ segments:
115
+ - 0
116
+ hash: 3199720615391178109
113
117
  required_rubygems_version: !ruby/object:Gem::Requirement
114
118
  none: false
115
119
  requirements:
116
120
  - - ! '>='
117
121
  - !ruby/object:Gem::Version
118
122
  version: '0'
123
+ segments:
124
+ - 0
125
+ hash: 3199720615391178109
119
126
  requirements: []
120
127
  rubyforge_project:
121
128
  rubygems_version: 1.8.25
@@ -123,6 +130,7 @@ signing_key:
123
130
  specification_version: 3
124
131
  summary: This gem can be used to talk to a WiFly RN-XV device at a specified address.
125
132
  test_files:
133
+ - spec/calculations_spec.rb
126
134
  - spec/connection_spec.rb
127
135
  - spec/control_spec.rb
128
136
  - spec/spec_helper.rb