From 50c90aa8afe5f17c60d17a61f01d99e06c94a0ea Mon Sep 17 00:00:00 2001 From: doinkythederp Date: Fri, 17 Nov 2023 17:14:28 -0800 Subject: [PATCH] feat(lcd): add methods for changing colors --- pros/Cargo.toml | 5 +--- pros/src/lcd/mod.rs | 16 ++++++++++- pros/src/lib.rs | 10 +------ pros/src/{lcd => lvgl}/colors.rs | 0 pros/src/lvgl/mod.rs | 2 +- pros/src/sensors/vision.rs | 47 +++++++++++++++----------------- 6 files changed, 40 insertions(+), 40 deletions(-) rename pros/src/{lcd => lvgl}/colors.rs (100%) diff --git a/pros/Cargo.toml b/pros/Cargo.toml index e1e6fb27..3b9f4da3 100644 --- a/pros/Cargo.toml +++ b/pros/Cargo.toml @@ -14,7 +14,7 @@ readme = "../README.md" [dependencies] lazy_static = { version = "1.4.0", features = ["spin_no_std"] } spin = "0.9.8" -pros-sys = { version = "0.3.0", path = "../pros-sys" } +pros-sys = { version = "0.3.0", path = "../pros-sys", features = ["xapi"] } snafu = { version = "0.7.5", default-features = false, features = [ "rust_1_61", ] } @@ -22,6 +22,3 @@ no_std_io = { version = "0.6.0", features = ["alloc"] } [target.'cfg(target_arch = "wasm32")'.dependencies] dlmalloc = { version = "0.2.4", features = ["global"] } - -[features] -lvgl = ["pros-sys/xapi"] diff --git a/pros/src/lcd/mod.rs b/pros/src/lcd/mod.rs index 2bf46cff..8b7d3f14 100644 --- a/pros/src/lcd/mod.rs +++ b/pros/src/lcd/mod.rs @@ -1,14 +1,28 @@ use snafu::Snafu; +use crate::lvgl::colors::LcdColor; use crate::sync::Mutex; #[macro_use] pub mod macros; pub mod buttons; -pub mod colors; pub(crate) mod writer; +pub fn set_background_color(color: LcdColor) { + unsafe { + pros_sys::lcd_initialize(); + pros_sys::lcd_set_background_color(*color); + } +} + +pub fn set_text_color(color: LcdColor) { + unsafe { + pros_sys::lcd_initialize(); + pros_sys::lcd_set_background_color(*color); + } +} + lazy_static::lazy_static! { pub(crate) static ref WRITER: Mutex = { Mutex::new(writer::ConsoleLcd::new()) diff --git a/pros/src/lib.rs b/pros/src/lib.rs index 9e2598e4..700715f3 100644 --- a/pros/src/lib.rs +++ b/pros/src/lib.rs @@ -11,25 +11,17 @@ pub mod position; pub mod sensors; pub mod sync; pub mod task; - #[doc(hidden)] pub use pros_sys as __pros_sys; - #[cfg(target_os = "vexos")] mod vexos_env; #[cfg(target_arch = "wasm32")] mod wasm_env; - -#[cfg(not(feature = "lvgl"))] #[macro_use] pub mod lcd; - -#[cfg(feature = "lvgl")] -#[macro_use] -pub mod lvgl; - pub mod adi; pub mod link; +pub mod lvgl; pub type Result = core::result::Result>; diff --git a/pros/src/lcd/colors.rs b/pros/src/lvgl/colors.rs similarity index 100% rename from pros/src/lcd/colors.rs rename to pros/src/lvgl/colors.rs diff --git a/pros/src/lvgl/mod.rs b/pros/src/lvgl/mod.rs index 8b137891..40fd5c10 100644 --- a/pros/src/lvgl/mod.rs +++ b/pros/src/lvgl/mod.rs @@ -1 +1 @@ - +pub mod colors; diff --git a/pros/src/sensors/vision.rs b/pros/src/sensors/vision.rs index 9b9a2791..5bbd9163 100644 --- a/pros/src/sensors/vision.rs +++ b/pros/src/sensors/vision.rs @@ -1,12 +1,9 @@ extern crate alloc; use alloc::vec::Vec; -use pros_sys::{lv_color_t, PROS_ERR, VISION_OBJECT_ERR_SIG}; +use pros_sys::{PROS_ERR, VISION_OBJECT_ERR_SIG}; use snafu::Snafu; -use crate::{ - error::{bail_errno, bail_on, map_errno, PortError}, - lcd::colors::LcdColor, -}; +use crate::error::{bail_errno, bail_on, map_errno, PortError}; /// Represents a vision sensor plugged into the vex. pub struct VisionSensor { @@ -171,26 +168,26 @@ 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, - } - } -} +// 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 {