Skip to content

Commit 7eac2d7

Browse files
authored
Merge pull request #7 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents ae42865 + d2be53e commit 7eac2d7

File tree

7 files changed

+185
-140
lines changed

7 files changed

+185
-140
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_lis3mdl.py

+73-48
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
from adafruit_register.i2c_struct import ROUnaryStruct, Struct
5050
from adafruit_register.i2c_bits import RWBits
5151
from adafruit_register.i2c_bit import RWBit
52+
5253
__version__ = "0.0.0-auto.0"
5354
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LSM6DSOX.git"
5455

@@ -64,16 +65,17 @@
6465
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LIS3MDL.git"
6566

6667
_LIS3MDL_WHO_AM_I = const(0x0F) # Register that contains the part ID
67-
_LIS3MDL_CTRL_REG1 = const(0x20) # Register address for control 1
68-
_LIS3MDL_CTRL_REG2 = const(0x21) # Register address for control 2
69-
_LIS3MDL_CTRL_REG3 = const(0x22) # Register address for control 3
70-
_LIS3MDL_CTRL_REG4 = const(0x23) # Register address for control 3
71-
_LIS3MDL_OUT_X_L = const(0x28) # Register address for X axis lower byte
72-
_LIS3MDL_INT_CFG = const(0x30) # Interrupt configuration register
73-
_LIS3MDL_INT_THS_L = const(0x32) # Low byte of the irq threshold
68+
_LIS3MDL_CTRL_REG1 = const(0x20) # Register address for control 1
69+
_LIS3MDL_CTRL_REG2 = const(0x21) # Register address for control 2
70+
_LIS3MDL_CTRL_REG3 = const(0x22) # Register address for control 3
71+
_LIS3MDL_CTRL_REG4 = const(0x23) # Register address for control 3
72+
_LIS3MDL_OUT_X_L = const(0x28) # Register address for X axis lower byte
73+
_LIS3MDL_INT_CFG = const(0x30) # Interrupt configuration register
74+
_LIS3MDL_INT_THS_L = const(0x32) # Low byte of the irq threshold
7475

7576
_GAUSS_TO_UT = 100
7677

78+
7779
class CV:
7880
"""struct helper"""
7981

@@ -94,27 +96,39 @@ def is_valid(cls, value):
9496
"Returns true if the given value is a member of the CV"
9597
return value in cls.string
9698

99+
97100
class Range(CV):
98101
"""Options for ``accelerometer_range``"""
99-
pass #pylint: disable=unnecessary-pass
100102

101-
Range.add_values((
102-
('RANGE_4_GAUSS', 0, 4, 6842),
103-
('RANGE_8_GAUSS', 1, 8, 3421),
104-
('RANGE_12_GAUSS', 2, 12, 2281),
105-
('RANGE_16_GAUSS', 3, 16, 1711)
106-
))
103+
pass # pylint: disable=unnecessary-pass
104+
105+
106+
Range.add_values(
107+
(
108+
("RANGE_4_GAUSS", 0, 4, 6842),
109+
("RANGE_8_GAUSS", 1, 8, 3421),
110+
("RANGE_12_GAUSS", 2, 12, 2281),
111+
("RANGE_16_GAUSS", 3, 16, 1711),
112+
)
113+
)
114+
107115

108116
class PerformanceMode(CV):
109117
"""Options for `performance_mode` """
110-
pass #pylint: disable=unnecessary-pass
111-
112-
PerformanceMode.add_values((
113-
('MODE_LOW_POWER', 0, 'Low Power', None),
114-
('MODE_MEDIUM', 1, 'Medium Performance', None),
115-
('MODE_HIGH', 2, 'High Performance', None),
116-
('MODE_ULTRA', 3, 'Ultra-high Performance', None)
117-
))
118+
119+
pass # pylint: disable=unnecessary-pass
120+
121+
122+
PerformanceMode.add_values(
123+
(
124+
("MODE_LOW_POWER", 0, "Low Power", None),
125+
("MODE_MEDIUM", 1, "Medium Performance", None),
126+
("MODE_HIGH", 2, "High Performance", None),
127+
("MODE_ULTRA", 3, "Ultra-high Performance", None),
128+
)
129+
)
130+
131+
118132
class Rate(CV):
119133
"""Options for `data_rate`
120134
@@ -136,23 +150,28 @@ class Rate(CV):
136150
============================= ============================================
137151
138152
"""
139-
pass #pylint: disable=unnecessary-pass
153+
154+
pass # pylint: disable=unnecessary-pass
155+
140156

