Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
feat(lcd): add LcdColor struct
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Nov 18, 2023
1 parent d2efe4d commit 68045ad
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
65 changes: 65 additions & 0 deletions pros/src/lcd/colors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
use core::ops::{Deref, DerefMut};
use pros_sys::lv_color_t;

Check failure on line 2 in pros/src/lcd/colors.rs

View workflow job for this annotation

GitHub Actions / Check

unresolved import `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<lv_color_t> 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);
}
1 change: 1 addition & 0 deletions pros/src/lcd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::sync::Mutex;
#[macro_use]
pub mod macros;
pub mod buttons;
pub mod colors;

pub(crate) mod writer;

Expand Down
28 changes: 26 additions & 2 deletions pros/src/sensors/vision.rs
Original file line number Diff line number Diff line change
@@ -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};

Check failure on line 3 in pros/src/sensors/vision.rs

View workflow job for this annotation

GitHub Actions / Check

unresolved import `pros_sys::lv_color_t`
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 {
Expand Down Expand Up @@ -168,6 +171,27 @@ impl From<u32> for Rgb {
}
}

impl From<Rgb> for LcdColor {
fn from(other: Rgb) -> Self {
Self(lv_color_t {
red: other.r,
green: other.g,
blue: other.b,
alpha: 0xFF,
})
}
}

impl From<LcdColor> for Rgb {
fn from(other: LcdColor) -> Self {
Self {
r: other.red,
g: other.green,
b: other.blue,
}
}
}

#[repr(u32)]
pub enum VisionZeroPoint {
TopLeft,
Expand Down

0 comments on commit 68045ad

Please sign in to comment.