object_oriented_beaglebone_black 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +7 -0
- data/config/environments/development.yml +3 -0
- data/config/environments/production.yml +3 -0
- data/config/environments/test.yml +3 -0
- data/config/i2c.json +26 -0
- data/config/pin_index.json +1519 -0
- data/config/uarts.json +31 -0
- data/examples/current_measurement.rb +7 -0
- data/examples/current_measurement/current_input.rb +16 -0
- data/examples/voltage_measurement.rb +7 -0
- data/examples/voltage_measurement/voltage_input.rb +16 -0
- data/lib/object_oriented_beaglebone_black.rb +26 -0
- data/lib/object_oriented_beaglebone_black/analog_input.rb +43 -0
- data/lib/object_oriented_beaglebone_black/gpio.rb +40 -0
- data/lib/object_oriented_beaglebone_black/io.rb +34 -0
- data/lib/object_oriented_beaglebone_black/io/direction.rb +10 -0
- data/lib/object_oriented_beaglebone_black/io/value.rb +10 -0
- data/lib/object_oriented_beaglebone_black/led.rb +43 -0
- data/lib/object_oriented_beaglebone_black/pin_mappings.rb +25 -0
- data/lib/object_oriented_beaglebone_black/pwm.rb +58 -0
- data/lib/object_oriented_beaglebone_black/version.rb +3 -0
- data/object_orieted_beaglebone_black.gemspec +27 -0
- data/spec/examples/current_measurement/current_input_spec.rb +46 -0
- data/spec/examples/voltage_measurement/voltage_input_spec.rb +46 -0
- data/spec/object_oriented_beaglebone_black/analog_input_spec.rb +49 -0
- data/spec/object_oriented_beaglebone_black/gpio_spec.rb +66 -0
- data/spec/object_oriented_beaglebone_black/led_spec.rb +29 -0
- data/spec/object_oriented_beaglebone_black/pin_mappings_spec.rb +35 -0
- data/spec/object_oriented_beaglebone_black/pwm_spec.rb +57 -0
- data/spec/spec_helper.rb +13 -0
- data/spec/support/analog_input_file_behavoir_helper.rb +34 -0
- data/spec/support/gpio_file_behavior_helper.rb +36 -0
- data/spec/support/pwm_file_behavior_helper.rb +23 -0
- metadata +138 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'voltage_measurement'
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
describe "Voltage measurement with voltage divider of 11:1, e.g. 51[kΩ] and 5.1[kΩ]", analog_input: true do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
|
9
|
+
@slots_directory = OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["slots_directory"]
|
10
|
+
@device_directory = OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"]
|
11
|
+
|
12
|
+
# In order to run this spec example in the real environment, the directories and files that already exist there are not created in that case.
|
13
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
14
|
+
FileUtils.mkdir_p(@slots_directory, mode: 0700) unless Dir.exists?(@slots_directory)
|
15
|
+
FileUtils.touch(File.join(@slots_directory, "slots"))
|
16
|
+
File.chmod(0700, File.join(@slots_directory, "slots"))
|
17
|
+
|
18
|
+
FileUtils.mkdir_p(@device_directory, mode: 0700) unless Dir.exists?(@device_directory)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:each) do
|
23
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
24
|
+
File.open(File.join(@slots_directory, "slots"), 'w') {|file| file.truncate(0) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should calculate the measuring voltage" do
|
29
|
+
|
30
|
+
pin_key = "P9_40"
|
31
|
+
expected_voltage = BigDecimal("20").to_f
|
32
|
+
expected_raw_value = (BigDecimal(expected_voltage.to_s) / BigDecimal("11")).to_f
|
33
|
+
|
34
|
+
voltage_input = VoltageMeasurement::VoltageInput.new(pin_key)
|
35
|
+
|
36
|
+
# Since the real "slots" file creates a directory structure when a device tree overlay is written to it,
|
37
|
+
# in the "test" environment with a regular file, it is mimiced here.
|
38
|
+
mimic_internal_analog_input_directory_creation(pin_key, expected_raw_value) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
39
|
+
|
40
|
+
expect(Dir.exists?(Dir["#{File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"], "helper.")}*"].first)).to be true
|
41
|
+
|
42
|
+
expect(voltage_input.value).to be_within(0.1).of(expected_voltage)
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
describe "ObjectOrientedBeagleboneBlack::AnalogInput", analog_input: true do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
|
9
|
+
@slots_directory = OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["slots_directory"]
|
10
|
+
@device_directory = OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"]
|
11
|
+
|
12
|
+
# In order to run this spec example in the real environment, the directories and files that already exist there are not created in that case.
|
13
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
14
|
+
FileUtils.mkdir_p(@slots_directory, mode: 0700) unless Dir.exists?(@slots_directory)
|
15
|
+
FileUtils.touch(File.join(@slots_directory, "slots"))
|
16
|
+
File.chmod(0700, File.join(@slots_directory, "slots"))
|
17
|
+
|
18
|
+
FileUtils.mkdir_p(@device_directory, mode: 0700) unless Dir.exists?(@device_directory)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
after(:each) do
|
23
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
24
|
+
File.open(File.join(@slots_directory, "slots"), 'w') {|file| file.truncate(0) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should read the value of the specified analog input pin" do
|
29
|
+
|
30
|
+
pin_key = "P9_40"
|
31
|
+
expected_raw_value = (BigDecimal("1630") / BigDecimal("1000")).to_f
|
32
|
+
expected_value = (BigDecimal(expected_raw_value.to_s) * (BigDecimal("1.0")/BigDecimal("1.8"))).to_f
|
33
|
+
|
34
|
+
analog_input = ObjectOrientedBeagleboneBlack::AnalogInput.new(pin_key)
|
35
|
+
|
36
|
+
# Since the real "slots" file creates a directory structure when a device tree overlay is written to it,
|
37
|
+
# in the "test" environment with a regular file, it is mimiced here.
|
38
|
+
mimic_internal_analog_input_directory_creation(pin_key, expected_raw_value) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
39
|
+
|
40
|
+
expect(Dir.exists?(Dir["#{File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"], "helper.")}*"].first)).to be true
|
41
|
+
|
42
|
+
# Instead of analog_read(pin_name), reading the value is responsibility of pin object.
|
43
|
+
# i.e. ordinary Object-Oriented way.
|
44
|
+
expect(analog_input.raw_value).to eq(expected_raw_value)
|
45
|
+
expect(analog_input.value).to eq(expected_value)
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe ObjectOrientedBeagleboneBlack::Gpio, gpio: true do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
@temp_gpio_directory = File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["io_root_directory"], "gpio")
|
8
|
+
|
9
|
+
# In order to run this spec example in the real environment, the directories and files that already exist there are not created in that case.
|
10
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
11
|
+
FileUtils.mkdir_p(@temp_gpio_directory, mode: 0700) unless Dir.exists?(@temp_gpio_directory)
|
12
|
+
FileUtils.touch(File.join(@temp_gpio_directory, "export"))
|
13
|
+
File.chmod(0700, File.join(@temp_gpio_directory, "export")) # Not same as the real one (with only write permission) but adding write permission as well just in case what is written there needs to be read.
|
14
|
+
FileUtils.touch(File.join(@temp_gpio_directory, "unexport"))
|
15
|
+
File.chmod(0700, File.join(@temp_gpio_directory, "unexport")) # Not same as the real one (with only write permission) but adding write permission as well just in case what is written there needs to be read.
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:each) do
|
20
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
21
|
+
File.open(File.join(@temp_gpio_directory, "export"), 'w') {|file| file.truncate(0) }
|
22
|
+
File.open(File.join(@temp_gpio_directory, "unexport"), 'w') {|file| file.truncate(0) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "test with same circuit setting as boneDeviceTree gpio/TestApplication.cpp" do
|
27
|
+
|
28
|
+
it "should blink LED's through GPIO defined by Device Tree Overlay" do
|
29
|
+
|
30
|
+
led_gpio_pin_number = 60
|
31
|
+
button_gpio_pin_number = 15
|
32
|
+
|
33
|
+
led_gpio = ObjectOrientedBeagleboneBlack::Gpio.new(led_gpio_pin_number)
|
34
|
+
|
35
|
+
led_gpio.export
|
36
|
+
# Since the real "export" file creates a directory structure when a pin number is written to it,
|
37
|
+
# in the "test" environment with a regular file, it is mimiced here.
|
38
|
+
mimic_internal_export(led_gpio_pin_number) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
39
|
+
|
40
|
+
expect(Dir.exists?(File.join(@temp_gpio_directory, "gpio#{led_gpio_pin_number}"))).to be true
|
41
|
+
|
42
|
+
led_gpio.direction = ObjectOrientedBeagleboneBlack::IO::Direction::OUT
|
43
|
+
|
44
|
+
expect(led_gpio.direction).to eq(ObjectOrientedBeagleboneBlack::IO::Direction::OUT)
|
45
|
+
|
46
|
+
(0..1).each do |second|
|
47
|
+
led_gpio.value = ObjectOrientedBeagleboneBlack::IO::Value::HIGH
|
48
|
+
expect(led_gpio.value).to eq(ObjectOrientedBeagleboneBlack::IO::Value::HIGH)
|
49
|
+
sleep(0.5)
|
50
|
+
led_gpio.value = ObjectOrientedBeagleboneBlack::IO::Value::LOW
|
51
|
+
expect(led_gpio.value).to eq(ObjectOrientedBeagleboneBlack::IO::Value::LOW)
|
52
|
+
sleep(0.5)
|
53
|
+
end
|
54
|
+
|
55
|
+
led_gpio.unexport
|
56
|
+
# Since the real "unexport" file deletes a directory structure when a pin number is written to it,
|
57
|
+
# in the "test" environment with a regular file, it is mimiced here.
|
58
|
+
mimic_internal_unexport(led_gpio_pin_number) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
59
|
+
|
60
|
+
expect(Dir.exists?(File.join(@temp_gpio_directory, "gpio#{led_gpio_pin_number}"))).to be false
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe ObjectOrientedBeagleboneBlack::Led do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
FileUtils.mkdir_p(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["io_root_directory"], mode: 0700) unless Dir.exists?(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["io_root_directory"])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should light LED 0 (mimicking http://192.168.7.2/Support/BoneScript/demo_blinkled/)" do
|
11
|
+
|
12
|
+
led = "USR0"
|
13
|
+
state = 1
|
14
|
+
|
15
|
+
led_0 = ObjectOrientedBeagleboneBlack::Led.new(led)
|
16
|
+
|
17
|
+
# Instead of pin_mode(pin_name, pin_mode), setting the pin_mode is responsibility of pin object (Led here).
|
18
|
+
# i.e. ordinary Object-Oriented way.
|
19
|
+
led_0.pin_mode = 'out'
|
20
|
+
|
21
|
+
# Instead of digital_write(pin_name, state), setting the state is responsibility of pin object (Led here).
|
22
|
+
# i.e. ordinary Object-Oriented way.
|
23
|
+
led_0.digital_write(state)
|
24
|
+
|
25
|
+
expect(led_0.state).to eq(state)
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ObjectOrientedBeagleboneBlack::PinMappings do
|
4
|
+
|
5
|
+
class TestPinMappingsClass
|
6
|
+
include ObjectOrientedBeagleboneBlack::PinMappings
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@test_pin_mappings = TestPinMappingsClass.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should get Hash for USR0 pin" do
|
14
|
+
|
15
|
+
expect(@test_pin_mappings.property_hash(name: "USR0")).to eq({"name" => "USR0",
|
16
|
+
"gpio" => 53,
|
17
|
+
"led" => "usr0",
|
18
|
+
"mux" => "gpmc_a5",
|
19
|
+
"key" => "USR0",
|
20
|
+
"muxRegOffset" => "0x054",
|
21
|
+
"options" => ["gpmc_a5", "gmii2_txd0", "rgmii2_td0", "rmii2_txd0", "gpmc_a21", "pr1_mii1_rxd3", "eqep1b_in", "gpio1_21"]})
|
22
|
+
|
23
|
+
expect(@test_pin_mappings.property_hash(key: "USR0")).to eq({"name" => "USR0",
|
24
|
+
"gpio" => 53,
|
25
|
+
"led" => "usr0",
|
26
|
+
"mux" => "gpmc_a5",
|
27
|
+
"key" => "USR0",
|
28
|
+
"muxRegOffset" => "0x054",
|
29
|
+
"options" => ["gpmc_a5", "gmii2_txd0", "rgmii2_td0", "rmii2_txd0", "gpmc_a21", "pr1_mii1_rxd3", "eqep1b_in", "gpio1_21"]})
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
describe ObjectOrientedBeagleboneBlack::Pwm, pwm: true do
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
|
8
|
+
@slots_directory = OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["slots_directory"]
|
9
|
+
@device_directory = OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"]
|
10
|
+
|
11
|
+
# In order to run this spec example in the real environment, the directories and files that already exist there are not created in that case.
|
12
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
13
|
+
FileUtils.mkdir_p(@slots_directory, mode: 0700) unless Dir.exists?(@slots_directory)
|
14
|
+
FileUtils.touch(File.join(@slots_directory, "slots"))
|
15
|
+
File.chmod(0700, File.join(@slots_directory, "slots"))
|
16
|
+
|
17
|
+
FileUtils.mkdir_p(@device_directory, mode: 0700) unless Dir.exists?(@device_directory)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
after(:each) do
|
22
|
+
if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
23
|
+
File.open(File.join(@slots_directory, "slots"), 'w') {|file| file.truncate(0) }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "test with same setting as in https://learn.adafruit.com/setting-up-io-python-library-on-beaglebone-black/pwm" do
|
28
|
+
|
29
|
+
it "should duty cycle" do
|
30
|
+
|
31
|
+
pwm_pin_key = "P9_14"
|
32
|
+
|
33
|
+
pwm = ObjectOrientedBeagleboneBlack::Pwm.new(pwm_pin_key)
|
34
|
+
|
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.
|
37
|
+
mimic_internal_pwm_directory_creation(pwm_pin_key) if ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] == 'test'
|
38
|
+
|
39
|
+
expect(Dir.exists?(File.join(@device_directory, "pwm_test_#{pwm_pin_key}.15"))).to be true
|
40
|
+
|
41
|
+
pwm.duty_cycle = 0.5
|
42
|
+
|
43
|
+
expect(pwm.polarity).to eq(ObjectOrientedBeagleboneBlack::Pwm::Polarity::DIRECT)
|
44
|
+
expect(pwm.duty_cycle).to eq(0.5)
|
45
|
+
|
46
|
+
sleep(2)
|
47
|
+
|
48
|
+
pwm.duty_cycle = 0.225
|
49
|
+
|
50
|
+
expect(pwm.polarity).to eq(ObjectOrientedBeagleboneBlack::Pwm::Polarity::DIRECT)
|
51
|
+
expect(pwm.duty_cycle).to eq(0.225)
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
ENV["OBJECT_ORIENTED_BEAGLEBONE_BLACK_ENV"] ||= 'test'
|
2
|
+
|
3
|
+
require 'object_oriented_beaglebone_black'
|
4
|
+
|
5
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
6
|
+
# in spec/support/ and its subdirectories.
|
7
|
+
Dir[File.join(File.expand_path('support/**/*.rb', __dir__))].each {|f| require f}
|
8
|
+
|
9
|
+
RSpec.configure do |c|
|
10
|
+
c.include GpioFileBehaviorHelper, gpio: true
|
11
|
+
c.include PwmFileBehaviorHelper, pwm: true
|
12
|
+
c.include AnalogInputFileBehaviorHelper, analog_input: true
|
13
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'bigdecimal'
|
3
|
+
|
4
|
+
module AnalogInputFileBehaviorHelper
|
5
|
+
include ObjectOrientedBeagleboneBlack::PinMappings
|
6
|
+
|
7
|
+
# In Embedded Linux, when a Device Tree Overlay for the specific Analog input PIN key is activated,
|
8
|
+
# a directory with the name including the pin key is created with the various files e.g. AIN0, etc. underneath the directory.
|
9
|
+
# This method is for performing that automatic behavior in the local test environment.
|
10
|
+
def mimic_internal_analog_input_directory_creation(pin_key, raw_value)
|
11
|
+
temp_specific_analog_input_directory = File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"], "helper.16")
|
12
|
+
|
13
|
+
unless Dir.exists?(temp_specific_analog_input_directory)
|
14
|
+
FileUtils.mkdir_p(temp_specific_analog_input_directory, mode: 0700)
|
15
|
+
|
16
|
+
for ain_file_index in 0..7
|
17
|
+
create_ain_file(temp_specific_analog_input_directory, ain_file_index)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
pin_name = property_hash(key: pin_key)["name"]
|
22
|
+
converted_raw_value = (BigDecimal(raw_value.to_s) * BigDecimal("1000")).to_i
|
23
|
+
File.open(File.join(temp_specific_analog_input_directory, pin_name), 'w') {|file| file.write(converted_raw_value) }
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def create_ain_file(temp_specific_analog_input_directory, ain_file_index)
|
29
|
+
FileUtils.touch(File.join(temp_specific_analog_input_directory, "AIN#{ain_file_index}"))
|
30
|
+
File.chmod(0700, File.join(temp_specific_analog_input_directory, "AIN#{ain_file_index}"))
|
31
|
+
File.open(File.join(temp_specific_analog_input_directory, "AIN#{ain_file_index}"), 'w') {|file| file.write(1630) }
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module GpioFileBehaviorHelper
|
4
|
+
|
5
|
+
# In Embedded Linux, when a GPIO pin number is written to /sys/class/gpio/export file,
|
6
|
+
# a directory with the name including the pin number is created with the various files e.g. direction, value, etc. underneath the directory.
|
7
|
+
# This method is for performing that automatic behavior in the local test environment.
|
8
|
+
def mimic_internal_export(gpio_pin_number)
|
9
|
+
temp_specific_gpio_directory = File.join(temp_gpio_directory, "gpio#{gpio_pin_number}")
|
10
|
+
|
11
|
+
unless Dir.exists?(temp_specific_gpio_directory)
|
12
|
+
FileUtils.mkdir_p(temp_specific_gpio_directory, mode: 0700)
|
13
|
+
|
14
|
+
FileUtils.touch(File.join(temp_specific_gpio_directory, "direction"))
|
15
|
+
File.chmod(0700, File.join(temp_specific_gpio_directory, "direction")) # Not same as the real one but I prefer for a file to have only a user permission
|
16
|
+
File.open(File.join(temp_specific_gpio_directory, "direction"), "w") { |file| file.write(ObjectOrientedBeagleboneBlack::IO::Direction::IN) }
|
17
|
+
|
18
|
+
FileUtils.touch(File.join(temp_specific_gpio_directory, "value"))
|
19
|
+
File.chmod(0700, File.join(temp_specific_gpio_directory, "value")) # Not same as the real one but I prefer for a file to have only a user permission
|
20
|
+
File.open(File.join(temp_specific_gpio_directory, "value"), "w") { |file| file.write(ObjectOrientedBeagleboneBlack::IO::Value::LOW) }
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def mimic_internal_unexport(gpio_pin_number)
|
26
|
+
temp_specific_gpio_directory = File.join(temp_gpio_directory, "gpio#{gpio_pin_number}")
|
27
|
+
|
28
|
+
FileUtils.rm_rf(temp_specific_gpio_directory)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def temp_gpio_directory
|
33
|
+
File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["io_root_directory"], "gpio")
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
module PwmFileBehaviorHelper
|
4
|
+
|
5
|
+
# In Embedded Linux, when a Device Tree Overlay for the specific PWM PIN key is activated,
|
6
|
+
# a directory with the name including the pin key is created with the various files e.g. duty, etc. underneath the directory.
|
7
|
+
# This method is for performing that automatic behavior in the local test environment.
|
8
|
+
def mimic_internal_pwm_directory_creation(pwm_pin_key)
|
9
|
+
temp_specific_pwm_directory = File.join(OBJECT_ORIENTED_BEAGLEBONE_BLACK_CONFIG["device_directory"], "pwm_test_#{pwm_pin_key}.15")
|
10
|
+
|
11
|
+
unless Dir.exists?(temp_specific_pwm_directory)
|
12
|
+
FileUtils.mkdir_p(temp_specific_pwm_directory, mode: 0700)
|
13
|
+
|
14
|
+
FileUtils.touch(File.join(temp_specific_pwm_directory, "duty"))
|
15
|
+
File.chmod(0700, File.join(temp_specific_pwm_directory, "duty"))
|
16
|
+
File.open(File.join(temp_specific_pwm_directory, "duty"), 'w') {|file| file.write(250000) }
|
17
|
+
FileUtils.touch(File.join(temp_specific_pwm_directory, "polarity"))
|
18
|
+
File.chmod(0700, File.join(temp_specific_pwm_directory, "polarity"))
|
19
|
+
File.open(File.join(temp_specific_pwm_directory, "polarity"), 'w') {|file| file.write(ObjectOrientedBeagleboneBlack::Pwm::Polarity::INVERSE) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: object_oriented_beaglebone_black
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tadatoshi Takahashi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Performs accessing GPIO, etc. in Object-Oriented way on BeagleBone Black
|
56
|
+
through Ruby.
|
57
|
+
email:
|
58
|
+
- tadatoshi@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- config/environments/development.yml
|
71
|
+
- config/environments/production.yml
|
72
|
+
- config/environments/test.yml
|
73
|
+
- config/i2c.json
|
74
|
+
- config/pin_index.json
|
75
|
+
- config/uarts.json
|
76
|
+
- examples/current_measurement.rb
|
77
|
+
- examples/current_measurement/current_input.rb
|
78
|
+
- examples/voltage_measurement.rb
|
79
|
+
- examples/voltage_measurement/voltage_input.rb
|
80
|
+
- lib/object_oriented_beaglebone_black.rb
|
81
|
+
- lib/object_oriented_beaglebone_black/analog_input.rb
|
82
|
+
- lib/object_oriented_beaglebone_black/gpio.rb
|
83
|
+
- lib/object_oriented_beaglebone_black/io.rb
|
84
|
+
- lib/object_oriented_beaglebone_black/io/direction.rb
|
85
|
+
- lib/object_oriented_beaglebone_black/io/value.rb
|
86
|
+
- lib/object_oriented_beaglebone_black/led.rb
|
87
|
+
- lib/object_oriented_beaglebone_black/pin_mappings.rb
|
88
|
+
- lib/object_oriented_beaglebone_black/pwm.rb
|
89
|
+
- lib/object_oriented_beaglebone_black/version.rb
|
90
|
+
- object_orieted_beaglebone_black.gemspec
|
91
|
+
- spec/examples/current_measurement/current_input_spec.rb
|
92
|
+
- spec/examples/voltage_measurement/voltage_input_spec.rb
|
93
|
+
- spec/object_oriented_beaglebone_black/analog_input_spec.rb
|
94
|
+
- spec/object_oriented_beaglebone_black/gpio_spec.rb
|
95
|
+
- spec/object_oriented_beaglebone_black/led_spec.rb
|
96
|
+
- spec/object_oriented_beaglebone_black/pin_mappings_spec.rb
|
97
|
+
- spec/object_oriented_beaglebone_black/pwm_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/support/analog_input_file_behavoir_helper.rb
|
100
|
+
- spec/support/gpio_file_behavior_helper.rb
|
101
|
+
- spec/support/pwm_file_behavior_helper.rb
|
102
|
+
homepage: ''
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
- examples
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: 2.1.2
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
requirements: []
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.4.3
|
124
|
+
signing_key:
|
125
|
+
specification_version: 4
|
126
|
+
summary: For using BeagleBone Black in Object-Oriented way through Ruby.
|
127
|
+
test_files:
|
128
|
+
- spec/examples/current_measurement/current_input_spec.rb
|
129
|
+
- spec/examples/voltage_measurement/voltage_input_spec.rb
|
130
|
+
- spec/object_oriented_beaglebone_black/analog_input_spec.rb
|
131
|
+
- spec/object_oriented_beaglebone_black/gpio_spec.rb
|
132
|
+
- spec/object_oriented_beaglebone_black/led_spec.rb
|
133
|
+
- spec/object_oriented_beaglebone_black/pin_mappings_spec.rb
|
134
|
+
- spec/object_oriented_beaglebone_black/pwm_spec.rb
|
135
|
+
- spec/spec_helper.rb
|
136
|
+
- spec/support/analog_input_file_behavoir_helper.rb
|
137
|
+
- spec/support/gpio_file_behavior_helper.rb
|
138
|
+
- spec/support/pwm_file_behavior_helper.rb
|