BBB 0.0.1 → 0.0.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: 63c2eceea0c267f57e2c21cec0d6d82cafc9fd01
4
- data.tar.gz: bf11fed2f5ee2654fa14442b74ce90d390e2c8e5
3
+ metadata.gz: 4573344a902cd2566d5521229f4d7529cb31f633
4
+ data.tar.gz: b75dc03459a79e65ee931f8c37482524bfa98576
5
5
  SHA512:
6
- metadata.gz: c07b23cdf6cec474c6d6633b0943dc1854a321fc6904eba49057c8732e19c739327619aef8d0e88a1e0f1b82f537901d246704c4b874b548e8cb48265d073647
7
- data.tar.gz: 2f9df659b737fd99151f9df9859fab689d63a483e690b200229d4e257f02c802317bf52266500f4ce571c9895cdbbe30c072912c75bc6e4f45f01d237ac9b1c3
6
+ metadata.gz: 67101648320187e3e261d19511db14d80a8b8a6ca21c811f8b2f1316fcfad48296cb245646e36d58933540cb09e2f663f2ae66df828a193e13860e017967e667
7
+ data.tar.gz: 8ffc3dc8effcbf3a7209e7e7f753e0effbdb2787353053f352410aa2bad5fe1c6275c4c21d5c5bf6232340f73503d24bcd9581ac278db79dc12a039d01c3d001
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - jruby-19mode
5
+ - rbx-19mode
6
+ - ruby-head
7
+ - jruby-head
data/Gemfile CHANGED
@@ -2,3 +2,8 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in BBB.gemspec
4
4
  gemspec
5
+ gem 'coveralls', require: false
6
+
7
+ group :test do
8
+ gem 'pry'
9
+ end
data/README.md CHANGED
@@ -1,7 +1,13 @@
1
+
1
2
  # BBB - BeagleBone Black
2
3
 
3
4
  Helper functions and modules to ruby around on the beagle bone black.
4
5
 
