EdSaGfmvA/src/utils/displayController.c
2025-09-02 17:10:09 +02:00

67 lines
1.8 KiB
C

#include <zephyr/kernel.h>
#include <string.h>
#include <stdio.h>
#include "utils/displayController.h"
#include "epaper/epaper.h"
#include "oled/oled.h"
static enum display_type_e {
DISPLAY_NONE,
DISPLAY_OLED,
DISPLAY_EPD
} display_type = DISPLAY_NONE;
static int display_slot = 0;
static bool initialized = false;
void dc_init(const char *type_str, int slot) {
if (initialized) return;
display_slot = slot;
if (strcmp(type_str, "EPD") == 0) {
#if DT_NODE_EXISTS(DT_NODELABEL(epd))
epd_init();
epd_draw_something(' ');
display_type = DISPLAY_EPD;
printk("EPD Display initialisiert (Slot %d)\n", slot);
#else
printk("Fehler: EPD ausgewählt, aber nicht im Devicetree vorhanden!\n");
return;
#endif
} else if (strcmp(type_str, "OLED") == 0) {
#if DT_NODE_EXISTS(DT_NODELABEL(oled))
oled_init();
oled_draw_something(' ');
display_type = DISPLAY_OLED;
printk("OLED Display initialisiert (Slot %d)\n", slot);
#endif
} else {
display_type = DISPLAY_NONE;
printk("Unbekannter Displaytyp: %s (Slot %d)\n", type_str, slot);
}
initialized = true;
}
void dc_draw_something(const char *message) {
char to_draw = message[display_slot];
switch (display_type) {
case DISPLAY_EPD:
#if DT_NODE_EXISTS(DT_NODELABEL(epd))
epd_draw_something(to_draw);
break;
#endif
case DISPLAY_OLED:
#if DT_NODE_EXISTS(DT_NODELABEL(oled))
oled_draw_something(to_draw);
break;
#endif
default:
printk("Kein gültiges Display initialisiert\n");
break;
}
}