BBB 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d18e3e61eefcd87ec52cd8b251cd6799597573cd
4
+ data.tar.gz: 4c282e7e33f04bc98aad8f2d0f4c41ad46208add
5
+ SHA512:
6
+ metadata.gz: 87f7819d093f819abcb8bf98e4aab0561cb29716887b49fb3b507b18b00586689f9a158cd097e9f27402fcd8cd56208034a444dd130e307e1c176e95ab149098
7
+ data.tar.gz: 22c811e2ed74ce86a22e3ddbb4e609f2d998e88a846f0e9ee735787ce38ae77b2531564896744cc034465bac9d0e36ae88093a047682aaa18a834b6d2adf7650
data/BBB.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.require_paths = ["lib"]
19
19
 
20
20
  spec.add_dependency "json"
21
+ spec.add_dependency "i2c"
21
22
  spec.add_development_dependency "bundler", "~> 1.3"
22
23
  spec.add_development_dependency "rake"
23
24
  spec.add_development_dependency "rspec"
data/lib/BBB.rb CHANGED
@@ -8,9 +8,11 @@ require "BBB/exceptions"
8
8
 
9
9
  require "BBB/pins/io/pin_mapper"
10
10
  require "BBB/pins/io/mapped"
11
+ require "BBB/pins/io/cape"
11
12
  require "BBB/pins/io/ain"
12
13
  require "BBB/pins/io/gpio"
13
14
  require "BBB/pins/io/pwm"
15
+ require "BBB/pins/io/i2c"
14
16
 
15
17
  require "BBB/pins/pinnable"
16
18
  require "BBB/pins/digital_pin"
@@ -0,0 +1,46 @@
1
+ module BBB
2
+ module Components
3
+ class ESC
4
+ include Pinnable
5
+ uses Pins::PWMPin, Pins::DigitalOutputPin
6
+
7
+ attr_accessor :min_duty, :max_duty, :period
8
+ attr_reader :duty
9
+
10
+ def initialize(period=10e6, min_duty=0.8e6, max_duty=2e6)
11
+ @period = period
12
+ @min_duty = min_duty
13
+ @max_duty = max_duty
14
+ end
15
+
16
+ def after_pin_initialization
17
+ power.off!
18
+ pwm.period = period
19
+ pwm.duty = min_duty
20
+ pwm.run = 1
21
+ end
22
+
23
+ def speed(value)
24
+ self.duty = min_duty + value * duty_range
25
+ end
26
+
27
+ def duty=(value)
28
+ @duty = value
29
+ pwm.duty = @duty
30
+ end
31
+
32
+ def duty_range
33
+ max_duty - min_duty
34
+ end
35
+
36
+ def pwm
37
+ pins.first
38
+ end
39
+
40
+ def power
41
+ pins.last
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -3,6 +3,7 @@ module BBB
3
3
  module IO
4
4
  class AIN
5
5
  include Mapped
6
+ include Cape
6
7
 
7
8
  attr_reader :io, :position
8
9
 
@@ -22,18 +23,15 @@ module BBB
22
23
  end
23
24
 
24
25
  def export
25
- cape_dir = "/sys/devices/bone_capemgr.*/slots"
26
- dir = Dir.glob(cape_dir)
27
- if dir.length == 0
28
- raise BoardError, "unable to access the capemgr directory: #{cape_dir}"
29
- end
30
- `echo cape-bone-iio > #{dir.first}`
26
+ `echo cape-bone-iio > #{cape_dir}`
31
27
  end
32
28
 
33
29
  def get_file_handle
34
30
  dir = Dir.glob("/sys/devices/ocp.*/helper.*/")
35
31
  file = File.expand_path("AIN#{pin_map.ain}", dir.first)
36
- return File.open(file, "r")
32
+ file = File.open(file, "r")
33
+ file.sync = true
34
+ return file
37
35
  end
38
36
 
39
37
  def self.setup
