text can now be drawed on screen
This commit is contained in:
Generated
+5
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
||||
Generated
+2
-2
@@ -25,7 +25,7 @@
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CASE_FROM_SWITCH/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_CLASS_MEMBERS_FROM_ACCESS_SPECIFIERS/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_COMMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="4" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_SIZE/@EntryValue" value="2" type="long" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INDENT_STYLE/@EntryValue" value="Space" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INITIALIZER_BRACES/@EntryValue" value="END_OF_LINE_NO_SPACE" type="string" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/INT_ALIGN_EQ/@EntryValue" value="false" type="bool" />
|
||||
@@ -82,7 +82,7 @@
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_ARGS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPACE_WITHIN_TEMPLATE_PARAMS/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/SPECIAL_ELSE_IF_TREATMENT/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="4" type="int" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/TAB_WIDTH/@EntryValue" value="2" type="long" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_BINARY_OPSIGN/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_DECLARATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/CodeStyle/CodeFormatting/CppFormatting/WRAP_AFTER_INVOCATION_LPAR/@EntryValue" value="false" type="bool" />
|
||||
|
||||
@@ -10,4 +10,7 @@
|
||||
#define TEXT_MAX_LENGTH 64
|
||||
#define MAX_TEXT_NODES_COUNT 4
|
||||
#define SMALL_TEXT_HEIGHT 7
|
||||
#define SMALL_TEXT_WIDTH 5
|
||||
#define SMALL_TEXT_WIDTH 5
|
||||
|
||||
#define MEDIUM_TEXT_HEIGHT 7
|
||||
#define MEDIUM_TEXT_WIDTH 5
|
||||
@@ -11,22 +11,76 @@
|
||||
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
|
||||
#endif
|
||||
|
||||
|
||||
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
|
||||
|
||||
TextNode text_nodes[MAX_TEXT_NODES_COUNT];
|
||||
|
||||
void addNewTextNode
|
||||
(
|
||||
char text[TEXT_MAX_LENGTH + 1], uint32_t color = 0x00010101, unsigned short pos_x = 65535, unsigned short pos_y = 0,
|
||||
bool is_small = true
|
||||
)
|
||||
{
|
||||
unsigned char text_length = strlen(text);
|
||||
if (text_length == 0){return;}
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (text_nodes[i].is_deleted)
|
||||
{
|
||||
strncpy(text_nodes[i].content, text, TEXT_MAX_LENGTH);
|
||||
text_nodes[i].color = color;
|
||||
text_nodes[i].pos_x = (pos_x == 65535) ? PANEL_MAX_X + 1 : pos_x;
|
||||
text_nodes[i].pos_y = pos_y;
|
||||
text_nodes[i].characterSize.height = is_small ? SMALL_TEXT_HEIGHT : MEDIUM_TEXT_HEIGHT;
|
||||
text_nodes[i].characterSize.width = is_small ? SMALL_TEXT_WIDTH : MEDIUM_TEXT_WIDTH;
|
||||
text_nodes[i].character_count = text_length;
|
||||
text_nodes[i].is_deleted = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void drawTextNodes()
|
||||
{
|
||||
for (unsigned char i = 0; i < MAX_TEXT_NODES_COUNT; i++)
|
||||
{
|
||||
if (!text_nodes[i].is_deleted)
|
||||
{
|
||||
Cursor cursor;
|
||||
cursor.x = text_nodes[i].pos_x;
|
||||
cursor.y = text_nodes[i].pos_y;
|
||||
|
||||
for (unsigned char j = 0; j < text_nodes[i].character_count; j++)
|
||||
{
|
||||
char ch = text_nodes[i].content[j];
|
||||
if (ch < '!' || ch > '~')
|
||||
{
|
||||
ch = ' ';
|
||||
}
|
||||
drawCharacter(font7x5[ch - '!'], text_nodes[i].characterSize.height, text_nodes[i].characterSize.width, text_nodes[i].color, &cursor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// void scrollTextNodeByAmount(unsigned )
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
pixels.begin();
|
||||
pixels.clear();
|
||||
drawCharacter(font7x5['A' - '!'], 7, 5, 0x00010101, &cursor1);
|
||||
|
||||
addNewTextNode("TEst", 0x0001700, 0, 0, true);
|
||||
drawTextNodes();
|
||||
pixels.show();
|
||||
start_server();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
shiftGivenRectangle(0, 0, 23, 7, 1);
|
||||
pixels.show();
|
||||
handle_server();
|
||||
}
|
||||
@@ -18,7 +18,7 @@ struct Pixel
|
||||
uint32_t color;
|
||||
};
|
||||
|
||||
struct Text
|
||||
struct TextNode
|
||||
{
|
||||
char content[TEXT_MAX_LENGTH];
|
||||
uint32_t color;
|
||||
@@ -30,10 +30,11 @@ struct Text
|
||||
unsigned short width;
|
||||
} characterSize;
|
||||
unsigned char character_count;
|
||||
bool deleted;
|
||||
bool is_deleted;
|
||||
bool is_scrolled;
|
||||
|
||||
|
||||
Text() : color(0), pos_x(0), pos_y(0), character_count(0), characterSize({7,5}), deleted(true) {}
|
||||
TextNode() : color(0), pos_x(0), pos_y(0), character_count(0), characterSize({7,5}), is_deleted(true) {}
|
||||
};
|
||||
|
||||
#endif // STRUCTS_H
|
||||
|
||||
Reference in New Issue
Block a user