object_oriented_beaglebone_black 0.0.2 → 0.2.0

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: 668bcd57ff71c597b1f24a3084d4d11202291d64
4
- data.tar.gz: 65e6e1629c619a3e90148612034a1daa28505c06
3
+ metadata.gz: dbe6449f8addf886e091badbb93261750b4dc6ba
4
+ data.tar.gz: 49cb896622d085d91b89cf18a22332da3fe06726
5
5
  SHA512:
6
- metadata.gz: e35ec82cf7065cc5f2a359ad4aea441d71940ff89d3ea05d3cf840be491b36749f70eb53e1ebdf75c1c98e2b83c2772a205a678c48bdd23c5f164eee9330d0bd
7
- data.tar.gz: 431e61ad98d696102b82258e6f61b5ec020ff77ed18ee83cc7ccab924a633aa3be1cb89f0c3d29e796d9af129eea1e9eb614ffe07cc0ee58881d582b52f1f47a
6
+ metadata.gz: dd858cf1e1c4af95a24f06c7ed2f2d86f281b849c551357ec4a468d3cdbc9bb4e415f3e972bfc59dcada5071fc4b7b16ee67c578ce92d8e175720b7facff5621
7
+ data.tar.gz: 7f89fe31bfc36a89a8aeac9729fee670954a94393054f1235967bb1bda8b7db55e89de515b21c3f35d08832126d3a6100bd95e581b7696fd4c528576156f0969
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.2.3
data/README.md CHANGED
@@ -5,7 +5,7 @@ This is for using Beaglebone Black in Object-Oriented way through Ruby code.
5
5
  There are many Ruby projects in GitHub to do a similar thing.
6
6
  But I have decided to develop my own from scratch this time instead of using an existing one like I always do.
7
7
 
8
- There are three reasons.
8
+ There are four reasons.
9
9
 
10
10
  1. Build my own expertise on controlling Beaglebone Black directly.
11
11
 
@@ -19,11 +19,11 @@ There are three reasons.
19
19
 
20
20
  3. Many existing ones don't have proper testings.
21
21
 
22
- I understand the difficulty of writing a test for a code to control hardware. But less test code makes the source code bulky and not modular. I want to make the code modular naturally by Test-Driven Development. (By Test-Driven Development, the code naturally becomes modular even when not consciously thinking about it by just thinking of making the code work.)
22
+ I understand the difficulty of writing a test for a code to control hardware. But less test code makes the source code bulky and not modular. I want to make the code modular naturally by Test-Driven Development. (By Test-Driven Development, the code naturally becomes modular even when not consciously thinking about it, by just thinking about making the code work.)
23
23
 
24
24
  4. Many existing ones for controlling hardware are focusing on Robotics (controlling motors).
25
25
 
26
- My objective is for developing a controller for DC-DC converter. Because of it, what makes existing ones good (for robotics) sometimes makes the code I need difficult to write for my objective.
26
+ My objective is for developing a controller related to Power Electronics. Because of it, what makes existing ones good (for robotics) sometimes makes the code I need difficult to write for my objective.
27
27
 
28
28
  The important point in this gem is that everything is Object-Oriented.
29
29
  In other words, controlling hardware in Object-Oriented way, treating everything as an Object.
@@ -104,6 +104,10 @@ Or install it yourself as:
104
104
 
105
105
  pwm.duty_cycle # Read the duty cycle. 0.5 as set above.
106
106
 
107
+ pwm.period = 1000 # Unit is [ns] (nano second)
108
+
109
+ pwm.period # Read the period. 1000[ns] as set above.
110
+
107
111
  ## Contributing
108
112
 
109
113
  1. Fork it ( https://github.com/[my-github-username]/object_oriented_beaglebone_black/fork )
@@ -1,3 +1,4 @@
1
+ require 'pry'
1
2
  require "object_oriented_beaglebone_black/version"
2
3
  require "erb"
3
4
 
@@ -8,8 +8,6 @@ module ObjectOrientedBeagleboneBlack
8
8
  INVERSE = 1
9
9
  end
10
10
 
11
- DUTY_VALUE_PER_ONE_HUNDREDTH = BigDecimal("5000")
12
-
13
11
  def initialize(pin_key)
14
12
  @pin_key = pin_key
15
13
  @slots_file_path = File.join(File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["slots_directory"], "slots"))
