Skip to content

Commit 914912c

Browse files
committed
Convert get_health and get_info to properties
1 parent 2d8f0b9 commit 914912c

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

adafruit_circuitpython_rplidar.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ def _read_response(self, dsize):
247247
raise RPLidarException('Wrong body size')
248248
return data
249249

250-
def get_info(self):
250+
@property
251+
def info(self):
251252
'''Get device information
252253
253254
Returns
@@ -258,7 +259,7 @@ def get_info(self):
258259
self._send_cmd(GET_INFO_BYTE)
259260
dsize, is_single, dtype = self._read_descriptor()
260261
if dsize != INFO_LEN:
261-
raise RPLidarException('Wrong get_info reply length')
262+
raise RPLidarException('Wrong info reply length')
262263
if not is_single:
263264
raise RPLidarException('Not a single response mode')
264265
if dtype != INFO_TYPE:
@@ -274,7 +275,8 @@ def get_info(self):
274275
}
275276
return data
276277

277-
def get_health(self):
278+
@proprety
279+
def health(self):
278280
'''Get device health state. When the core system detects some
279281
potential risk that may cause hardware failure in the future,
280282
the returned status value will be 'Warning'. But sensor can still work
@@ -292,15 +294,15 @@ def get_health(self):
292294
self._send_cmd(GET_HEALTH_BYTE)
293295
dsize, is_single, dtype = self._read_descriptor()
294296
if dsize != HEALTH_LEN:
295-
raise RPLidarException('Wrong get_info reply length')
297+
raise RPLidarException('Wrong info reply length')
296298
if not is_single:
297299
raise RPLidarException('Not a single response mode')
298300
if dtype != HEALTH_TYPE:
299301
raise RPLidarException('Wrong response data type')
300302
raw = self._read_response(dsize)
301303
status = _HEALTH_STATUSES[raw[0]]
302304
error_code = (raw[1] << 8) + raw[2]
303-
return status, error_code
305+
return (status, error_code)
304306

305307
def clear_input(self):
306308
'''Clears input buffer by reading all available data'''
@@ -345,13 +347,13 @@ def iter_measurments(self, max_buf_meas=500):
345347
In millimeter unit. Set to 0 when measurment is invalid.
346348
'''
347349
self.start_motor()
348-
status, error_code = self.get_health()
350+
status, error_code = self.health
349351
self.log('debug', 'Health status: %s [%d]' % (status, error_code))
350352
if status == _HEALTH_STATUSES[2]:
351353
self.log('warning', 'Trying to reset sensor due to the error. '
352354
'Error code: %d' % (error_code))
353355
self.reset()
354-
status, error_code = self.get_health()
356+
status, error_code = self.health
355357
if status == _HEALTH_STATUSES[2]:
356358
raise RPLidarException('RPLidar hardware failure. '
357359
'Error code: %d' % error_code)
@@ -362,7 +364,7 @@ def iter_measurments(self, max_buf_meas=500):
362364
self._send_cmd(cmd)
363365
dsize, is_single, dtype = self._read_descriptor()
364366
if dsize != 5:
365-
raise RPLidarException('Wrong get_info reply length')
367+
raise RPLidarException('Wrong info reply length')
366368
if is_single:
367369
raise RPLidarException('Not a multiple response mode')
368370
if dtype != SCAN_TYPE:

0 commit comments

Comments
 (0)