Skip to content

Simplify constructor use and documentation improvement#20

Open
drepper wants to merge 2 commits into
Harbys:masterfrom
drepper:master
Open

Simplify constructor use and documentation improvement#20
drepper wants to merge 2 commits into
Harbys:masterfrom
drepper:master

Conversation

@drepper

@drepper drepper commented Aug 15, 2024

Copy link
Copy Markdown

The SSD1306 constructor should not require duplicated information and bleeding of details (i.e., the I²C address) into the application code.

The documentation shows an inefficient use to construct the SSD1306 object. A minimal change does away with that and removes the superfluous double use of the full type name (alternative: use auto).

Except for non-standard devices, the address value and the display size
change in unisom.  There are exactly two pairs of these values and
therefore requiring the caller to specify both the address and size
in the construtor means more work, more possible errors, and knowledge
on the side of the user of the library which can be avoided to be
hardcoded.

This patch introduces a second constructor which takes only the size
parameter and derives the address parameter.
In the example code in the readme.md file, the code shows to use the
initialization of the display variable with the help of a copy
constructor.  This is not necessary, just call the constructor
directly.
Comment thread ssd1306.h
/// \brief SSD1306 constructor with implied standard address.
/// \param i2CInst - i2c instance. Either i2c0 or i2c1
/// \param size - display size. Acceptable values W128xH32 or W128xH64
SSD1306(i2c_inst *i2CInst, Size size) : SSD1306(i2CInst, size == Size::W128xH32 ? 0x3C : 0x3D, size) { }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this might not be a valid assumption. Most of my 128x64's are 0x3C, one is not, dependant on brand. It might be confusing to users if they see this assuming it will choose a sane default for them when such a default is entirely model dependant.

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