There was an error while loading. Please reload this page.
2 parents 8ff3a5f + abefe63 commit 1377d27Copy full SHA for 1377d27
1 file changed
opensourceleg/sensors/adc.py
@@ -152,9 +152,18 @@ def reset(self) -> None:
152
def update(self) -> None:
153
"""
154
Update the ADC data by reading the latest voltage values in millivolts.
155
+ Attempts to read a maximum of 1000 times before throwing an error.
156
157
+ MAX_ATTEMPTS = 1000
158
+ attempts = 0
159
while not self._ready_to_read():
160
sleep(0.001)
161
+ attempts += 1
162
+ if attempts > MAX_ATTEMPTS:
163
+ raise RuntimeError(
164
+ "Couldn't connect to the ADC, please ensure that the device is connected and powered on."
165
+ )
166
+
167
self._data = self._read_data_millivolts()
168
169
def calibrate(self) -> None:
0 commit comments