lib/firmata/board.rb in hybridgroup-firmata-0.2.0 vs lib/firmata/board.rb in hybridgroup-firmata-0.2.1

- old
+ new

@@ -142,33 +142,32 @@ # Internal: Read data from the underlying serial port. # # Returns String data read for serial port. def read - serial_port.read_nonblock(4096) + return serial_port.read_nonblock(1024) rescue EOFError rescue Errno::EAGAIN end # Internal: Process a series of bytes. # # data: The String data to process. # # Returns nothing. def process(data) - bytes = StringIO.new(String(data)).bytes - bytes.each do |byte| + bytes = StringIO.new(String(data)) + while byte = bytes.getbyte case byte when REPORT_VERSION - @major_version = bytes.next - @minor_version = bytes.next - + @major_version = bytes.getbyte + @minor_version = bytes.getbyte emit('report_version') when ANALOG_MESSAGE_RANGE - least_significant_byte = bytes.next - most_significant_byte = bytes.next + least_significant_byte = bytes.getbyte + most_significant_byte = bytes.getbyte value = least_significant_byte | (most_significant_byte << 7) pin = byte & 0x0F if analog_pin = analog_pins[pin] @@ -178,12 +177,12 @@ emit("analog-read-#{pin}", value) end when DIGITAL_MESSAGE_RANGE port = byte & 0x0F - first_bitmask = bytes.next - second_bitmask = bytes.next + first_bitmask = bytes.getbyte + second_bitmask = bytes.getbyte port_value = first_bitmask | (second_bitmask << 7) 8.times do |i| pin_number = 8 * port + i if pin = pins[pin_number] and pin.mode == INPUT @@ -195,10 +194,10 @@ end when START_SYSEX current_buffer = [byte] begin - current_buffer.push(bytes.next) + current_buffer.push(bytes.getbyte) end until current_buffer.last == END_SYSEX command = current_buffer[1] case command