rambo / TinyWire

My modifications to TinyWire Arduino libs
284 stars 121 forks source link

TWI_RX_BUFFER_SIZE should be wrapped in #indef #6

Closed Gadgetoid closed 10 years ago

Gadgetoid commented 10 years ago

I recommend that the definition of TWI_RX_BUFFER_SIZE should be wrapped in #indef so it can be modified by defining this constant before including the library, rather than modifying the library directly.

Thanks for an awesome library otherwise! Works beautifully on the Adafruit Trinket.

Gadgetoid commented 10 years ago

Sorry, this isn't possible as the #define at the Sketch level will never be visible during the replacement in the Library.

Is there a better way to handle variable TWI_RX_BUFFER_SIZE values, without having to modify the library?

Due to my needing an abnormally large buffer, perhaps I should reimplement with available() and read()

rambo commented 10 years ago

Figure out as much while testing myself, pushed a #ifndef wrap change anyway since it won't hurt. The problem is that pesky extern (I think), but without it there will be other trouble.

calling available in a tight loop will allow you to empty the buffer early but you need to track the transaction somehow then.

I guess checking with available just after the stop_check and reading from the buffer to another, larger one you maintain and then appending to said buffer on the onReceive callback would work, but it is a bit contrived.

Gadgetoid commented 10 years ago

Thanks for the suggestion. It's certainly contrived but it's a lot better than simply using an available()/read() loop, which I've found, when using Serial comms, is clunky and hard to follow.

I think I'll fork the repo and hard-code in a 128byte buffer for my purposes ( making a NeoPixel i2c driver for use with the Pi and Adafruit Trinket ). Although I'm finding that setting a pixel at a time with i2cset is simple and easy to understand it would be nice to stream further RGB triplets to set every pixel in a strip with one command.

rambo commented 10 years ago

Another option (but with more overhead) would be to have a status/command register where you can write a flag to trigger writing out of the whole RGB bytestream in the registers. much like one of the examples with the library that uses such flag to write new slave address to EEPROM.