-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add dial turn flash behavior and pulse interval setting * Swap dial turn led indication to default on state * Update to latest panel-protocol * This is for Edward * Add fade * Fix fading * Remove extra comments * Update to latest 0.4 * Add full fading for all colors * Slightly adjust fade constant for more of a trail * Add dial turn flash behavior and pulse interval setting * This is for Edward * Add fade * Update to latest 0.4 * Add full fading for all colors * Slightly adjust fade constant for more of a trail * Break out rgb, general cleanup, adjust constants * Minor cleanup for dialturn logic * Update fade constant and move it * Cleanup naming and visibility * Fix target_led_color naming * One more naming fix * One more naming fix again Co-authored-by: Brian Schwind <[email protected]>
- Loading branch information
Showing
3 changed files
with
89 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use core::ops::{Add, Mul}; | ||
|
||
#[derive(Copy, Clone)] | ||
pub struct Rgb { | ||
/// All in the range 0.0 - 255.0 | ||
/// Rounded when actually in use | ||
r: f32, | ||
g: f32, | ||
b: f32, | ||
} | ||
|
||
impl Rgb { | ||
pub fn new(r: f32, g: f32, b: f32) -> Self { | ||
Self { r, g, b } | ||
} | ||
|
||
pub fn new_from_u8(r: u8, g: u8, b: u8) -> Self { | ||
Self::new(r as f32, g as f32, b as f32) | ||
} | ||
|
||
/// Fade the current color toward the other one with a simple moving average | ||
pub fn fade_towards(&mut self, other: &Self, fade_const: f32) { | ||
*self = *self * fade_const + *other * (1.0 - fade_const); | ||
} | ||
|
||
pub fn r(&self) -> u8 { | ||
self.r.clamp(0.0, 255.0) as u8 | ||
} | ||
|
||
pub fn g(&self) -> u8 { | ||
self.g.clamp(0.0, 255.0) as u8 | ||
} | ||
|
||
pub fn b(&self) -> u8 { | ||
self.b.clamp(0.0, 255.0) as u8 | ||
} | ||
} | ||
|
||
impl Mul<f32> for Rgb { | ||
type Output = Rgb; | ||
|
||
fn mul(self, rhs: f32) -> Self::Output { | ||
Rgb::new(self.r * rhs, self.g * rhs, self.b * rhs) | ||
} | ||
} | ||
|
||
impl Add<Rgb> for Rgb { | ||
type Output = Rgb; | ||
|
||
fn add(self, rhs: Rgb) -> Self::Output { | ||
Rgb::new(self.r + rhs.r, self.g + rhs.g, self.b + rhs.b) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters