Skip to content

Bug Fix: Remove sendCommand(NORMALDISPLAY) from setContrast() - #427

Merged
marcelstoer merged 3 commits into
ThingPulse:masterfrom
jasonacox:preserve-invert-state
Jan 9, 2026
Merged

marcelstoer merged 3 commits into
ThingPulse:masterfrom
jasonacox:preserve-invert-state

Conversation

@jasonacox

@jasonacox jasonacox commented Dec 31, 2025 •

Copy link
Copy Markdown
Contributor

This pull request updates the setContrast method to fix an unwanted call to reset the display to NORMALDISPLAY mode rather than just sending the contrast related commands.

Removes sendCommand(NORMALDISPLAY):

void OLEDDisplay::setContrast(uint8_t contrast, uint8_t precharge, uint8_t comdetect) {
  sendCommand(SETPRECHARGE); //0xD9
  sendCommand(precharge); //0xF1 default, to lower the contrast, put 1-1F
  sendCommand(SETCONTRAST);
  sendCommand(contrast); // 0-255
  sendCommand(SETVCOMDETECT); //0xDB, (additionally needed to lower the contrast)
  sendCommand(comdetect);	//0x40 default, to lower the contrast, put 0
  sendCommand(DISPLAYALLON_RESUME);
// sendCommand(NORMALDISPLAY);
  sendCommand(DISPLAYON);
}

Minor:

  • Updated comments in both README.md and src/OLEDDisplay.h to clarify that setBrightness is a convenience method for setContrast with only the brightness parameter. [1] [2]

Closes #426

Copilot AI review requested due to automatic review settings December 31, 2025 20:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds a forceNormal parameter to the setContrast and setBrightness methods to allow users to preserve the current display mode (normal/inverted) when adjusting brightness or contrast settings. The parameter defaults to true for backward compatibility.

Key changes:

  • Added forceNormal boolean parameter (default: true) to setContrast and setBrightness methods
  • Modified implementations to conditionally apply normal display mode based on the new parameter
  • Updated documentation in header file and README to describe the new parameter behavior

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/OLEDDisplay.h Added forceNormal parameter with default value to method signatures and updated documentation comments
src/OLEDDisplay.cpp Implemented conditional logic for forceNormal parameter in both methods and passed parameter through from setBrightness to setContrast
README.md Updated API documentation to reflect the new parameter and its behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/OLEDDisplay.cpp Outdated
@jasonacox

Copy link
Copy Markdown
Contributor Author

Based on discussion in issue #427 - updating PR to simply remove sendCommand(NORMALDISPLAY) from setContrast().

@jasonacox jasonacox changed the title Add pram to setContrast to preserve display mode state Bug Fix: Remove sendCommand(NORMALDISPLAY) from setContrast() Jan 9, 2026
@marcelstoer
marcelstoer merged commit 2ec3cae into ThingPulse:master Jan 9, 2026
6 checks passed
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.

Calling setBrightness() reverses invertDisplay()

3 participants