@@ -0,0 +1,19 @@
1
+ module BBB
2
+ module Pins
3
+ module IO
4
+ module Cape
5
+ def cape_dir
6
+ return @cape_dir if @cape_dir
7
+
8
+ cape_dir = "/sys/devices/bone_capemgr.*/slots"
9
+ dir = Dir.glob(cape_dir)
10
+ if dir.length == 0
11
+ raise BoardError, "unable to access the capemgr directory: #{cape_dir}"
12
+ end
13
+ @cape_dir = dir.first
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -27,11 +27,13 @@ module BBB
27
27
  return @io unless @io.nil?
28
28
  value_file = gpio_pin_dir + "/value"
29
29
  @io = file_class.open(value_file, file_mode)
30
+ @io.sync = true
31
+
32
+ return @io
30
33
  end
31
34
 
32
35
  def write(value)
33
36
  io.write(value_map[value])
34
- io.flush
35
37
  end
36
38
 
37
39
  def read
@@ -0,0 +1,52 @@
1
+ require 'i2c'
2
+
3
+ module BBB
4
+ module Pins
5
+ module IO
6
+ class I2C
7
+ include Mapped
8
+ include Cape
9
+
10
+ attr_reader :backend
11
+
12
+ ##
13
+ # Initializes two I2C pins. The initializer takes the cape argument,
14
+ # where most other IO classes in the library take a position. This is
15
+ # because it seems more natural to indicate BB-I2C1 as opposed to
16
+ # figuring out that I2C1 is mapped to P9_18, and P9_17 (sda, scl) and
17
+ # then give those positions.
18
+ #
19
+ # @param cape [String] The cape name of the I2C chip.
20
+ #
21
+ def initialize(cape)
22
+ @cape = cape
23
+ self.export
24
+ end
25
+
26
+ def position
27
+ @cape
28
+ end
29
+
30
+ def export
31
+ tree = pin_map.devicetree
32
+ system("echo #{tree} > #{cape_dir}")
33
+ sleep(0.2) # Give the kernel time to load the cape
34
+ @backend = I2C.create(pin_map.path)
35
+ end
36
+
37
+ def write(address, *params)
38
+ @backend.write(address, params)
39
+ end
40
+
41
+ def read(address, size, *params)
42
+ @backend.read(address, size, params)
43
+ end
44
+
45
+ def pin_map_key
46
+ :devicetree
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
@@ -18,8 +18,8 @@ module BBB
18
18
 
19
19
  class Pin < Struct.new(:name, :gpio, :led, :mux, :key, :mux_reg_offset,
20
20
  :options, :eeprom, :pwm, :ain, :scale); end
21
- class UART < Struct.new(:devicetree, :rx, :tx); end
22
- class I2C < Struct.new(:devicetree, :path, :sda, :scl); end
21
+ class UART < Struct.new(:devicetree, :rx, :tx, :filesystem); end
22
+ class I2C < Struct.new(:devicetree, :path, :sda, :scl, :filesystem); end
23
23
 
24
24
  attr_reader :data
25
25
 
@@ -58,7 +58,11 @@ module BBB
58
58
  def self.map(pin_symbol)
59
59
  @map ||= convert(PIN_MAP_FILE)
60
60
  begin
61
- @map.pins.fetch(pin_symbol.upcase.to_sym)
61
+ sym = pin_symbol.upcase
62
+ map = @map.pins.fetch(sym, nil)
63
+ map = @map.i2c.fetch(sym) if map.nil?
64
+
65
+ return map
62
66
  rescue Exception => e
63
67
  raise UnknownPinException, "Pin #{pin_symbol} could not be mapped"
64
68
  end
@@ -155,6 +159,30 @@ module BBB
155
159
  # "scl": "P9_17"
156
160
  # }
157
161
  #
162
+ # Mind you, the mapping actually turns some of these keys around. The
163
+ # resulting hash takes the "devicetree" as the main key, and adds the
164
+ # key of the JSON object "/dev/i2c-1" as the value of the key
165
+ # :filesystem in the resulting hash. So, to follow the example above,
166
+ # the "mapping" of the example above is:
167
+ #
168
+ # @example
169
+ # i2c = I2C.new
170
+ # i2c.devicetree = "BB-I2C1"
171
+ # i2c.filesystem = "/dev/i2c-1"
172
+ # i2c.path = "/dev/i2c-2",
173
+ # i2c.sda = "P9_18"
174
+ # i2c.scl = "P9_17"
175
+ #
176
+ # map = {:'BB-I2C1' => i2c}
177
+ #
178
+ # ** Beware **
179
+ #
180
+ # The filesystem and path properties are not always the same! Check for
181
+ # example the i2c-1, it is found under the JSON key of /dev/i2c-1 but
182
+ # maps it's path to /dev/i2c-2. It's rather odd...
183
+ #
184
+ # ** End of Beware **
185
+ #
158
186
  # @param [Hash] data_hash with strings as keys and hashes as values
