Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I2C Error handling #6689

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

nefelim4ag
Copy link
Contributor

@nefelim4ag nefelim4ag commented Sep 14, 2024

As mentioned: #6674 (comment)
That would be nice to handle I2C errors, instead of the current shutdown approach.

There is a refactoring part to make things more obvious, where is the dev and where is the bus.

Errors handling works, but:

  • Some MCUs do not clearly state what happens underneath.
  • There should be a better way to define & pass errors to Klippy. I think it would be possible to reuse static_stings_id for that.
  • When klippy inits and I2C returns an error, it is an unhandled exception, so it only appears in logs. There should be a fix actually to show it to frontends as before with shutdown msg.
  • Missing handling for ldc1612 - used in homing sequence, there is no reason or way to handle errors.
  • mpu9250 - used as an accelerometer, it looks safe to ignore anything, as with SPI sensors.
  • Most sensors for now do something like:
def _sample():
        try:
            <code here>
        except Exception:
            logging.exception(...)
            self.temp = self.humidity = .0
            return self.reactor.NEVER

So, they stop updating data, if there is no heater for them, the machine will continue running.


About the code itself:

  • Refactoring is done for clarity, it can be dropped or moved to separate PR.
    (I still somewhat think about non-blocking i2c, it feels right to store queue/buf at bus level),
  • int ret looks a little dirty to me, maybe it is a bad approach here, I will be glad to receive any feedback.
    (maybe with timers there is a simple way with callbacks, cause we don't need to do something with stack).

Thanks.

@nefelim4ag nefelim4ag marked this pull request as draft September 14, 2024 20:24
@nefelim4ag nefelim4ag force-pushed the i2c-error-handling branch 8 times, most recently from 4488c11 to 4648028 Compare September 18, 2024 18:39
pins.py code ensure that pins will not mix
between HW/SW buses.

I2C bus can handle several devices,
but we pass it around by pointers,
so it does not actually duplicate.

Signed-off-by: Timofey Titovets <[email protected]>
I2C Address is the param of a device, not a bus.
Done separate addresses from bus implementation.

Signed-off-by: Timofey Titovets <[email protected]>
Signed-off-by: Timofey Titovets <[email protected]>
Signed-off-by: Timofey Titovets <[email protected]>
Signed-off-by: Timofey Titovets <[email protected]>
@nefelim4ag
Copy link
Contributor Author

I think this is more or less ready to gather feedback, so I will remove the "draft" label.
It feels stable, but it looks like initialization is now a little bit slower, because i2c write now is "synchronous".

@nefelim4ag nefelim4ag marked this pull request as ready for review September 28, 2024 18:02
Copy link

Thank you for your contribution to Klipper. Unfortunately, a reviewer has not assigned themselves to this GitHub Pull Request. All Pull Requests are reviewed before merging, and a reviewer will need to volunteer. Further information is available at: https://www.klipper3d.org/CONTRIBUTING.html

There are some steps that you can take now:

  1. Perform a self-review of your Pull Request by following the steps at: https://www.klipper3d.org/CONTRIBUTING.html#what-to-expect-in-a-review
    If you have completed a self-review, be sure to state the results of that self-review explicitly in the Pull Request comments. A reviewer is more likely to participate if the bulk of a review has already been completed.
  2. Consider opening a topic on the Klipper Discourse server to discuss this work. The Discourse server is a good place to discuss development ideas and to engage users interested in testing. Reviewers are more likely to prioritize Pull Requests with an active community of users.
  3. Consider helping out reviewers by reviewing other Klipper Pull Requests. Taking the time to perform a careful and detailed review of others work is appreciated. Regular contributors are more likely to prioritize the contributions of other regular contributors.

Unfortunately, if a reviewer does not assign themselves to this GitHub Pull Request then it will be automatically closed. If this happens, then it is a good idea to move further discussion to the Klipper Discourse server. Reviewers can reach out on that forum to let you know if they are interested and when they are available.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant