Skip to content

Conversation

robomike
Copy link

SPI device was missing read and write functionality. So I added it based on the I2CDevice , it works now.

@tannewt
Copy link
Member

tannewt commented May 21, 2017

Hi Mike, I'm really happy to see this pull. I'm glad you are figuring things out on your own.

However, we removed read_into and write intentionally because they don't add any value. Its the documentation that you pointed to that is wrong and it would be awesome if you corrected that instead. Inside the with statement it should be spi.read_into() instead of spi_device.read_into. This works because with calls __enter__ which returns self.spi and its saved by the with as spi.

@tannewt tannewt self-assigned this May 21, 2017
@robomike
Copy link
Author

Scott, working on the code example, SPI has no attribute read_into. Also, I2C devices has those functions, wouldn't be better for users if they worked the same way?

@tannewt
Copy link
Member

tannewt commented May 26, 2017

On SPI its readinto which matches Python's formatting. We should switch I2CDevice to it too.

I2CDevice needs to wrap write and readinto because it stores the device address. Having SPIDevice return the spi object instead of itself means the structure is the same while saving a bit of memory by not having dumb wrapper functions.

@tannewt
Copy link
Member

tannewt commented Aug 10, 2017

This isn't needed because SPIDevice relies on SPI's methods directly. It does this by returning self.spi from __enter__ unlike I2CDevice which returns self. Thank you anyway for the pull request!

@tannewt tannewt closed this Aug 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants