This commit is contained in:
2025-09-13 17:55:22 +02:00
commit 0315b4a559
8 changed files with 2125 additions and 0 deletions

30
src/lib.rs Normal file
View File

@@ -0,0 +1,30 @@
#![no_std]
use rgb::Rgb;
/// Scales the requested brightness to stay within power consumption limits
pub fn brightness_for_mw(total_mw : u32, target : u8, max_power: u32) -> u8 {
let target32 = target as u32;
let requested_mw = (total_mw * target32) / 256;
if requested_mw > max_power {
((target32 * max_power) / requested_mw) as u8
} else {
target
}
}
/// Calculate the estimated power draw of a single pixel, in milliwatts
pub fn as_milliwatts(pixel: &Rgb<u8>) -> u32 {
// These values are copied from the original FastLED implementation
const RED_MW : u32 = 16 * 5; //< 16mA @ 5v = 80mW
const GREEN_MW : u32 = 11 * 5; //< 11mA @ 5v = 55mW
const BLUE_MW : u32 = 15 * 5; //< 15mA @ 5v = 75mW
const DARK_MW : u32 = 5; //< 1mA @ 5v = 5mW
let red = (pixel.r as u32 * RED_MW).wrapping_shr(8);
let green = (pixel.g as u32 * GREEN_MW).wrapping_shr(8);
let blue = (pixel.b as u32 * BLUE_MW).wrapping_shr(8);
red + green + blue + DARK_MW
}