build: configure different displays based on cargo configs

This commit is contained in:
2024-10-30 19:52:02 +01:00
parent 739d7c2e6d
commit f803d8fe93
7 changed files with 221 additions and 160 deletions

View File

@@ -1,9 +1,8 @@
use palette::convert::FromColorUnclamped;
use palette::encoding::srgb::Srgb;
use palette::Hsv;
use embedded_graphics::pixelcolor::RgbColor;
use embedded_graphics::pixelcolor::PixelColor;
use embedded_graphics::pixelcolor::raw::RawU8;
use crate::power::AsMilliwatts;
#[derive(PartialEq, Debug, Copy, Clone)]
pub struct RGB8 {
@@ -22,31 +21,6 @@ impl RGB8 {
}
}
impl RgbColor for RGB8 {
fn r(&self) -> u8 { self.red }
fn g(&self) -> u8 { self.green }
fn b(&self) -> u8 { self.blue }
const MAX_R: u8 = 255;
const MAX_G: u8 = 255;
const MAX_B: u8 = 255;
const BLACK: Self = Self::new(0, 0, 0);
const WHITE: Self = Self::new(255, 255, 255);
const RED: Self = Self::new(255, 0, 0);
const GREEN: Self = Self::new(0, 255, 0);
const BLUE: Self = Self::new(0, 0, 255);
const YELLOW: Self = Self::new(255, 0, 0);
const CYAN: Self = Self::new(0, 255, 0);
const MAGENTA: Self = Self::new(0, 0, 255);
}
impl PixelColor for RGB8 {
type Raw = RawU8;
}
impl FromColorUnclamped<Hsv<Srgb, u8>> for RGB8 {
fn from_color_unclamped(hsv: Hsv<Srgb, u8>) -> RGB8 {
if hsv.saturation == 0 {
@@ -70,3 +44,66 @@ impl FromColorUnclamped<Hsv<Srgb, u8>> for RGB8 {
}
}
}
impl AsMilliwatts for RGB8 {
fn as_milliwatts(&self) -> u32 {
const RED_MW : u32 = 16 * 5; //< 16mA @ 5v = 80mW
const GREEN_MW : u32 = 11 * 5; //< 11mA @ 5v = 55mW
const BLUE_MW : u32 = 15 * 5; //< 15mA @ 5v = 75mW
const DARK_MW : u32 = 1 * 5; //< 1mA @ 5v = 5mW
let red = (self.red as u32 * RED_MW).wrapping_shr(8);
let green = (self.green as u32 * GREEN_MW).wrapping_shr(8);
let blue = (self.blue as u32 * BLUE_MW).wrapping_shr(8);
return red + green + blue + DARK_MW;
}
}
#[cfg(feature="embedded-graphics")]
mod embedded_graphics {
use embedded_graphics::pixelcolor::RgbColor;
use embedded_graphics::pixelcolor::PixelColor;
use embedded_graphics::pixelcolor::raw::RawU8;
impl RgbColor for RGB8 {
fn r(&self) -> u8 { self.red }
fn g(&self) -> u8 { self.green }
fn b(&self) -> u8 { self.blue }
const MAX_R: u8 = 255;
const MAX_G: u8 = 255;
const MAX_B: u8 = 255;
const BLACK: Self = Self::new(0, 0, 0);
const WHITE: Self = Self::new(255, 255, 255);
const RED: Self = Self::new(255, 0, 0);
const GREEN: Self = Self::new(0, 255, 0);
const BLUE: Self = Self::new(0, 0, 255);
const YELLOW: Self = Self::new(255, 0, 0);
const CYAN: Self = Self::new(0, 255, 0);
const MAGENTA: Self = Self::new(0, 0, 255);
}
impl PixelColor for RGB8 {
type Raw = RawU8;
}
impl<T: RgbColor> AsMilliwatts for T {
fn as_milliwatts(&self) -> u32 {
const RED_MW : u32 = 16 * 5; //< 16mA @ 5v = 80mW
const GREEN_MW : u32 = 11 * 5; //< 11mA @ 5v = 55mW
const BLUE_MW : u32 = 15 * 5; //< 15mA @ 5v = 75mW
const DARK_MW : u32 = 1 * 5; //< 1mA @ 5v = 5mW
let red = (self.r() as u32 * RED_MW).wrapping_shr(8);
let green = (self.g() as u32 * GREEN_MW).wrapping_shr(8);
let blue = (self.b() as u32 * BLUE_MW).wrapping_shr(8);
return red + green + blue + DARK_MW;
}
}
}