Class: PwmPin

Inherits:
Object
  • Object
show all
Defined in:
lib/pwm_pin.rb

Constant Summary collapse

SLOTS =
"/sys/devices/bone_capemgr.*"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pin) ⇒ PwmPin

Returns a new instance of PwmPin.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/pwm_pin.rb', line 5

def initialize(pin)
  @pin = pin.to_s.upcase
  File.open("#{Dir.glob(SLOTS).first}/slots", "w") { |f|
    f.write("am33xx_pwm")
  }
  File.open("#{Dir.glob(SLOTS).first}/slots", "w") { |f|
    f.write('bone_pwm_' + @pin)
  }
  @pwm_device = Dir.glob(Dir.glob("/sys/devices/ocp.*").first+"/pwm_test_" + @pin + ".*").first
  File.open(@pwm_device + "/run", "w") { |f| f.write(1) }
  pwm_write(0)
end

Instance Attribute Details

#pinObject (readonly)

Returns the value of attribute pin.



2
3
4
# File 'lib/pwm_pin.rb', line 2

def pin
  @pin
end

#pwm_deviceObject (readonly)

Returns the value of attribute pwm_device.



2
3
4
# File 'lib/pwm_pin.rb', line 2

def pwm_device
  @pwm_device
end

Instance Method Details

#pwm_write(period, duty = 0) ⇒ Object



18
19
20
21
# File 'lib/pwm_pin.rb', line 18

def pwm_write(period, duty=0)
  File.open(@pwm_device + "/period", "w") { |f| f.write(period) }
  File.open(@pwm_device + "/duty", "w") { |f| f.write(duty) }
end

#releaseObject



23
24
25
# File 'lib/pwm_pin.rb', line 23

def release
  File.open(@pwm_device + "/run", "w") { |f| f.write(0) }
end