Permalink
Browse files

Add calculate_max_brightness_for_power_mW/vmA functions to do power c…

…alculations on individual strips
  • Loading branch information...
focalintent committed May 4, 2016
1 parent 160becb commit 3ddad32a30baadad98962086aee16d98974eae87
Showing with 32 additions and 0 deletions.
  1. +16 −0 power_mgt.cpp
  2. +16 −0 power_mgt.h
View
@@ -77,6 +77,22 @@ uint32_t calculate_unscaled_power_mW( const CRGB* ledbuffer, uint16_t numLeds )
}
uint8_t calculate_max_brightness_for_power_vmA(const CRGB* ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_V, uint32_t max_power_mA) {
return calculate_max_brightness_for_power_mW(ledbuffer, numLeds, target_brightness, max_power_V * max_power_mA);
}
uint8_t calculate_max_brightness_for_power_mW(const CRGB* ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_mW) {
uint32_t total_mW = calculate_unscaled_power_mW( ledbuffer, numLeds);
uint32_t requested_power_mW = ((uint32_t)total_mW * target_brightness) / 256;
uint8_t recommended_brightness = target_brightness;
if(requested_power_mW > max_power_mW) {
recommended_brightness = (uint32_t)((uint8_t)(target_brightness) * (uint32_t)(max_power_mW)) / ((uint32_t)(requested_power_mW));
}
return recommended_brightness;
}
// sets brightness to
// - no more than target_brightness
View
@@ -57,6 +57,22 @@ void delay_at_max_brightness_for_power( uint16_t ms);
///
uint32_t calculate_unscaled_power_mW( const CRGB* ledbuffer, uint16_t numLeds);
/// calculate_max_brightness_for_power_mW tells you the highest brightness
/// level you can use and still stay under the specified power budget for
/// a given set of leds. It takes a pointer to an array of CRGB objects, a
/// count, a 'target brightness' which is the brightness you'd ideally like
/// to use, and the max power draw desired in milliwatts. The result from
/// this function will be no higher than the target_brightess you supply, but may be lower.
uint8_t calculate_max_brightness_for_power_mW(const CRGB* ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_mW);
/// calculate_max_brightness_for_power_mW tells you the highest brightness
/// level you can use and still stay under the specified power budget for
/// a given set of leds. It takes a pointer to an array of CRGB objects, a
/// count, a 'target brightness' which is the brightness you'd ideally like
/// to use, and the max power in volts and milliamps. The result from this
/// function will be no higher than the target_brightess you supply, but may be lower.
uint8_t calculate_max_brightness_for_power_vmA(const CRGB* ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_V, uint32_t max_power_mA);
/// calculate_max_brightness_for_power_mW tells you the highest brightness
/// level you can use and still stay under the specified power budget. It
/// takes a 'target brightness' which is the brightness you'd ideally like

0 comments on commit 3ddad32

Please sign in to comment.