Skip to content

Commit

Permalink
mpu9250: Handle module not being installed gracefully
Browse files Browse the repository at this point in the history
Don't complain or print empty output if the accelerometer
module is not installed
  • Loading branch information
thaytan committed Jan 22, 2018
1 parent 622be53 commit af209ac
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions software/lib/mpu9250.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,29 @@ def initialise(settings, i2c_bus):

try:
mpu = MPU9250(i2c_bus, settings["accel_max_g"], settings["i2c_addr"])
print("MPU9250 initialised")
except MPU9250Exception:
print("MPU9250 module not detected.")
print("MPU9250 initialised")

def readZ():
if mpu:
return mpu.readZ()
return 0
return (0,0)

# FIXME: Replace with general timer implementation
def accel_check():
global time_last_check, maxZ, minZ
time_now = time.ticks_ms()

if mpu is None:
return

# Track the max/min accelerometer reading between updates
# and output them once per second
curZ = readZ()
maxZ = max(curZ[0], maxZ)
minZ = min(curZ[0], minZ)

time_now = time.ticks_ms()
if time_now >= time_last_check + 1000:
time_last_check = time_now
print ("Accel Z {} min {} max {}".format(readZ(), minZ, maxZ))
Expand Down

0 comments on commit af209ac

Please sign in to comment.