ldab / KXTJ3-1057

KXTJ3-1057 Tri-axis Digital Accelerometer - Arduino Library
MIT License
14 stars 8 forks source link

Add software reset functionality #7

Closed nomakewan closed 1 year ago

nomakewan commented 1 year ago

According to Kionix document TN017 Power-On Procedure it is recommended to perform a software reset on every power-up to be assured that the IMU will both be ready for communication at its expected address and will be sending good data. They note that in certain situations, the IMU may accidentally boot into a state where its I2C address is "bit-flipped," and thus will not respond to I2C commands at the usual address but is otherwise functional. This state can be remedied by sending the software reset command to that alternate address, which will initiate a RAM reset on the IMU and return it to proper working order. Even if the IMU comes up at the correct address, they still recommend performing this procedure to be absolutely certain the IMU is ready for operation.

This PR adds this functionality as softwareReset() and calls it automatically in begin(), moves the start-up delay to its own dedicated function called startupDelay() and calls it for standby(false) and applySettings(), makes it so that a hard failure during initialization will return immediately rather than continue banging on the I2C bus, and cleans up some code formatting.

ldab commented 1 year ago

I have added a CI runner, so please rebase so it can run on this PR... Also have add clang format checker so you don't need to manually change the formatting.

nomakewan commented 1 year ago

Okay, I actually have no idea why the clang runner is not working here. It's complaining about two lines that appear to have no issues whatsoever. I even copied them from this repo and when I paste the copied lines in Github's editor says there are no changes to commit.

ldab commented 1 year ago

Okay, I actually have no idea why the clang runner is not working here. It's complaining about two lines that appear to have no issues whatsoever. I even copied them from this repo and when I paste the copied lines in Github's editor says there are no changes to commit.

you can run for example clang-format -style=file -i ./src/kxtj3-1057.h locally and after diff, it will show the problem, for example when doing it on your branch:

image

ldab commented 1 year ago

closing and reopen to see if the CI runs

nomakewan commented 1 year ago

I ended up finding a solution but you'd already fixed it before I could do it.

Oddly neither of the changes that my clang formatter suggested were the ones that the clang runner was claiming were wrong. It claimed the issues were with these...

clang

Thanks for the fix!

ldab commented 1 year ago

are you working on something else ot should I tag a new release?

nomakewan commented 1 year ago

are you working on something else ot should I tag a new release?

There's resolving the preprocessor directive thing I'd like to resolve before a new release. Would it be okay to just have debug mode and high resolution mode be parameters passed to begin() like sample rate and accel scale are? If so I'll make those changes and open another PR with them to close that issue.

ldab commented 1 year ago

that should be ok,

nomakewan commented 1 year ago

I have to step out for a bit, but should be back in an hour or so. I'll get to making those changes as soon as I return. Thanks!

nomakewan commented 1 year ago

Wasn't startupDelay already private? It was under the 'private' label on line 107.