Rename RGB to Rgb
This commit is contained in:
parent
fa2f55c170
commit
8791b64636
28
src/color.rs
28
src/color.rs
@ -1,6 +1,6 @@
|
||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||
pub struct RGB(pub u8, pub u8, pub u8);
|
||||
impl RGB {
|
||||
pub struct Rgb(pub u8, pub u8, pub u8);
|
||||
impl Rgb {
|
||||
pub const fn to_tuple(self) -> (u8, u8, u8) {
|
||||
(self.0, self.1, self.2)
|
||||
}
|
||||
@ -13,9 +13,9 @@ impl RGB {
|
||||
// }
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub const BLACK: RGB = RGB(0, 0, 0);
|
||||
pub const BLACK: Rgb = Rgb(0, 0, 0);
|
||||
#[allow(dead_code)]
|
||||
pub const WHITE: RGB = RGB(255, 255, 255);
|
||||
pub const WHITE: Rgb = Rgb(255, 255, 255);
|
||||
|
||||
// Corrections:
|
||||
// R: 0x10, G: 0x08, B: 0x00
|
||||
@ -33,14 +33,14 @@ pub const WHITE: RGB = RGB(255, 255, 255);
|
||||
// 177, 180, 182, 184, 186, 189, 191, 193, 196, 198, 200, 203, 205, 208, 210, 213, 215, 218, 220,
|
||||
// 223, 225, 228, 231, 233, 236, 239, 241, 244, 247, 249, 252, 255,
|
||||
// ];
|
||||
pub const RAINBOW: [RGB; 7] = [
|
||||
RGB(255, 0, 0), // R
|
||||
RGB(255, 128, 0), // O
|
||||
RGB(255, 255, 0), // Y
|
||||
RGB(0, 255, 0), // G
|
||||
RGB(0, 0, 255), // B
|
||||
RGB(75, 0, 130), // I
|
||||
RGB(148, 0, 211), // V
|
||||
pub const RAINBOW: [Rgb; 7] = [
|
||||
Rgb(255, 0, 0), // R
|
||||
Rgb(255, 128, 0), // O
|
||||
Rgb(255, 255, 0), // Y
|
||||
Rgb(0, 255, 0), // G
|
||||
Rgb(0, 0, 255), // B
|
||||
Rgb(75, 0, 130), // I
|
||||
Rgb(148, 0, 211), // V
|
||||
];
|
||||
|
||||
#[cfg(test)]
|
||||
@ -48,13 +48,13 @@ mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn test_to_tuple() {
|
||||
assert_eq!(RGB(213, 14, 0).to_tuple(), (213, 14, 0));
|
||||
assert_eq!(Rgb(213, 14, 0).to_tuple(), (213, 14, 0));
|
||||
assert_eq!(WHITE.to_tuple(), (255, 255, 255));
|
||||
assert_eq!(BLACK.to_tuple(), (0, 0, 0));
|
||||
}
|
||||
#[test]
|
||||
fn test_black() {
|
||||
// Most important because this will blank out the strip
|
||||
assert_eq!(BLACK, RGB(0, 0, 0));
|
||||
assert_eq!(BLACK, Rgb(0, 0, 0));
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::color::RGB;
|
||||
use crate::color::Rgb;
|
||||
|
||||
pub mod collide;
|
||||
pub mod fade;
|
||||
@ -14,20 +14,20 @@ pub use solid::Solid;
|
||||
pub trait Pattern: std::fmt::Debug {
|
||||
fn init(&mut self, num_lights: u16) -> Result<(), ()>;
|
||||
fn step(&mut self) -> Result<bool, ()>;
|
||||
fn get_strip(&self) -> &[RGB];
|
||||
// fn get_strip_mut(&mut self) -> &[RGB];
|
||||
fn get_strip(&self) -> &[Rgb];
|
||||
// fn get_strip_mut(&mut self) -> &[Rgb];
|
||||
}
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod tests {
|
||||
// use super::*;
|
||||
// const NUM_LIGHTS: u16 = 10;
|
||||
// fn test_strip() -> Vec<RGB> {
|
||||
// fn test_strip() -> Vec<Rgb> {
|
||||
// vec![color::BLACK; NUM_LIGHTS.into()]
|
||||
// }
|
||||
// #[test]
|
||||
// fn moving_pixel() {
|
||||
// let color = RGB(123, 152, 89);
|
||||
// let color = Rgb(123, 152, 89);
|
||||
// let mut pat = MovingPixel::new(color.clone());
|
||||
// let mut strip = test_strip();
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
use super::Pattern;
|
||||
use crate::color::{self, RGB};
|
||||
use crate::color::{self, Rgb};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Collide {
|
||||
num_lights: u16,
|
||||
left_color: RGB,
|
||||
right_color: RGB,
|
||||
conjoined_color: RGB,
|
||||
left_color: Rgb,
|
||||
right_color: Rgb,
|
||||
conjoined_color: Rgb,
|
||||
step: u16,
|
||||
step_max: u16,
|
||||
conjoined_bounds: (u16, u16),
|
||||
@ -14,10 +14,10 @@ pub struct Collide {
|
||||
offset: u16,
|
||||
previous_offset: u16,
|
||||
increase_offset: bool,
|
||||
lights_buf: Vec<RGB>,
|
||||
lights_buf: Vec<Rgb>,
|
||||
}
|
||||
impl Collide {
|
||||
pub const fn new(left_color: RGB, right_color: RGB, conjoined_color: RGB) -> Self {
|
||||
pub const fn new(left_color: Rgb, right_color: Rgb, conjoined_color: Rgb) -> Self {
|
||||
Self {
|
||||
num_lights: 0,
|
||||
left_color,
|
||||
@ -147,7 +147,7 @@ impl Pattern for Collide {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_strip(&self) -> &[RGB] {
|
||||
fn get_strip(&self) -> &[Rgb] {
|
||||
&self.lights_buf
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
use super::Pattern;
|
||||
use crate::color::{self, RGB};
|
||||
use crate::color::{self, Rgb};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Fade {
|
||||
color: RGB,
|
||||
color: Rgb,
|
||||
step: u8,
|
||||
direction: bool,
|
||||
num_lights: u16,
|
||||
lights_buf: Vec<RGB>,
|
||||
lights_buf: Vec<Rgb>,
|
||||
}
|
||||
impl Fade {
|
||||
pub const fn new(color: RGB) -> Self {
|
||||
pub const fn new(color: Rgb) -> Self {
|
||||
Self {
|
||||
color,
|
||||
step: 0,
|
||||
@ -33,7 +33,7 @@ impl Pattern for Fade {
|
||||
}
|
||||
self.step = self.step.saturating_sub(1);
|
||||
}
|
||||
self.lights_buf = vec![RGB(self.step, self.step, self.step); self.num_lights.into()];
|
||||
self.lights_buf = vec![Rgb(self.step, self.step, self.step); self.num_lights.into()];
|
||||
Ok(true)
|
||||
}
|
||||
fn init(&mut self, num_lights: u16) -> Result<(), ()> {
|
||||
@ -46,7 +46,7 @@ impl Pattern for Fade {
|
||||
self.lights_buf = vec![color::BLACK; self.num_lights.into()];
|
||||
Ok(())
|
||||
}
|
||||
fn get_strip(&self) -> &[RGB] {
|
||||
fn get_strip(&self) -> &[Rgb] {
|
||||
&self.lights_buf
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,16 @@
|
||||
use super::Pattern;
|
||||
use crate::color::{self, RGB};
|
||||
use crate::color::{self, Rgb};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MovingPixel {
|
||||
color: RGB,
|
||||
color: Rgb,
|
||||
num_lights: u16,
|
||||
step: u16,
|
||||
lights_buf: Vec<RGB>,
|
||||
lights_buf: Vec<Rgb>,
|
||||
}
|
||||
|
||||
impl MovingPixel {
|
||||
pub const fn new(color: RGB) -> Self {
|
||||
pub const fn new(color: Rgb) -> Self {
|
||||
Self {
|
||||
color,
|
||||
step: 0,
|
||||
@ -42,7 +42,7 @@ impl Pattern for MovingPixel {
|
||||
*self.lights_buf.get_mut(0).ok_or(())? = self.color;
|
||||
Ok(())
|
||||
}
|
||||
fn get_strip(&self) -> &[RGB] {
|
||||
fn get_strip(&self) -> &[Rgb] {
|
||||
&self.lights_buf
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
use super::Pattern;
|
||||
use crate::color::{RAINBOW, RGB};
|
||||
use crate::color::{Rgb, RAINBOW};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MovingRainbow {
|
||||
lights_buf: Vec<RGB>,
|
||||
lights_buf: Vec<Rgb>,
|
||||
}
|
||||
impl MovingRainbow {
|
||||
pub const fn new() -> Self {
|
||||
@ -31,10 +31,10 @@ impl Pattern for MovingRainbow {
|
||||
.into(),
|
||||
)
|
||||
.copied()
|
||||
.collect::<Vec<RGB>>();
|
||||
.collect::<Vec<Rgb>>();
|
||||
Ok(())
|
||||
}
|
||||
fn get_strip(&self) -> &[RGB] {
|
||||
fn get_strip(&self) -> &[Rgb] {
|
||||
&self.lights_buf
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
use super::Pattern;
|
||||
use crate::color::RGB;
|
||||
use crate::color::Rgb;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Solid {
|
||||
color: RGB,
|
||||
color: Rgb,
|
||||
has_run: bool,
|
||||
lights_buf: Vec<RGB>,
|
||||
lights_buf: Vec<Rgb>,
|
||||
}
|
||||
impl Solid {
|
||||
pub const fn new(color: RGB) -> Self {
|
||||
pub const fn new(color: Rgb) -> Self {
|
||||
Self {
|
||||
color,
|
||||
has_run: false,
|
||||
@ -31,7 +31,7 @@ impl Pattern for Solid {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_strip(&self) -> &[RGB] {
|
||||
fn get_strip(&self) -> &[Rgb] {
|
||||
&self.lights_buf
|
||||
}
|
||||
}
|
||||
|
14
src/ui.rs
14
src/ui.rs
@ -1,4 +1,4 @@
|
||||
use crate::color::RGB;
|
||||
use crate::color::Rgb;
|
||||
use crate::pattern::{self, Pattern};
|
||||
use crate::strip;
|
||||
use std::io;
|
||||
@ -20,7 +20,7 @@ fn parse_cmd(tx: &Sender<strip::Message>, s: &str) -> Result<(), String> {
|
||||
.as_slice()
|
||||
{
|
||||
["f", r, g, b] => {
|
||||
let color = RGB(
|
||||
let color = Rgb(
|
||||
r.parse::<u8>()
|
||||
.map_err(|_| String::from("Red could not be parsed"))?,
|
||||
g.parse::<u8>()
|
||||
@ -34,11 +34,11 @@ fn parse_cmd(tx: &Sender<strip::Message>, s: &str) -> Result<(), String> {
|
||||
let color_value = c
|
||||
.parse::<u8>()
|
||||
.map_err(|_| String::from("Could not parse color"))?;
|
||||
let color = RGB(color_value, color_value, color_value);
|
||||
let color = Rgb(color_value, color_value, color_value);
|
||||
change_pattern(tx, Box::new(pattern::Fade::new(color)))
|
||||
}
|
||||
["m", r, g, b] => {
|
||||
let color = RGB(
|
||||
let color = Rgb(
|
||||
r.parse::<u8>()
|
||||
.map_err(|_| String::from("Red could not be parsed"))?,
|
||||
g.parse::<u8>()
|
||||
@ -52,7 +52,7 @@ fn parse_cmd(tx: &Sender<strip::Message>, s: &str) -> Result<(), String> {
|
||||
let color_value = c
|
||||
.parse::<u8>()
|
||||
.map_err(|_| String::from("Could not parse color"))?;
|
||||
let color = RGB(color_value, color_value, color_value);
|
||||
let color = Rgb(color_value, color_value, color_value);
|
||||
change_pattern(tx, Box::new(pattern::MovingPixel::new(color)))
|
||||
},
|
||||
["c", r, g, b] => {
|
||||
@ -89,8 +89,8 @@ fn parse_cmd(tx: &Sender<strip::Message>, s: &str) -> Result<(), String> {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_color(r: &str, g: &str, b: &str) -> Result<RGB, String> {
|
||||
Ok(RGB(
|
||||
fn parse_color(r: &str, g: &str, b: &str) -> Result<Rgb, String> {
|
||||
Ok(Rgb(
|
||||
r.parse::<u8>()
|
||||
.map_err(|_| String::from("Red could not be parsed"))?,
|
||||
g.parse::<u8>()
|
||||
|
Loading…
Reference in New Issue
Block a user