First commit - WIP
This commit is contained in:
135
src/grafik.cpp
Normal file
135
src/grafik.cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
// Grafik Routinen
|
||||
#define GRAFIK
|
||||
|
||||
#include "grafik.h"
|
||||
|
||||
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
|
||||
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
|
||||
|
||||
void setup_grafik(void) {
|
||||
lv_init();
|
||||
lv_display_t * disp;
|
||||
disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
|
||||
}
|
||||
|
||||
void buildarc(ARC arc) {
|
||||
lv_obj_set_size(arc.arc, arc.size, arc.size);
|
||||
lv_arc_set_rotation(arc.arc, 180);
|
||||
lv_arc_set_bg_angles(arc.arc, 0, 180);
|
||||
lv_arc_set_value(arc.arc, arc.value);
|
||||
lv_obj_align(arc.arc, LV_ALIGN_LEFT_MID, arc.x, arc.y);
|
||||
lv_obj_remove_style(arc.arc, NULL, LV_PART_KNOB);
|
||||
|
||||
// Style this arc
|
||||
static lv_style_t style_arc;
|
||||
lv_style_init(&style_arc);
|
||||
lv_style_set_arc_width(&style_arc, 20);
|
||||
lv_style_set_arc_rounded(&style_arc, false);
|
||||
lv_obj_add_style(arc.arc, &style_arc, LV_PART_MAIN);
|
||||
lv_obj_add_style(arc.arc, &style_arc, LV_PART_INDICATOR);
|
||||
|
||||
lv_obj_t * low_label = lv_label_create(arc.arc);
|
||||
char valuelow[10];
|
||||
sprintf(valuelow, "%d", arc.lowvalue);
|
||||
lv_label_set_text(low_label, valuelow);
|
||||
lv_obj_align(low_label, LV_ALIGN_LEFT_MID, 0, 8);
|
||||
static lv_style_t style_low_label;
|
||||
lv_style_init(&style_low_label);
|
||||
lv_style_set_text_font(&style_low_label, &lv_font_montserrat_10);
|
||||
lv_obj_add_style(low_label, &style_low_label, 0);
|
||||
|
||||
lv_obj_t * value_label = lv_label_create(arc.arc);
|
||||
char value[10];
|
||||
sprintf(value, arc.valformat, arc.value);
|
||||
Serial.println(value);
|
||||
lv_label_set_text(value_label, value);
|
||||
lv_obj_align(value_label, LV_ALIGN_LEFT_MID, 38, -10);
|
||||
static lv_style_t style_value_label;
|
||||
lv_style_init(&style_value_label);
|
||||
lv_style_set_text_font(&style_value_label, &lv_font_montserrat_18);
|
||||
lv_obj_add_style(value_label, &style_value_label, 0);
|
||||
|
||||
lv_obj_t * high_label = lv_label_create(arc.arc);
|
||||
char valuehigh[10];
|
||||
sprintf(valuehigh, "%d", arc.highvalue);
|
||||
lv_label_set_text(high_label, valuehigh);
|
||||
lv_obj_align(high_label, LV_ALIGN_LEFT_MID, 90, 8);
|
||||
static lv_style_t style_high_label;
|
||||
lv_style_init(&style_high_label);
|
||||
lv_style_set_text_font(&style_high_label, &lv_font_montserrat_10);
|
||||
lv_obj_add_style(high_label, &style_high_label, 0);
|
||||
|
||||
lv_obj_t * unit_label = lv_label_create(arc.arc);
|
||||
lv_label_set_text(unit_label, arc.unit);
|
||||
lv_obj_align(unit_label, LV_ALIGN_LEFT_MID, 48, 8);
|
||||
static lv_style_t style_unit_label;
|
||||
lv_style_init(&style_unit_label);
|
||||
lv_style_set_text_font(&style_unit_label, &lv_font_montserrat_12);
|
||||
lv_obj_add_style(unit_label, &style_unit_label, 0);
|
||||
}
|
||||
|
||||
void lv_create_main_gui(void) {
|
||||
// Create a text label aligned on top: https://docs.lvgl.io/master/widgets/label.html
|
||||
lv_obj_t * date_label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(date_label, "17:30");
|
||||
lv_obj_align(date_label, LV_ALIGN_TOP_MID, 0, 10);
|
||||
|
||||
// Set font type and font size. More information: https://docs.lvgl.io/master/overview/font.html
|
||||
static lv_style_t style_date_label;
|
||||
lv_style_init(&style_date_label);
|
||||
lv_style_set_text_font(&style_date_label, &lv_font_montserrat_28);
|
||||
lv_obj_add_style(date_label, &style_date_label, 0);
|
||||
|
||||
// Create a text label aligned on top: https://docs.lvgl.io/master/widgets/label.html
|
||||
lv_obj_t * time_label = lv_label_create(lv_screen_active());
|
||||
lv_label_set_text(time_label, "Dienstag, 12. Dezember 2024");
|
||||
lv_obj_align(time_label, LV_ALIGN_TOP_MID, 0, 40);
|
||||
|
||||
// Set font type and font size. More information: https://docs.lvgl.io/master/overview/font.html
|
||||
static lv_style_t style_time_label;
|
||||
lv_style_init(&style_time_label);
|
||||
lv_style_set_text_font(&style_time_label, &lv_font_montserrat_12);
|
||||
lv_obj_add_style(time_label, &style_time_label, 0);
|
||||
|
||||
// lv_obj_t * label = lv_label_create(lv_screen_active());
|
||||
|
||||
/*Create an Arc*/
|
||||
lv_obj_t * aTemp = lv_arc_create(lv_screen_active());
|
||||
arcTemp.arc = aTemp;
|
||||
buildarc(arcTemp);
|
||||
lv_obj_t * aHum = lv_arc_create(lv_screen_active());
|
||||
arcHum.arc = aHum;
|
||||
buildarc(arcHum);
|
||||
}
|
||||
|
||||
void setValuetoArc(ARC arc, float value) {
|
||||
char s[60];
|
||||
int r = arc.highvalue - arc.lowvalue;
|
||||
int v = (value - arc.lowvalue) * 100 / r;
|
||||
arc.value = v;
|
||||
sprintf(s,"high: %d, low: %d, value: %.1f, v: %d\n", arc.highvalue, arc.lowvalue, arc.value, v);
|
||||
Serial.println(s);
|
||||
lv_arc_set_value(arc.arc, arc.value);
|
||||
lv_obj_t * value_label = lv_obj_get_child(arc.arc, 1);
|
||||
char valuestr[10];
|
||||
sprintf(valuestr, arc.valformat, value);
|
||||
lv_label_set_text(value_label, valuestr);
|
||||
|
||||
sprintf(s,"name: %s, value: %.1f, green: %d, yellow: %d", arc.name, arc.value, arc.green, arc.yellow);
|
||||
Serial.println(s);
|
||||
static lv_style_t style_arc;
|
||||
lv_style_init(&style_arc);
|
||||
if (arc.value < arc.green) {
|
||||
lv_style_set_arc_color(&style_arc, lv_palette_main(LV_PALETTE_GREEN));
|
||||
} else if (arc.value < arc.yellow) {
|
||||
lv_style_set_arc_color(&style_arc, lv_palette_main(LV_PALETTE_YELLOW));
|
||||
} else {
|
||||
lv_style_set_arc_color(&style_arc, lv_palette_main(LV_PALETTE_RED));
|
||||
}
|
||||
lv_obj_add_style(arc.arc, &style_arc, LV_PART_INDICATOR);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user