Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Garcia <danielgarcia@gmail.com>2015-11-12 02:11:55 +0300
committerDaniel Garcia <danielgarcia@gmail.com>2015-11-12 02:11:55 +0300
commit6ebcb6436273cc9a9dc91733af8dfd1fedde6d60 (patch)
tree92aef5d8fbd2dc768c250b4a03a49bced5a04303
parent270932ad0d7c6e874f4026632cd83167d4d88c4b (diff)
Rolled power management back into the FastLED object directly - mark the old external power management functions as deprecated
-rw-r--r--FastLED.cpp11
-rw-r--r--FastLED.h18
-rw-r--r--power_mgt.cpp21
-rw-r--r--power_mgt.h4
-rw-r--r--release_notes.md1
5 files changed, 35 insertions, 20 deletions
diff --git a/FastLED.cpp b/FastLED.cpp
index 9de0ce33..6d4bf5e1 100644
--- a/FastLED.cpp
+++ b/FastLED.cpp
@@ -23,6 +23,8 @@ CFastLED::CFastLED() {
// m_nControllers = 0;
m_Scale = 255;
m_nFPS = 0;
+ m_pPowerFunc = NULL;
+ m_nPowerData = 0xFFFFFFFF;
}
CLEDController &CFastLED::addLeds(CLEDController *pLed,
@@ -42,6 +44,11 @@ void CFastLED::show(uint8_t scale) {
while(m_nMinMicros && ((micros()-lastshow) < m_nMinMicros));
lastshow = micros();
+ // If we have a function for computing power, use it!
+ if(m_pPowerFunc) {
+ scale = (*m_pPowerFunc)(scale, m_nPowerData);
+ }
+
CLEDController *pCur = CLEDController::head();
while(pCur) {
uint8_t d = pCur->getDither();
@@ -200,10 +207,10 @@ void CFastLED::countFPS(int nFrames) {
}
void CFastLED::setMaxRefreshRate(uint16_t refresh, bool constrain) {
- if(constrain) {
+ if(constrain) {
// if we're constraining, the new value of m_nMinMicros _must_ be higher than previously (because we're only
// allowed to slow things down if constraining)
- if(refresh > 0) {
+ if(refresh > 0) {
m_nMinMicros = ( (1000000/refresh) > m_nMinMicros) ? (1000000/refresh) : m_nMinMicros;
}
} else if(refresh > 0) {
diff --git a/FastLED.h b/FastLED.h
index a571fe0f..d77ea2f5 100644
--- a/FastLED.h
+++ b/FastLED.h
@@ -7,9 +7,9 @@
#define xstr(s) str(s)
#define str(s) #s
-#define FASTLED_VERSION 3001000
+#define FASTLED_VERSION 3001001
#ifndef FASTLED_INTERNAL
-#warning FastLED version 3.001.000 (Not really a warning, just telling you here.)
+#warning FastLED version 3.001.001 (Not really a warning, just telling you here.)
#endif
#ifndef __PROG_TYPES_COMPAT__
@@ -128,6 +128,8 @@ enum EBlockChipsets {
#define NUM_CONTROLLERS 8
#endif
+typedef uint8_t (*power_func)(uint8_t scale, uint32_t data);
+
/// High level controller interface for FastLED. This class manages controllers, global settings and trackings
/// such as brightness, and refresh rates, and provides access functions for driving led data to controllers
/// via the show/showColor/clear methods.
@@ -137,6 +139,9 @@ class CFastLED {
uint8_t m_Scale; ///< The current global brightness scale setting
uint16_t m_nFPS; ///< Tracking for current FPS value
uint32_t m_nMinMicros; ///< minimum µs between frames, used for capping frame rates.
+ uint32_t m_nPowerData; ///< max power use parameter
+ power_func m_pPowerFunc; ///< function for overriding brightness when using FastLED.show();
+
public:
CFastLED();
@@ -396,6 +401,15 @@ public:
/// @returns the current global brightness value
uint8_t getBrightness() { return m_Scale; }
+ /// Set the maximum power to be used, given in volts and milliamps.
+ /// @param volts - how many volts the leds are being driven at (usually 5 or 12)
+ /// @param milliamps - the maximum milliamps of power draw you want
+ inline void setMaxPowerInVoltsAndMilliamps(uint8_t volts, uint32_t milliamps) { setMaxPowerInMilliWatts(volts * milliamps); }
+
+ /// Set the maximum power to be used, given in milliwatts
+ /// @param milliwatts - the max power draw desired, in milliwatts
+ inline void setMaxPowerInMilliWatts(uint32_t milliwatts) { m_pPowerFunc = &calculate_max_brightness_for_power_mW; m_nPowerData = milliwatts; }
+
/// Update all our controllers with the current led colors, using the passed in brightness
/// @param scale temporarily override the scale
void show(uint8_t scale);
diff --git a/power_mgt.cpp b/power_mgt.cpp
index c4cbf548..95f98e5e 100644
--- a/power_mgt.cpp
+++ b/power_mgt.cpp
@@ -44,8 +44,6 @@ static const uint8_t gDark_mW = 1 * 5; // 1mA @ 5v = 5mW
// Power consumed by the MCU
static const uint8_t gMCU_mW = 25 * 5; // 25mA @ 5v = 125 mW
-
-static uint32_t gMaxPowerInMilliwatts = (uint32_t)(400) * (uint32_t)(5); // 400mA @ 5v default to avoid USB bricking
static uint8_t gMaxPowerIndicatorLEDPinNumber = 0; // default = Arduino onboard LED pin. set to zero to skip this.
@@ -149,32 +147,23 @@ void set_max_power_indicator_LED( uint8_t pinNumber)
void set_max_power_in_volts_and_milliamps( uint8_t volts, uint32_t milliamps)
{
- gMaxPowerInMilliwatts = (uint32_t)((uint32_t)(volts) * milliamps);
+ FastLED.setMaxPowerInVoltsAndMilliamps(volts, milliamps);
}
void set_max_power_in_milliwatts( uint32_t powerInmW)
{
- gMaxPowerInMilliwatts = powerInmW;
+ FastLED.setMaxPowerInMilliWatts(powerInmW);
}
void show_at_max_brightness_for_power()
{
- uint8_t targetBrightness = FastLED.getBrightness();
- uint8_t max = calculate_max_brightness_for_power_mW( targetBrightness, gMaxPowerInMilliwatts);
-
- FastLED.setBrightness( max );
- FastLED.show();
- FastLED.setBrightness( targetBrightness );
+ // power management usage is now in FastLED.show, no need for this function
+ FastLED.show();
}
void delay_at_max_brightness_for_power( uint16_t ms)
{
- uint8_t targetBrightness = FastLED.getBrightness();
- uint8_t max = calculate_max_brightness_for_power_mW( targetBrightness, gMaxPowerInMilliwatts);
-
- FastLED.setBrightness( max );
- FastLED.delay( ms);
- FastLED.setBrightness( targetBrightness );
+ FastLED.delay(ms);
}
FASTLED_NAMESPACE_END
diff --git a/power_mgt.h b/power_mgt.h
index 4672f0ea..9ff6f208 100644
--- a/power_mgt.h
+++ b/power_mgt.h
@@ -15,12 +15,14 @@ FASTLED_NAMESPACE_BEGIN
//
/// Set the maximum power used in milliamps for a given voltage
+/// @deprecated - use FastLED.setMaxPowerInVoltsAndMilliamps()
void set_max_power_in_volts_and_milliamps( uint8_t volts, uint32_t milliamps);
/// Set the maximum power used in watts
void set_max_power_in_milliwatts( uint32_t powerInmW);
/// Select a ping with an led that will be flashed to indicate that power management
/// is pulling down the brightness
+/// @deprecated - use FastLED.setMaxPowerInMilliWatts
void set_max_power_indicator_LED( uint8_t pinNumber); // zero = no indicator LED
@@ -38,9 +40,11 @@ void set_max_power_indicator_LED( uint8_t pinNumber); // zero = no indicator LED
/// Similar to FastLED.show, but pre-adjusts brightness to keep below the power
/// threshold.
+/// @deprecated this has now been moved to FastLED.show();
void show_at_max_brightness_for_power();
/// Similar to FastLED.delay, but pre-adjusts brightness to keep below the power
/// threshold.
+/// @deprecated this has now been rolled into FastLED.delay();
void delay_at_max_brightness_for_power( uint16_t ms);
diff --git a/release_notes.md b/release_notes.md
index e1496556..8b508d34 100644
--- a/release_notes.md
+++ b/release_notes.md
@@ -4,6 +4,7 @@ FastLED3.1.1pre
* Fix edge case bug w/HSV palette blending
* Fix power management issue w/parallel output
* Use static_asserts for some more useful compile time errors around bad pins
+* Roll power management into FastLED.show/delay directly
FastLED3.1.0
============