From 8791b646360164b3e68cdef81a0cc4aed142b5f2 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Fri, 6 Aug 2021 23:27:41 -0400 Subject: [PATCH] Rename RGB to Rgb --- src/color.rs | 28 ++++++++++++++-------------- src/pattern.rs | 10 +++++----- src/pattern/collide.rs | 14 +++++++------- src/pattern/fade.rs | 12 ++++++------ src/pattern/moving_pixel.rs | 10 +++++----- src/pattern/moving_rainbow.rs | 8 ++++---- src/pattern/solid.rs | 10 +++++----- src/ui.rs | 14 +++++++------- 8 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/color.rs b/src/color.rs index 8b40489..af4386f 100644 --- a/src/color.rs +++ b/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)); } } diff --git a/src/pattern.rs b/src/pattern.rs index a31fe23..8dbf662 100644 --- a/src/pattern.rs +++ b/src/pattern.rs @@ -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; - 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 { +// fn test_strip() -> Vec { // 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(); diff --git a/src/pattern/collide.rs b/src/pattern/collide.rs index fa28002..3366bbf 100644 --- a/src/pattern/collide.rs +++ b/src/pattern/collide.rs @@ -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, + lights_buf: Vec, } 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 } } diff --git a/src/pattern/fade.rs b/src/pattern/fade.rs index 4626eef..902ac25 100644 --- a/src/pattern/fade.rs +++ b/src/pattern/fade.rs @@ -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, + lights_buf: Vec, } 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 } } diff --git a/src/pattern/moving_pixel.rs b/src/pattern/moving_pixel.rs index 53d5ee3..a8694ee 100644 --- a/src/pattern/moving_pixel.rs +++ b/src/pattern/moving_pixel.rs @@ -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, + lights_buf: Vec, } 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 } } diff --git a/src/pattern/moving_rainbow.rs b/src/pattern/moving_rainbow.rs index b6264d4..644837b 100644 --- a/src/pattern/moving_rainbow.rs +++ b/src/pattern/moving_rainbow.rs @@ -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, + lights_buf: Vec, } impl MovingRainbow { pub const fn new() -> Self { @@ -31,10 +31,10 @@ impl Pattern for MovingRainbow { .into(), ) .copied() - .collect::>(); + .collect::>(); Ok(()) } - fn get_strip(&self) -> &[RGB] { + fn get_strip(&self) -> &[Rgb] { &self.lights_buf } } diff --git a/src/pattern/solid.rs b/src/pattern/solid.rs index 4b54403..53a4a07 100644 --- a/src/pattern/solid.rs +++ b/src/pattern/solid.rs @@ -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, + lights_buf: Vec, } 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 } } diff --git a/src/ui.rs b/src/ui.rs index bac603b..eec884f 100644 --- a/src/ui.rs +++ b/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, s: &str) -> Result<(), String> { .as_slice() { ["f", r, g, b] => { - let color = RGB( + let color = Rgb( r.parse::() .map_err(|_| String::from("Red could not be parsed"))?, g.parse::() @@ -34,11 +34,11 @@ fn parse_cmd(tx: &Sender, s: &str) -> Result<(), String> { let color_value = c .parse::() .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::() .map_err(|_| String::from("Red could not be parsed"))?, g.parse::() @@ -52,7 +52,7 @@ fn parse_cmd(tx: &Sender, s: &str) -> Result<(), String> { let color_value = c .parse::() .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, s: &str) -> Result<(), String> { } } -fn parse_color(r: &str, g: &str, b: &str) -> Result { - Ok(RGB( +fn parse_color(r: &str, g: &str, b: &str) -> Result { + Ok(Rgb( r.parse::() .map_err(|_| String::from("Red could not be parsed"))?, g.parse::()