FIX: Buffer overflow: Mode::timers
This commit is contained in:
parent
c562c7d932
commit
d53d60fb2c
@ -8,7 +8,6 @@
|
|||||||
#include "mode/NewYear/NewYear.h"
|
#include "mode/NewYear/NewYear.h"
|
||||||
#include "mode/Starfield/Starfield.h"
|
#include "mode/Starfield/Starfield.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "mode/Matrix/Matrix.h"
|
|
||||||
|
|
||||||
ModeId currentModeId = NONE;
|
ModeId currentModeId = NONE;
|
||||||
|
|
||||||
@ -23,8 +22,6 @@ void loadNewMode();
|
|||||||
void mode_step();
|
void mode_step();
|
||||||
|
|
||||||
void mode_loop() {
|
void mode_loop() {
|
||||||
Serial.print("\n");
|
|
||||||
|
|
||||||
if (currentModeId != config.mode) {
|
if (currentModeId != config.mode) {
|
||||||
unloadOldMode();
|
unloadOldMode();
|
||||||
loadNewMode();
|
loadNewMode();
|
||||||
@ -52,7 +49,6 @@ void setSpeed(double speed) {
|
|||||||
|
|
||||||
void unloadOldMode() {
|
void unloadOldMode() {
|
||||||
if (mode != nullptr) {
|
if (mode != nullptr) {
|
||||||
Serial.print("[MODE] unload\n");
|
|
||||||
delete mode;
|
delete mode;
|
||||||
mode = nullptr;
|
mode = nullptr;
|
||||||
}
|
}
|
||||||
@ -62,7 +58,6 @@ void unloadOldMode() {
|
|||||||
void loadNewMode() {
|
void loadNewMode() {
|
||||||
currentModeId = config.mode;
|
currentModeId = config.mode;
|
||||||
lastMicros = 0;
|
lastMicros = 0;
|
||||||
Serial.printf("[MODE] loading %d\n", currentModeId);
|
|
||||||
switch (currentModeId) {
|
switch (currentModeId) {
|
||||||
case BORDER:
|
case BORDER:
|
||||||
mode = new Border(display);
|
mode = new Border(display);
|
||||||
@ -94,9 +89,6 @@ void loadNewMode() {
|
|||||||
case STARFIELD:
|
case STARFIELD:
|
||||||
mode = new Starfield(display);
|
mode = new Starfield(display);
|
||||||
break;
|
break;
|
||||||
case MATRIX:
|
|
||||||
mode = new Matrix(display);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
Serial.print("No mode loaded.\n");
|
Serial.print("No mode loaded.\n");
|
||||||
display.clear();
|
display.clear();
|
||||||
|
|||||||
@ -19,10 +19,8 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
void draw(Display &display) override {
|
void draw(Display &display) override {
|
||||||
Serial.print("[BORDER] draw\n");
|
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
Serial.printf("[BORDER] draw %d / %d\n", x, y);
|
|
||||||
if (x == 0 || x == width - 1 || y == 0 || y == height - 1) {
|
if (x == 0 || x == width - 1 || y == 0 || y == height - 1) {
|
||||||
display.set(x, y, WHITE);
|
display.set(x, y, WHITE);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -16,7 +16,6 @@ enum ModeId {
|
|||||||
SPACE_INVADERS,
|
SPACE_INVADERS,
|
||||||
NEW_YEAR,
|
NEW_YEAR,
|
||||||
STARFIELD,
|
STARFIELD,
|
||||||
MATRIX,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Mode {
|
class Mode {
|
||||||
@ -83,18 +82,14 @@ public:
|
|||||||
virtual const char *getName() = 0;
|
virtual const char *getName() = 0;
|
||||||
|
|
||||||
void loop(microseconds_t dt) {
|
void loop(microseconds_t dt) {
|
||||||
Serial.print("[MODE] realtime\n");
|
|
||||||
realtime();
|
realtime();
|
||||||
|
|
||||||
Serial.print("[MODE] handleTimers\n");
|
|
||||||
handleTimers();
|
handleTimers();
|
||||||
|
|
||||||
Serial.print("[MODE] step\n");
|
|
||||||
step(dt);
|
step(dt);
|
||||||
|
|
||||||
if (dirty) {
|
if (dirty) {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
Serial.print("[MODE] draw\n");
|
|
||||||
draw(_display);
|
draw(_display);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user