From b3ae465e2a51a8b628c2dbfc03ab711467a009e2 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 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/firmware/src/display.rs b/firmware/src/display.rs index 4af70b8..201bfc9 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,18 @@ impl Display { Ok(Display { driver }) } + /// Turn display off + 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 +84,7 @@ impl Display { ) .draw(&mut self.driver)?; self.driver.flush()?; + self.driver.set_display_on(true)?; Ok(()) } @@ -92,6 +101,7 @@ impl Display { ) .draw(&mut self.driver)?; self.driver.flush()?; + self.driver.set_display_on(true)?; Ok(()) } }