lib/mono_matrix.rb in mono_matrix-0.0.3 vs lib/mono_matrix.rb in mono_matrix-1.0.0
- old
+ new
@@ -1,54 +1,55 @@
-
require 'serialport'
-class MonoMatrix
- def initialize(tty)
- # Instance variables
- @tty = tty
- end
+module MonoMatrix
+ class Switcher
- def switch(channel, input)
+ def initialize(tty)
+ # Instance variables
+ @tty = tty
- # 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";
- end_bytes = ["\xD5","\x7B"]
- if channel == "A"
- case input
- when 1
- bytes = ["\x00", "\xFF"] + end_bytes
- when 2
- bytes = ["\x01", "\xFE"] + end_bytes
- when 3
- bytes = ["\x02", "\xFD"] + end_bytes
- when 4
- bytes = ["\x03", "\xFC"] + end_bytes
- end
+ @end_bytes = ["\xD5","\x7B"]
+ @channels = {
+ "A" => [
+ ["\x00", "\xFF"],
+ ["\x01", "\xFE"],
+ ["\x02", "\xFD"],
+ ["\x03", "\xFC"]
+ ],
- elsif channel == "B"
- case input
- when 1
- bytes = ["\x04", "\xFB"] + end_bytes
- when 2
- bytes = ["\x05", "\xFA"] + end_bytes
- when 3
- bytes = ["\x06", "\xF9"] + end_bytes
- when 4
- bytes = ["\x07", "\xF8"] + end_bytes
+ "B" => [
+ ["\x04", "\xFB"],
+ ["\x05", "\xFA"],
+ ["\x06", "\xF9"],
+ ["\x07", "\xF8"]
+ ]
+ }
+ end
+
+ 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
- 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
+end
\ No newline at end of file