class PiLightsControl::Command
Attributes
repeat_count[RW]
Public Class Methods
new(pin, options = {})
click to toggle source
# File lib/pi-lights-control/command.rb, line 5 def initialize(pin, options = {}) RPi::GPIO.set_numbering(options[:numbering] || :board) @repeat_count = 6 @pin = pin end
Public Instance Methods
power_off()
click to toggle source
# File lib/pi-lights-control/command.rb, line 11 def power_off transmit_command(PiLightsControl::COMMAND_TABLE[:power_off]) end
power_on()
click to toggle source
# File lib/pi-lights-control/command.rb, line 15 def power_on transmit_command(PiLightsControl::COMMAND_TABLE[:power_on]) end
program(name)
click to toggle source
# File lib/pi-lights-control/command.rb, line 19 def program(name) program_name = "program_#{name}" transmit_command(PiLightsControl::COMMAND_TABLE[program_name.to_sym]) end
sync_lights()
click to toggle source
# File lib/pi-lights-control/command.rb, line 24 def sync_lights transmit_command(PiLightsControl::COMMAND_TABLE[:sync_lights]) end
Private Instance Methods
transmit_command(command)
click to toggle source
# File lib/pi-lights-control/command.rb, line 30 def transmit_command(command) RPi::GPIO.setup @pin, as: :output @repeat_count.times do command.each do |code| high_length = PiLightsControl::CODE_TABLE[code][0] low_length = PiLightsControl::CODE_TABLE[code][1] RPi::GPIO.set_high @pin sleep(high_length * PiLightsControl::TIME_DELAY / 1E6) RPi::GPIO.set_low @pin sleep(low_length * PiLightsControl::TIME_DELAY / 1E6) end end RPi::GPIO.clean_up @pin end