From 6c297fab1ef9fc4bb5fe79f3aafd710187a03d43 Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Mon, 6 Feb 2017 16:03:15 -0500 Subject: [PATCH] Add nextFrameDEV() function for checking CPU load --- keywords.txt | 1 + src/Arduboy2.cpp | 12 ++++++++++++ src/Arduboy2.h | 29 ++++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/keywords.txt b/keywords.txt index 866dc2a..28442b8 100644 --- a/keywords.txt +++ b/keywords.txt @@ -57,6 +57,7 @@ invert KEYWORD2 justPressed KEYWORD2 justReleased KEYWORD2 nextFrame KEYWORD2 +nextFrameDEV KEYWORD2 notPressed KEYWORD2 off KEYWORD2 on KEYWORD2 diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index 9b5c5e5..e3666bb 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -169,6 +169,18 @@ bool Arduboy2Base::nextFrame() return post_render; } +bool Arduboy2Base::nextFrameDEV() { + bool ret = nextFrame(); + + if (ret) { + if (lastFrameDurationMs > eachFrameMillis) + TXLED1; + else + TXLED0; + } + return ret; +} + int Arduboy2Base::cpuLoad() { return lastFrameDurationMs*100 / eachFrameMillis; diff --git a/src/Arduboy2.h b/src/Arduboy2.h index 61740a3..1ef35a2 100644 --- a/src/Arduboy2.h +++ b/src/Arduboy2.h @@ -613,10 +613,37 @@ class Arduboy2Base : public Arduboy2Core * } * \endcode * - * \see setFrameRate() + * \see setFrameRate() nextFrameDEV() */ bool nextFrame(); + /** \brief + * Indicate that it's time to render the next frame, and visually indicate + * if the code is running slower than the desired frame rate. + * **FOR USE DURING DEVELOPMENT** + * + * \return `true` if it's time for the next frame. + * + * \details + * This function is intended to be used in place of `nextFrame()` during the + * development of a sketch. It does the same thing as `nextFrame()` but + * additionally will light the yellow TX LED (at the bottom, to the left + * of the USB connector) whenever a frame takes longer to generate than the + * time allotted per frame, as determined by the `setFrameRate()` function. + * + * Therefore, whenever the TX LED comes on (while not communicating over + * USB), it indicates that the sketch is running slower than the desired + * rate set by `setFrameRate()`. In this case the developer may wish to set + * a slower frame rate, or reduce or optimize the code for such frames. + * + * \note + * Once a sketch is ready for release, it would be expected that + * `nextFrameDEV()` calls be restored to `nextFrame()`. + * + * \see nextFrame() cpuLoad() setFrameRate() + */ + bool nextFrameDEV(); + /** \brief * Indicate if the specified number of frames has elapsed. *