show FPS option
This commit is contained in:
parent
6328cd8145
commit
14f8512eca
@ -33,10 +33,16 @@ public:
|
|||||||
|
|
||||||
const uint16_t pixelCount;
|
const uint16_t pixelCount;
|
||||||
|
|
||||||
|
bool fpsShow = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Adafruit_NeoPixel leds;
|
Adafruit_NeoPixel leds;
|
||||||
|
|
||||||
|
unsigned long fpsLastMillis = 0;
|
||||||
|
|
||||||
|
int fps = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Display(uint8_t width, uint8_t height) :
|
Display(uint8_t width, uint8_t height) :
|
||||||
@ -109,7 +115,7 @@ public:
|
|||||||
if ((y % 2) != 0) {
|
if ((y % 2) != 0) {
|
||||||
x = width - x - 1;
|
x = width - x - 1;
|
||||||
}
|
}
|
||||||
leds.setPixelColor(y * width + x, color);
|
setIndex(y * width + x, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
@ -117,9 +123,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
calculateFPS();
|
||||||
|
drawFpsBorder();
|
||||||
leds.show();
|
leds.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void calculateFPS() {
|
||||||
|
fps = (int) round(1000.0 / (millis() - fpsLastMillis));
|
||||||
|
fpsLastMillis = millis();
|
||||||
|
}
|
||||||
|
|
||||||
void setBrightness(uint8_t brightness) {
|
void setBrightness(uint8_t brightness) {
|
||||||
leds.setBrightness(brightness);
|
leds.setBrightness(brightness);
|
||||||
}
|
}
|
||||||
@ -129,7 +142,53 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void setIndex(uint16_t index, uint8_t r, uint8_t g, uint8_t b) {
|
void setIndex(uint16_t index, uint8_t r, uint8_t g, uint8_t b) {
|
||||||
leds.setPixelColor(index, r, g, b);
|
uint32_t color = (r << 8 | g) << 8 | b;
|
||||||
|
setIndex(index, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setIndex(uint16_t index, uint32_t color) {
|
||||||
|
leds.setPixelColor(index, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawFpsBorder() {
|
||||||
|
if (!fpsShow) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int frames = fps;
|
||||||
|
|
||||||
|
uint8_t red = 255;
|
||||||
|
uint8_t green = 0;
|
||||||
|
uint8_t blue = 0;
|
||||||
|
if (frames > 3 * 76) {
|
||||||
|
frames -= 3 * 76;
|
||||||
|
red = 255;
|
||||||
|
green = 255;
|
||||||
|
blue = 255;
|
||||||
|
} else if (frames > 2 * 76) {
|
||||||
|
frames -= 2 * 76;
|
||||||
|
red = 0;
|
||||||
|
green = 0;
|
||||||
|
blue = 255;
|
||||||
|
} else if (frames > 76) {
|
||||||
|
frames -= 76;
|
||||||
|
red = 0;
|
||||||
|
green = 255;
|
||||||
|
blue = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x = 0; x <= width - 1 && frames-- > 0; x++) {
|
||||||
|
set(x, 0, red, green, blue);
|
||||||
|
}
|
||||||
|
for (int y = 0; y <= height - 1 && frames-- > 0; y++) {
|
||||||
|
set(width - 1, y, red, green, blue);
|
||||||
|
}
|
||||||
|
for (int x = width - 1; x >= 0 && frames-- > 0; x--) {
|
||||||
|
set(x, height - 1, red, green, blue);
|
||||||
|
}
|
||||||
|
for (int y = height - 1; y >= 0 && frames-- > 0; y--) {
|
||||||
|
set(0, y, red, green, blue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -32,7 +32,8 @@ void server_setup() {
|
|||||||
server.on("/faster", web_faster);
|
server.on("/faster", web_faster);
|
||||||
server.on("/faster/", web_faster);
|
server.on("/faster/", web_faster);
|
||||||
server.on("/slower", web_slower);
|
server.on("/slower", web_slower);
|
||||||
server.on("/slower/", web_slower);
|
server.on("/fps/on", web_fps_on);
|
||||||
|
server.on("/fps/off", web_fps_off);
|
||||||
server.begin();
|
server.begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,6 +56,7 @@ void web_index() {
|
|||||||
server.sendContent("<a href='/mode?mode=9'>NEW_YEAR</a><br>");
|
server.sendContent("<a href='/mode?mode=9'>NEW_YEAR</a><br>");
|
||||||
server.sendContent("Helligkeit: <a href='/brighter'>+</a> / <a href='/darker'>-</a><br>");
|
server.sendContent("Helligkeit: <a href='/brighter'>+</a> / <a href='/darker'>-</a><br>");
|
||||||
server.sendContent("Geschwindigkeit: <a href='/faster'>+</a> / <a href='/slower'>-</a><br>");
|
server.sendContent("Geschwindigkeit: <a href='/faster'>+</a> / <a href='/slower'>-</a><br>");
|
||||||
|
server.sendContent("FPS: <a href='/fps/on'>EIN</a> / <a href='/fps/off'>AUS</a><br>");
|
||||||
server.client().flush();
|
server.client().flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,3 +98,18 @@ void web_slower() {
|
|||||||
server.sendHeader("location", "/");
|
server.sendHeader("location", "/");
|
||||||
server.send(301, "text/plain", "ok");
|
server.send(301, "text/plain", "ok");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void web_fps_on() {
|
||||||
|
display.fpsShow = true;
|
||||||
|
redirect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void web_fps_off() {
|
||||||
|
display.fpsShow = false;
|
||||||
|
redirect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void redirect() {
|
||||||
|
server.sendHeader("location", "/");
|
||||||
|
server.send(301, "text/plain", "ok");
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user