Chart geht schon fast

This commit is contained in:
rxf
2024-07-07 15:33:47 +02:00
parent 87eb2a30d4
commit b1be91b52f
6 changed files with 125 additions and 26 deletions

View File

@@ -1,15 +1,25 @@
// Grafik Routinen
#define GRAFIK
#include "handlebme280.h"
#include "main.h"
#include "grafik.h"
#define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
uint32_t draw_buf[DRAW_BUF_SIZE / 4];
static lv_obj_t * chart;
static lv_coord_t bmewert[MAXREADINGS];
static lv_coord_t bmewert_hum[MAXREADINGS];
void setup_grafik(void) {
lv_init();
lv_display_t * disp;
disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
for (int i = 0; i < MAXREADINGS; i++) {
bmewert[i] = 0;
bmewert_hum[i] = 25;
}
}
void buildarc(ARC arc) {
@@ -41,7 +51,7 @@ void buildarc(ARC arc) {
lv_obj_t * value_label = lv_label_create(arc.arc);
char value[10];
sprintf(value, arc.valformat, arc.value);
Serial.println(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;
@@ -66,6 +76,7 @@ void buildarc(ARC arc) {
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) {
@@ -91,7 +102,11 @@ void lv_create_main_gui(void) {
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());
/* Refresh-Symbol anzeigen
lv_obj_t * refresh_label = lv_label_create(lv_screen_active());
lv_label_set_text(refresh_label, LV_SYMBOL_REFRESH);
lv_obj_align(refresh_label, LV_ALIGN_CENTER, 0, -45);
*/
/*Create an Arc*/
lv_obj_t * aTemp = lv_arc_create(lv_screen_active());
@@ -100,39 +115,95 @@ void lv_create_main_gui(void) {
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 st_arc;
lv_style_init(&st_arc);
if (arc.value < arc.green) {
lv_style_set_arc_color(&st_arc, lv_palette_main(LV_PALETTE_GREEN));
Serial.println("green");
} else if (arc.value < arc.yellow) {
lv_style_set_arc_color(&st_arc, lv_palette_main(LV_PALETTE_YELLOW));
Serial.println("yellow");
} else {
lv_style_set_arc_color(&st_arc, lv_palette_main(LV_PALETTE_RED));
Serial.println("red");
if (value < arc.green)
{
lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_GREEN), LV_PART_INDICATOR);
}
else if (value < arc.yellow)
{
lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_YELLOW), LV_PART_INDICATOR);
}
else
{
lv_obj_set_style_arc_color(arc.arc, lv_palette_main(LV_PALETTE_RED), LV_PART_INDICATOR);
}
}
lv_obj_add_style(arc.arc, &st_arc, LV_PART_INDICATOR);
void drawChart() {
Serial.println("draw_chart ");
// Create a chart in lower third of screen
// lv_obj_t * chart;
chart = lv_chart_create(lv_screen_active());
lv_obj_set_size(chart, 300, 90);
lv_obj_align(chart, LV_ALIGN_BOTTOM_MID, 0, -5);
lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/
lv_chart_set_point_count(chart, MAXREADINGS);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 100);
lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 10, 30);
lv_obj_set_style_size(chart, 0, 0, LV_PART_INDICATOR); // No points on line
/*Add data series*/
lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
lv_chart_set_point_count(chart, MAXREADINGS);
lv_chart_set_ext_y_array(chart, ser1, (lv_coord_t *)bmewert);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_SECONDARY_Y);
lv_chart_set_point_count(chart, MAXREADINGS);
lv_chart_set_ext_y_array(chart, ser2, (lv_coord_t *)bmewert_hum);
lv_chart_refresh(chart); /*Required after direct set*/
// Axen
lv_obj_t * scale = lv_scale_create(chart);
lv_obj_set_size(scale, lv_pct(80), 70);
Serial.printf("lv_pct(80) %d\n", lv_pct(80));
lv_scale_set_mode(scale, LV_SCALE_MODE_VERTICAL_LEFT);
lv_obj_align(scale, LV_ALIGN_BOTTOM_LEFT, -215, 0);
lv_scale_set_label_show(scale, true);
lv_scale_set_total_tick_count(scale, 21);
lv_scale_set_major_tick_every(scale, 5);
lv_obj_set_style_length(scale, 3, LV_PART_ITEMS);
lv_obj_set_style_length(scale, 6, LV_PART_INDICATOR);
lv_obj_set_style_line_width(scale, 1, LV_PART_ITEMS);
lv_obj_set_style_line_width(scale, 1, LV_PART_INDICATOR);
lv_obj_set_style_line_width(scale, 1, LV_PART_MAIN);
lv_scale_set_range(scale, 10, 30);
static lv_style_t style_scale;
lv_style_init(&style_scale);
lv_style_set_text_font(&style_scale, &lv_font_montserrat_10);
lv_obj_add_style(scale, &style_scale, 0);
}
void updatechartData(float value, float humvalue) {
int i = 0;
for (i = 0; i < MAXREADINGS - 1; i++) {
bmewert[i] = bmewert[i + 1];
bmewert_hum[i] = bmewert_hum[i + 1];
}
bmewert[MAXREADINGS - 1] = value;
bmewert_hum[MAXREADINGS - 1] = humvalue;
lv_chart_refresh(chart);
}