159
187
  #
160
188
  # @return [Hash] with strings of I2C folders as keys and I2C objects as
@@ -177,8 +205,9 @@ module BBB
177
205
  info_hash.each_pair do |key, value|
178
206
  instance[key] = value
179
207
  end
208
+ instance[:filesystem] = filesystem
180
209
 
181
- hash[filesystem] = instance
210
+ hash[instance.devicetree] = instance
182
211
  end
183
212
 
184
213
  return hash
@@ -187,7 +216,7 @@ module BBB
187
216
  ##
188
217
  # Makes an underscored, lowercase form from the expression in the string.
189
218
  #
190
- # Gracefully copied from ActiveSupport::Inflections
219
+ # Copied from ActiveSupport::Inflections
191
220
  # http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-underscore
192
221
  #
193
222
  # Changes '::' to '/' to convert namespaces to paths.
@@ -3,6 +3,7 @@ module BBB
3
3
  module IO
4
4
  class PWM
5
5
  include Mapped
6
+ include Cape
6
7
 
7
8
  attr_reader :handles, :position
8
9
 
@@ -23,29 +24,30 @@ module BBB
23
24
 
24
25
  files.each do |file|
25
26
  file_path = File.expand_path(file, path)
26
- handles[file.to_sym] = File.open(file_path, "r+")
27
+ f = File.open(file_path, "r+")
28
+ f.sync = true
29
+ handles[file.to_sym] = f
27
30
  end
28
31
 
29
32
  return handles
30
33
  end
31
34
 
32
35
  def export
33
- cape_dir = "/sys/devices/bone_capemgr.*/slots"
34
- dir = Dir.glob(cape_dir)
35
- if dir.length == 0
36
- raise BoardError, "unable to access the capemgr directory: #{cape_dir}"
37
- end
38
-
39
36
  pin_map_key = pin_map.key # This calls the pin map, which raises an error in case pin can't be mapped.
40
- system("echo am33xx_pwm > #{dir.first}")
41
- system("echo bone_pwm_#{pin_map_key} > #{dir.first}")
37
+
38
+ system("echo am33xx_pwm > #{cape_dir}")
39
+ system("echo bone_pwm_#{pin_map_key} > #{cape_dir}")
40
+ sleep(0.2) # This seems to be necessary for te driver to load
42
41
  end
43
42
 
44
43
  def write(symbol, value)
45
44
  handle = handles[symbol]
46
45
  handle.rewind
47
- handle.write(value)
48
- handle.flush
46
+ begin
47
+ handle.write(value)
48
+ rescue Errno::EINVAL
49
+ puts "Could not write the value #{value} to the handle #{symbol}"
50
+ end
49
51
  return value
50
52
  end
51
53
 
data/lib/BBB/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module BBB
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe BBB::Pins::IO::I2C do
4
+ let(:i2c) { BBB::Pins::IO::I2C }
5
+
6
+ #it "initializes" do
7
+ #i2c.any_instance.should_receive(:system)
8
+ #i2c.any_instance.should_receive(:export)
9
+ #i2c.new("BB-I2C1").should_not raise_error
10
+ #end
11
+ end
metadata CHANGED
@@ -1,36 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: BBB
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
5
- prerelease:
4
+ version: 0.1.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Wilco van Duinkerken
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-30 00:00:00.000000000 Z
11
+ date: 2014-01-06 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: json
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: i2c
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
28
39
  - !ruby/object:Gem::Version
29
40
  version: '0'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: bundler
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
45
  - - ~>
36
46
  - !ruby/object:Gem::Version
@@ -38,7 +48,6 @@ dependencies:
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
52
  - - ~>
