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>2014-10-02 06:12:00 +0400
committerDaniel Garcia <danielgarcia@gmail.com>2014-10-02 06:12:00 +0400
commit1f0a65b39e9b0ad528fe74373ec871bb160f075a (patch)
tree540e72bafa6ab54dbf85f968a21c9df28d8a89e8
parent75e312d39e5c505231f14adb525c97d2b5f78447 (diff)
Tweak countFPS to only count (adding a getFPS method for getting the current FPS rate). Also, now that it only counts, modify Show method to always count.
-rw-r--r--FastLED.cpp30
-rw-r--r--FastLED.h9
2 files changed, 18 insertions, 21 deletions
diff --git a/FastLED.cpp b/FastLED.cpp
index b5a28ae9..814cfbf5 100644
--- a/FastLED.cpp
+++ b/FastLED.cpp
@@ -20,6 +20,7 @@ CFastLED::CFastLED() {
// clear out the array of led controllers
// m_nControllers = 0;
m_Scale = 255;
+ m_nFPS = 0;
}
CLEDController &CFastLED::addLeds(CLEDController *pLed,
@@ -39,6 +40,7 @@ void CFastLED::show(uint8_t scale) {
pCur->showLeds(scale);
pCur = pCur->next();
}
+ countFPS();
}
int CFastLED::count() {
@@ -69,6 +71,7 @@ void CFastLED::showColor(const struct CRGB & color, uint8_t scale) {
pCur->showColor(color, scale);
pCur = pCur->next();
}
+ countFPS();
}
void CFastLED::clear(boolean writeData) {
@@ -122,21 +125,14 @@ extern int noise_min;
extern int noise_max;
void CFastLED::countFPS(int nFrames) {
- if(Serial) {
- static int br = 0;
- static uint32_t lastframe = 0; // millis();
-
- br++;
- if(br == nFrames) {
- uint32_t now = millis();
- Serial.print(lastframe); Serial.print("ms and now it is "); Serial.print(now); Serial.println("ms");
- now -= lastframe;
- uint32_t fps = (br * 1000) / now;
- /*Serial.print('('); Serial.print(noise_min); Serial.print(','); Serial.print(noise_max); Serial.print(") "); */
- Serial.print(now); Serial.print("ms for "); Serial.print(br); Serial.print(" frames, aka ");
- Serial.print(fps); Serial.println(" fps. ");
- br = 0;
- lastframe = millis();
- }
- }
+ static int br = 0;
+ static uint32_t lastframe = 0; // millis();
+
+ if(br++ >= nFrames) {
+ uint32_t now = millis();
+ now -= lastframe;
+ m_nFPS = (br * 1000) / now;
+ br = 0;
+ lastframe = millis();
+ }
}
diff --git a/FastLED.h b/FastLED.h
index ff8300f8..c1990197 100644
--- a/FastLED.h
+++ b/FastLED.h
@@ -87,8 +87,8 @@ enum EBlockChipsets {
class CFastLED {
// int m_nControllers;
- uint8_t m_Scale;
-
+ uint8_t m_Scale;
+ uint16_t m_nFPS;
public:
CFastLED();
@@ -220,9 +220,10 @@ public:
void setDither(uint8_t ditherMode = BINARY_DITHER);
// for debugging, will keep track of time between calls to countFPS, and every
- // nFrames calls, it will print a summary of FPS info out to the serial port.
- // If the serial port isn't opened, this function does nothing.
+ // nFrames calls, it will update an internal counter for the current FPS.
void countFPS(int nFrames=25);
+ // Get the number of frames/second being written out
+ uint16_t getFPS();
// returns the number of controllers (strips) that have been added with addLeds
int count();