Skip to content

Commit

Permalink
Add mirror (vertical flip) option (#161)
Browse files Browse the repository at this point in the history
* Add mirror (vertical flip) option

* Change the description

* Swap 90d and 270d

* Add changelog entry
  • Loading branch information
mryndzionek authored Feb 10, 2022
1 parent 15e47c1 commit 01e8b5a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

## [Unreleased] - ReleaseDate

### Added

- [#161](https://github.com/jamwaffles/ssd1306/pull/161) Added a `set_mirror` method to enable or disable display mirroring.

## [0.7.0] - 2021-07-08

### Changed
Expand Down
27 changes: 27 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,33 @@ where
Ok(())
}

/// Set mirror enabled/disabled.
pub fn set_mirror(&mut self, mirror: bool) -> Result<(), DisplayError> {
if mirror {
match self.rotation {
DisplayRotation::Rotate0 => {
Command::SegmentRemap(false).send(&mut self.interface)?;
Command::ReverseComDir(true).send(&mut self.interface)?;
}
DisplayRotation::Rotate90 => {
Command::SegmentRemap(false).send(&mut self.interface)?;
Command::ReverseComDir(false).send(&mut self.interface)?;
}
DisplayRotation::Rotate180 => {
Command::SegmentRemap(true).send(&mut self.interface)?;
Command::ReverseComDir(false).send(&mut self.interface)?;
}
DisplayRotation::Rotate270 => {
Command::SegmentRemap(true).send(&mut self.interface)?;
Command::ReverseComDir(true).send(&mut self.interface)?;
}
};
} else {
self.set_rotation(self.rotation)?;
}
Ok(())
}

/// Change the display brightness.
pub fn set_brightness(&mut self, brightness: Brightness) -> Result<(), DisplayError> {
// Should be moved to Brightness::new once conditions can be used in const functions
Expand Down

0 comments on commit 01e8b5a

Please sign in to comment.