From 15d1b0dab4ac6e1148d5115d17c6904ea942cd7b Mon Sep 17 00:00:00 2001 From: Scott Allen Date: Thu, 15 Sep 2016 18:12:27 -0400 Subject: [PATCH] Revert nextFrame() back to the original version A change made to nextFrame(), from the Arduboy library, caused it to not work correctly. The original version works as designed. Also: - Changed longs to unsigned longs for better type matching. - Removed the frameRate variable. It was being set but never used. - Added a missing return value to the write() function. - Changed a int8_t to uint8_t in function lcdCommandMode() to address a compiler warning. - Rearranged the specification of the font[] array to address a compiler warning. --- library.json | 2 +- library.properties | 2 +- src/Arduboy2.cpp | 26 ++++---------------------- src/Arduboy2.h | 5 ++--- src/ArduboyCore.cpp | 2 +- src/glcdfont.c | 2 +- 6 files changed, 10 insertions(+), 29 deletions(-) diff --git a/library.json b/library.json index b655a0a..9986fcc 100644 --- a/library.json +++ b/library.json @@ -7,7 +7,7 @@ "type": "git", "url": "https://github.com/MLXXXp/Arduboy2.git" }, - "version": "2.0.2", + "version": "2.0.3", "exclude": "extras", "frameworks": "arduino", "platforms": "atmelavr" diff --git a/library.properties b/library.properties index f8caa00..5c17c8e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduboy2 -version=2.0.2 +version=2.0.3 author=Chris J. Martinez, Kevin Bates, Josh Goebel, Scott Allen, Ross O. Shoger maintainer=Scott Allen saydisp-git@yahoo.ca sentence=An alternative library for use with the Arduboy game system. diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index f79e5a1..cfd08f3 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -112,8 +112,7 @@ void Arduboy2Base::bootLogo() void Arduboy2Base::setFrameRate(uint8_t rate) { - frameRate = rate; - eachFrameMillis = 1000/rate; + eachFrameMillis = 1000 / rate; } bool Arduboy2Base::everyXFrames(uint8_t frames) @@ -123,7 +122,7 @@ bool Arduboy2Base::everyXFrames(uint8_t frames) bool Arduboy2Base::nextFrame() { - long now = millis(); + unsigned long now = millis(); uint8_t remaining; // post render @@ -144,26 +143,8 @@ bool Arduboy2Base::nextFrame() } // pre-render - - // next frame should start from last frame start + frame duration - nextFrameStart = lastFrameStart + eachFrameMillis; - // If we're running CPU at 100%+ (too slow to complete each loop within - // the frame duration) then it's possible that we get "behind"... Say we - // took 5ms too long, resulting in nextFrameStart being 5ms in the PAST. - // In that case we simply schedule the next frame to start immediately. - // - // If we were to let the nextFrameStart slide further and further into - // the past AND eventually the CPU usage dropped then frame management - // would try to "catch up" (by speeding up the game) to make up for all - // that lost time. That would not be good. We allow frames to take too - // long (what choice do we have?), but we do not allow super-fast frames - // to make up for slow frames in the past. - if (nextFrameStart < now) { - nextFrameStart = now; - } - + nextFrameStart = now + eachFrameMillis; lastFrameStart = now; - post_render = true; return post_render; } @@ -783,6 +764,7 @@ size_t Arduboy2::write(uint8_t c) write('\n'); } } + return 1; } void Arduboy2::drawChar diff --git a/src/Arduboy2.h b/src/Arduboy2.h index 7ef79b6..3e1be37 100644 --- a/src/Arduboy2.h +++ b/src/Arduboy2.h @@ -222,11 +222,10 @@ protected: static uint8_t sBuffer[(HEIGHT*WIDTH)/8]; // For frame funcions - uint8_t frameRate; uint16_t frameCount; uint8_t eachFrameMillis; - long lastFrameStart; - long nextFrameStart; + unsigned long lastFrameStart; + unsigned long nextFrameStart; bool post_render; uint8_t lastFrameDurationMs; }; diff --git a/src/ArduboyCore.cpp b/src/ArduboyCore.cpp index 923d1d2..a5dc51e 100644 --- a/src/ArduboyCore.cpp +++ b/src/ArduboyCore.cpp @@ -169,7 +169,7 @@ void ArduboyCore::bootOLED() LCDCommandMode(); // run our customized boot-up command sequence against the // OLED to initialize it properly for Arduboy - for (int8_t i=0; i < sizeof(lcdBootProgram); i++) { + for (uint8_t i = 0; i < sizeof(lcdBootProgram); i++) { SPI.transfer(pgm_read_byte(lcdBootProgram + i)); } LCDDataMode(); diff --git a/src/glcdfont.c b/src/glcdfont.c index bcd778e..f8b3e86 100644 --- a/src/glcdfont.c +++ b/src/glcdfont.c @@ -5,7 +5,7 @@ #define FONT5X7_H // standard ascii 5x7 font -const static unsigned char font[] PROGMEM = +static const unsigned char font[] PROGMEM = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x5B, 0x4F, 0x5B, 0x3E,