From 64a0fa907e72cde653ea489350180fc72d9365bd Mon Sep 17 00:00:00 2001 From: "MisterYsLab@gmail.com" Date: Thu, 18 Feb 2016 08:41:24 -0500 Subject: [PATCH] Assure 7 bit bytes are sent to Firmata --- documentation/changelog.md | 12 ++++++++++ pymata_aio/private_constants.py | 2 +- pymata_aio/pymata_core.py | 41 +++++++++++++++++---------------- setup.py | 2 +- 4 files changed, 35 insertions(+), 22 deletions(-) diff --git a/documentation/changelog.md b/documentation/changelog.md index e889b41..373de34 100644 --- a/documentation/changelog.md +++ b/documentation/changelog.md @@ -5,6 +5,18 @@ There were still issues with Sonar and this release addresses those. +## Release 2.101 + +18 February 2016 + +* Assures all data sent to Firmata consists of 7 bit bytes + +## Release 2.10 + +11 February 2016 + +* Additional Fixes [issue #35](https://github.com/MrYsLab/pymata-aio/issues/35) and [issue #36](https://github.com/MrYsLab/pymata-aio/issues/36) + ## Release 2.9 9 February 2016 diff --git a/pymata_aio/private_constants.py b/pymata_aio/private_constants.py index cd0b101..562dcd8 100644 --- a/pymata_aio/private_constants.py +++ b/pymata_aio/private_constants.py @@ -70,7 +70,7 @@ class PrivateConstants: SYSEX_REALTIME = 0x7F # MIDI Reserved for realtime messages # reserved for PyMata - PYMATA_VERSION = "2.10" + PYMATA_VERSION = "2.11" # each byte represents a digital port # and its value contains the current port settings diff --git a/pymata_aio/pymata_core.py b/pymata_aio/pymata_core.py index afc5d94..c9005e8 100644 --- a/pymata_aio/pymata_core.py +++ b/pymata_aio/pymata_core.py @@ -464,7 +464,7 @@ async def analog_write(self, pin, value): """ if PrivateConstants.ANALOG_MESSAGE + pin < 0xf0: command = [PrivateConstants.ANALOG_MESSAGE + pin, value & 0x7f, - value >> 7] + (value >> 7) & 0x7f] await self._send_command(command) else: await self.extended_analog(pin, value) @@ -501,7 +501,7 @@ async def digital_write(self, pin, value): # Assemble the command command = (calculated_command, PrivateConstants.DIGITAL_OUTPUT_PORT_PINS[port] & 0x7f, - PrivateConstants.DIGITAL_OUTPUT_PORT_PINS[port] >> 7) + (PrivateConstants.DIGITAL_OUTPUT_PORT_PINS[port] >> 7) & 0x7f) await self._send_command(command) @@ -606,7 +606,7 @@ async def extended_analog(self, pin, data): :param data: 0 - 0xfffff :returns: No return value """ - analog_data = [pin, data & 0x7f, (data >> 7) & 0x7f, data >> 14] + analog_data = [pin, data & 0x7f, (data >> 7) & 0x7f, (data >> 14) & 0x7f] await self._send_sysex(PrivateConstants.EXTENDED_ANALOG, analog_data) async def get_analog_latch_data(self, pin): @@ -752,7 +752,7 @@ async def i2c_config(self, read_delay_time=0): default is 0 :returns: No Return Value """ - data = [read_delay_time & 0x7f, read_delay_time >> 7] + data = [read_delay_time & 0x7f, (read_delay_time >> 7) & 0x7f] await self._send_sysex(PrivateConstants.I2C_CONFIG, data) async def i2c_read_data(self, address): @@ -796,8 +796,8 @@ async def i2c_read_request(self, address, register, number_of_bytes, # self.i2c_map[address] = [None, cb] self.i2c_map[address] = {'value': None, 'callback': cb, 'callback_type': cb_type} - data = [address, read_type, register & 0x7f, register >> 7, - number_of_bytes & 0x7f, number_of_bytes >> 7] + data = [address, read_type, register & 0x7f, (register >> 7) & 0x7f, + number_of_bytes & 0x7f, (number_of_bytes >> 7) & 0x7f] await self._send_sysex(PrivateConstants.I2C_REQUEST, data) async def i2c_write_request(self, address, args): @@ -813,7 +813,7 @@ async def i2c_write_request(self, address, args): for item in args: item_lsb = item & 0x7f data.append(item_lsb) - item_msb = item >> 7 + item_msb = (item >> 7) & 0x7f data.append(item_msb) await self._send_sysex(PrivateConstants.I2C_REQUEST, data) @@ -838,7 +838,7 @@ async def keep_alive(self, period=1, margin=.3): if margin > .9: margin = .9 self.margin = margin - self.keep_alive_interval = [period & 0x7f, period >> 7] + self.keep_alive_interval = [period & 0x7f, (period >> 7) & 0x7f] await self._send_sysex(PrivateConstants.SAMPLING_INTERVAL, self.keep_alive_interval) while True: @@ -868,12 +868,12 @@ async def play_tone(self, pin, tone_command, frequency, duration): if tone_command == Constants.TONE_TONE: # duration is specified if duration: - data = [tone_command, pin, frequency & 0x7f, frequency >> 7, - duration & 0x7f, duration >> 7] + data = [tone_command, pin, frequency & 0x7f, (frequency >> 7) & 0x7f, + duration & 0x7f, (duration >> 7) & 0x7f] else: data = [tone_command, pin, - frequency & 0x7f, frequency >> 7, 0, 0] + frequency & 0x7f, (frequency >> 7) & 0x7f, 0, 0] # turn off tone else: data = [tone_command, pin] @@ -901,8 +901,8 @@ async def servo_config(self, pin, min_pulse=544, max_pulse=2400): :param max_pulse: Max pulse width in ms. :returns: No return value """ - command = [pin, min_pulse & 0x7f, min_pulse >> 7, max_pulse & 0x7f, - max_pulse >> 7] + command = [pin, min_pulse & 0x7f, (min_pulse >> 7) & 0x7f, max_pulse & 0x7f, + (max_pulse >> 7) & 0x7f] await self._send_sysex(PrivateConstants.SERVO_CONFIG, command) @@ -1019,7 +1019,7 @@ async def set_sampling_interval(self, interval): in milliseconds :returns: No return value. """ - data = [interval & 0x7f, interval >> 7] + data = [interval & 0x7f, (interval >> 7) & 0x7f] await self._send_sysex(PrivateConstants.SAMPLING_INTERVAL, data) async def shutdown(self): @@ -1092,7 +1092,7 @@ async def sonar_config(self, trigger_pin, echo_pin, cb=None, if max_distance > 200: max_distance = 200 max_distance_lsb = max_distance & 0x7f - max_distance_msb = max_distance >> 7 + max_distance_msb = (max_distance >> 7) & 0x7f data = [trigger_pin, echo_pin, ping_interval, max_distance_lsb, max_distance_msb] await self.set_pin_mode(trigger_pin, Constants.SONAR, Constants.INPUT) @@ -1136,7 +1136,7 @@ async def stepper_config(self, steps_per_revolution, stepper_pins): :returns: No return value. """ data = [PrivateConstants.STEPPER_CONFIGURE, steps_per_revolution & 0x7f, - steps_per_revolution >> 7] + (steps_per_revolution >> 7) & 0x7f] for pin in range(len(stepper_pins)): data.append(stepper_pins[pin]) await self._send_sysex(PrivateConstants.STEPPER_DATA, data) @@ -1157,8 +1157,8 @@ async def stepper_step(self, motor_speed, number_of_steps): direction = 0 abs_number_of_steps = abs(number_of_steps) data = [PrivateConstants.STEPPER_STEP, motor_speed & 0x7f, - (motor_speed >> 7) & 0x7f, motor_speed >> 14, - abs_number_of_steps & 0x7f, abs_number_of_steps >> 7, direction] + (motor_speed >> 7) & 0x7f, (motor_speed >> 14) & 0x7f, + abs_number_of_steps & 0x7f, (abs_number_of_steps >> 7) & 0x7f, direction] await self._send_sysex(PrivateConstants.STEPPER_DATA, data) async def pixy_init(self, max_blocks=5, cb=None, cb_type=None): @@ -1199,7 +1199,7 @@ async def pixy_set_brightness(self, brightness): :param brightness: range between 0 and 255 with 255 being the brightest setting :returns: No return value. """ - data = [PrivateConstants.PIXY_SET_BRIGHTNESS, brightness & 0x7f, brightness >> 7] + data = [PrivateConstants.PIXY_SET_BRIGHTNESS, brightness & 0x7f, (brightness >> 7) & 0x7f] await self._send_sysex(PrivateConstants.PIXY_CONFIG, data) async def pixy_set_led(self, r, g, b): @@ -1212,7 +1212,8 @@ async def pixy_set_led(self, r, g, b): :param b: blue range between 0 and 255 :returns: No return value. """ - data = [PrivateConstants.PIXY_SET_LED, r & 0x7f, r >> 7, g & 0x7f, g >> 7, b & 0x7f, b >> 7] + data = [PrivateConstants.PIXY_SET_LED, r & 0x7f, (r >> 7) & 0x7f, g & 0x7f, (g >> 7) & 0x7f, b & 0x7f, + (b >> 7) & 0x7f] await self._send_sysex(PrivateConstants.PIXY_CONFIG, data) async def _command_dispatcher(self): diff --git a/setup.py b/setup.py index 4aec614..c14b852 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='pymata-aio', - version='2.10', + version='2.11', packages=['pymata_aio'], install_requires=['pyserial>=2.7', 'autobahn[asyncio]>=0.10.4'], url='https://github.com/MrYsLab/pymata-aio/wiki',