PierreRust / apigpio

apigpio - an asyncio-based python client for pigpio
MIT License
19 stars 11 forks source link

add i2c commands #11

Open jabdoa2 opened 6 years ago

jabdoa2 commented 6 years ago

Add some i2c commands:

Fix locking and asyncio sendall calls

PierreRust commented 6 years ago

Thanks for your contribution ! I cannot test it right now (no i2c device at hand), do you need it integrated quickly (with a pip release) or can it wait a bit ?

jabdoa2 commented 6 years ago

It can wait a bit. The feature is not upstream yet in MPF so our users are not using it yet. I tested it with a RPi3 and a MMA8451.

orbsmiv commented 6 years ago

I'm wanting to use an i2c LCD display (using the pigpio I2C LCD class) asynchronously. I think that everything is covered in this PR, except the _i2c_writedevice method. I'm still getting to grips with async in Python so have broadly adapted the pigpio module's code, following your refactoring process to get the following code:

@asyncio.coroutine
def i2c_write_device(self, handle, data):
    """Writes the data bytes to the raw device associated with handle."""
    if len(data):
        res = yield from self._pigpio_aio_command_ext(_PI_CMD_I2CWD, handle, 0, len(data), [data])
        return _u2i(res)
    else:
        return 0

If this is correct, please can you add it to this PR? Thanks!

jabdoa2 commented 6 years ago

@orbsmiv: just create a PR based on my PR. Please also test it.

orbsmiv commented 6 years ago

@jabdoa2 sure, although I've not done a stacked PR before... is the process to fork your repo and then submit a PR on your _add_i2ccommands branch?

jabdoa2 commented 6 years ago

Fork mine and then create a PR against this repo. That will also contain the changes of my PR which then would have to be merged first

jabdoa2 commented 4 years ago

@PierreRust any chance we can merge this?