Skip to content

Commit 2147cd7

Browse files
committed
Checked code style with Black and pre-commit
1 parent 74c53d2 commit 2147cd7

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

adafruit_lidarlite.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
_CMD_DISTANCENOBIAS = const(0x03)
5858
_CMD_DISTANCEWITHBIAS = const(0x04)
5959
_CMD_DISTANCE_V3HP = const(0x03)
60-
_NUM_DIST_BYTES = 2 # How many bytes is the returned distance measurement?
60+
_NUM_DIST_BYTES = 2 # How many bytes is the returned distance measurement?
6161

62-
TYPE_V3 = 'V3'
63-
TYPE_V3HP = 'V3HP'
62+
TYPE_V3 = "V3"
63+
TYPE_V3HP = "V3HP"
6464

6565
CONFIG_DEFAULT = 0
6666
CONFIG_SHORTFAST = 1
@@ -145,16 +145,14 @@ def reset(self):
145145
try:
146146
self._write_reg(_REG_ACQ_COMMAND, _CMD_RESET)
147147
except OSError:
148-
print('OSError')
149-
pass # it doesnt respond well once reset
148+
print("OSError")
150149
time.sleep(1)
151150
# take 100 readings to 'flush' out sensor!
152151
for _ in range(100):
153152
try:
154153
self.read_distance_v3(True)
155154
except RuntimeError:
156-
print('RuntimeError')
157-
pass
155+
print("RuntimeError")
158156

159157
def configure(self, config):
160158
"""Set the LIDAR desired style of measurement. There are a few common
@@ -177,19 +175,18 @@ def read_distance_v3(self, bias=False):
177175
if self._status & (STATUS_NO_PEAK | STATUS_SECOND_RETURN):
178176
if self._status & STATUS_NO_PEAK:
179177
raise RuntimeError("Measurement failure STATUS_NO_PEAK")
180-
elif self._status & STATUS_SECOND_RETURN:
178+
if self._status & STATUS_SECOND_RETURN:
181179
raise RuntimeError("Measurement failure STATUS_NO_PEAK")
182-
else:
183-
raise RuntimeError("Some other runtime error")
180+
raise RuntimeError("Some other runtime error")
184181

185182
if (self._status & STATUS_SYS_ERROR) or (not self._status & STATUS_HEALTHY):
186183
raise RuntimeError("System failure")
187184
return dist[0] << 8 | dist[1]
188185

189186
def read_distance_v3hp(self):
190-
"""Perform a distance measurement for the v3 HP sensor
191-
"""
192-
# Any non-zero value written to _REG_ACQ_COMMAND will start a reading on v3HP, no bias vs. non-bias
187+
"""Perform a distance measurement for the v3 HP sensor"""
188+
# Any non-zero value written to _REG_ACQ_COMMAND will start a reading on v3HP, no bias vs.
189+
# non-bias
193190
self._write_reg(_REG_ACQ_COMMAND, _CMD_DISTANCEWITHBIAS)
194191
dist = self._read_reg(_REG_DIST_MEAS_V3HP, _NUM_DIST_BYTES)
195192
return dist[0] << 8 | dist[1]
@@ -221,8 +218,8 @@ def health_status(self):
221218
"""Reads health status for v3HP (not available on v3, will return -1)"""
222219
if self._sensor_type == TYPE_V3HP:
223220
return self._read_reg(_REG_HEALTH_STATUS_V3HP, 1)[0]
224-
else:
225-
return -1
221+
222+
return -1
226223

227224
@property
228225
def signal_strength(self):
@@ -238,17 +235,20 @@ def unit_id(self):
238235
return high_byte[0] << 8 | low_byte[0]
239236

240237
@property
241-
def distance(self):
238+
def distance(self): # pylint: disable=R1710
242239
"""The measured distance in cm. Will take a bias reading every 100 calls"""
243240
self._bias_count -= 1
244241

245242
if self._bias_count < 0:
246243
self._bias_count = 100 # every 100 reads, check bias
247244
if self._sensor_type == TYPE_V3:
248245
return self.read_distance_v3(self._bias_count <= 0)
249-
elif self._sensor_type == TYPE_V3HP:
246+
if self._sensor_type == TYPE_V3HP:
250247
return self.read_distance_v3hp()
251248

249+
# If no sensor type has been identified, return a negative distance as an error
250+
return -1.0
251+
252252
@property
253253
def status(self):
254254
"""The status byte, check datasheet for bitmask"""

0 commit comments

Comments
 (0)