def run(self):
<EOL>self.command_dispatch.update({self.REPORT_VERSION: [self.report_version, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.REPORT_FIRMWARE: [self.report_firmware, <NUM_LIT:1>]})<EOL>self.command_dispatch.update({self.ANALOG_MESSAGE: [self.analog_message, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.DIGITAL_MESSAGE: [self.digital_message, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.ENCODER_DATA: [self.encoder_data, <NUM_LIT:3>]})<EOL>self.command_dispatch.update({self.SONAR_DATA: [self.sonar_data, <NUM_LIT:3>]})<EOL>self.command_dispatch.update({self.STRING_DATA: [self._string_data, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.I2C_REPLY: [self.i2c_reply, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.CAPABILITY_RESPONSE: [self.capability_response, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.PIN_STATE_RESPONSE: [self.pin_state_response, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.ANALOG_MAPPING_RESPONSE: [self.analog_mapping_response, <NUM_LIT:2>]})<EOL>self.command_dispatch.update({self.STEPPER_DATA: [self.stepper_version_response, <NUM_LIT:2>]})<EOL>while not self.is_stopped():<EOL><INDENT>if len(self.pymata.command_deque):<EOL><INDENT>data = self.pymata.command_deque.popleft()<EOL>command_data = []<EOL>if data == self.START_SYSEX:<EOL><INDENT>while len(self.pymata.command_deque) == <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>sysex_command = self.pymata.command_deque.popleft()<EOL>dispatch_entry = self.command_dispatch.get(sysex_command)<EOL>method = dispatch_entry[<NUM_LIT:0>]<EOL>end_of_sysex = False<EOL>while not end_of_sysex:<EOL><INDENT>while len(self.pymata.command_deque) == <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>data = self.pymata.command_deque.popleft()<EOL>if data != self.END_SYSEX:<EOL><INDENT>command_data.append(data)<EOL><DEDENT>else:<EOL><INDENT>end_of_sysex = True<EOL>method(command_data)<EOL><DEDENT><DEDENT>continue<EOL><DEDENT>elif <NUM_LIT> <= data <= <NUM_LIT>:<EOL><INDENT>if <NUM_LIT> <= data <= <NUM_LIT>:<EOL><INDENT>port = data & <NUM_LIT><EOL>command_data.append(port)<EOL>data = <NUM_LIT><EOL><DEDENT>elif <NUM_LIT> <= data <= <NUM_LIT>:<EOL><INDENT>pin = data & <NUM_LIT><EOL>command_data.append(pin)<EOL>data = <NUM_LIT><EOL><DEDENT>else:<EOL><INDENT>pass<EOL><DEDENT>dispatch_entry = self.command_dispatch.get(data)<EOL>method = dispatch_entry[<NUM_LIT:0>]<EOL>num_args = dispatch_entry[<NUM_LIT:1>]<EOL>for i in range(num_args):<EOL><INDENT>while len(self.pymata.command_deque) == <NUM_LIT:0>:<EOL><INDENT>pass<EOL><DEDENT>data = self.pymata.command_deque.popleft()<EOL>command_data.append(data)<EOL><DEDENT>method(command_data)<EOL>continue<EOL><DEDENT><DEDENT>else:<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL><DEDENT><DEDENT>
This method starts the thread that continuously runs to receive and interpret
messages coming from Firmata. This must be the last method in this file
It also checks the deque for messages to be sent to Firmata.