@@ -20,14 +18,22 @@ module ObjectOrientedBeagleboneBlack
20
18
  def activate_device_tree_overlays
21
19
  # Note: Since slots file acts as an interface to activate Device Tree Overlay, simply writing to it does what needs to be done.
22
20
  # I'm using appending here so that testing in a local environment becomes straightfoward.
23
- File.open(@slots_file_path, "a") { |file| file.write("am33xx_pwm") }
24
- File.open(@slots_file_path, "a") { |file| file.write("bone_pwm_#{@pin_key}") }
21
+ # Note: Closing this file caused an error in BeagleBone Black:
22
+ # Errno::ENOENT:
23
+ # No such file or directory @ fptr_finalize - /sys/devices/bone_capemgr.9/slots
24
+ # So modified the code not to close the file.
25
+ # File.open(@slots_file_path, "a") do |file|
26
+ # file.write("am33xx_pwm")
27
+ # file.write("bone_pwm_#{@pin_key}")
28
+ # end
29
+ File.open(@slots_file_path, "a").write("am33xx_pwm")
30
+ File.open(@slots_file_path, "a").write("bone_pwm_#{@pin_key}")
25
31
  end
26
32
 
27
33
  # duty_cycle (value between 0 and 1)
28
34
  def duty_cycle=(duty_cycle)
29
35
  self.polarity = ObjectOrientedBeagleboneBlack::Pwm::Polarity::DIRECT
30
- internal_duty_value = (BigDecimal(duty_cycle.to_s) * BigDecimal("100") * DUTY_VALUE_PER_ONE_HUNDREDTH).to_i
36
+ internal_duty_value = (BigDecimal(duty_cycle.to_s) * BigDecimal(period.to_s)).to_i
31
37
  File.open(File.join(pwm_directory, "duty"), "w") { |file| file.write(internal_duty_value) }
32
38
  end
33
39
 
@@ -35,7 +41,7 @@ module ObjectOrientedBeagleboneBlack
35
41
  # Using this instead of simple "File.open(file_path).read" in order to close file after reading.
36
42
  internal_duty_value = nil
37
43
  File.open(File.join(pwm_directory, "duty"), "r") { |file| internal_duty_value = file.read.strip }
38
- duty_cycle = (BigDecimal(internal_duty_value.to_s) / DUTY_VALUE_PER_ONE_HUNDREDTH / BigDecimal("100")).to_f
44
+ duty_cycle = (BigDecimal(internal_duty_value.to_s) / BigDecimal(period.to_s)).to_f
39
45
  duty_cycle
40
46
  end
41
47
 
@@ -49,6 +55,17 @@ module ObjectOrientedBeagleboneBlack
49
55
  internal_polarity_value
50
56
  end
51
57
 
58
+ def period=(period)
59
+ File.open(File.join(pwm_directory, "period"), "w") { |file| file.write(period) }
60
+ end
61
+
62
+ # Unit: [ns] (nano second)
63
+ def period
64
+ internal_period_value = nil
65
+ File.open(File.join(pwm_directory, "period"), "r") { |file| internal_period_value = file.read.strip.to_i }
66
+ internal_period_value
67
+ end
68
+
52
69
  private
53
70
  def pwm_directory
54
71
  Dir["#{File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"], "pwm_test_#{@pin_key}.")}*"].first
@@ -1,3 +1,3 @@
1
1
  module ObjectOrientedBeagleboneBlack
2
- VERSION = "0.0.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -33,7 +33,7 @@ describe ObjectOrientedBeagleboneBlack::Pwm, pwm: true do
33
33
  pwm = ObjectOrientedBeagleboneBlack::Pwm.new(pwm_pin_key)
34
34
 
35
35
  # Since the real "slots" file creates a directory structure when a device tree overlay is written to it,
36
- # in the "test" environment with a regular file, it is mimiced here.
36
+ # in the "test" environment with a regular file, it is mimicked here.
37
37
  mimic_internal_pwm_directory_creation(pwm_pin_key) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
