Skip to content

Commit

Permalink
add convert traits for TriColor
Browse files Browse the repository at this point in the history
  • Loading branch information
pbert committed Jun 18, 2022
1 parent b99a07c commit 3296c83
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,40 @@ impl PixelColor for TriColor {
type Raw = ();
}

#[cfg(feature = "graphics")]
impl From<BinaryColor> for TriColor {
fn from(b: BinaryColor) -> TriColor {
match b {
BinaryColor::On => TriColor::Black,
BinaryColor::Off => TriColor::White,
}
}
}
#[cfg(feature = "graphics")]
impl From<embedded_graphics_core::pixelcolor::Rgb888> for TriColor {
fn from(rgb: embedded_graphics_core::pixelcolor::Rgb888) -> Self {
use embedded_graphics_core::pixelcolor::RgbColor;
if rgb == RgbColor::BLACK {
TriColor::Black
} else if rgb == RgbColor::WHITE {
TriColor::White
} else {
TriColor::Chromatic
}
}
}
#[cfg(feature = "graphics")]
impl From<TriColor> for embedded_graphics_core::pixelcolor::Rgb888 {
fn from(tri_color: TriColor) -> Self {
use embedded_graphics_core::pixelcolor::RgbColor;
match tri_color {
TriColor::Black => embedded_graphics_core::pixelcolor::Rgb888::BLACK,
TriColor::White => embedded_graphics_core::pixelcolor::Rgb888::WHITE,
TriColor::Chromatic => embedded_graphics_core::pixelcolor::Rgb888::new(255, 0, 0),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 3296c83

Please sign in to comment.