Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] One instance - multiple devices #272

Open
edhinard opened this issue May 13, 2024 · 0 comments
Open

[Feature Request] One instance - multiple devices #272

edhinard opened this issue May 13, 2024 · 0 comments

Comments

@edhinard
Copy link

If I understand correctly how the class works, displaying is a two stages process:

  1. Preparation of the pixel map in MCU's RAM
    • buffer size = W*(H+7)/8
    • GFX methods: drawLine(), drawRect(),...
    • SSD1306 method: ClearDisplay()
  1. 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 to display() and startscrollxx()

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.

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

No branches or pull requests

1 participant