repeating texts

This commit is contained in:
2026-02-06 10:40:56 +01:00
parent 10c11415c1
commit b9eabc2d61
5 changed files with 279 additions and 22 deletions
+105 -7
View File
@@ -98,27 +98,124 @@ void handleBmpUpload() {
void handleText() {
if (server.hasArg("text") && server.hasArg("color") && server.hasArg("position") && server.hasArg("slowness")) {
if (server.hasArg("text") && server.hasArg("color") && server.hasArg("slowness")) {
String text_str = server.arg("text");
String colorStr = server.arg("color");
String position = server.arg("position");
unsigned char slowness = server.arg("slowness").toInt();
short disappear_time = server.hasArg("disappear") ? server.arg("disappear").toInt() : -1;
bool is_small = true;
if (server.hasArg("fontSize") && server.arg("fontSize") != "") {
if (server.arg("fontSize") == "medium") {
is_small = false;
}
}
bool is_repeating = false;
if (server.hasArg("is_repeating")) {
is_repeating = server.arg("is_repeating") == "true";
}
char text[TEXT_MAX_LENGTH + 1];
text_str.toCharArray(text, TEXT_MAX_LENGTH + 1);
uint32_t color = strtol(colorStr.substring(1).c_str(), NULL, 16);
if (position == "top") {
addNewTextNode(text, color, false, 43, 0, slowness, true, false, disappear_time);
} else if (position == "bottom") {
addNewTextNode(text, color, false, -text_str.length() * 6, 9, slowness, true, false, disappear_time);
if (server.hasArg("position")) {
String position = server.arg("position");
if (position == "top") {
addNewTextNode(text, color, false, 43, 0, slowness, true, is_small, disappear_time, is_repeating);
} else if (position == "bottom") {
addNewTextNode(text, color, false, -text_str.length() * 6, 9, slowness, true, is_small, disappear_time, is_repeating);
}
server.send(200, "text/plain", "OK");
} else {
short x = 0;
short y = 0;
if (server.hasArg("x") && server.arg("x") != "") {
x = server.arg("x").toInt();
}
if (server.hasArg("y") && server.arg("y") != "") {
y = server.arg("y").toInt();
}
addNewTextNode(text, color, false, x, y, slowness, true, is_small, disappear_time, is_repeating);
server.send(200, "text/plain", "OK");
}
} else {
server.send(400, "text/plain", "Invalid arguments for /text");
}
}
void handleMulticolorText() {
if (server.hasArg("text") && server.hasArg("colors") && server.hasArg("slowness")) {
String text_str = server.arg("text");
String colors_str = server.arg("colors");
unsigned char slowness = server.arg("slowness").toInt();
short disappear_time = server.hasArg("disappear") ? server.arg("disappear").toInt() : -1;
bool is_small = true;
if (server.hasArg("fontSize") && server.arg("fontSize") != "") {
if (server.arg("fontSize") == "medium") {
is_small = false;
}
}
bool is_repeating = false;
if (server.hasArg("is_repeating")) {
is_repeating = server.arg("is_repeating") == "true";
}
char text[TEXT_MAX_LENGTH + 1];
text_str.toCharArray(text, TEXT_MAX_LENGTH + 1);
RGBWithIndex colors[4];
int color_count = 0;
String color_part = "";
int last_comma = -1;
for (int i = 0; i < colors_str.length() && color_count < 4; i++) {
if (colors_str.charAt(i) == ',') {
color_part = colors_str.substring(last_comma + 1, i);
last_comma = i;
if (color_part.length() > 0) {
long color_val = strtol(color_part.substring(1).c_str(), NULL, 16);
colors[color_count].r = (color_val >> 16) & 0xFF;
colors[color_count].g = (color_val >> 8) & 0xFF;
colors[color_count].b = color_val & 0xFF;
color_count++;
}
}
}
// last color
if (color_count < 4) {
color_part = colors_str.substring(last_comma + 1);
if (color_part.length() > 0) {
long color_val = strtol(color_part.substring(1).c_str(), NULL, 16);
colors[color_count].r = (color_val >> 16) & 0xFF;
colors[color_count].g = (color_val >> 8) & 0xFF;
colors[color_count].b = color_val & 0xFF;
color_count++;
}
}
if (color_count > 0) {
int text_len = text_str.length();
int part_len = text_len / color_count;
for (int i = 0; i < color_count; i++) {
colors[i].start_index = i * part_len;
}
}
short x = 0;
short y = 0;
if (server.hasArg("x") && server.arg("x") != "") {
x = server.arg("x").toInt();
}
if (server.hasArg("y") && server.arg("y") != "") {
y = server.arg("y").toInt();
}
addNewMultiColor(text, colors, color_count, false, x, y, slowness, true, is_small, disappear_time, is_repeating);
server.send(200, "text/plain", "OK");
} else {
server.send(400, "text/plain", "Invalid arguments");
server.send(400, "text/plain", "Invalid arguments for /multicolor-text");
}
}
@@ -137,6 +234,7 @@ void start_server()
server.on("/", handleRoot);
server.on("/text", HTTP_POST, handleText);
server.on("/multicolor-text", HTTP_POST, handleMulticolorText);
server.on("/brightness", HTTP_POST, handleBrightness);
server.on("/upload-page", HTTP_GET, handleUploadPage);
server.on("/upload-bmp", HTTP_POST, []() {