Skip to content

Commit

Permalink
Merge pull request #9 from auscompgeek/nicer-read-errors
Browse files Browse the repository at this point in the history
registerio: Regularly print read errors
  • Loading branch information
virtuald committed Feb 5, 2019
2 parents 2498b02 + 27e068c commit eb44f1a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions navx/registerio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
# in the root directory of the project
# ----------------------------------------------------------------------------

from ._impl import AHRSProtocol, IMUProtocol, IMURegisters
import logging
import time

from wpilib.timer import Timer

import logging
from ._impl import AHRSProtocol, IMUProtocol, IMURegisters

logger = logging.getLogger("navx")

Expand Down Expand Up @@ -79,6 +80,7 @@ def shutdown(self):

def run(self):
logger.info("NavX io thread starting")
monotonic = time.monotonic

try:
self.io_provider.init()
Expand All @@ -99,7 +101,7 @@ def run(self):
self.board_id.fw_ver_minor,
)

log_error = True
last_read_error_ts = 0

# Calculate delay to match configured update rate
# Note: some additional time is removed from the
Expand All @@ -120,12 +122,11 @@ def run(self):

try:
self.getCurrentData()
except IOError:
if log_error:
logger.exception("Error getting data")
log_error = False
else:
log_error = True
except IOError as e:
now = monotonic()
if now - last_read_error_ts > 1.0:
logger.error("Error reading data: %s", e)
last_read_error_ts = now

Timer.delay(update_rate)
except Exception:
Expand Down

0 comments on commit eb44f1a

Please sign in to comment.