Merge branch 'main' into '44-als-gebruiker-wil-ik-dat-de-website-automatisch-het-aantal-nodes-dat-ik-heb-aangesloten-op-de'
# Conflicts: # arduino/node-code/node-code-final/node-code-final.ino # arduino/node-code/node-code-final/nodeCodeFinal.ino # arduino/node-code/node-code-final/nodeCodeHeader.h
This commit is contained in:
@@ -39,27 +39,5 @@ void loop() {
|
||||
// writeText(Answer[0], 2, 50, 300, 4000);
|
||||
displayText.writeText(Question[i], 3, 0, 0, 0, true, false);
|
||||
displayText.writeText(Answer[i], 3, 0, 200, 0, true, true);
|
||||
delay(20000);
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
// void writeText(char* text, int size, int posX, int posY, int screenTime, bool center){
|
||||
// //if true overwrites x
|
||||
// if (center){
|
||||
// posX = centerText(text);
|
||||
// }
|
||||
// tft.setCursor(posX, posY); // Set the cursor to the top left corner
|
||||
// tft.setTextSize(size); // Set textsize
|
||||
// tft.println(text);
|
||||
// delay(screenTime);
|
||||
// }
|
||||
|
||||
// int centerText(char* text) {
|
||||
// int16_t x1, y1;
|
||||
// uint16_t w, h;
|
||||
|
||||
// tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h); // Calculate the width of the text
|
||||
// int x = (tft.width() - w) / 2; // Calculate the x-coordinate for the centered text
|
||||
|
||||
// return x;
|
||||
// }
|
@@ -6,20 +6,21 @@ DisplayText::DisplayText(Adafruit_ST7796S_kbv& tftDisplay) : tft(tftDisplay) {
|
||||
tft.setCursor(0,0);
|
||||
tft.fillScreen(ST7796S_BLACK);
|
||||
}
|
||||
|
||||
//display text public function
|
||||
void DisplayText::writeText(char* text, int size, int posX, int posY, int screenTime, bool center, bool bottom) {
|
||||
if (center) {
|
||||
posX = centerText(text);
|
||||
}
|
||||
if (bottom) {
|
||||
posY = bottomText(text);
|
||||
}
|
||||
// if (bottom) {
|
||||
// posY = bottomText(text);
|
||||
// }
|
||||
tft.setCursor(posX, posY);
|
||||
tft.setTextSize(size);
|
||||
printWordsFull(text);
|
||||
delay(screenTime);
|
||||
}
|
||||
|
||||
//to center the text when enabled in the public function
|
||||
int DisplayText::centerText(char* text) {
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
@@ -28,45 +29,48 @@ int DisplayText::centerText(char* text) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int DisplayText::bottomText(char* text) {
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
|
||||
int y = (tft.height() - h);
|
||||
return y;
|
||||
}
|
||||
// //to display the text at the bottom when enabled in the public function
|
||||
// int DisplayText::bottomText(char* text) {
|
||||
// int16_t x1, y1;
|
||||
// uint16_t w, h;
|
||||
// tft.getTextBounds(text, 0, 0, &x1, &y1, &w, &h);
|
||||
// int y = (tft.height() - h);
|
||||
// return y;
|
||||
// }
|
||||
|
||||
//attempt to write the text out in full (wip)
|
||||
void DisplayText::printWordsFull(char* text) {
|
||||
|
||||
char* textArray[100];
|
||||
int i = 0;
|
||||
|
||||
char* textCopy = strdup(text);
|
||||
const int screenWidth = 320; // replace with your TFT display width
|
||||
const int lineHeight = 22; // replace with your text line height
|
||||
|
||||
char* word = strtok(text, " ");
|
||||
char line[100] = "";
|
||||
int lineCount = 0;
|
||||
|
||||
while (word != NULL) {
|
||||
textArray[i] = word;
|
||||
word = strtok(NULL, " ");
|
||||
i++;
|
||||
}
|
||||
char tempLine[100];
|
||||
strcpy(tempLine, line);
|
||||
strcat(tempLine, word);
|
||||
strcat(tempLine, " ");
|
||||
|
||||
int lineWidth = 0;
|
||||
int maxLineWidth = 320; // replace with the width of your TFT display
|
||||
int charWidth = 11; // replace with the width of your characters
|
||||
int16_t x1, y1;
|
||||
uint16_t w, h;
|
||||
tft.getTextBounds(tempLine, 0, 0, &x1, &y1, &w, &h);
|
||||
|
||||
for (int j = 0; j < i; j++) {
|
||||
int wordLength = strlen(textArray[j]);
|
||||
|
||||
// If the word won't fit on the current line, move to the next line
|
||||
if (lineWidth + wordLength * charWidth > maxLineWidth) {
|
||||
tft.println();
|
||||
lineWidth = 0;
|
||||
if (w > screenWidth && strlen(line) > 0) {
|
||||
tft.setCursor(0, lineHeight * lineCount);
|
||||
tft.println(line);
|
||||
lineCount++;
|
||||
strcpy(line, word);
|
||||
strcat(line, " ");
|
||||
} else {
|
||||
strcpy(line, tempLine);
|
||||
}
|
||||
|
||||
tft.print(textArray[j]);
|
||||
tft.print(" ");
|
||||
lineWidth += (wordLength + 1) * charWidth; // +1 for the space
|
||||
word = strtok(NULL, " ");
|
||||
}
|
||||
free(textCopy);
|
||||
|
||||
// print the last line
|
||||
tft.setCursor(0, lineHeight * lineCount);
|
||||
tft.println(line);
|
||||
}
|
@@ -8,7 +8,7 @@ class DisplayText {
|
||||
private:
|
||||
Adafruit_ST7796S_kbv& tft;
|
||||
int centerText(char* text);
|
||||
int bottomText(char* text);
|
||||
// int bottomText(char* text);
|
||||
void printWordsFull(char* text);
|
||||
|
||||
public:
|
||||
|
@@ -3,8 +3,6 @@
|
||||
#include "Adafruit_ST7796S_kbv.h"
|
||||
#include "displayText.h"
|
||||
|
||||
|
||||
|
||||
#define TFT_CS 14
|
||||
#define TFT_DC 13
|
||||
#define TFT_RST 12
|
||||
|
18
arduino/node-code/node-code-final/nodeCode.cpp
Normal file
18
arduino/node-code/node-code-final/nodeCode.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "arduino.h"
|
||||
#include "nodeCodeHeader.h"
|
||||
|
||||
nodeReadings::nodeReadings() {
|
||||
}
|
||||
|
||||
void nodeReadings::resetValues() {
|
||||
counter = 0;
|
||||
eCO2 = 0;
|
||||
TVOC = 0;
|
||||
temperature = 0;
|
||||
humidity = 0;
|
||||
currentMillis = 0;
|
||||
lastMillis = 0;
|
||||
errorSGP30 = false;
|
||||
errorDHT11 = false;
|
||||
noise = false;
|
||||
}
|
Reference in New Issue
Block a user