diff --git a/pros/src/lcd/colors.rs b/pros/src/lcd/colors.rs new file mode 100644 index 00000000..eb84a638 --- /dev/null +++ b/pros/src/lcd/colors.rs @@ -0,0 +1,65 @@ +use core::ops::{Deref, DerefMut}; +use pros_sys::lv_color_t; + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct LcdColor(pub lv_color_t); + +impl LcdColor { + pub const fn new_rgb(red: u8, green: u8, blue: u8) -> Self { + Self(lv_color_t { + red, + green, + blue, + alpha: 0xFF, + }) + } + pub const fn new_rgba(red: u8, green: u8, blue: u8, alpha: u8) -> Self { + Self(lv_color_t { + red, + green, + blue, + alpha, + }) + } +} + +impl From for LcdColor { + fn from(other: lv_color_t) -> Self { + Self(other) + } +} + +impl Deref for LcdColor { + type Target = lv_color_t; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for LcdColor { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl LcdColor { + pub const WHITE: Self = Self::new_rgb(0xFF, 0xFF, 0xFF); + pub const SILVER: Self = Self::new_rgb(0xC0, 0xC0, 0xC0); + pub const GRAY: Self = Self::new_rgb(0x80, 0x80, 0x80); + pub const BLACK: Self = Self::new_rgb(0x00, 0x00, 0x00); + pub const RED: Self = Self::new_rgb(0xFF, 0x00, 0x00); + pub const MAROON: Self = Self::new_rgb(0x80, 0x00, 0x00); + pub const YELLOW: Self = Self::new_rgb(0xFF, 0xFF, 0x00); + pub const OLIVE: Self = Self::new_rgb(0x80, 0x80, 0x00); + pub const LIME: Self = Self::new_rgb(0x00, 0xFF, 0x00); + pub const GREEN: Self = Self::new_rgb(0x00, 0x80, 0x00); + pub const CYAN: Self = Self::new_rgb(0x00, 0xFF, 0xFF); + pub const AQUA: Self = Self::CYAN; + pub const TEAL: Self = Self::new_rgb(0x00, 0x80, 0x80); + pub const BLUE: Self = Self::new_rgb(0x00, 0x00, 0xFF); + pub const NAVY: Self = Self::new_rgb(0x00, 0x00, 0x80); + pub const MAGENTA: Self = Self::new_rgb(0xFF, 0x00, 0xFF); + pub const PURPLE: Self = Self::new_rgb(0x80, 0x00, 0x80); + pub const ORANGE: Self = Self::new_rgb(0xFF, 0xA5, 0x00); +} diff --git a/pros/src/lcd/mod.rs b/pros/src/lcd/mod.rs index 97361adf..2bf46cff 100644 --- a/pros/src/lcd/mod.rs +++ b/pros/src/lcd/mod.rs @@ -5,6 +5,7 @@ use crate::sync::Mutex; #[macro_use] pub mod macros; pub mod buttons; +pub mod colors; pub(crate) mod writer; diff --git a/pros/src/sensors/vision.rs b/pros/src/sensors/vision.rs index e4f5db66..9b9a2791 100644 --- a/pros/src/sensors/vision.rs +++ b/pros/src/sensors/vision.rs @@ -1,9 +1,12 @@ extern crate alloc; use alloc::vec::Vec; -use pros_sys::{PROS_ERR, VISION_OBJECT_ERR_SIG}; +use pros_sys::{lv_color_t, PROS_ERR, VISION_OBJECT_ERR_SIG}; use snafu::Snafu; -use crate::error::{bail_errno, bail_on, map_errno, PortError}; +use crate::{ + error::{bail_errno, bail_on, map_errno, PortError}, + lcd::colors::LcdColor, +}; /// Represents a vision sensor plugged into the vex. pub struct VisionSensor { @@ -168,6 +171,27 @@ impl From for Rgb { } } +impl From for LcdColor { + fn from(other: Rgb) -> Self { + Self(lv_color_t { + red: other.r, + green: other.g, + blue: other.b, + alpha: 0xFF, + }) + } +} + +impl From for Rgb { + fn from(other: LcdColor) -> Self { + Self { + r: other.red, + g: other.green, + b: other.blue, + } + } +} + #[repr(u32)] pub enum VisionZeroPoint { TopLeft,