Skip to content

Commit

Permalink
Merge pull request #4 from BrianPugh/upgrade-belay
Browse files Browse the repository at this point in the history
Upgrade belay
  • Loading branch information
BrianPugh authored Feb 11, 2023
2 parents fcb83b9 + 478befb commit 1a9fd07
Show file tree
Hide file tree
Showing 26 changed files with 1,366 additions and 659 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ exclude =
.env
venv
.venv
magnetometer/dependencies
magnetometer/sensors

extend-immutable-calls =
Argument
Expand Down
23 changes: 12 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
exclude: ^(magnetometer/dependencies/)
repos:
- repo: https://github.com/codespell-project/codespell
rev: v2.1.0
rev: v2.2.2
hooks:
- id: codespell

Expand All @@ -12,7 +13,7 @@ repos:
args: ["-c", "pyproject.toml"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
name: isort
Expand All @@ -23,7 +24,7 @@ repos:
args: ["--profile=black"]

- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.1.0
hooks:
- id: black
args:
Expand All @@ -33,17 +34,17 @@ repos:
types: [python]

- repo: https://github.com/asottile/blacken-docs
rev: v1.12.1
rev: 1.13.0
hooks:
- id: blacken-docs

- repo: https://github.com/kynan/nbstripout
rev: 0.5.0
rev: 0.6.1
hooks:
- id: nbstripout

- repo: https://github.com/nbQA-dev/nbQA
rev: 1.3.1
rev: 1.6.1
hooks:
- id: nbqa-isort
args: ["--profile=black"]
Expand All @@ -57,7 +58,7 @@ repos:
- id: nbqa-flake8

- repo: https://github.com/pre-commit/pygrep-hooks
rev: v1.9.0
rev: v1.10.0
hooks:
- id: python-check-mock-methods
- id: python-no-log-warn
Expand All @@ -68,7 +69,7 @@ repos:
types: [text]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.2.0
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -94,15 +95,15 @@ repos:
exclude: \.(html|svg)$

- repo: https://github.com/asottile/setup-cfg-fmt
rev: v1.20.1
rev: v2.2.0
hooks:
- id: setup-cfg-fmt

- repo: https://github.com/PyCQA/flake8
rev: 4.0.1
rev: 6.0.0
hooks:
- id: flake8
exclude: ^(magnetometer/board/)
exclude: ^(magnetometer/sensors/)
additional_dependencies:
- flake8-2020
- flake8-bugbear
Expand Down
1 change: 0 additions & 1 deletion magnetometer/asciichartpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def scaled(y):
result[rows - scaled(d0)][offset - 1] = symbols[0]

for i in range(0, len(series)):

color = colors[i % len(colors)]

# plot the line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
import time

try:
from types import TracebackType
from typing import Optional, Type
from types import TracebackType
from circuitpython_typing import ReadableBuffer, WriteableBuffer

# Used only for type annotations.
from busio import I2C
from circuitpython_typing import ReadableBuffer, WriteableBuffer
except ImportError:
pass

Expand Down Expand Up @@ -109,7 +109,7 @@ def write_then_readinto(
out_start: int = 0,
out_end: Optional[int] = None,
in_start: int = 0,
in_end: Optional[int] = None,
in_end: Optional[int] = None
) -> None:
"""
Write the bytes from ``out_buffer`` to the device, then immediately
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import time

try:
from types import TracebackType
from typing import Optional, Type
from types import TracebackType

# Used only for type annotations.
from busio import SPI
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(
baudrate: int = 100000,
polarity: int = 0,
phase: int = 0,
extra_clocks: int = 0,
extra_clocks: int = 0
) -> None:
self.spi = spi
self.baudrate = baudrate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@
"""

from time import sleep

from micropython import const
from adafruit_bus_device.i2c_device import I2CDevice
from adafruit_register.i2c_struct import UnaryStruct, ROUnaryStruct
from adafruit_register.i2c_bit import RWBit
from adafruit_register.i2c_bits import RWBits
from adafruit_register.i2c_struct import ROUnaryStruct, UnaryStruct
from micropython import const

try:
from typing import Tuple
from typing_extensions import Literal
from busio import I2C
except ImportError:
pass

__version__ = "0.0.0+auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LIS2MDL.git"
Expand Down Expand Up @@ -158,15 +164,15 @@ class LIS2MDL: # pylint: disable=too-many-instance-attributes
_y_offset = UnaryStruct(OFFSET_Y_REG_L, "<h")
_z_offset = UnaryStruct(OFFSET_Z_REG_L, "<h")

def __init__(self, i2c):
def __init__(self, i2c: I2C) -> None:
self.i2c_device = I2CDevice(i2c, _ADDRESS_MAG)

if self._device_id != 0x40:
raise AttributeError("Cannot find an LIS2MDL")

self.reset()

def reset(self):
def reset(self) -> None:
"""Reset the sensor to the default state set by the library"""
self._soft_reset = True
sleep(0.100)
Expand All @@ -183,7 +189,7 @@ def reset(self):
sleep(0.030) # sleep 20ms to allow measurements to stabilize

@property
def magnetic(self):
def magnetic(self) -> Tuple[float, float, float]:
"""The processed magnetometer sensor values.
A 3-tuple of X, Y, Z axis values in microteslas that are signed floats.
"""
Expand All @@ -195,12 +201,12 @@ def magnetic(self):
)

