Skip to content

Commit f3d12c2

Browse files
author
marcusw
committed
Fixing r227 with the new patch from Issue 22.
1 parent ab95bbb commit f3d12c2

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

nxt/sensor/hitechnic.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ class EOPD(BaseAnalogSensor):
244244
# To be divided by processed value.
245245
_SCALE_CONSTANT = 250
246246

247+
# Maximum distance the sensor can detect.
248+
_MAX_DISTANCE = 1023
249+
247250
def __init__(self, brick, port):
248251
super(EOPD, self).__init__(brick, port)
249252
from math import sqrt
@@ -267,7 +270,7 @@ def set_range_short(self):
267270
def get_raw_value(self):
268271
'''Unscaled value read from sensor.'''
269272

270-
return 1023 - self.get_input_values().raw_ad_value
273+
return self._MAX_DISTANCE - self.get_input_values().raw_ad_value
271274

272275
def get_processed_value(self):
273276
'''Derived from the square root of the raw value.'''
@@ -280,7 +283,12 @@ def get_scaled_value(self):
280283
generally be called to get EOPD sensor data.
281284
'''
282285

283-
return self._SCALE_CONSTANT / self.get_processed_value()
286+
try:
287+
result = self._SCALE_CONSTANT / self.get_processed_value()
288+
return result
289+
290+
except ZeroDivisionError:
291+
return self._SCALE_CONSTANT
284292

285293
get_sample = get_processed_value
286294

0 commit comments

Comments
 (0)