38
38
 
39
39
  expect(Dir.exists?(File.join(@device_directory, "pwm_test_#{pwm_pin_key}.15"))).to be true
@@ -54,4 +54,49 @@ describe ObjectOrientedBeagleboneBlack::Pwm, pwm: true do
54
54
 
55
55
  end
56
56
 
57
+ context 'period' do
58
+
59
+ it 'should set the period' do
60
+
61
+ pwm_pin_key = 'P9_14'
62
+
63
+ pwm = ObjectOrientedBeagleboneBlack::Pwm.new(pwm_pin_key)
64
+
65
+ # Since the real "slots" file creates a directory structure when a device tree overlay is written to it,
66
+ # in the "test" environment with a regular file, it is mimicked here.
67
+ mimic_internal_pwm_directory_creation(pwm_pin_key) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
68
+
69
+ expect(Dir.exists?(File.join(@device_directory, "pwm_test_#{pwm_pin_key}.15"))).to be true
70
+
71
+ pwm.period = 10000 # [ns]: nano second
72
+
73
+ expect(pwm.period).to eq(10000)
74
+
75
+ end
76
+
77
+ it 'should set the duty cycle corresponding to the specified period' do
78
+
79
+ pwm_pin_key = 'P9_14'
80
+
81
+ pwm = ObjectOrientedBeagleboneBlack::Pwm.new(pwm_pin_key)
82
+
83
+ # Since the real "slots" file creates a directory structure when a device tree overlay is written to it,
84
+ # in the "test" environment with a regular file, it is mimicked here.
85
+ mimic_internal_pwm_directory_creation(pwm_pin_key) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
86
+
87
+ expect(Dir.exists?(File.join(@device_directory, "pwm_test_#{pwm_pin_key}.15"))).to be true
88
+
89
+ pwm.period = 1000 # [ns]: nano second
90
+
91
+ expect(pwm.period).to eq(1000)
92
+
93
+ pwm.duty_cycle = 0.5
94
+
95
+ expect(pwm.polarity).to eq(ObjectOrientedBeagleboneBlack::Pwm::Polarity::DIRECT)
96
+ expect(pwm.duty_cycle).to eq(0.5)
97
+
98
+ end
99
+
100
+ end
101
+
57
102
  end
@@ -10,14 +10,21 @@ module PwmFileBehaviorHelper
10
10
 
11
11
  unless Dir.exists?(temp_specific_pwm_directory)
12
12
  FileUtils.mkdir_p(temp_specific_pwm_directory, mode: 0700)
13
+ end
13
14
 
15
+ # "period" must be set to the default value, because duty value is relative to it:
16
+ FileUtils.touch(File.join(temp_specific_pwm_directory, "period"))
17
+ File.chmod(0700, File.join(temp_specific_pwm_directory, "period"))
18
+ File.open(File.join(temp_specific_pwm_directory, "period"), 'w') {|file| file.write(500000) }
19
+
20
+ unless Dir.exists?(temp_specific_pwm_directory)
14
21
  FileUtils.touch(File.join(temp_specific_pwm_directory, "duty"))
15
22
  File.chmod(0700, File.join(temp_specific_pwm_directory, "duty"))
16
23
  File.open(File.join(temp_specific_pwm_directory, "duty"), 'w') {|file| file.write(250000) }
17
24
  FileUtils.touch(File.join(temp_specific_pwm_directory, "polarity"))
18
25
  File.chmod(0700, File.join(temp_specific_pwm_directory, "polarity"))
19
26
  File.open(File.join(temp_specific_pwm_directory, "polarity"), 'w') {|file| file.write(ObjectOrientedBeagleboneBlack::Pwm::Polarity::INVERSE) }
20
- end
27
+ end
21
28
  end
22
29
 
23
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: object_oriented_beaglebone_black
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tadatoshi Takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-26 00:00:00.000000000 Z
11
+ date: 2015-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  requirements: []
122
122
  rubyforge_project:
123
- rubygems_version: 2.4.5
123
+ rubygems_version: 2.4.5.1
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: For using BeagleBone Black in Object-Oriented way through Ruby.