44
53
  - !ruby/object:Gem::Version
@@ -46,33 +55,29 @@ dependencies:
46
55
  - !ruby/object:Gem::Dependency
47
56
  name: rake
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - '>='
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - '>='
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  - !ruby/object:Gem::Dependency
63
70
  name: rspec
64
71
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
72
  requirements:
67
- - - ! '>='
73
+ - - '>='
68
74
  - !ruby/object:Gem::Version
69
75
  version: '0'
70
76
  type: :development
71
77
  prerelease: false
72
78
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
79
  requirements:
75
- - - ! '>='
80
+ - - '>='
76
81
  - !ruby/object:Gem::Version
77
82
  version: '0'
78
83
  description: Helper functions to ruby around on the BeagleBone Black
@@ -97,6 +102,7 @@ files:
97
102
  - lib/BBB/application.rb
98
103
  - lib/BBB/circuit.rb
99
104
  - lib/BBB/components/analog_component.rb
105
+ - lib/BBB/components/esc.rb
100
106
  - lib/BBB/components/led.rb
101
107
  - lib/BBB/components/pinnable.rb
102
108
  - lib/BBB/components/servo.rb
@@ -104,7 +110,9 @@ files:
104
110
  - lib/BBB/pins/analog_pin.rb
105
111
  - lib/BBB/pins/digital_pin.rb
106
112
  - lib/BBB/pins/io/ain.rb
113
+ - lib/BBB/pins/io/cape.rb
107
114
  - lib/BBB/pins/io/gpio.rb
115
+ - lib/BBB/pins/io/i2c.rb
108
116
  - lib/BBB/pins/io/mapped.rb
109
117
  - lib/BBB/pins/io/pin_mapper.rb
110
118
  - lib/BBB/pins/io/pwm.rb
@@ -123,6 +131,7 @@ files:
123
131
  - spec/pins/digital_input_pin_spec.rb
124
132
  - spec/pins/digital_output_pin_spec.rb
125
133
  - spec/pins/digital_pin_spec.rb
134
+ - spec/pins/io/i2c_spec.rb
126
135
  - spec/pins/io/mapped_spec.rb
127
136
  - spec/pins/io/pin_mapper_spec.rb
128
137
  - spec/pins/pinnable_spec.rb
@@ -131,33 +140,26 @@ files:
131
140
  homepage:
132
141
  licenses:
133
142
  - MIT
143
+ metadata: {}
134
144
  post_install_message:
135
145
  rdoc_options: []
136
146
  require_paths:
137
147
  - lib
138
148
  required_ruby_version: !ruby/object:Gem::Requirement
139
- none: false
140
149
  requirements:
141
- - - ! '>='
150
+ - - '>='
142
151
  - !ruby/object:Gem::Version
143
152
  version: '0'
144
- segments:
145
- - 0
146
- hash: -4269646228377431993
147
153
  required_rubygems_version: !ruby/object:Gem::Requirement
148
- none: false
149
154
  requirements:
150
- - - ! '>='
155
+ - - '>='
151
156
  - !ruby/object:Gem::Version
152
157
  version: '0'
153
- segments:
154
- - 0
155
- hash: -4269646228377431993
156
158
  requirements: []
157
159
  rubyforge_project:
158
- rubygems_version: 1.8.25
160
+ rubygems_version: 2.0.3
159
161
  signing_key:
160
- specification_version: 3
162
+ specification_version: 4
161
163
  summary: Helper functions to ruby around on the BeagleBone Black
162
164
  test_files:
163
165
  - spec/application_spec.rb
@@ -170,8 +172,10 @@ test_files:
170
172
  - spec/pins/digital_input_pin_spec.rb
171
173
  - spec/pins/digital_output_pin_spec.rb
172
174
  - spec/pins/digital_pin_spec.rb
175
+ - spec/pins/io/i2c_spec.rb
173
176
  - spec/pins/io/mapped_spec.rb
174
177
  - spec/pins/io/pin_mapper_spec.rb
175
178
  - spec/pins/pinnable_spec.rb
176
179
  - spec/pins/pwm_pin_spec.rb
177
180
  - spec/spec_helper.rb
181
+ has_rdoc: