Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello. Thank you very much for writing this library! I hope you accept this pull request.
Short version: I added an optional parameter to init() and open() to tell the device select function to use "I2C_SLAVE_FORCE" instead of "I2C_SLAVE". Existing code should be unaffected. Test code is included.
Long version:
I have a C.H.I.P board (see https://getchip.com) and wanted to be able to access the power controller (AXP209) on bus 0. However, this library, and the original smbus library it was based on, says that the device is busy. This is presumably because the kernel is using it.
Imagine my surprise when the i2c command-line tools are able to access it just fine. A bit of research shows why: i2c command-line tools use I2C_SLAVE_FORCE, while the libraries use "I2C_SLAVE".
I can understand why the library would not use _FORCE: it is dangerous. The kernel keeps track of the state of the device, and if you change that state out from under the kernel, bad things can happen, up to and including panicking the kernel.
I can also understand why the i2c tools use _FORCE: if an administrator, who presumably knows what he is doing, needs to diddle something, he needs a tool to do it. Fortunately, the administrator needs root access to do it.
But so does a python programmer. I.e. adding the ability to use _FORCE with this library doesn't make the overall system any more vulnerable or dangerous. Since python is a widely-used language by administrators, I think the library should grant the same access as the command-line tools.
So I added the "dangerous" flag to both init() and open(). :-) It is an optional parameter, so existing code should not be affected. I called it "dangerous" instead of "force" because in the future we may find other restrictions which are generally a good idea to enforce, but want a bypass for those who like to live on the edge.
Since I don't have an RPi, I couldn't run the test code. So I wrote an additional test program which works on C.H.I.P. That program demonstrates its use.
Steve