main_backup.cpp
unknown
plain_text
7 months ago
2.6 kB
4
Indexable
#include <Arduino.h>
#include "epd_driver.h"
#include "firasans.h"
#include "../include/lightning.h"
#include "../include/rock.h"
#include "../include/scissors.h"
#include "../include/paper.h"
uint8_t *framebuffer;
int32_t cursor_x = 270;
int32_t cursor_y = 300;
const uint8_t* getImageData(const char* gesture, int &width, int &height) {
if (strcmp(gesture, "none") == 0) {
width = lightning_width;
height = lightning_height;
return lightning_data;
}
else if (strcmp(gesture, "rock") == 0) {
width = rock_width;
height = rock_height;
return rock_data;
} else if (strcmp(gesture, "paper") == 0) {
width = paper_width;
height = paper_height;
return paper_data;
} else if (strcmp(gesture, "scissors") == 0) {
width = scissors_width;
height = scissors_height;
return scissors_data;
}
return nullptr;
}
void displayText(const char* text) {
Serial.printf("Zeige Text: %s\n", text);
memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);
// **Schrift rendern**
cursor_x = 270;
cursor_y = 300;
write_string((GFXfont *)&FiraSans, (char *)text, &cursor_x, &cursor_y, framebuffer);
epd_poweron();
epd_clear();
epd_draw_grayscale_image(epd_full_screen(), framebuffer);
epd_poweroff();
}
void updateDisplay(const char* gesture) {
int width, height;
const uint8_t* imageData = getImageData(gesture, width, height);
if (imageData) {
Rect_t area = {
.x = (EPD_WIDTH - width) / 2,
.y = (EPD_HEIGHT - height) / 2,
.width = width,
.height = height
};
Serial.printf("Zeige Bild für Geste: %s\n", gesture);
epd_poweron();
epd_clear();
epd_draw_grayscale_image(area, (uint8_t *)imageData);
epd_poweroff();
} else {
Serial.println("Unbekannte Geste empfangen.");
}
}
void setup() {
Serial.begin(115200);
epd_init();
framebuffer = (uint8_t *)heap_caps_malloc(EPD_WIDTH * EPD_HEIGHT / 2, MALLOC_CAP_SPIRAM);
if (!framebuffer) {
Serial.println("Speicher konnte nicht allokiert werden!");
while (1);
}
memset(framebuffer, 0xFF, EPD_WIDTH * EPD_HEIGHT / 2);
Serial.println("System bereit. Warte auf Gesten...");
displayText("Gestenerkennung startet");
}
void loop() {
if (Serial.available() > 0) {
String gesture = Serial.readStringUntil('\n');
gesture.trim();
updateDisplay(gesture.c_str());
}
}
Editor is loading...
Leave a Comment