6
+ ## Badges
7
+
8
+ [![Coverage Status](https://coveralls.io/repos/Sparkboxx/bbb/badge.png)](https://coveralls.io/r/Sparkboxx/bbb)
9
+ [![Build Status](https://travis-ci.org/Sparkboxx/bbb.png?branch=master)](https://travis-ci.org/Sparkboxx/bbb)
10
+
5
11
  ## Installation
6
12
 
7
13
  Add this line to your application's Gemfile:
@@ -27,3 +33,28 @@ TODO: Write usage instructions here
27
33
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
34
  4. Push to the branch (`git push origin my-new-feature`)
29
35
  5. Create new Pull Request
36
+
37
+ ## License
38
+
39
+ Copyright (c) 2013 Wilco van Duinkerken
40
+
41
+ MIT License
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ "Software"), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
57
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
58
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
59
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
60
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1 +1,5 @@
1
1
  require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ task :default => :spec
5
+ RSpec::Core::RakeTask.new
data/examples/led.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'BBB'
2
+
3
+ ##
4
+ # Setup the LED Circuit
5
+ #
6
+ class Circuit < BBB::Circuit
7
+ def initialize
8
+ # Attach the led to pin P8_10
9
+ attach BBB::Components::Led, pin: :P8_10, as: :led
10
+ end
11
+ end
12
+
13
+ ##
14
+ # Setup the actual Application
15
+ #
16
+ class LedExampleApplication < BBB::Application
17
+ # Run this on the BeableBoneBlack
18
+ board BBB::Board.new
19
+
20
+ # Connection the led circuit
21
+ circuit LedExample::Circuit.new
22
+
23
+ # This is the basic run loop
24
+ def run
25
+ led.on! # this does what you think it does
26
+ sleep(1) # sleep for 1 second, kind of blunt, since it blocks everthing.
27
+ led.off!
28
+ sleep(1)
29
+ end
30
+ end
31
+
32
+ # Initialize and run the LedExampleApplication
33
+ app = LedExampleApplication.new
34
+ app.start
@@ -0,0 +1,86 @@
1
+ require 'bbb'
2
+
3
+ module Thunderball
4
+ class Copter << BBB::Application
5
+ ##
6
+ # Use the BBB as the board, allows for possible ports to e.g. the Pi
7
+ #
8
+ board BBB::Board.new
9
+
10
+ ##
11
+ # Load the thunderball layout
12
+ #
13
+ layout Thunderball::Circuit.new
14
+
15
+ attr_reader :stabalizer, :mover
16
+
17
+ def initialize
18
+ @stabalizer = Stabalizer.new(escs: escs,
19
+ gyro: gyro,
20
+ accelerometer: acc)
21
+
22
+ @mover = Mover.new(escs: escs)
23
+ end
24
+
25
+ ##
26
+ # Once start is called the run function will be called in a loop
27
+ #
28
+ def run
29
+ stabalizer
30
+ move(:forward=>20, :right=>10)
31
+ end
32
+
33
+ ##
34
+ # Stabalize function is just syntactic sugar to make the run method look nice.
35
+ #
36
+ def stabilize
37
+ stabalizer.update
38
+ end
39
+
40
+ ##
41
+ # move function is just syntactic sugar to make the run method look nice.
42
+ #
43
+ def move
44
+ mover.update
45
+ end
46
+ end # Copter
47
+
48
+ class Circuit < BBB::Circuit
49
+ def initialize
50
+ attach_escs
51
+ attach_led
52
+ end
53
+
54
+ def attach_escs
55
+ attach ESC, :pins=>[:P8_1, :P8_2], :as=>:esc_1, :group=>:escs
56
+ attach ESC, :pins=>[:P9_1, :P9_2], :as=>:esc_2, :group=>:escs
57
+ end
58
+
59
+ def attach_leds
60
+ attach Led, :pin=>:P9_12
61
+ end
62
+ end # Circuit
63
+
64
+ class Mover
65
+ def initialize(opts={})
66
+ @escs = opts[:escs]
67
+ end
68
+
69
+ def move
70
+ # Do some complex logic here with the escs
71
+ end
72
+ end # Mover
73
+
74
+ def Stabalizer
75
+ def initialize(opts={})
76
+ @escs = opts[:escs]
77
+ @gyo = opts[:gyro]
78
+ @accelerometer = opts[:accelerometer]
79
+ end
80
+
81
+ def stabalize
82
+ # Do someting complex with all the components
83
+ # and update all values
84
+ end
85
+ end #Stabalizer
86
+ end
data/lib/BBB.rb CHANGED
@@ -1,5 +1,22 @@
1
1
  require "BBB/version"
2
+ require "BBB/board"
3
+ require "BBB/test_board"
4
+ require "BBB/circuit"
5
+ require "BBB/pin_mapper"
6
+ require "BBB/exceptions"
7
+
8
+ require "BBB/gpio/base"
9
+ require "BBB/gpio/digital_pin"
10
+ require "BBB/gpio/pin_converter"
11
+
12
+ require "BBB/io/pinnable"
13
+ require "BBB/io/digital_pin"
14
+ require "BBB/io/mock_pin"
15
+
16
+ require "BBB/components/pinnable"
17
+ require "BBB/components/led"
18
+
19
+ require "BBB/application"
2
20
 
3
21
  module BBB
4
- # Your code goes here...
5
22
  end
@@ -0,0 +1,44 @@
1
+ module BBB
2
+ class Application
3
+
4
+ def self.board(board)
5
+ @_board = board
6
+ connect unless @_circuit.nil?
7
+ end
8
+
9
+ def self.circuit(circuit)
10
+ @_circuit = circuit
11
+ connect unless @_board.nil?
12
+ end
13
+
14
+ def self._board
15
+ @_board
16
+ end
17
+
18
+ def self._circuit
19
+ @_circuit
20
+ end
21
+
22
+ def self.connect
23
+ @_circuit.components.each_pair do |name, component|
24
+ component.pins.each do |pin|
25
+ @_board.connect_io_pin(pin)
26
+ end
27
+
28
+ define_method(name) do
29
+ circuit.send(name)
30
+ end
31
+ end
32
+ end
33
+
34
+ def board
35
+ @board ||= self.class._board
36
+ end
37
+
38
+ def circuit
39
+ @circuit ||= self.class._circuit
40
+ end
41
+
42
+
43
+ end
44
+ end
data/lib/BBB/board.rb ADDED
@@ -0,0 +1,41 @@
1
+ module BBB
2
+ class Board
3
+ attr_reader :gpio, :pin_converter
4
+
5
+ def initialize(pin_converter=nil)
6
+ @pin_converter = pin_converter || self.class.pin_converter
7
+ @pins = {}
8
+ end
9
+
10
+ ##
11
+ # Define methods for a GPIO::PIN
12
+ #
13
+ def setup_pin(pin)
14
+ @pins[pin.position] = pin
15
+
16
+ metaclass = class << self; self; end
17
+ metaclass.class_eval do
18
+ define_method("p#{pin.position.to_s[1..-1]}") do
19
+ @pins[pin.position].read
20
+ end
21
+
22
+ define_method("p#{pin.position.to_s[1..-1]}=") do |value|
23
+ @pins[pin.position].write value
24
+ end if pin.mode == :output
25
+ end
26
+ end
27
+
28
+ def connect_io_pin(pin)
29
+ gpio_pin = pin_converter.convert(pin)
30
+ pin.pin_io = gpio_pin
31
+ setup_pin(pin)
32
+ end
33
+
34
+ private
35
+
36
+ def self.pin_converter
37
+ GPIO::PinConverter.new
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,72 @@
1
+ module BBB
2
+ ##
3
+ # The idea here is to attach a piece of equipment to a circuit. The circuit
4
+ # will later be connected to a board.
5
+ #
6
+ # A component (e.g. Led or Servo) will define generic pins, like
7
+ # DigitalInput or AnalogOutput. And then, when the circuit gets attached to
8
+ # the board those pins will be "connected" to their "physical" counterparts
9
+ # on the board.
10
+ #
11
+ # This allows you to develop generic circuits that can be attached to any
12
+ # board. At least, in theory :-)
13
+ #
14
+ # For now the attachment will be made onto specific pin numbers. For the BBB
15
+ # this might for example be :P8_3, however, the plan is to, in a future
16
+ # release, make sure that there are converters between the different kind of
17
+ # boards. For example by mapping P8_3 on BBB to P1 on an Arduino.
18
+ #
19
+ # As of now, the act of "attaching" something onto the circuit equals
20
+ # setting up a component with generic pins.
21
+ #
22
+ class Circuit
23
+ attr_reader :components
24
+
25
+ def components
26
+ @components ||= {}
27
+ end
28
+
29
+ ##
30
+ # Attach a component of a certain type to the circuit
31
+ #
32
+ # @param component [Class] The class of the object you # want to attach.
33
+ # @param opts [Hash] Hash of options that setup the component
34
+ #
35
+ # @option opts [Array<Symbol>] :pins The list of pin numbers used on the
36
+ # circuit.
37
+ #
38
+ def attach(component, opts={})
39
+ if component.kind_of?(Class)
40
+ component = component.new
41
+ end
42
+
43
+ if pin_positions = opts[:pins] || [opts[:pin]]
44
+ component_pins = component.pins
45
+ verify_pin_argument_count(component_pins.count, pin_positions.count)
46
+ component.register_pin_positions(pin_positions)
47
+ end
48
+
49
+ name = opts.fetch(:as)
50
+ register_component(component, name)
51
+ end
52
+
53
+ def register_component(component, name)
54
+ components[name] = component
55
+ eigenclass = class << self; self; end
56
+ eigenclass.class_eval do
57
+ define_method(name) do
58
+ components[name]
59
+ end
60
+ end
61
+ end
62
+
63
+ def verify_pin_argument_count(type_count, position_count)
64
+ if type_count != position_count
65
+ raise PinsDoNotMatchException,
66
+ "#{object.to_s} requires #{types_count} but received #{position_count} pin arguments."
67
+ end
68
+ end
69
+
70
+
71
+ end
72
+ end
@@ -0,0 +1,33 @@
1
+ module BBB
2
+ module Components
3
+ class Led
4
+ include Pinnable
5
+ attr_reader :state, :pin
6
+
7
+ def initialize
8
+ @state = :low
9
+ @pin = BBB::IO::DigitalPin.new(:output)
10
+ @pins = [@pin]
11
+ end
12
+
13
+ def on!
14
+ pin.on!
15
+ @state = :high
16
+ end
17
+
18
+ def off!
19
+ pin.off!
20
+ @state = :low
21
+ end
22
+
23
+ def on?
24
+ state == :high
25
+ end
26
+
27
+ def off?
28
+ state == :low
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module BBB
2
+ module Components
3
+ module Pinnable
4
+ attr_reader :pins
5
+
6
+ def register_pin_positions(*positions)
7
+ positions.flatten!
8
+ pins.each_with_index do |pin, index|
9
+ pin.position=positions[index]
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module BBB
2
+ class UnknownPinException < ArgumentError; end
3
+ class UnknownPinModeException < ArgumentError; end
4
+ class PinsDoNotMatchException < ArgumentError; end
5
+ end