aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgamerdonkey2025-04-05 15:18:29 -0500
committergamerdonkey2025-04-05 15:18:29 -0500
commita6f1fb40749a2bc24fc19c5ef00848cc6a76fcdc (patch)
treeb2cc702accae471f9b2f6340029c16e311c6591f
parentc6abf41ea1fc89a08677130275a9c1186df4f450 (diff)
downloadesp32-inova-led-controller-a6f1fb40749a2bc24fc19c5ef00848cc6a76fcdc.tar.gz
esp32-inova-led-controller-a6f1fb40749a2bc24fc19c5ef00848cc6a76fcdc.tar.bz2
esp32-inova-led-controller-a6f1fb40749a2bc24fc19c5ef00848cc6a76fcdc.zip
Making a formatted text object and some experimental usage.HEADmainesp32s3
-rw-r--r--main/CMakeLists.txt2
-rw-r--r--main/DisplayText.cpp62
-rw-r--r--main/DisplayText.h27
-rw-r--r--main/main.cpp46
4 files changed, 124 insertions, 13 deletions
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 114e8ad..0a16397 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -1,2 +1,2 @@
-idf_component_register(SRCS "main.cpp" "InovaLedDisplay.cpp"
+idf_component_register(SRCS "main.cpp" "InovaLedDisplay.cpp" "DisplayText.cpp"
INCLUDE_DIRS ".")
diff --git a/main/DisplayText.cpp b/main/DisplayText.cpp
new file mode 100644
index 0000000..ceeed86
--- /dev/null
+++ b/main/DisplayText.cpp
@@ -0,0 +1,62 @@
+#include "DisplayText.h"
+
+#include "InovaLedDisplay.h"
+
+
+DisplayText::DisplayText(std::string text, int16_t y, uint16_t color, int16_t alignment) {
+ this->text = text;
+ this->width = text.length() * 6;
+ this->scroll = (this->width > NUM_COL);
+ this->y = y;
+ this->color = color;
+
+ if(!scroll) {
+ // we only use alignment if we don't have to scroll
+
+ if(alignment < 0) {
+ this->x = 0;
+ }
+
+ else if(alignment == 0) {
+ this->x = (NUM_COL - this->width) / 2;
+ }
+
+ else if(alignment > 0) {
+ this->x = (NUM_COL - this->width);
+ }
+ }
+ else {
+ this->x = NUM_COL;
+ }
+}
+
+
+const char* DisplayText::getText() {
+ return text.c_str();
+}
+
+
+int16_t DisplayText::getX() {
+ return x;
+}
+
+
+int16_t DisplayText::getY() {
+ return y;
+}
+
+
+uint16_t DisplayText::getColor() {
+ return color;
+}
+
+
+void DisplayText::step() {
+ if(scroll) {
+ x--;
+
+ if(x < -width) {
+ x = NUM_COL;
+ }
+ }
+}
diff --git a/main/DisplayText.h b/main/DisplayText.h
new file mode 100644
index 0000000..57a739e
--- /dev/null
+++ b/main/DisplayText.h
@@ -0,0 +1,27 @@
+#ifndef DISPLAYTEXT_H
+#define DISPLAYTEXT_H
+
+#include <string>
+
+class DisplayText {
+ public:
+ DisplayText(std::string text, int16_t y, uint16_t color, int16_t alignment);
+
+ const char* getText();
+
+ int16_t getX();
+
+ int16_t getY();
+
+ uint16_t getColor();
+
+ void step();
+
+ private:
+ int16_t x, y, width;
+ uint16_t color;
+ bool scroll;
+ std::string text;
+};
+
+#endif
diff --git a/main/main.cpp b/main/main.cpp
index 7a1a082..b00f9e3 100644
--- a/main/main.cpp
+++ b/main/main.cpp
@@ -2,6 +2,7 @@
#include <string.h>
#include "InovaLedDisplay.h"
+#include "DisplayText.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@@ -46,16 +47,40 @@ extern "C" void app_main(void) {
xTaskCreate(runDisplayTask, "updateDisplay", STACK_SIZE, &display, tskIDLE_PRIORITY + 1, &taskHandle);
display.fillScreen(0);
-
- display.setTextColor(RED);
display.setTextWrap(false);
- display.setCursor(0, 0);
- display.print("Line 0 0123456789");
- display.setCursor(0, 8);
- display.print("Line 1 0123456789");
- display.setCursor(0, 16);
- display.print("Line 2 0123456789");
- display.swapBuffer();
+
+ DisplayText scene[] = {
+ DisplayText("LEFT", 0, RED, -1),
+ DisplayText("RIGHT", 0, GREEN, 1),
+ DisplayText("CENTER", 0, ORANGE, 0),
+ DisplayText("This text is too long to fit on a single line (105 chars) so it has to scroll in order for you to read it.", 8, GREEN, 0),
+ DisplayText("Bottom text.", 16, ORANGE, 0)
+ };
+ uint8_t sceneLength = 5;
+
+ uint8_t i;
+ while(true) {
+ for(i = 0; i < sceneLength; i++) {
+ display.setTextColor(scene[i].getColor());
+ display.setCursor(scene[i].getX(), scene[i].getY());
+ display.print(scene[i].getText());
+
+ scene[i].step();
+ }
+ display.swapBuffer();
+
+ vTaskDelay(50 / portTICK_PERIOD_MS);
+ }
+
+ /* display.setTextColor(RED); */
+ /* display.setTextWrap(false); */
+ /* display.setCursor(0, 0); */
+ /* display.print("Line 0 0123456789"); */
+ /* display.setCursor(0, 8); */
+ /* display.print("Line 1 0123456789"); */
+ /* display.setCursor(0, 16); */
+ /* display.print("Line 2 0123456789"); */
+ /* display.swapBuffer(); */
/*
int j = display.width();
@@ -78,7 +103,4 @@ extern "C" void app_main(void) {
vTaskDelay(50 / portTICK_PERIOD_MS);
}
*/
- while(true) {
- vTaskDelay(50 / portTICK_PERIOD_MS);
- }
}