artoo-beaglebone 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da58ec62c81ebfdea9be0e49806cb6790b1816cf
4
- data.tar.gz: adf28851c3b42c2c3722f10d2e54bd19feed2bbd
3
+ metadata.gz: 79716534c1f12420b57e972d15074cc723d4fd81
4
+ data.tar.gz: 665b6c8e33a6f02347ad20c7fa7f96813a6661e3
5
5
  SHA512:
6
- metadata.gz: 36f9b54633c413b170dd270aab9847704faf33e3e8a7bc805a83e17f984baca027e16aed96fb7effee8ba1e8416b0e5d499271b30552f45cf1f68618df19ac3a
7
- data.tar.gz: 00918328fea3788e53bf5327b7c88c0586e936d5f2ff387db5cc5d45703a3a460718d55c36143818334d1915112cb60092725bac2226c3703a9b2d189db8d799
6
+ metadata.gz: 24142106fa25cad95b87110dc0571afe991bd7dd441f14f3a585e04860549585e969ecffdc92be1378f150efa1a44f4c0e1502466bde8058639695b8e3e4a54b
7
+ data.tar.gz: f1c3bfc3c26ac898fcf77fb2d934d21169fed0eaa47c61386796b943924b49c751c73cb4b417e0af4c62aa4f21985eb000781f887e71d9315520c30cd7b97733
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - jruby-1.7.4
6
+ - rbx-19mode
7
+ matrix:
8
+ allow_failures:
9
+ - rvm: jruby-1.7.4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- artoo-beaglebone (0.1.0)
4
+ artoo-beaglebone (0.2.0)
5
5
  artoo (>= 1.3.0)
6
6
  artoo-gpio
7
7
  artoo-i2c
@@ -0,0 +1,18 @@
1
+ require 'artoo'
2
+
3
+ connection :beaglebone, :adaptor => :beaglebone
4
+ device :led, :driver => :led, :pin => :P9_21
5
+
6
+ brightness = 0
7
+ fade_amount = 5
8
+
9
+
10
+ work do
11
+ every(0.05) do
12
+ led.brightness(brightness)
13
+ brightness = brightness + fade_amount
14
+ if brightness == 0 or brightness == 60
15
+ fade_amount = -fade_amount
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Artoo
2
2
  module Beaglebone
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
@@ -1,5 +1,6 @@
1
1
  require 'artoo/adaptors/adaptor'
2
2
  require 'artoo/adaptors/io'
3
+ require 'pwm_pin'
3
4
 
4
5
  module Artoo
5
6
  module Adaptors
@@ -74,7 +75,15 @@ module Artoo
74
75
  :P9_30 => 112,
75
76
  :P9_31 => 110
76
77
  }
77
- attr_reader :pins, :i2c
78
+ attr_reader :pins, :i2c, :pwm_pins
79
+
80
+ # Creates a connection with device
81
+ # @return [Boolean]
82
+ def connect
83
+ @pins = [] if @pins.nil?
84
+ @pwm_pins = [] if @pwm_pins.nil?
85
+ super
86
+ end
78
87
 
79
88
  # Name of device
80
89
  # @return [String]
@@ -110,6 +119,21 @@ module Artoo
110
119
  i2c.read len
111
120
  end
112
121
 
122
+ def pwm_write(pin, period, duty=0)
123
+ pin = pwm_pin(pin)
124
+ pin.pwm_write(period, duty)
125
+ end
126
+
127
+ def release_pwm(pin)
128
+ pin = translate_pin(pin)
129
+ pwm_pins[pin].release
130
+ pwm_pins[pin] = nil
131
+ end
132
+
133
+ def release_all_pwm_pins
134
+ pwm_pins.each_value { |pwm_pin| pwm_pin.release }
135
+ end
136
+
113
137
  private
114
138
 
115
139
  def translate_pin pin
@@ -127,6 +151,16 @@ module Artoo
127
151
  @pins[pin]
128
152
  end
129
153
 
154
+ def pwm_used?(pin)
155
+ (pwm_pins[translate_pin(pin)].nil?) ? false : true
156
+ end
157
+
158
+ def pwm_pin(pin)
159
+ translated_pin = translate_pin(pin)
160
+ pwm_pins[translated_pin] = PwmPin.new(pin) if pwm_pins[translated_pin].nil?
161
+ pwm_pins[translated_pin]
162
+ end
163
+
130
164
  def i2c2_file
131
165
  "/dev/i2c-1"
132
166
  end
data/lib/pwm_pin.rb ADDED
@@ -0,0 +1,24 @@
1
+ class PwmPin
2
+ attr_reader :pin, :pwm_device
3
+
4
+ SLOTS = "/sys/devices/bone_capemgr.*"
5
+ def initialize(pin)
6
+ @pin = pin.to_s.upcase
7
+ File.open("#{Dir.glob(SLOTS).first}/slots", "w") { |f|
8
+ f.write("am33xx_pwm")
9
+ f.write('bone_pwm_' + @pin)
10
+ }
11
+ @pwm_device = Dir.glob(Dir.glob("/sys/devices/ocp.*").first+"/pwm_test_" + @pin + ".*").first
12
+ File.open(@pwm_device + "/run", "w") { |f| f.write(1) }
13
+ pwm_write(0)
14
+ end
15
+
16
+ def pwm_write(period, duty=0)
17
+ File.open(@pwm_device + "/period", "w") { |f| f.write(period) }
18
+ File.open(@pwm_device + "/duty", "w") { |f| f.write(duty) }
19
+ end
20
+
21
+ def release
22
+ File.open(@pwm_device + "/run", "w") { |f| f.write(0) }
23
+ end
24
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: artoo-beaglebone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Zankich
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-05 00:00:00.000000000 Z
12
+ date: 2013-10-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: artoo
@@ -103,6 +103,7 @@ extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
105
  - .gitignore
106
+ - .travis.yml
106
107
  - Gemfile
107
108
  - Gemfile.lock
108
109
  - LICENSE
@@ -110,10 +111,12 @@ files:
110
111
  - Rakefile
111
112
  - artoo-beaglebone.gemspec
112
113
  - examples/blink.rb
114
+ - examples/led_brightness.rb
113
115
  - examples/wiichuck.rb
114
116
  - lib/artoo-beaglebone.rb
115
117
  - lib/artoo-beaglebone/version.rb
116
118
  - lib/artoo/adaptors/beaglebone.rb
119
+ - lib/pwm_pin.rb
117
120
  - test/adaptors/beaglebone_adaptor_test.rb
118
121
  - test/test_helper.rb
119
122
  homepage: https://github.com/hybridgroup/artoo-beaglebone