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

Commit

Permalink
Assure 7 bit bytes are sent to Firmata
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterYsLab@gmail.com committed Feb 18, 2016
1 parent 3883fe8 commit 64a0fa9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
12 changes: 12 additions & 0 deletions documentation/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pymata_aio/private_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 21 additions & 20 deletions pymata_aio/pymata_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand All @@ -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:
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 64a0fa9

Please sign in to comment.