Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #76 from TeamWildCards/patch-2
Browse files Browse the repository at this point in the history
Minor updates to pymata_core.py
  • Loading branch information
MrYsLab authored Aug 21, 2018
2 parents 45a597f + ee180fb commit d156d26
Showing 1 changed file with 13 additions and 26 deletions.
39 changes: 13 additions & 26 deletions pymata_aio/pymata_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,14 @@ def start(self):
self.the_task = self.loop.create_task(self._command_dispatcher())

# get arduino firmware version and print it
asyncio.ensure_future(self.get_firmware_version())

firmware_version = self.loop.run_until_complete(self.get_firmware_version())
if self.log_output:
log_string = "\nArduino Firmware ID: " + firmware_version
logging.exception(log_string)
else:
print("\nArduino Firmware ID: " + firmware_version)

# get an analog pin map
asyncio.ensure_future(self.get_analog_map())

# try to get an analog report. if it comes back as none - shutdown
# try to get an analog pin map. if it comes back as none - shutdown
report = self.loop.run_until_complete(self.get_analog_map())
if not report:
if self.log_output:
Expand Down Expand Up @@ -443,10 +438,7 @@ async def start_aio(self):
else:
print("\nArduino Firmware ID: " + firmware_version)

# get an analog pin map
asyncio.ensure_future(self.get_analog_map())

# try to get an analog report. if it comes back as none - shutdown
# try to get an analog pin map. if it comes back as none - shutdown
# report = await self.get_analog_map()
report = await self.get_analog_map()
if not report:
Expand Down Expand Up @@ -787,12 +779,6 @@ async def get_firmware_version(self):
if elapsed_time - current_time > 2:
return None
await asyncio.sleep(self.sleep_tune)
reply = ''
for x in self.query_reply_data.get(PrivateConstants.REPORT_FIRMWARE):
reply_data = ord(x)
if reply_data:
reply += chr(reply_data)
self.query_reply_data[PrivateConstants.REPORT_FIRMWARE] = reply
return self.query_reply_data.get(PrivateConstants.REPORT_FIRMWARE)

async def get_protocol_version(self):
Expand Down Expand Up @@ -875,15 +861,15 @@ async def i2c_read_request(self, address, register, number_of_bytes,
device it will be sent to the callback method.
Some devices require that transmission be restarted
(e.g. MMA8452Q accelerometer).
Use Constants.I2C_READ | Constants.I2C_RESTART_TX for those cases.
Use Constants.I2C_READ | Constants.I2C_END_TX_MASK for those cases.
:param address: i2c device address
:param register: register number (can be set to zero)
:param number_of_bytes: number of bytes expected to be returned
:param read_type: I2C_READ or I2C_READ_CONTINUOUSLY. I2C_RESTART_TX
:param read_type: I2C_READ or I2C_READ_CONTINUOUSLY. I2C_END_TX_MASK
may be OR'ed when required
:param cb: Optional callback function to report i2c data as a
Expand Down Expand Up @@ -1213,7 +1199,7 @@ async def sonar_config(self, trigger_pin, echo_pin, cb=None,
:param cb: optional callback function to report sonar data changes
:param ping_interval: Minimum interval between pings. Lowest number
to use is 33 ms.Max is 127
to use is 33 ms. Max is 127ms.
:param max_distance: Maximum distance in cm. Max is 200.
Expand Down Expand Up @@ -1408,8 +1394,8 @@ async def _command_dispatcher(self):
# handle the digital message
elif 0x90 <= next_command_byte <= 0x9F:
command = []
pin = next_command_byte & 0x0f
command.append(pin)
port = next_command_byte & 0x0f
command.append(port)
command = await self._wait_for_data(command, 2)
await self._digital_message(command)
# handle all other messages by looking them up in the
Expand Down Expand Up @@ -1698,11 +1684,12 @@ async def _report_firmware(self, sysex_data):
# number up until, but not including the END_SYSEX byte

name = sysex_data[3:-1]

# convert the identifier to printable text and add each character
# to the version string
for e in name:
version_string += chr(e)
firmware_name_iterator = iter(name)

# convert each element from two 7-bit bytes into characters, then add each
# character to the version string
for e in firmware_name_iterator:
version_string += chr(e + (next(firmware_name_iterator) << 7))

# store the value
self.query_reply_data[PrivateConstants.REPORT_FIRMWARE] = version_string
Expand Down

0 comments on commit d156d26

Please sign in to comment.