pub mod fonts;
pub mod logo;
use core::convert::Infallible;
use embedded_graphics_core::{pixelcolor::Rgb888, prelude::*};
use vex_sdk::{vexDisplayCopyRect, vexDisplayForegroundColor, vexDisplayRectFill};
use vexide::display::{Display, RenderMode, TouchEvent};
pub struct DisplayDriver {
display: Display,
buffer:
Box<[u32; Display::HORIZONTAL_RESOLUTION as usize * Display::VERTICAL_RESOLUTION as usize]>,
}
impl DisplayDriver {
#[must_use]
pub fn new(display: Display) -> Self {
Self {
display,
buffer: Box::new(
[0; Display::HORIZONTAL_RESOLUTION as usize *
Display::VERTICAL_RESOLUTION as usize],
),
}
}
#[must_use]
pub fn touch_status(&self) -> TouchEvent { self.display.touch_status() }
pub fn set_render_mode(&mut self, mode: RenderMode) { self.display.set_render_mode(mode); }
#[must_use]
pub fn render_mode(&self) -> RenderMode { self.display.render_mode() }
pub fn render(&mut self) { self.display.render(); }
}
impl OriginDimensions for DisplayDriver {
fn size(&self) -> Size {
Size {
width: Display::HORIZONTAL_RESOLUTION as _,
height: Display::VERTICAL_RESOLUTION as _,
}
}
}
impl DrawTarget for DisplayDriver {
type Color = Rgb888;
type Error = Infallible;
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where I: IntoIterator<Item = Pixel<Self::Color>> {
pixels.into_iter().for_each(|Pixel(pos, color)| {
if pos.x >= 0 &&
pos.x < Display::HORIZONTAL_RESOLUTION as i32 &&
pos.y >= 0 &&
pos.y < Display::VERTICAL_RESOLUTION as i32
{
unsafe {
vex_sdk::vexDisplayForegroundColor(color.into_storage());
vex_sdk::vexDisplayPixelSet(pos.x as u32, pos.y as u32);
}
}
});
Ok(())
}
fn fill_contiguous<I>(
&mut self,
area: &embedded_graphics_core::primitives::Rectangle,
colors: I,
) -> Result<(), Self::Error>
where
I: IntoIterator<Item = Self::Color>,
{
if let Some(bottom_right) = area.bottom_right() {
colors.into_iter().enumerate().for_each(|(i, color)| {
self.buffer[i] = color.into_storage();
});
unsafe {
vexDisplayCopyRect(
area.top_left.x,
area.top_left.y,
bottom_right.x,
bottom_right.y,
self.buffer.as_mut_ptr(),
area.size.width as i32,
);
}
}
Ok(())
}
fn fill_solid(
&mut self,
area: &embedded_graphics_core::primitives::Rectangle,
color: Self::Color,
) -> Result<(), Self::Error> {
if let Some(bottom_right) = area.bottom_right() {
unsafe {
vexDisplayForegroundColor(color.into_storage());
vexDisplayRectFill(
area.top_left.x,
area.top_left.y,
bottom_right.x,
bottom_right.y,
);
}
}
Ok(())
}
}