lib/arduino_firmata/arduino.rb in arduino_firmata-0.2.9 vs lib/arduino_firmata/arduino.rb in arduino_firmata-0.3.0
- old
+ new
@@ -207,23 +207,21 @@
@wait_for_data -= 1
@stored_input_data[@wait_for_data] = input_data
if @execute_multi_byte_command != 0 and @wait_for_data == 0
case @execute_multi_byte_command
when DIGITAL_MESSAGE
- digital_inputs = @digital_input_data.clone
- @digital_input_data[@multi_byte_channel] = (@stored_input_data[0] << 7) + @stored_input_data[1]
- 0.upto(15).each do |i|
- current = digital_read i
- if current != ((digital_inputs[i >> 3] >> (i & 0x07)) & 0x01 > 0)
- emit :digital_read, i, current
- end
+ input_data = (@stored_input_data[0] << 7) + @stored_input_data[1]
+ diff = @digital_input_data[@multi_byte_channel] ^ input_data
+ @digital_input_data[@multi_byte_channel] = input_data
+ 0.upto(13).each do |i|
+ next unless (0x01 << i) & diff > 0
+ emit :digital_read, i, (input_data & diff > 0)
end
when ANALOG_MESSAGE
analog_value = (@stored_input_data[0] << 7) + @stored_input_data[1]
- unless @analog_input_data[@multi_byte_channel] == analog_value
- emit :analog_read, @multi_byte_channel, analog_value
- end
+ old = analog_read(@multi_byte_channel)
@analog_input_data[@multi_byte_channel] = analog_value
+ emit :analog_read, @multi_byte_channel, analog_value if old != analog_value
when REPORT_VERSION
@version = "#{@stored_input_data[1]}.#{@stored_input_data[0]}"
end
end
else