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 methods for changing colors
Browse files Browse the repository at this point in the history
  • Loading branch information
doinkythederp committed Nov 18, 2023
1 parent 68045ad commit 50c90aa
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
5 changes: 1 addition & 4 deletions pros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ 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",
] }
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"]
16 changes: 15 additions & 1 deletion pros/src/lcd/mod.rs
Original file line number Diff line number Diff line change
@@ -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<writer::ConsoleLcd> = {
Mutex::new(writer::ConsoleLcd::new())
Expand Down
10 changes: 1 addition & 9 deletions pros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T = ()> = core::result::Result<T, alloc::boxed::Box<dyn core::error::Error>>;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pros/src/lvgl/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@

pub mod colors;
47 changes: 22 additions & 25 deletions pros/src/sensors/vision.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -171,26 +168,26 @@ 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,
}
}
}
// 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 {
Expand Down

0 comments on commit 50c90aa

Please sign in to comment.