reverting into node system
This commit is contained in:
@@ -18,15 +18,18 @@ Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
TextNode text_nodes[MAX_TEXT_NODES_COUNT];
|
||||
MultiColorTextNode multi_color_text_node[MAX_TEXT_NODES_COUNT];
|
||||
Cursor cursor;
|
||||
unsigned char ever_created_text_nodes = 0;
|
||||
unsigned char ever_created_multi_color_text_nodes = 0;
|
||||
unsigned char global_node_id = 0;
|
||||
|
||||
bool main_animation_started = false;
|
||||
unsigned char bottom_text_state = 0; // 0 = "Technik informatyk", 1 = "technik programista"
|
||||
unsigned char scroll_node_global_id = 0; // tracks current bottom-row node
|
||||
bool scroll_node_active = false;
|
||||
|
||||
Image saved_images[MAX_IMAGES_SAVED] = {
|
||||
{},{}
|
||||
};
|
||||
|
||||
|
||||
|
||||
short getTextNodeY2(TextNode *node)
|
||||
{
|
||||
return node->pos_y + node->characterSize.height - 1;
|
||||
@@ -38,14 +41,14 @@ short getTextNodeX2(TextNode *node)
|
||||
return node->pos_x + (node->characterSize.width * node->character_count) + (node->character_count - 1) - 1;
|
||||
}
|
||||
|
||||
void addNewTextNode
|
||||
TextNode* 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, bool is_repeating
|
||||
)
|
||||
{
|
||||
unsigned char text_length = strlen(text);
|
||||
if (text_length == 0){return;}
|
||||
if (text_length == 0){return nullptr;}
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (text_nodes[i].disappear_time == 0)
|
||||
@@ -71,23 +74,24 @@ void addNewTextNode
|
||||
text_nodes[i].is_scrolling = is_scrolling;
|
||||
text_nodes[i].is_repeating = is_repeating;
|
||||
text_nodes[i].disappear_time = disappear_time;
|
||||
text_nodes[i].id = ever_created_text_nodes;
|
||||
ever_created_text_nodes++;
|
||||
text_nodes[i].global_id = global_node_id;
|
||||
global_node_id++;
|
||||
|
||||
if (handle_pos_via_cursor)
|
||||
{
|
||||
cursor.x += (text_nodes[i].characterSize.width + 1) * text_length;
|
||||
}
|
||||
break;
|
||||
return &text_nodes[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void modifyTextNodeById(unsigned char id, uint32_t new_color, char new_text[TEXT_MAX_LENGTH + 1], unsigned char new_slowness)
|
||||
void modifyTextNodeByGlobalId(unsigned char global_id, uint32_t new_color, char new_text[TEXT_MAX_LENGTH + 1], unsigned char new_slowness)
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (text_nodes[i].id == id && text_nodes[i].disappear_time != 0)
|
||||
if (text_nodes[i].global_id == global_id && text_nodes[i].disappear_time != 0)
|
||||
{
|
||||
text_nodes[i].color = new_color;
|
||||
strncpy(text_nodes[i].content, new_text, TEXT_MAX_LENGTH);
|
||||
@@ -98,11 +102,11 @@ void modifyTextNodeById(unsigned char id, uint32_t new_color, char new_text[TEXT
|
||||
}
|
||||
}
|
||||
|
||||
void modifyMultiColorTextNodeById(unsigned char id, char new_text[TEXT_MAX_LENGTH + 1], RGBWithIndex new_colors[4], unsigned char new_color_count)
|
||||
void modifyMultiColorTextNodeByGlobalId(unsigned char global_id, char new_text[TEXT_MAX_LENGTH + 1], RGBWithIndex new_colors[4], unsigned char new_color_count)
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (multi_color_text_node[i].id == id && multi_color_text_node[i].disappear_time != 0)
|
||||
if (multi_color_text_node[i].global_id == global_id && multi_color_text_node[i].disappear_time != 0)
|
||||
{
|
||||
strncpy(multi_color_text_node[i].content, new_text, TEXT_MAX_LENGTH);
|
||||
multi_color_text_node[i].character_count = strlen(new_text);
|
||||
@@ -184,14 +188,14 @@ void scrollAllScrollableTexts(bool split_scroll_mode = false)
|
||||
}
|
||||
}
|
||||
|
||||
void addNewMultiColor
|
||||
MultiColorTextNode* 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, bool is_repeating
|
||||
)
|
||||
{
|
||||
unsigned char text_length = strlen(text);
|
||||
if (text_length == 0){return;}
|
||||
if (text_length == 0){return nullptr;}
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (multi_color_text_node[i].disappear_time == 0)
|
||||
@@ -221,16 +225,17 @@ void addNewMultiColor
|
||||
multi_color_text_node[i].is_scrolling = is_scrolling;
|
||||
multi_color_text_node[i].is_repeating = is_repeating;
|
||||
multi_color_text_node[i].disappear_time = disappear_time;
|
||||
multi_color_text_node[i].id = ever_created_multi_color_text_nodes;
|
||||
ever_created_multi_color_text_nodes++;
|
||||
multi_color_text_node[i].global_id = global_node_id;
|
||||
global_node_id++;
|
||||
|
||||
if (handle_pos_via_cursor)
|
||||
{
|
||||
cursor.x += (multi_color_text_node[i].characterSize.width + 1) * text_length;
|
||||
}
|
||||
break;
|
||||
return &multi_color_text_node[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
short getMultiColorTextNodeX2(MultiColorTextNode *node)
|
||||
@@ -363,6 +368,27 @@ void handleMultiColorDisappearTimers()
|
||||
}
|
||||
}
|
||||
|
||||
bool isNodeExistingByGlobal(unsigned char global_id)
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (text_nodes[i].global_id == global_id && text_nodes[i].disappear_time != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (multi_color_text_node[i].global_id == global_id && multi_color_text_node[i].disappear_time != 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void resetGlobalIdToAfterIntroValue()
|
||||
{
|
||||
global_node_id = 2;
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@@ -371,21 +397,61 @@ void setup()
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
|
||||
addNewTextNode("NET", 0xFF050505, false, 0, 0, 1, true, true, 100);
|
||||
addNewTextNode("AWAIT", 0xFF050505, false, 0, 9, 1, true, true, 100);
|
||||
addNewTextNode("NO", 0xFF050505, false, 0, 0, 1, true, true);
|
||||
addNewTextNode("INTERNET", 0xFF050505, false, 0, 9, 1, true, true);
|
||||
|
||||
scrollAllScrollableTexts(true);
|
||||
pixels.show();
|
||||
start_server();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (!main_animation_started)
|
||||
{
|
||||
if (!isNodeExistingByGlobal(0) && !isNodeExistingByGlobal(1))
|
||||
{
|
||||
main_animation_started = true;
|
||||
|
||||
// Top row: "Witamy w PTI" — slow scroll, repeating, white + blue PTI
|
||||
addNewMultiColor("Witamy w PTI",
|
||||
(RGBWithIndex[4]){
|
||||
{40, 40, 40, 0}, // white (dimmed) from char 0
|
||||
{0, 0, 50, 9} // blue (dimmed) from char 9 ("PTI")
|
||||
}, 2, false, 0, 0, 3, true, true, -1, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Bottom row: alternating scrolling texts
|
||||
if (main_animation_started &&
|
||||
(!scroll_node_active || !isNodeExistingByGlobal(scroll_node_global_id)))
|
||||
{
|
||||
TextNode* node = nullptr;
|
||||
if (bottom_text_state == 0)
|
||||
{
|
||||
node = addNewTextNode("Technik informatyk",
|
||||
pixels.Color(0, 0, 50), // blue (dimmed)
|
||||
false, DISPLAY_MAX_X, 9, 1, true, true, -1, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
node = addNewTextNode("technik programista",
|
||||
pixels.Color(50, 40, 0), // gold (dimmed)
|
||||
false, DISPLAY_MAX_X, 9, 1, true, true, -1, false);
|
||||
}
|
||||
if (node != nullptr)
|
||||
{
|
||||
scroll_node_global_id = node->global_id;
|
||||
scroll_node_active = true;
|
||||
bottom_text_state = (bottom_text_state + 1) % 2;
|
||||
}
|
||||
}
|
||||
|
||||
pixels.clear();
|
||||
handle_server();
|
||||
handleDisappearTimers();
|
||||
handleMultiColorDisappearTimers();
|
||||
scrollAllScrollableTexts();
|
||||
scrollAllMultiColorTexts();
|
||||
|
||||
scrollAllScrollableTexts(true);
|
||||
scrollAllMultiColorTexts(true);
|
||||
pixels.show();
|
||||
}
|
||||
Reference in New Issue
Block a user