Skip to content

Commit

Permalink
Merge pull request mirte-robot#26 from ArendJan/25-mirteget_pin_value…
Browse files Browse the repository at this point in the history
…-never-returning_v2

Fix get pin value not returning
  • Loading branch information
mklomp authored Oct 10, 2023
2 parents b948ed2 + ab459e9 commit 5918798
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mirte_telemetrix/scripts/ROS_telemetrix_aio_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,14 @@ def handle_get_pin_value(req):
if req.type == "digital":
asyncio.run(board.set_pin_mode_digital_input(pin, callback=data_callback))

while not pin in pin_values:
time.sleep(0.00001)
# timeout after 5s, don't keep waiting on something that will never happen.
start_time = time.time()
while not pin in pin_values and time.time() - start_time < 5.0:
time.sleep(0.001)
if pin in pin_values:
value = pin_values[pin]
else:
value = -1 # device did not report back, so return error value.

value = pin_values[pin]
return GetPinValueResponse(value)
Expand Down

0 comments on commit 5918798

Please sign in to comment.