From 268d70fa488c562a63f083868779f5a84c7926bb Mon Sep 17 00:00:00 2001 From: Andreas Neuhaus Date: Sun, 11 Aug 2024 00:29:35 +0200 Subject: [PATCH] Add support to turn off the display --- firmware/src/display.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/firmware/src/display.rs b/firmware/src/display.rs index 4af70b8..ecc3730 100644 --- a/firmware/src/display.rs +++ b/firmware/src/display.rs @@ -4,7 +4,7 @@ use embedded_graphics::pixelcolor::BinaryColor; use embedded_graphics::prelude::*; use embedded_graphics::text::{Alignment, Text}; use embedded_hal::i2c::I2c; -use log::info; +use log::{debug, info}; use ssd1306::mode::{BufferedGraphicsMode, DisplayConfig}; use ssd1306::prelude::I2CInterface; use ssd1306::rotation::DisplayRotation; @@ -44,10 +44,19 @@ impl Display { Ok(Display { driver }) } + /// Turn display off + #[allow(dead_code)] + pub fn turn_off(&mut self) -> Result<(), Error> { + debug!("Display: Power off"); + self.driver.set_display_on(false)?; + Ok(()) + } + /// Clear display pub fn clear(&mut self) -> Result<(), Error> { self.driver.clear(BinaryColor::Off)?; self.driver.flush()?; + self.driver.set_display_on(true)?; Ok(()) } @@ -76,6 +85,7 @@ impl Display { ) .draw(&mut self.driver)?; self.driver.flush()?; + self.driver.set_display_on(true)?; Ok(()) } @@ -92,6 +102,7 @@ impl Display { ) .draw(&mut self.driver)?; self.driver.flush()?; + self.driver.set_display_on(true)?; Ok(()) } }