24 lines
859 B
Rust
24 lines
859 B
Rust
|
use embedded_graphics::pixelcolor::RgbColor;
|
||
|
|
||
|
pub fn colorToMW(color : impl RgbColor) -> u32 {
|
||
|
const gRed_mW : u32 = 16 * 5; //< 16mA @ 5v = 80mW
|
||
|
const gGreen_mW : u32 = 11 * 5; //< 11mA @ 5v = 55mW
|
||
|
const gBlue_mW : u32 = 15 * 5; //< 15mA @ 5v = 75mW
|
||
|
const gDark_mW : u32 = 1 * 5; //< 1mA @ 5v = 5mW
|
||
|
|
||
|
let redMW = (color.r() as u32 * gRed_mW).wrapping_shr(8);
|
||
|
let greenMW = (color.g() as u32 * gGreen_mW).wrapping_shr(8);
|
||
|
let blueMW = (color.b() as u32 * gBlue_mW).wrapping_shr(8);
|
||
|
|
||
|
return redMW + greenMW + blueMW + gDark_mW;
|
||
|
}
|
||
|
|
||
|
pub fn brightnessForMW(totalMW : u32, target : u8, maxPower: u32) -> u8 {
|
||
|
let target32 = target as u32;
|
||
|
let requestedMW = (totalMW * target32) / 256;
|
||
|
if requestedMW > maxPower {
|
||
|
return ((target32 * maxPower) / requestedMW).try_into().unwrap();
|
||
|
}
|
||
|
return target;
|
||
|
}
|