Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/lis2mdl/lis2mdl/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def heading_from_vectors(self, x, y, z, calibrated=True):
x = (x - self.x_off) / (self.x_scale or 1.0)
y = (y - self.y_off) / (self.y_scale or 1.0)
# IMPORTANT: atan2(Y, X)
ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right)
ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right)
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

heading_from_vectors() computes ang using math.atan2(x, y), but both the preceding comment and the tilt-compensated path use the atan2(y, x) convention (see heading_with_tilt_compensation() using math.atan2(yh, xh)). With a flat accelerometer input (roll/pitch = 0), this makes heading_flat_only() inconsistent with the tilt-compensated heading. Align the argument order (or adjust the comments) so both methods produce the same heading when the board is flat.

Suggested change
ang = math.degrees(math.atan2(x, y)) # atan2(Y, X) for compass heading (Y is forward, X is right)
ang = math.degrees(math.atan2(y, x)) # atan2(Y, X) for compass heading (Y is forward, X is right)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR — this is a pre-existing bug in the LIS2MDL compass heading code, not related to the ruff preview rules change. Created a note to investigate separately.

ang = self._apply_heading_offsets(ang)
return self._filter_heading(ang)

Expand Down
4 changes: 2 additions & 2 deletions lib/wsen-pads/examples/altitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from machine import I2C
from wsen_pads import WSEN_PADS

SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation
EXPONENT = 0.1903 # standard atmosphere exponent for altitude calculation
SEA_LEVEL_PRESSURE = 1013.25 # depends on your location, you can adjust it for better altitude estimation
EXPONENT = 0.1903 # standard atmosphere exponent for altitude calculation

i2c = I2C(1)

Expand Down
2 changes: 1 addition & 1 deletion lib/wsen-pads/examples/pressure_trend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

pressure_history = []
MAX_VALUES = 10
THRESHOLD = 0.5 # sensitivity (hPa)
THRESHOLD = 0.5 # sensitivity (hPa)

def get_trend(values):
if len(values) < 2:
Expand Down
4 changes: 2 additions & 2 deletions lib/wsen-pads/examples/threshold_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from wsen_pads import WSEN_PADS
from wsen_pads.const import ODR_10_HZ

PRESSURE_ALERT_HPA = 1000 # Alert threshold
READ_INTERVAL_S = 1 # Time between printed readings
PRESSURE_ALERT_HPA = 1000 # Alert threshold
READ_INTERVAL_S = 1 # Time between printed readings

i2c = I2C(1)
sensor = WSEN_PADS(i2c)
Expand Down
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ markers = [

[tool.ruff]
line-length = 99
target-version = "py37"
target-version = "py310"

[tool.ruff.lint]
preview = true
explicit-preview-rules = true
select = [
"A", # flake8-builtins: prevent shadowing builtins
"ASYNC", # flake8-async
Expand All @@ -45,6 +47,10 @@ select = [
"C90", # McCabe cyclomatic complexity
"DTZ", # flake8-datetimez
"E", # pycodestyle
"E225", # (preview) missing whitespace around operator
"E261", # (preview) at least two spaces before inline comment
"E262", # (preview) inline comment must start with '# '
"E265", # (preview) block comment must start with '# '
"EXE", # flake8-executable
"F", # Pyflakes
"G", # flake8-logging-format
Expand All @@ -70,6 +76,7 @@ select = [
"YTT", # flake8-2020
]
ignore = [
"B905", # zip() strict= not available in micropython
"E501", # line length, recommended to disable
"E741", # 'l' is currently widely used
"ISC001", # conflicts with formatter
Expand Down Expand Up @@ -108,6 +115,7 @@ max-statements = 65
"**/examples/*.py" = ["T20", "N806"]
"lib/mcp23009e/examples/i2c_scan.py" = ["PERF203"]
"tests/**/*.py" = ["T20", "PLR0911", "PLR0912", "PLR0915"]
"lib/lis2mdl/**/*.py" = ["RUF001", "RUF002", "RUF003"] # µ (microtesla) is intentional

[tool.ruff.format]
quote-style = "double"
Expand Down
Loading