adafruit / Adafruit_SSD1306

Arduino library for SSD1306 monochrome 128x64 and 128x32 OLEDs
http://www.adafruit.com/category/63_98
Other
1.75k stars 964 forks source link

-Added typedef dfunc_t for user display function #221

Closed bmoniey closed 2 years ago

bmoniey commented 2 years ago

Hello,

This pull request has 2 changes.

I was finding that on an Arduino Nano the update rate to a 128 x 64 OLED display was taking about 32ms. I needed to poll a position sensor at least every 7ms to not miss counts and wrap around. I added a new display method which calls a users void function every row update. This allowed me to not miss counts any more. I think others might need something like this when critical code needs to get run during a long display update. I opted to create a new method to not impact others working code in any way. I have included a before and after scope shot where a debug pin set high then low on entry and exit to the function.

I was also frustrated when developing this code by the private settings of the class and would like to suggest the private data be protected to allow for easier experimentation.

My project is currently in a test branch called protected which goes along with this fork and branch called protected

https://github.com/bmoniey/FilamentMeasuringTool/blob/protected/fmt20/fmt20.ino

and

https://github.com/bmoniey/Adafruit_SSD1306/tree/protected

Thanks,

Brian

SDS00027_after_display_d SDS00025_before_display_d

ladyada commented 2 years ago

hi if you need to poll a sensor, why not use an IRQ - that's the easiest way to schedule a timing-critical interrupt event

bmoniey commented 2 years ago

Hello,

I think this is a special case, but could be common with the number of i2c sensors out there. In this case an AMS5600 magnetic rotary encoder is on the same i2c bus as the display. I don't think I could safely access the i2c bus from an ISR during a display update. Looking at the twi library for Arduino it is often disabling interrupts and waiting for transactions to complete. Perhaps some comments about this function related to polling i2c sensors on the same bus would improve this pull request!

Many thanks to all the hard work from Adafruit!

ladyada commented 2 years ago

we probably wouldn't accept the irq change, its a very very specialized case - you could use a secondary i2c port, or simply maintain a fork. for private to protected you can submit a separate PR

ladyada commented 2 years ago

alternatively, connect to the OLED over SPI, its 10x faster and doesnt share I2C

bmoniey commented 2 years ago

Thanks for the feedback. I'll close the request and submit a PR request for the protected change. This example can easily be an addition in a derived class, which was my original plan, but the private allocations made it impossible to access the private members of the class.

ladyada commented 2 years ago

thanks! :)