diff --git a/mipidsi/CHANGELOG.md b/mipidsi/CHANGELOG.md index 85886e3..b4e3d24 100644 --- a/mipidsi/CHANGELOG.md +++ b/mipidsi/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - added `GC9A01` model support - added `Display::wake` method - added `Display::sleep` method +- added `Display::is_sleeping` method ## [v0.7.1] - 2023-05-24 diff --git a/mipidsi/src/builder.rs b/mipidsi/src/builder.rs index 40a8e65..fec2f5f 100644 --- a/mipidsi/src/builder.rs +++ b/mipidsi/src/builder.rs @@ -140,6 +140,7 @@ where rst, options: self.options, madctl, + sleeping: false, // TODO: init should lock state }; Ok(display) diff --git a/mipidsi/src/lib.rs b/mipidsi/src/lib.rs index 4fe1e64..45ef797 100644 --- a/mipidsi/src/lib.rs +++ b/mipidsi/src/lib.rs @@ -119,6 +119,8 @@ where options: ModelOptions, // Current MADCTL value copy for runtime updates madctl: dcs::SetAddressMode, + // State monitor for sleeping TODO: refactor to a Model-connected state machine + sleeping: bool, } impl Display @@ -255,6 +257,13 @@ where .write_command(dcs::SetTearingEffect(tearing_effect)) } + /// + /// Returns `true` if display is currently set to sleep. + /// + pub fn is_sleeping>(&self) -> bool { + self.sleeping + } + /// /// Puts the display to sleep, reducing power consumption. /// Need to call [Self::wake] before issuing other commands @@ -263,6 +272,7 @@ where self.dcs.write_command(dcs::EnterSleepMode)?; // All supported models requires a 120ms delay before issuing other commands delay.delay_us(120_000); + self.sleeping = true; Ok(()) } @@ -273,6 +283,7 @@ where self.dcs.write_command(dcs::ExitSleepMode)?; // ST7789 and st7735s have the highest minimal delay of 120ms delay.delay_us(120_000); + self.sleeping = false; Ok(()) } }