diff options
author | Daniel Garcia <danielgarcia@gmail.com> | 2016-05-05 01:54:37 +0300 |
---|---|---|
committer | Daniel Garcia <danielgarcia@gmail.com> | 2016-05-05 01:54:37 +0300 |
commit | 3ddad32a30baadad98962086aee16d98974eae87 (patch) | |
tree | 9b2d530064874d5175d4b843eebd6b9ae69cf40a | |
parent | 160becb01f0e2bc11d630adbb24e84020e8c6ec2 (diff) |
Add calculate_max_brightness_for_power_mW/vmA functions to do power calculations on individual strips
-rw-r--r-- | power_mgt.cpp | 16 | ||||
-rw-r--r-- | power_mgt.h | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/power_mgt.cpp b/power_mgt.cpp index 95f98e5e..e197755f 100644 --- a/power_mgt.cpp +++ b/power_mgt.cpp @@ -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 diff --git a/power_mgt.h b/power_mgt.h index 5d0ec61c..1720befa 100644 --- a/power_mgt.h +++ b/power_mgt.h @@ -58,6 +58,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 /// to use. The result from this function will be no higher than the |