33
44from machine import I2C
55from lis2mdl .const import *
6- import time
6+ from time import sleep_ms
77import math
88
99
@@ -24,7 +24,7 @@ def __init__(
2424 odr_hz = 10 ,
2525 temp_comp = True ,
2626 low_power = False ,
27- drdy_pin = False ,
27+ drdy_enable = False ,
2828 ):
2929 # Initialize the LIS2MDL sensor with the given I2C interface and settings.
3030 self .i2c = i2c
@@ -35,7 +35,7 @@ def __init__(
3535 # Perform a soft reset to ensure the sensor starts in a known state.
3636 self .setReg (0x20 , LIS2MDL_CFG_REG_A ) # SOFT_RST=1 (not 0x10)
3737 try :
38- time . sleep_ms (10 ) # Small delay for reset to complete
38+ sleep_ms (10 ) # Small delay for reset to complete
3939 except :
4040 pass
4141
@@ -50,7 +50,7 @@ def __init__(
5050 self .setReg (0x00 , LIS2MDL_CFG_REG_B ) # Default: LPF and offset cancellation off
5151
5252 # Enable block data update and optionally configure the DRDY pin.
53- cfg_c = 0x10 | (0x01 if drdy_pin else 0x00 )
53+ cfg_c = 0x10 | (0x01 if drdy_enable else 0x00 )
5454 self .setReg (cfg_c , LIS2MDL_CFG_REG_C )
5555
5656 ##
@@ -311,7 +311,7 @@ def calibrate_minmax_2d(self, samples=300, delay_ms=20):
311311 xmax = max (xmax , x )
312312 ymin = min (ymin , y )
313313 ymax = max (ymax , y )
314- time . sleep_ms (delay_ms )
314+ sleep_ms (delay_ms )
315315
316316 self .x_off = (xmax + xmin ) / 2.0
317317 self .y_off = (ymax + ymin ) / 2.0
@@ -338,7 +338,7 @@ def calibrate_minmax_3d(self, samples=600, delay_ms=20):
338338 ymax = max (ymax , y )
339339 zmin = min (zmin , z )
340340 zmax = max (zmax , z )
341- time . sleep_ms (delay_ms )
341+ sleep_ms (delay_ms )
342342
343343 self .x_off = (xmax + xmin ) / 2.0
344344 self .y_off = (ymax + ymin ) / 2.0
@@ -373,7 +373,7 @@ def calibrate_quality(self, samples_check=200, delay_ms=10):
373373 xs .append (xc )
374374 ys .append (yc )
375375 zs .append (zc )
376- time . sleep_ms (delay_ms )
376+ sleep_ms (delay_ms )
377377
378378 # Means (residual center)
379379 mx = sum (xs ) / len (xs )
@@ -555,7 +555,7 @@ def soft_reset(self, wait_ms: int = 10):
555555 r |= 1 << 5 # SOFT_RST
556556 self .setReg (r , LIS2MDL_CFG_REG_A )
557557 try :
558- time . sleep_ms (wait_ms )
558+ sleep_ms (wait_ms )
559559 except :
560560 pass
561561
@@ -568,7 +568,7 @@ def reboot(self, wait_ms: int = 10):
568568 r |= 1 << 6 # REBOOT
569569 self .setReg (r , LIS2MDL_CFG_REG_A )
570570 try :
571- time . sleep_ms (wait_ms )
571+ sleep_ms (wait_ms )
572572 except :
573573 pass
574574
0 commit comments