Skip to content

Commit

Permalink
black and pylint cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CTho9305 committed Jan 4, 2025
1 parent c4930c8 commit 7fcada8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions adafruit_mpu6050.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class Rate: # pylint: disable=too-few-public-methods
CYCLE_40_HZ = 3 # 40 Hz


class MPU6050:
class MPU6050: # pylint: disable=too-many-instance-attributes
"""Driver for the MPU6050 6-DoF accelerometer and gyroscope.
:param ~busio.I2C i2c_bus: The I2C bus the device is connected to
Expand Down Expand Up @@ -218,7 +218,7 @@ def __init__(self, i2c_bus: I2C, address: int = _MPU6050_DEFAULT_ADDRESS) -> Non
self._filter_bandwidth = Bandwidth.BAND_260_HZ
self._gyro_range = GyroRange.RANGE_500_DPS
self._accel_range = Range.RANGE_2_G
self._accel_scale = 1.0/[16384,8192,4096,2048][self._accel_range]
self._accel_scale = 1.0 / [16384,8192,4096,2048][self._accel_range]
sleep(0.100)
self.clock_source = (
ClockSource.CLKSEL_INTERNAL_X
Expand Down Expand Up @@ -277,10 +277,10 @@ def temperature(self) -> float:
def acceleration(self) -> Tuple[float, float, float]:
"""Acceleration X, Y, and Z axis data in :math:`m/s^2`"""
raw_data = self._raw_accel_data
return self.scale_accel([raw_data[0][0],raw_data[1][0],raw_data[2][0]])
return self.scale_accel([raw_data[0][0], raw_data[1][0], raw_data[2][0]])

def scale_accel(self, raw_data) -> Tuple[float, float, float]:
# setup range dependent scaling
"""Scale raw X, Y, and Z axis data to :math:`m/s^2`"""
accel_x = (raw_data[0] * self._accel_scale) * STANDARD_GRAVITY
accel_y = (raw_data[1] * self._accel_scale) * STANDARD_GRAVITY
accel_z = (raw_data[2] * self._accel_scale) * STANDARD_GRAVITY
Expand All @@ -293,6 +293,7 @@ def gyro(self) -> Tuple[float, float, float]:
return self.scale_gyro((raw_data[0][0], raw_data[1][0], raw_data[2][0]))

def scale_gyro(self, raw_data) -> Tuple[float, float, float]:
"""Scale raw gyro data to :math:`º/s`"""
raw_x = raw_data[0]
raw_y = raw_data[1]
raw_z = raw_data[2]
Expand Down Expand Up @@ -348,7 +349,7 @@ def accelerometer_range(self, value: int) -> None:
if (value < 0) or (value > 3):
raise ValueError("accelerometer_range must be a Range")
self._accel_range = value
self._accel_scale = 1.0/[16384,8192,4096,2048][value]
self._accel_scale = 1.0 / [16384,8192,4096,2048][value]
sleep(0.01)

@property
Expand Down Expand Up @@ -392,8 +393,8 @@ def clock_source(self, value: int) -> None:
def read_whole_fifo(self):
"""Return raw FIFO bytes"""
# This code must be fast to ensure samples are contiguous
c = self.fifo_count
buf = bytearray(c)
count = self.fifo_count
buf = bytearray(count)
buf[0] = _MPU6050_FIFO_R_W
with self.i2c_device:
self.i2c_device.write_then_readinto(buf, buf, out_end=1, in_start=0)
Expand Down

0 comments on commit 7fcada8

Please sign in to comment.