@property
def data_rate(self):
def data_rate(self) -> Literal[0x00, 0x01, 0x02, 0x03]:
"""The magnetometer update rate."""
return self._data_rate

@data_rate.setter
def data_rate(self, value):
def data_rate(self, value: Literal[0x00, 0x01, 0x02, 0x03]) -> None:
if not value in (
DataRate.Rate_10_HZ,
DataRate.Rate_20_HZ,
Expand All @@ -211,31 +217,31 @@ def data_rate(self, value):
self._data_rate = value

@property
def interrupt_threshold(self):
def interrupt_threshold(self) -> float:
"""The threshold (in microteslas) for magnetometer interrupt generation. Given value is
compared against all axes in both the positive and negative direction"""
return self._interrupt_threshold * _MAG_SCALE

@interrupt_threshold.setter
def interrupt_threshold(self, value):
def interrupt_threshold(self, value: float) -> None:
if value < 0:
value = -value
self._interrupt_threshold = int(value / _MAG_SCALE)

@property
def interrupt_enabled(self):
def interrupt_enabled(self) -> bool:
"""Enable or disable the magnetometer interrupt"""
return self._int_enable

@interrupt_enabled.setter
def interrupt_enabled(self, val):
def interrupt_enabled(self, val: bool) -> None:
self._x_int_enable = val
self._y_int_enable = val
self._z_int_enable = val
self._int_enable = val

@property
def faults(self):
def faults(self) -> Tuple[bool, bool, bool, bool, bool, bool, bool]:
"""A tuple representing interrupts on each axis in a positive and negative direction
``(x_hi, y_hi, z_hi, x_low, y_low, z_low, int_triggered)``"""
int_status = self._int_source
Expand All @@ -250,31 +256,31 @@ def faults(self):
return (x_hi, y_hi, z_hi, x_low, y_low, z_low, int_triggered)

@property
def x_offset(self):
def x_offset(self) -> float:
"""An offset for the X-Axis to subtract from the measured value to correct
for magnetic interference"""
return self._x_offset * _MAG_SCALE

@x_offset.setter
def x_offset(self, value):
def x_offset(self, value: float) -> None:
self._x_offset = int(value / _MAG_SCALE)

@property
def y_offset(self):
def y_offset(self) -> float:
"""An offset for the Y-Axis to subtract from the measured value to correct
for magnetic interference"""
return self._y_offset * _MAG_SCALE

@y_offset.setter
def y_offset(self, value):
def y_offset(self, value: float) -> None:
self._y_offset = int(value / _MAG_SCALE)

@property
def z_offset(self):
def z_offset(self) -> float:
"""An offset for the Z-Axis to subtract from the measured value to correct
for magnetic interference"""
return self._z_offset * _MAG_SCALE

@z_offset.setter
def z_offset(self, value):
def z_offset(self, value: float) -> None:
self._z_offset = int(value / _MAG_SCALE)
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@
* Adafruit's Register library: https://github.com/adafruit/Adafruit_CircuitPython_Register
"""
from time import sleep

from micropython import const
from adafruit_bus_device import i2c_device
from adafruit_register.i2c_bit import RWBit
from adafruit_register.i2c_bits import RWBits
from adafruit_register.i2c_struct import ROUnaryStruct, Struct
from micropython import const
from adafruit_register.i2c_bits import RWBits
from adafruit_register.i2c_bit import RWBit

try:
from typing import Iterable, Optional, Tuple, Union

from typing import Iterable, Tuple, Union, Optional
from busio import I2C
except ImportError:
pass
Expand Down Expand Up @@ -70,7 +68,7 @@ class CV:
def add_values(
cls, value_tuples: Iterable[Tuple[str, int, Union[int, str], Optional[int]]]
):
"creates CV entries"
"creates CV entires"
cls.string = {}
cls.lsb = {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@
"""

import time

from micropython import const
from adafruit_bus_device import i2c_device
from adafruit_register.i2c_bit import RWBit
from adafruit_register.i2c_struct import ROUnaryStruct, UnaryStruct
from micropython import const
from adafruit_register.i2c_bit import RWBit

try:
from typing import Tuple

from busio import I2C
except ImportError:
pass
Expand Down Expand Up @@ -178,7 +176,7 @@ def data_rate(self, value: int) -> None:

@property
def continuous_mode(self) -> bool:
"""Whether or not to put the chip in continuous mode - be sure
"""Whether or not to put the chip in continous mode - be sure
to set the data_rate as well!
"""
return self._ctrl2_cache & 0x10
Expand Down
Loading

0 comments on commit 1a9fd07

Please sign in to comment.