From f2aff4a80be75b5fe148427f38b33f9a4af4757f Mon Sep 17 00:00:00 2001 From: Ales Katona Date: Fri, 6 Oct 2023 09:09:27 -0700 Subject: [PATCH 1/2] add Display::is_sleeping fixes #77 --- mipidsi/CHANGELOG.md | 1 + mipidsi/src/builder.rs | 1 + mipidsi/src/lib.rs | 12 ++++++++++++ 3 files changed, 14 insertions(+) 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..fc84561 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,14 @@ where .write_command(dcs::SetTearingEffect(tearing_effect)) } + /// + /// Returns `true` if display is currently set to sleep. + /// NOTE: value before call to `init` is considered undefined. + /// + 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 +273,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 +284,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(()) } } From 000ea47d0731b3916e67cdbc40c109f9880b961b Mon Sep 17 00:00:00 2001 From: Ales Katona Date: Mon, 23 Oct 2023 09:06:51 -0700 Subject: [PATCH 2/2] remove init comment --- mipidsi/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/mipidsi/src/lib.rs b/mipidsi/src/lib.rs index fc84561..45ef797 100644 --- a/mipidsi/src/lib.rs +++ b/mipidsi/src/lib.rs @@ -259,7 +259,6 @@ where /// /// Returns `true` if display is currently set to sleep. - /// NOTE: value before call to `init` is considered undefined. /// pub fn is_sleeping>(&self) -> bool { self.sleeping