Adafruit_SSD1306
Adafruit_SSD1306 copied to clipboard
[Feature Request] One instance - multiple devices
If I understand correctly how the class works, displaying is a two stages process:
- Preparation of the pixel map in MCU's RAM
- buffer size = W*(H+7)/8
- GFX methods:
drawLine()
,drawRect()
,... - SSD1306 method:
ClearDisplay()
- Transfer of the pixel map to the hardware with the
display()
method- whether by I2C if a Wire reference is given in constructor or SPI
- when I2C, the device address is given as a parameter of the
begin()
method - when SPI the method (hardware or software) and the pins are given in the constructor
Scroll methods do not change the pixel map in RAM and just send commands to the display that do the job.
With minor code changes, it should be possible to manage 2 or more I2C displays of the same width and height with a single class. Thus reducing the need of RAM. We just need to allow user code to change i2caddr
attribute. For that:
- make it public
- or add a setter method
- or add a
i2caddr
parameter todisplay()
andstartscrollxx()
Another solution, which has my preference since it should work with different size displays and for SPI as well, is to:
- add a
reset()
method that free pixel map memory.
An additional logic which manage peripheral's begin function would be a plus. For example with the help of a periphHasBegun
protected attribute. From user perspective the code will be:
A first example with only one instance for 2 devices (same dimensions) sharing the same I2C bus:
Adafruit_SSD1306 display1(WIDTH, HEIGHT, &Wire);
display.begin(SSD1306_SWITCHCAPVCC, ADDR1);
...
display.reset();
display.begin(SSD1306_SWITCHCAPVCC, ADDR2); // no need to "periphBegin=0" after first call of begin()
...
display.reset();
A second example with two instances, SPI and I2C and different dimensions, but only one pixel map in RAM at a time:
Adafruit_SSD1306 display1(WIDTH1, HEIGHT1, &Wire);
Adafruit_SSD1306 display2(WIDTH2, HEIGHT2, &SPI...);
display1.begin(SSD1306_SWITCHCAPVCC, ADDR);
...
display1.reset();
display2.begin(SSD1306_SWITCHCAPVCC);
...
display2.reset();
Question to the library maintainer:
Would you accept a modification in this direction (reset method)?
I would like to propose a modification. The problem is that I don't have anything to test it at the moment. And certainly not with varied configurations.