Class: MonomeSerial::MonomeCommunicator
- Inherits:
-
Object
- Object
- MonomeSerial::MonomeCommunicator
- Defined in:
- lib/monome_serial/monome_communicator.rb
Instance Attribute Summary collapse
-
#communicator ⇒ Object
readonly
It’s important to note that the vanilla behaviour of these methods doesn’t match that of the OSC protocol specification as implemented by the original OS X MonomeSerial application.
-
#protocol ⇒ Object
readonly
It’s important to note that the vanilla behaviour of these methods doesn’t match that of the OSC protocol specification as implemented by the original OS X MonomeSerial application.
-
#serial ⇒ Object
readonly
It’s important to note that the vanilla behaviour of these methods doesn’t match that of the OSC protocol specification as implemented by the original OS X MonomeSerial application.
Instance Method Summary collapse
- #brightness=(intensity) ⇒ Object
- #extinguish_all ⇒ Object
- #extinguish_lamp(x, y) ⇒ Object
- #illuminate_all ⇒ Object
- #illuminate_column(col, pattern) ⇒ Object
- #illuminate_frame(quadrant, patterns) ⇒ Object
- #illuminate_lamp(x, y) ⇒ Object
- #illuminate_row(row, pattern) ⇒ Object
-
#initialize(tty_path, opts = {}) ⇒ MonomeCommunicator
constructor
A new instance of MonomeCommunicator.
- #is_real? ⇒ Boolean
- #read ⇒ Object
Constructor Details
#initialize(tty_path, opts = {}) ⇒ MonomeCommunicator
Returns a new instance of MonomeCommunicator.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/monome_serial/monome_communicator.rb', line 12 def initialize(tty_path, opts = {}) opts.reverse_merge! :brightness => 10, :ignore_intro => false, :protocol => 'series' raise ArgumentError, "Unexpected protocol type: #{opts[:protocol]}. Expected 40h or series" unless ['40h', 'series'].include?(opts[:protocol]) @protocol = opts[:protocol] #try to pull out serial for the monome represented by #this tty_path match = tty_path.match /m(\d+h?)-(\d+)/ @serial = match ? match[2] : "Serial Unknown" #get communicator (will return a DummyCommunicator if the path #isn't correct) @communicator = SerialCommunicator.get_communicator(tty_path) #include the correct binary patterns if @protocol == "40h" extend SerialCommunicator::BinaryPatterns::Fourtyh else extend SerialCommunicator::BinaryPatterns::Series end if is_real? run_intromation unless opts[:ignore_intro] self.brightness = opts[:brightness] end end |
Instance Attribute Details
#communicator ⇒ Object (readonly)
It’s important to note that the vanilla behaviour of these methods doesn’t match that of the OSC protocol specification as implemented by the original OS X MonomeSerial application. In order to match these behviours it is necessary to map the calls appropriately for the given device and rotation. This class just provides raw access to the serial protocol and serves it unadultered.
10 11 12 |
# File 'lib/monome_serial/monome_communicator.rb', line 10 def communicator @communicator end |
#protocol ⇒ Object (readonly)
It’s important to note that the vanilla behaviour of these methods doesn’t match that of the OSC protocol specification as implemented by the original OS X MonomeSerial application. In order to match these behviours it is necessary to map the calls appropriately for the given device and rotation. This class just provides raw access to the serial protocol and serves it unadultered.
10 11 12 |
# File 'lib/monome_serial/monome_communicator.rb', line 10 def protocol @protocol end |
#serial ⇒ Object (readonly)
It’s important to note that the vanilla behaviour of these methods doesn’t match that of the OSC protocol specification as implemented by the original OS X MonomeSerial application. In order to match these behviours it is necessary to map the calls appropriately for the given device and rotation. This class just provides raw access to the serial protocol and serves it unadultered.
10 11 12 |
# File 'lib/monome_serial/monome_communicator.rb', line 10 def serial @serial end |
Instance Method Details
#brightness=(intensity) ⇒ Object
84 85 86 |
# File 'lib/monome_serial/monome_communicator.rb', line 84 def brightness=(intensity) @communicator.write([brightness_pattern(intensity)]) end |
#extinguish_all ⇒ Object
74 75 76 |
# File 'lib/monome_serial/monome_communicator.rb', line 74 def extinguish_all @communicator.write([clear_pattern]) end |
#extinguish_lamp(x, y) ⇒ Object
44 45 46 |
# File 'lib/monome_serial/monome_communicator.rb', line 44 def extinguish_lamp(x,y) @communicator.write([led_off_pattern, x_y_coord_pattern(x,y)]) end |
#illuminate_all ⇒ Object
70 71 72 |
# File 'lib/monome_serial/monome_communicator.rb', line 70 def illuminate_all @communicator.write([all_pattern]) end |
#illuminate_column(col, pattern) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/monome_serial/monome_communicator.rb', line 59 def illuminate_column(col, pattern) case pattern.size when 8 then @communicator.write([col_of_8_pattern(col), pattern]) when 16 then @communicator.write([col_of_16_pattern(col), pattern[0..7], pattern[8..15]]) else raise ArgumentError, "Incorrect length of pattern sent to MonomeSerial::Monome#illumninate_col. Expected 8 or 16, got #{pattern.size}" end end |
#illuminate_frame(quadrant, patterns) ⇒ Object
78 79 80 81 82 |
# File 'lib/monome_serial/monome_communicator.rb', line 78 def illuminate_frame(quadrant, patterns) raise ArgumentError, "Incorrect number of patterns sent to MonomeSerial::Monome#illuminate_frame. Expected 8, got #{patterns.size}" unless patterns.size == 8 reversed_patterns = patterns.map{|pat| pat.reverse} @communicator.write([frame_pattern(quadrant), *reversed_patterns]) end |
#illuminate_lamp(x, y) ⇒ Object
40 41 42 |
# File 'lib/monome_serial/monome_communicator.rb', line 40 def illuminate_lamp(x,y) @communicator.write([led_on_pattern, x_y_coord_pattern(x,y)]) end |
#illuminate_row(row, pattern) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/monome_serial/monome_communicator.rb', line 48 def illuminate_row(row, pattern) case pattern.size when 8 then @communicator.write([row_of_8_pattern(row), pattern]) when 16 then @communicator.write([row_of_16_pattern(row), pattern[0..7], pattern[8..15]]) else raise ArgumentError, "Incorrect length of pattern sent to MonomeSerial::Monome#illumninate_row. Expected 8 or 16, got #{pattern.size}" end end |
#is_real? ⇒ Boolean
92 93 94 |
# File 'lib/monome_serial/monome_communicator.rb', line 92 def is_real? @communicator && @communicator.class != MonomeSerial::SerialCommunicator::DummyCommunicator end |
#read ⇒ Object
88 89 90 |
# File 'lib/monome_serial/monome_communicator.rb', line 88 def read @communicator.read end |