Class: MonoMatrix::Switcher
- Inherits:
-
Object
- Object
- MonoMatrix::Switcher
- Defined in:
- lib/mono_matrix.rb
Instance Method Summary collapse
-
#initialize(tty) ⇒ Switcher
constructor
A new instance of Switcher.
- #switch(channel, input) ⇒ Object
Constructor Details
#initialize(tty) ⇒ Switcher
Returns a new instance of Switcher.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mono_matrix.rb', line 7 def initialize(tty) # Instance variables @tty = tty @end_bytes = ["\xD5","\x7B"] @channels = { "A" => [ ["\x00", "\xFF"], ["\x01", "\xFE"], ["\x02", "\xFD"], ["\x03", "\xFC"] ], "B" => [ ["\x04", "\xFB"], ["\x05", "\xFA"], ["\x06", "\xF9"], ["\x07", "\xF8"] ] } end |
Instance Method Details
#switch(channel, input) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mono_matrix.rb', line 30 def switch(channel, input) channel = channel.upcase input = input.to_i - 1 # A = 1 "\x00\xFF\xD5\x7B"; # A = 2 "\x01\xFE\xD5\x7B"; # A = 3 "\x02\xFD\xD5\x7B"; # A = 4 "\x03\xFC\xD5\x7B"; # B = 1 "\x04\xFB\xD5\x7B"; # B = 2 "\x05\xFA\xD5\x7B"; # B = 3 "\x06\xF9\xD5\x7B"; # B = 4 "\x07\xF8\xD5\x7B"; bytes = @channels[channel][input] + @end_bytes if @channels[channel] && @channels[channel][input] if bytes puts channel +" to "+ input.to_s serialConnection = SerialPort.new @tty, 9600 bytes.each {|byte| serialConnection.write byte} bytes.each {|byte| serialConnection.write byte} serialConnection.close end end |