emori/emori.rb

25 lines
719 B
Ruby
Raw Normal View History

2014-06-11 22:40:23 +02:00
#!/usr/bin/env ruby
require 'rubygems'
require 'serialport'
# If the main monitor is off, the Arduino is also off because it is connected to
# the USB hub inside the monitor. So, if the main monitor is off, the user can't
# control the lights any more and the LED stripes are off too.
abort unless File.exists?('/dev/ttyUSB0')
# Create the serial connection and send the given command.
2014-06-11 22:40:23 +02:00
SerialPort.open('/dev/ttyUSB0', 9600, 8, 1, SerialPort::NONE) do |s|
2014-06-23 23:38:38 +02:00
command = ARGV.join(' ')
if command == 'on' or command == 'off'
puts 'all ' + command + '...'
2014-06-23 23:39:49 +02:00
['a', 'b', 'c', 'd'].each do |port|
2014-06-23 23:38:38 +02:00
s.puts(command + ' ' + port)
end
s.puts('led ' + command)
else
s.puts(ARGV.join(' '))
end
2014-06-11 22:40:23 +02:00
end