|
32 | 32 | * Author(s): Tony DiCola
|
33 | 33 | """
|
34 | 34 | import time
|
35 |
| -import ustruct |
| 35 | +try: |
| 36 | + import ustruct as struct |
| 37 | +except ImportError: |
| 38 | + import struct |
36 | 39 |
|
37 | 40 | import adafruit_bus_device.i2c_device as i2c_device
|
38 | 41 | from micropython import const
|
@@ -127,28 +130,28 @@ def read_raw(self):
|
127 | 130 | self._device.write(self._BUFFER, end=1, stop=False)
|
128 | 131 | self._device.readinto(self._BUFFER)
|
129 | 132 | # Parse out the gyroscope data as 16-bit signed data.
|
130 |
| - raw_x = ustruct.unpack_from('>h', self._BUFFER[0:2])[0] |
131 |
| - raw_y = ustruct.unpack_from('>h', self._BUFFER[2:4])[0] |
132 |
| - raw_z = ustruct.unpack_from('>h', self._BUFFER[4:6])[0] |
| 133 | + raw_x = struct.unpack_from('>h', self._BUFFER[0:2])[0] |
| 134 | + raw_y = struct.unpack_from('>h', self._BUFFER[2:4])[0] |
| 135 | + raw_z = struct.unpack_from('>h', self._BUFFER[4:6])[0] |
133 | 136 | return (raw_x, raw_y, raw_z)
|
134 | 137 |
|
135 | 138 | # pylint is confused and incorrectly marking this function as bad return
|
136 | 139 | # types. Perhaps it doesn't understand map returns an iterable value.
|
137 | 140 | # Disable the warning.
|
138 |
| - # pylint: disable=inconsistent-return-statements |
139 | 141 | @property
|
140 | 142 | def gyroscope(self):
|
141 | 143 | """Read the gyroscope value and return its X, Y, Z axis values as a
|
142 | 144 | 3-tuple in radians/second.
|
143 | 145 | """
|
144 | 146 | raw = self.read_raw()
|
145 | 147 | # Compensate values depending on the resolution
|
| 148 | + factor = 0 |
146 | 149 | if self._gyro_range == GYRO_RANGE_250DPS:
|
147 |
| - return map(lambda x: x * _GYRO_SENSITIVITY_250DPS, raw) |
| 150 | + factor = _GYRO_SENSITIVITY_250DPS |
148 | 151 | elif self._gyro_range == GYRO_RANGE_500DPS:
|
149 |
| - return map(lambda x: x * _GYRO_SENSITIVITY_500DPS, raw) |
| 152 | + factor = _GYRO_SENSITIVITY_500DPS |
150 | 153 | elif self._gyro_range == GYRO_RANGE_1000DPS:
|
151 |
| - return map(lambda x: x * _GYRO_SENSITIVITY_1000DPS, raw) |
| 154 | + factor = _GYRO_SENSITIVITY_1000DPS |
152 | 155 | elif self._gyro_range == GYRO_RANGE_2000DPS:
|
153 |
| - return map(lambda x: x * _GYRO_SENSITIVITY_2000DPS, raw) |
154 |
| - # pylint: enable=inconsistent-return-statements |
| 156 | + factor = _GYRO_SENSITIVITY_2000DPS |
| 157 | + return [x * factor for x in raw] |
0 commit comments