141157
# The magnetometer data rate, includes FAST_ODR bit
142-
Rate.add_values((
143-
('RATE_0_625_HZ', 0b0000, 0.625, None),
144-
('RATE_1_25_HZ', 0b0010, 1.25, None),
145-
('RATE_2_5_HZ', 0b0100, 2.5, None),
146-
('RATE_5_HZ', 0b0110, 5.0, None),
147-
('RATE_10_HZ', 0b1000, 10.0, None),
148-
('RATE_20_HZ', 0b1010, 20.0, None),
149-
('RATE_40_HZ', 0b1100, 40.0, None),
150-
('RATE_80_HZ', 0b1110, 80.0, None),
151-
('RATE_155_HZ', 0b0001, 155.0, None),
152-
('RATE_300_HZ', 0b0011, 300.0, None),
153-
('RATE_560_HZ', 0b0101, 560.0, None),
154-
('RATE_1000_HZ', 0b0111, 1000.0, None),
155-
))
158+
Rate.add_values(
159+
(
160+
("RATE_0_625_HZ", 0b0000, 0.625, None),
161+
("RATE_1_25_HZ", 0b0010, 1.25, None),
162+
("RATE_2_5_HZ", 0b0100, 2.5, None),
163+
("RATE_5_HZ", 0b0110, 5.0, None),
164+
("RATE_10_HZ", 0b1000, 10.0, None),
165+
("RATE_20_HZ", 0b1010, 20.0, None),
166+
("RATE_40_HZ", 0b1100, 40.0, None),
167+
("RATE_80_HZ", 0b1110, 80.0, None),
168+
("RATE_155_HZ", 0b0001, 155.0, None),
169+
("RATE_300_HZ", 0b0011, 300.0, None),
170+
("RATE_560_HZ", 0b0101, 560.0, None),
171+
("RATE_1000_HZ", 0b0111, 1000.0, None),
172+
)
173+
)
174+
156175

157176
class OperationMode(CV):
158177
"""Options for `operation_mode`
@@ -166,25 +185,31 @@ class OperationMode(CV):
166185
============================= ============================================
167186
168187
"""
169-
pass #pylint: disable=unnecessary-pass
170188

171-
OperationMode.add_values((
172-
('CONTINUOUS', 0b00, 'Continuous', None),
173-
('SINGLE', 0b01, 'Single', None),
174-
('POWER_DOWN', 0b11, 'Power Down', None)
175-
))
189+
pass # pylint: disable=unnecessary-pass
190+
191+
192+
OperationMode.add_values(
193+
(
194+
("CONTINUOUS", 0b00, "Continuous", None),
195+
("SINGLE", 0b01, "Single", None),
196+
("POWER_DOWN", 0b11, "Power Down", None),
197+
)
198+
)
176199
# /** The magnetometer operation mode */
177200
# typedef enum {
178201
# LIS3MDL_CONTINUOUSMODE = , ///< Continuous conversion
179202
# LIS3MDL_SINGLEMODE = , ///< Single-shot conversion
180203
# LIS3MDL_POWERDOWNMODE = , ///< Powered-down mode
181204
# } lis3mdl_operationmode_t;
182205

206+
183207
class LIS3MDL:
184208
"""Driver for the LIS3MDL 3-axis magnetometer.
185209
:param ~busio.I2C i2c_bus: The I2C bus the LIS3MDL is connected to.
186210
:param address: The I2C slave address of the sensor
187211
"""
212+
188213
_chip_id = ROUnaryStruct(_LIS3MDL_WHOAMI, "<b")
189214

190215
_perf_mode = RWBits(2, _LIS3MDL_CTRL_REG1, 5)
@@ -200,7 +225,7 @@ class LIS3MDL:
200225
_reset = RWBit(_LIS3MDL_CTRL_REG2, 2)
201226

202227
def __init__(self, i2c_bus, address=_LIS3MDL_DEFAULT_ADDRESS):
203-
#pylint: disable=no-member
228+
# pylint: disable=no-member
204229
self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
205230
if self._chip_id != _LIS3MDL_CHIP_ID:
206231
raise RuntimeError("Failed to find LIS3MDL - check your wiring!")
@@ -214,7 +239,7 @@ def __init__(self, i2c_bus, address=_LIS3MDL_DEFAULT_ADDRESS):
214239

215240
sleep(0.010)
216241

217-
def reset(self): #pylint: disable=no-self-use
242+
def reset(self): # pylint: disable=no-self-use
218243
"""Reset the sensor to the default state set by the library"""
219244
self._reset = True
220245
sleep(0.010)
@@ -230,9 +255,9 @@ def magnetic(self):
230255
y = self._scale_mag_data(raw_mag_data[1])
231256
z = self._scale_mag_data(raw_mag_data[2])
232257

233-
return(x, y, z)
258+
return (x, y, z)
234259

235-
def _scale_mag_data(self, raw_measurement): #pylint: disable=no-self-use
260+
def _scale_mag_data(self, raw_measurement): # pylint: disable=no-self-use
236261
return (raw_measurement / Range.lsb[self.range]) * _GAUSS_TO_UT
237262

238263
@property
@@ -256,7 +281,7 @@ def data_rate(self):
256281

257282
@data_rate.setter
258283
def data_rate(self, value):
259-
#pylint: disable=no-member
284+
# pylint: disable=no-member
260285
if value is Rate.RATE_155_HZ:
261286
self.performance_mode = PerformanceMode.MODE_ULTRA
262287
if value is Rate.RATE_300_HZ:

0 commit comments

Comments
 (0)