ai added lifespans

This commit is contained in:
2026-02-06 09:51:22 +01:00
parent 88bf1e3bb2
commit 3695f1e139
4 changed files with 61 additions and 23 deletions
+47 -15
View File
@@ -41,14 +41,14 @@ short getTextNodeX2(TextNode *node)
void addNewTextNode void addNewTextNode
( (
char text[TEXT_MAX_LENGTH + 1], uint32_t color, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0, char text[TEXT_MAX_LENGTH + 1], uint32_t color, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0,
unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true, short disappear_time = -1
) )
{ {
unsigned char text_length = strlen(text); unsigned char text_length = strlen(text);
if (text_length == 0){return;} if (text_length == 0){return;}
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++) for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
{ {
if (text_nodes[i].is_deleted) if (text_nodes[i].disappear_time == 0)
{ {
strncpy(text_nodes[i].content, text, TEXT_MAX_LENGTH); strncpy(text_nodes[i].content, text, TEXT_MAX_LENGTH);
text_nodes[i].color = color; text_nodes[i].color = color;
@@ -69,7 +69,7 @@ void addNewTextNode
text_nodes[i].character_count = text_length; text_nodes[i].character_count = text_length;
text_nodes[i].scroll_slowness = scroll_slowness; text_nodes[i].scroll_slowness = scroll_slowness;
text_nodes[i].is_scrolling = is_scrolling; text_nodes[i].is_scrolling = is_scrolling;
text_nodes[i].is_deleted = false; text_nodes[i].disappear_time = disappear_time;
ever_created_text_nodes++; ever_created_text_nodes++;
if (handle_pos_via_cursor) if (handle_pos_via_cursor)
@@ -85,7 +85,7 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
{ {
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++) for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
{ {
if (text_nodes[i].is_deleted) {continue;} if (text_nodes[i].disappear_time == 0) {continue;}
if (text_nodes[i].is_scrolling) if (text_nodes[i].is_scrolling)
{ {
@@ -103,7 +103,7 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
{ {
if (x2 < 0) if (x2 < 0)
{ {
text_nodes[i].is_deleted = true; text_nodes[i].disappear_time = 1;
continue; continue;
} }
text_nodes[i].pos_x--; text_nodes[i].pos_x--;
@@ -112,7 +112,7 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
{ {
if (x1 > DISPLAY_MAX_X) if (x1 > DISPLAY_MAX_X)
{ {
text_nodes[i].is_deleted = true; text_nodes[i].disappear_time = 1;
continue; continue;
} }
text_nodes[i].pos_x++; text_nodes[i].pos_x++;
@@ -138,14 +138,14 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
void addNewMultiColor void addNewMultiColor
( (
char text[TEXT_MAX_LENGTH + 1], RGBWithIndex colors[4], unsigned char color_count, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0, char text[TEXT_MAX_LENGTH + 1], RGBWithIndex colors[4], unsigned char color_count, bool handle_pos_via_cursor = true, short pos_x = 0, short pos_y = 0,
unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true unsigned char scroll_slowness = 1, bool is_scrolling = true, bool is_small = true, short disappear_time = -1
) )
{ {
unsigned char text_length = strlen(text); unsigned char text_length = strlen(text);
if (text_length == 0){return;} if (text_length == 0){return;}
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++) for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
{ {
if (multi_color_text_node[i].is_deleted) if (multi_color_text_node[i].disappear_time == 0)
{ {
strncpy(multi_color_text_node[i].content, text, TEXT_MAX_LENGTH); strncpy(multi_color_text_node[i].content, text, TEXT_MAX_LENGTH);
multi_color_text_node[i].color_count = color_count; multi_color_text_node[i].color_count = color_count;
@@ -170,7 +170,7 @@ void addNewMultiColor
multi_color_text_node[i].character_count = text_length; multi_color_text_node[i].character_count = text_length;
multi_color_text_node[i].scroll_slowness = scroll_slowness; multi_color_text_node[i].scroll_slowness = scroll_slowness;
multi_color_text_node[i].is_scrolling = is_scrolling; multi_color_text_node[i].is_scrolling = is_scrolling;
multi_color_text_node[i].is_deleted = false; multi_color_text_node[i].disappear_time = disappear_time;
ever_created_multi_color_text_nodes++; ever_created_multi_color_text_nodes++;
if (handle_pos_via_cursor) if (handle_pos_via_cursor)
@@ -192,7 +192,7 @@ void scrollAllMultiColorTexts(bool split_scroll_mode = false)
{ {
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++) for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
{ {
if (multi_color_text_node[i].is_deleted) {continue;} if (multi_color_text_node[i].disappear_time == 0) {continue;}
if (multi_color_text_node[i].is_scrolling) if (multi_color_text_node[i].is_scrolling)
{ {
@@ -210,7 +210,7 @@ void scrollAllMultiColorTexts(bool split_scroll_mode = false)
{ {
if (x2 < 0) if (x2 < 0)
{ {
multi_color_text_node[i].is_deleted = true; multi_color_text_node[i].disappear_time = 1;
continue; continue;
} }
multi_color_text_node[i].pos_x--; multi_color_text_node[i].pos_x--;
@@ -219,7 +219,7 @@ void scrollAllMultiColorTexts(bool split_scroll_mode = false)
{ {
if (x1 > DISPLAY_MAX_X) if (x1 > DISPLAY_MAX_X)
{ {
multi_color_text_node[i].is_deleted = true; multi_color_text_node[i].disappear_time = 1;
continue; continue;
} }
multi_color_text_node[i].pos_x++; multi_color_text_node[i].pos_x++;
@@ -268,6 +268,36 @@ void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short po
} }
} }
void handleDisappearTimers()
{
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
{
if (text_nodes[i].disappear_time > 0)
{
text_nodes[i].disappear_time--;
if (text_nodes[i].disappear_time == 0)
{
fillPixels(text_nodes[i].pos_x, text_nodes[i].pos_y, getTextNodeX2(&text_nodes[i]), getTextNodeY2(&text_nodes[i]), 0);
}
}
}
}
void handleMultiColorDisappearTimers()
{
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
{
if (multi_color_text_node[i].disappear_time > 0)
{
multi_color_text_node[i].disappear_time--;
if (multi_color_text_node[i].disappear_time == 0)
{
fillPixels(multi_color_text_node[i].pos_x, multi_color_text_node[i].pos_y, getMultiColorTextNodeX2(&multi_color_text_node[i]), multi_color_text_node[i].pos_y + multi_color_text_node[i].characterSize.height - 1, 0);
}
}
}
}
void setup() void setup()
{ {
Serial.begin(115200); Serial.begin(115200);
@@ -276,11 +306,11 @@ void setup()
pixels.begin(); pixels.begin();
pixels.clear(); pixels.clear();
addNewTextNode("NET", 0xFF050505, false, 0, 0); addNewTextNode("NET", 0xFF050505, false, 0, 0, 1, true, true, -1);
addNewTextNode("AWAIT", 0xFF050505, false, 0, 9); addNewTextNode("AWAIT", 0xFF050505, false, 0, 9, 1, true, true, -1);
RGBWithIndex colors[2] = {RGBWithIndex(255, 0, 0, 0), RGBWithIndex(0, 0, 255, 6)}; RGBWithIndex colors[2] = {RGBWithIndex(255, 0, 0, 0), RGBWithIndex(0, 0, 255, 6)};
addNewMultiColor("HELLO WORLD", colors, 2, false, 0, 0, 1, true, true); addNewMultiColor("HELLO WORLD", colors, 2, false, 0, 0, 1, true, true, -1);
pixels.show(); pixels.show();
start_server(); start_server();
@@ -290,6 +320,8 @@ void loop()
{ {
pixels.clear(); pixels.clear();
handle_server(); handle_server();
handleDisappearTimers();
handleMultiColorDisappearTimers();
scrollAllScrollableTexts(); scrollAllScrollableTexts();
scrollAllMultiColorTexts(); scrollAllMultiColorTexts();
+7 -2
View File
@@ -16,11 +16,16 @@ void drawImageFromMemoryByIndex(unsigned char image_index, short pos_x, short po
void setPixel(short x, short y, uint32_t color); void setPixel(short x, short y, uint32_t color);
void start_server(); void start_server();
void handle_server(); void handle_server();
void addNewTextNode(char text[TEXT_MAX_LENGTH + 1], uint32_t color, bool handle_pos_via_cursor, short pos_x, short pos_y, unsigned char scroll_slowness, bool is_scrolling, bool is_small); void addNewTextNode(char text[TEXT_MAX_LENGTH + 1], uint32_t color, bool handle_pos_via_cursor, short pos_x, short pos_y, unsigned char scroll_slowness, bool is_scrolling, bool is_small, short disappear_time);
void scrollAllScrollableTexts(bool split_scroll_mode); void scrollAllScrollableTexts(bool split_scroll_mode);
void addNewMultiColor(char text[TEXT_MAX_LENGTH + 1], RGBWithIndex colors[4], unsigned char color_count, bool handle_pos_via_cursor, short pos_x, short pos_y, unsigned char scroll_slowness, bool is_scrolling, bool is_small); void addNewMultiColor(char text[TEXT_MAX_LENGTH + 1], RGBWithIndex colors[4], unsigned char color_count, bool handle_pos_via_cursor, short pos_x, short pos_y, unsigned char scroll_slowness, bool is_scrolling, bool is_small, short disappear_time);
void scrollAllMultiColorTexts(bool split_scroll_mode); void scrollAllMultiColorTexts(bool split_scroll_mode);
void drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, uint32_t color, Cursor (*used_cursor)); void drawCharacter(const bool (*character)[5], unsigned char height, unsigned char width, uint32_t color, Cursor (*used_cursor));
void handleDisappearTimers();
void handleMultiColorDisappearTimers();
short getTextNodeY2(TextNode *node);
short getTextNodeX2(TextNode *node);
short getMultiColorTextNodeX2(MultiColorTextNode *node);
#endif // PROTOTYPES_H #endif // PROTOTYPES_H
+3 -2
View File
@@ -103,6 +103,7 @@ void handleText() {
String colorStr = server.arg("color"); String colorStr = server.arg("color");
String position = server.arg("position"); String position = server.arg("position");
unsigned char slowness = server.arg("slowness").toInt(); unsigned char slowness = server.arg("slowness").toInt();
short disappear_time = server.hasArg("disappear") ? server.arg("disappear").toInt() : -1;
char text[TEXT_MAX_LENGTH + 1]; char text[TEXT_MAX_LENGTH + 1];
text_str.toCharArray(text, TEXT_MAX_LENGTH + 1); text_str.toCharArray(text, TEXT_MAX_LENGTH + 1);
@@ -110,9 +111,9 @@ void handleText() {
uint32_t color = strtol(colorStr.substring(1).c_str(), NULL, 16); uint32_t color = strtol(colorStr.substring(1).c_str(), NULL, 16);
if (position == "top") { if (position == "top") {
addNewTextNode(text, color, false, 43, 0, slowness, true, false); addNewTextNode(text, color, false, 43, 0, slowness, true, false, disappear_time);
} else if (position == "bottom") { } else if (position == "bottom") {
addNewTextNode(text, color, false, -text_str.length() * 6, 9, slowness, true, false); addNewTextNode(text, color, false, -text_str.length() * 6, 9, slowness, true, false, disappear_time);
} }
server.send(200, "text/plain", "OK"); server.send(200, "text/plain", "OK");
+4 -4
View File
@@ -32,11 +32,11 @@ struct TextNode
unsigned char character_count; unsigned char character_count;
unsigned char scroll_slowness; unsigned char scroll_slowness;
unsigned char scroll_progress; unsigned char scroll_progress;
bool is_deleted; short disappear_time;
bool is_scrolling; bool is_scrolling;
TextNode() : color(0), pos_x(0), pos_y(0), character_count(0), scroll_slowness(0), scroll_progress(0), characterSize({7,5}), is_deleted(true), is_scrolling(true) {} TextNode() : color(0), pos_x(0), pos_y(0), character_count(0), scroll_slowness(0), scroll_progress(0), characterSize({7,5}), disappear_time(0), is_scrolling(true) {}
}; };
struct RGB struct RGB
@@ -75,10 +75,10 @@ struct MultiColorTextNode
unsigned char character_count; unsigned char character_count;
unsigned char scroll_slowness; unsigned char scroll_slowness;
unsigned char scroll_progress; unsigned char scroll_progress;
bool is_deleted; short disappear_time;
bool is_scrolling; bool is_scrolling;
MultiColorTextNode() : pos_x(0), pos_y(0), character_count(0), scroll_slowness(0), scroll_progress(0), characterSize({7,5}), is_deleted(true), is_scrolling(true), color_count(0) {} MultiColorTextNode() : pos_x(0), pos_y(0), character_count(0), scroll_slowness(0), scroll_progress(0), characterSize({7,5}), disappear_time(0), is_scrolling(true), color_count(0) {}
}; };
struct Image struct Image