From: Tilman Sauerbeck Date: Tue, 31 Dec 2019 08:17:08 +0000 (+0100) Subject: common: Implement display::show_icon() and display::hide_icon(). X-Git-Url: http://git.code-monkey.de/?a=commitdiff_plain;h=a1fc8859c0fd557c5f9049e77d1c39fed791a042;p=gps-watch.git common: Implement display::show_icon() and display::hide_icon(). This only supports the alarm, heart and satellite icons for now, but not the battery meter icon. --- diff --git a/src/common/display.rs b/src/common/display.rs index 4f09ef5..04f6c35 100644 --- a/src/common/display.rs +++ b/src/common/display.rs @@ -32,6 +32,14 @@ pub struct Display { i2c_slave_address: u8, } +pub enum Icon { + SatelliteBody, + SatelliteWave1, + SatelliteWave2, + Heart, + Alarm, +} + fn delay(u: u32) { let mut r = u; @@ -73,6 +81,8 @@ fn delay2(u: u32) { } } +const ICON_COLUMN: usize = 8; + impl Display { pub fn new(reset_gpio: u32, reset_gpio_pin: u32, i2c_slave_address: u8) -> Display { Display { @@ -114,6 +124,30 @@ impl Display { } } + fn icon_row(&self, icon: Icon) -> usize { + match icon { + Icon::SatelliteBody => 31, + Icon::SatelliteWave1 => 29, + Icon::SatelliteWave2 => 27, + Icon::Heart => 45, + Icon::Alarm => 61, + } + } + + pub fn show_icon(&mut self, icon: Icon) { + let row = self.icon_row(icon); + + self.seek(row, ICON_COLUMN); + self.write_data(0x80); + } + + pub fn hide_icon(&mut self, icon: Icon) { + let row = self.icon_row(icon); + + self.seek(row, ICON_COLUMN); + self.write_data(0x00); + } + pub fn clear(&mut self) { self.seek(0, 0);