Skip to content

Commit

Permalink
Merge pull request #215 from andber1/impl-pixelcolor
Browse files Browse the repository at this point in the history
Implement PixelColor for Color and TriColor
  • Loading branch information
caemor authored Oct 30, 2024
2 parents 38b1031 + b01193a commit d9f9b4e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 2 additions & 3 deletions examples/epd7in5_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use embedded_graphics::{
primitives::{Circle, Line, PrimitiveStyleBuilder},
text::{Baseline, Text, TextStyleBuilder},
};
use embedded_graphics_core::pixelcolor::{BinaryColor, PixelColor};
use embedded_hal::delay::DelayNs;
#[cfg(feature = "graphics")]
use epd_waveshare::{color::Color, epd7in5_v2::*, graphics::DisplayRotation, prelude::*};
Expand Down Expand Up @@ -147,9 +146,9 @@ fn main() -> Result<(), SPIError> {
println!("Draw Ferris");
display.clear(Color::Black).ok();
let data = include_bytes!("./assets/ferris.raw");
let raw_image = ImageRaw::<BinaryColor>::new(data, 460);
let raw_image = ImageRaw::<Color>::new(data, 460);
let image = Image::new(&raw_image, Point::zero());
image.draw(&mut display.color_converted()).unwrap();
image.draw(&mut display).unwrap();
epd7in5.update_and_display_frame(&mut spi, display.buffer(), &mut delay)?;

// Clear and sleep
Expand Down
30 changes: 28 additions & 2 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,21 @@ impl From<u8> for Color {
}
}

#[cfg(feature = "graphics")]
impl From<embedded_graphics_core::pixelcolor::raw::RawU1> for Color {
fn from(b: embedded_graphics_core::pixelcolor::raw::RawU1) -> Self {
use embedded_graphics_core::prelude::RawData;
if b.into_inner() == 0 {
Color::White
} else {
Color::Black
}
}
}

#[cfg(feature = "graphics")]
impl PixelColor for Color {
type Raw = ();
type Raw = embedded_graphics_core::pixelcolor::raw::RawU1;
}

#[cfg(feature = "graphics")]
Expand Down Expand Up @@ -351,9 +363,23 @@ impl TriColor {
}
}

#[cfg(feature = "graphics")]
impl From<embedded_graphics_core::pixelcolor::raw::RawU2> for TriColor {
fn from(b: embedded_graphics_core::pixelcolor::raw::RawU2) -> Self {
use embedded_graphics_core::prelude::RawData;
if b.into_inner() == 0b00 {
TriColor::White
} else if b.into_inner() == 0b01 {
TriColor::Black
} else {
TriColor::Chromatic
}
}
}

#[cfg(feature = "graphics")]
impl PixelColor for TriColor {
type Raw = ();
type Raw = embedded_graphics_core::pixelcolor::raw::RawU2;
}

#[cfg(feature = "graphics")]
Expand Down

0 comments on commit d9f9b4e

Please sign in to comment.