feat(display): add air quality pages, history and display settings
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
idf_component_register(
|
||||
SRCS
|
||||
"ui.c"
|
||||
"ui_navigation.c"
|
||||
"ui_dashboard.c"
|
||||
"ui_model.c"
|
||||
"images.c"
|
||||
"screens.c"
|
||||
"styles.c"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,15 +1,22 @@
|
||||
#ifndef EEZ_LVGL_UI_SCREENS_H
|
||||
#define EEZ_LVGL_UI_SCREENS_H
|
||||
|
||||
#include <lvgl.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct _objects_t {
|
||||
/* Generated by firmware/tools/export_display.py from the EEZ project. */
|
||||
#pragma once
|
||||
#include <lvgl.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
typedef struct {
|
||||
lv_obj_t *main;
|
||||
lv_obj_t *page_2;
|
||||
lv_obj_t *history;
|
||||
lv_obj_t *device;
|
||||
lv_obj_t *obj0;
|
||||
lv_obj_t *obj5;
|
||||
lv_obj_t *obj6;
|
||||
lv_obj_t *obj7;
|
||||
lv_obj_t *obj8;
|
||||
lv_obj_t *obj9;
|
||||
lv_obj_t *obj10;
|
||||
lv_obj_t *obj11;
|
||||
lv_obj_t *obj1;
|
||||
lv_obj_t *obj2;
|
||||
lv_obj_t *obj3;
|
||||
@@ -20,32 +27,63 @@ typedef struct _objects_t {
|
||||
lv_obj_t *influx_off;
|
||||
lv_obj_t *mdns_ok;
|
||||
lv_obj_t *mdns_off;
|
||||
lv_obj_t *obj5;
|
||||
lv_obj_t *obj6;
|
||||
lv_obj_t *obj7;
|
||||
lv_obj_t *obj8;
|
||||
lv_obj_t *obj9;
|
||||
lv_obj_t *obj10;
|
||||
lv_obj_t *obj11;
|
||||
lv_obj_t *main_notice;
|
||||
lv_obj_t *page_dot_0_0;
|
||||
lv_obj_t *page_dot_0_1;
|
||||
lv_obj_t *page_dot_0_2;
|
||||
lv_obj_t *page_dot_0_3;
|
||||
lv_obj_t *page_2_title;
|
||||
lv_obj_t *room_state;
|
||||
lv_obj_t *room_co2;
|
||||
lv_obj_t *room_unit;
|
||||
lv_obj_t *room_voc;
|
||||
lv_obj_t *room_nox;
|
||||
lv_obj_t *room_chart;
|
||||
lv_obj_t *room_chart_caption;
|
||||
lv_obj_t *page_dot_1_0;
|
||||
lv_obj_t *page_dot_1_1;
|
||||
lv_obj_t *page_dot_1_2;
|
||||
lv_obj_t *page_dot_1_3;
|
||||
lv_obj_t *history_title;
|
||||
lv_obj_t *history_metric;
|
||||
lv_obj_t *history_range;
|
||||
lv_obj_t *history_chart;
|
||||
lv_obj_t *history_caption;
|
||||
lv_obj_t *page_dot_2_0;
|
||||
lv_obj_t *page_dot_2_1;
|
||||
lv_obj_t *page_dot_2_2;
|
||||
lv_obj_t *page_dot_2_3;
|
||||
lv_obj_t *device_title;
|
||||
lv_obj_t *device_wifi;
|
||||
lv_obj_t *device_influx;
|
||||
lv_obj_t *device_sensor;
|
||||
lv_obj_t *brightness_label;
|
||||
lv_obj_t *brightness;
|
||||
lv_obj_t *dim_label;
|
||||
lv_obj_t *dim_timeout;
|
||||
lv_obj_t *page_dot_3_0;
|
||||
lv_obj_t *page_dot_3_1;
|
||||
lv_obj_t *page_dot_3_2;
|
||||
lv_obj_t *page_dot_3_3;
|
||||
} objects_t;
|
||||
|
||||
extern objects_t objects;
|
||||
|
||||
enum ScreensEnum {
|
||||
SCREEN_ID_MAIN = 1,
|
||||
SCREEN_ID_PAGE_2 = 2,
|
||||
SCREEN_ID_HISTORY = 3,
|
||||
SCREEN_ID_DEVICE = 4,
|
||||
};
|
||||
|
||||
void create_screen_main();
|
||||
void tick_screen_main();
|
||||
|
||||
void tick_screen_by_id(enum ScreensEnum screenId);
|
||||
void create_screen_main(void);
|
||||
void tick_screen_main(void);
|
||||
void create_screen_page_2(void);
|
||||
void tick_screen_page_2(void);
|
||||
void create_screen_history(void);
|
||||
void tick_screen_history(void);
|
||||
void create_screen_device(void);
|
||||
void tick_screen_device(void);
|
||||
void create_screens(void);
|
||||
void tick_screen(int screen_index);
|
||||
|
||||
void create_screens();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*EEZ_LVGL_UI_SCREENS_H*/
|
||||
void tick_screen_by_id(enum ScreensEnum screen_id);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
#include "ui_dashboard.h"
|
||||
#include "ui_model.h"
|
||||
#include "ui.h"
|
||||
#include "fonts.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static ui_display_config_t config;
|
||||
static ui_brightness_cb_t set_brightness;
|
||||
static ui_save_config_cb_t save_config;
|
||||
static lv_chart_series_t *room_series, *history_series;
|
||||
static uint32_t last_activity;
|
||||
static bool initialized, dimmed, suppress_touch;
|
||||
static const uint16_t dim_seconds[] = {0, 30, 60, 120};
|
||||
static const char *units[] = {"ppm", "µg/m³", "°C", "%", "Index", "Index"};
|
||||
|
||||
static void update_brightness_label(void)
|
||||
{
|
||||
lv_label_set_text_fmt(objects.brightness_label, "Licht %u%%", config.brightness);
|
||||
}
|
||||
|
||||
static void settings_event(lv_event_t *event)
|
||||
{
|
||||
lv_obj_t *target = lv_event_get_target(event);
|
||||
if (target == objects.brightness) {
|
||||
config.brightness = (uint8_t)lv_slider_get_value(target);
|
||||
set_brightness(config.brightness);
|
||||
update_brightness_label();
|
||||
/* Dragging previews immediately, persistence happens only on release. */
|
||||
if (lv_event_get_code(event) == LV_EVENT_RELEASED && save_config) save_config(&config);
|
||||
} else if (target == objects.dim_timeout) {
|
||||
unsigned selected = lv_dropdown_get_selected(target);
|
||||
if (selected < sizeof(dim_seconds) / sizeof(dim_seconds[0])) {
|
||||
config.dim_after_s = dim_seconds[selected];
|
||||
if (save_config) save_config(&config);
|
||||
}
|
||||
}
|
||||
last_activity = lv_tick_get();
|
||||
}
|
||||
|
||||
static void status_clicked(lv_event_t *event)
|
||||
{
|
||||
(void)event;
|
||||
loadScreen(SCREEN_ID_DEVICE);
|
||||
}
|
||||
|
||||
void ui_dashboard_init(ui_display_config_t selected, ui_brightness_cb_t brightness,
|
||||
ui_save_config_cb_t save)
|
||||
{
|
||||
config = selected;
|
||||
if (config.brightness < 20 || config.brightness > 100) config.brightness = 100;
|
||||
unsigned dim_index = 2;
|
||||
for (unsigned i = 0; i < 4; ++i) if (config.dim_after_s == dim_seconds[i]) dim_index = i;
|
||||
config.dim_after_s = dim_seconds[dim_index];
|
||||
set_brightness = brightness;
|
||||
save_config = save;
|
||||
dimmed = suppress_touch = false;
|
||||
last_activity = lv_tick_get();
|
||||
initialized = true;
|
||||
lv_slider_set_value(objects.brightness, config.brightness, LV_ANIM_OFF);
|
||||
lv_obj_set_ext_click_area(objects.brightness, 12);
|
||||
lv_dropdown_set_selected(objects.dim_timeout, dim_index);
|
||||
update_brightness_label();
|
||||
/* Custom Ubuntu fonts do not contain LVGL's private-use arrow glyphs. */
|
||||
lv_obj_set_style_text_font(objects.history_metric, LV_FONT_DEFAULT, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_text_font(objects.dim_timeout, LV_FONT_DEFAULT, LV_PART_INDICATOR);
|
||||
lv_obj_add_event_cb(objects.brightness, settings_event, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_obj_add_event_cb(objects.brightness, settings_event, LV_EVENT_RELEASED, NULL);
|
||||
lv_obj_add_event_cb(objects.dim_timeout, settings_event, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_obj_t *icons[] = {objects.wifi_ok, objects.wifi_off, objects.influx_ok,
|
||||
objects.influx_off, objects.mdns_ok, objects.mdns_off};
|
||||
for (unsigned i = 0; i < sizeof(icons) / sizeof(icons[0]); ++i) {
|
||||
lv_obj_add_flag(icons[i], LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_add_event_cb(icons[i], status_clicked, LV_EVENT_CLICKED, NULL);
|
||||
}
|
||||
lv_chart_set_point_count(objects.room_chart, UI_HISTORY_POINTS);
|
||||
lv_chart_set_point_count(objects.history_chart, UI_HISTORY_POINTS);
|
||||
room_series = lv_chart_add_series(objects.room_chart, lv_color_hex(0x62D6C5), LV_CHART_AXIS_PRIMARY_Y);
|
||||
history_series = lv_chart_add_series(objects.history_chart, lv_color_hex(0x62D6C5), LV_CHART_AXIS_PRIMARY_Y);
|
||||
lv_chart_set_all_value(objects.room_chart, room_series, LV_CHART_POINT_NONE);
|
||||
lv_chart_set_all_value(objects.history_chart, history_series, LV_CHART_POINT_NONE);
|
||||
lv_obj_set_style_size(objects.room_chart, 0, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_size(objects.history_chart, 0, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_line_width(objects.room_chart, 2, LV_PART_ITEMS);
|
||||
lv_obj_set_style_line_width(objects.history_chart, 2, LV_PART_ITEMS);
|
||||
set_brightness(config.brightness);
|
||||
}
|
||||
|
||||
void ui_dashboard_filter_touch(lv_indev_data_t *data)
|
||||
{
|
||||
if (!initialized) return;
|
||||
const bool pressed = data->state == LV_INDEV_STATE_PRESSED;
|
||||
if (pressed) {
|
||||
last_activity = lv_tick_get();
|
||||
if (dimmed) {
|
||||
dimmed = false;
|
||||
suppress_touch = true;
|
||||
set_brightness(config.brightness);
|
||||
}
|
||||
}
|
||||
if (suppress_touch) {
|
||||
data->state = LV_INDEV_STATE_RELEASED;
|
||||
if (!pressed) suppress_touch = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void format_value(lv_obj_t *label, const char *prefix, float value, unsigned decimals)
|
||||
{
|
||||
if (!isfinite(value)) lv_label_set_text_fmt(label, "%s--", prefix);
|
||||
else {
|
||||
/* LVGL's compact printf is built without floating-point support. */
|
||||
char text[64];
|
||||
snprintf(text, sizeof(text), "%s%.*f", prefix, (int)decimals, (double)value);
|
||||
lv_label_set_text(label, text);
|
||||
}
|
||||
}
|
||||
|
||||
static void fill_chart(lv_obj_t *chart, lv_chart_series_t *series,
|
||||
ui_metric_t metric, uint64_t now_ms, lv_obj_t *range_label)
|
||||
{
|
||||
float values[UI_HISTORY_POINTS];
|
||||
ui_model_history(metric, now_ms, values);
|
||||
float low = INFINITY, high = -INFINITY;
|
||||
for (unsigned i = 0; i < UI_HISTORY_POINTS; ++i) {
|
||||
if (isfinite(values[i])) {
|
||||
if (values[i] < low) low = values[i];
|
||||
if (values[i] > high) high = values[i];
|
||||
}
|
||||
}
|
||||
/* Values use tenths in the plot. Never overflow LVGL's 16-bit coordinates. */
|
||||
const float scale = metric == UI_METRIC_CO2 ? 1.0f : 10.0f;
|
||||
int minimum = isfinite(low) ? (int)floorf(low * scale) : 0;
|
||||
int maximum = isfinite(high) ? (int)ceilf(high * scale) : 10;
|
||||
int margin = (maximum - minimum) / 10;
|
||||
if (margin < 5) margin = 5;
|
||||
minimum -= margin; maximum += margin;
|
||||
if (metric != UI_METRIC_TEMP && minimum < 0) minimum = 0;
|
||||
if (minimum < -32000) minimum = -32000;
|
||||
if (maximum > 32000) maximum = 32000;
|
||||
if (maximum <= minimum) maximum = minimum + 1;
|
||||
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, minimum, maximum);
|
||||
for (unsigned i = 0; i < UI_HISTORY_POINTS; ++i) {
|
||||
float value = values[i] * scale;
|
||||
series->y_points[i] = !isfinite(value) ? LV_CHART_POINT_NONE :
|
||||
(lv_coord_t)lroundf(fminf(32000, fmaxf(-32000, value)));
|
||||
}
|
||||
lv_chart_refresh(chart);
|
||||
if (range_label) {
|
||||
if (isfinite(low)) {
|
||||
char text[64];
|
||||
snprintf(text, sizeof(text), "%.0f..%.0f %s", minimum / scale, maximum / scale, units[metric]);
|
||||
lv_label_set_text(range_label, text);
|
||||
}
|
||||
else lv_label_set_text(range_label, "Noch keine Daten");
|
||||
}
|
||||
}
|
||||
|
||||
void ui_dashboard_tick(uint64_t now_ms, const ui_device_status_t *status)
|
||||
{
|
||||
if (!initialized) return;
|
||||
lv_obj_t *on[] = {objects.wifi_ok, objects.influx_ok, objects.mdns_ok};
|
||||
lv_obj_t *off[] = {objects.wifi_off, objects.influx_off, objects.mdns_off};
|
||||
bool ok[] = {status->wifi_connected, status->influx_ok, status->mdns_ok};
|
||||
for (unsigned i = 0; i < 3; ++i) {
|
||||
lv_obj_add_flag(ok[i] ? off[i] : on[i], LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(ok[i] ? on[i] : off[i], LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
if (!dimmed && config.dim_after_s &&
|
||||
lv_tick_elaps(last_activity) >= (uint32_t)config.dim_after_s * 1000) {
|
||||
dimmed = true;
|
||||
set_brightness(15);
|
||||
}
|
||||
ui_sample_t sample;
|
||||
ui_model_snapshot(&sample);
|
||||
const uint64_t age = sample.available && now_ms >= sample.timestamp_ms ? now_ms - sample.timestamp_ms : 0;
|
||||
const bool fresh = sample.available && now_ms >= sample.timestamp_ms && age <= UI_SENSOR_STALE_MS;
|
||||
const char *state = !sample.available ? "Sensor startet ..." : fresh ? "Live / 1 Messung pro Sekunde" : "Messwerte veraltet";
|
||||
lv_label_set_text(objects.room_state, state);
|
||||
if (fresh) lv_obj_add_flag(objects.main_notice, LV_OBJ_FLAG_HIDDEN);
|
||||
else {
|
||||
lv_obj_clear_flag(objects.main_notice, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_label_set_text(objects.main_notice, state);
|
||||
lv_obj_t *values[] = {objects.obj5, objects.obj6, objects.obj7, objects.obj8,
|
||||
objects.obj9, objects.obj10, objects.obj11};
|
||||
for (unsigned i = 0; i < sizeof(values) / sizeof(values[0]); ++i) lv_label_set_text(values[i], "--");
|
||||
}
|
||||
format_value(objects.room_co2, "", fresh ? sample.values[UI_METRIC_CO2] : NAN, 0);
|
||||
format_value(objects.room_voc, "VOC-Index ", fresh ? sample.values[UI_METRIC_VOC] : NAN, 0);
|
||||
format_value(objects.room_nox, "NOx-Index ", fresh ? sample.values[UI_METRIC_NOX] : NAN, 0);
|
||||
if (fresh && !isfinite(sample.values[UI_METRIC_CO2]))
|
||||
lv_label_set_text(objects.room_state, "CO2-Kanal nicht verfügbar");
|
||||
fill_chart(objects.room_chart, room_series, UI_METRIC_CO2, now_ms, NULL);
|
||||
unsigned metric = lv_dropdown_get_selected(objects.history_metric);
|
||||
if (metric >= UI_METRIC_COUNT) metric = UI_METRIC_CO2;
|
||||
fill_chart(objects.history_chart, history_series, (ui_metric_t)metric, now_ms, objects.history_range);
|
||||
lv_label_set_text_fmt(objects.device_wifi, "WLAN: %s", status->wifi_connected ? status->ip : "nicht verbunden");
|
||||
if (status->last_influx_success_ms && now_ms >= status->last_influx_success_ms) {
|
||||
unsigned seconds = (unsigned)((now_ms - status->last_influx_success_ms) / 1000);
|
||||
if (seconds < 60) lv_label_set_text_fmt(objects.device_influx, "Influx: vor %u s / %s", seconds, status->influx_ok ? "OK" : "Fehler");
|
||||
else lv_label_set_text_fmt(objects.device_influx, "Influx: vor %u min / %s", seconds / 60, status->influx_ok ? "OK" : "Fehler");
|
||||
} else lv_label_set_text(objects.device_influx, "Influx: noch keine Übertragung");
|
||||
if (!sample.available) lv_label_set_text(objects.device_sensor, "Sensor: startet / wartet auf Daten");
|
||||
else lv_label_set_text_fmt(objects.device_sensor, "Sensor: %s / vor %u s", fresh ? "OK" : "veraltet", (unsigned)(age / 1000));
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <lvgl.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint8_t brightness; /* 20..100 percent */
|
||||
uint16_t dim_after_s; /* 0, 30, 60, 120 */
|
||||
} ui_display_config_t;
|
||||
typedef struct {
|
||||
bool wifi_connected, influx_ok, mdns_ok;
|
||||
char ip[16];
|
||||
uint64_t last_influx_success_ms; /* zero until first successful HTTP 204 */
|
||||
} ui_device_status_t;
|
||||
typedef void (*ui_brightness_cb_t)(uint8_t percent);
|
||||
typedef void (*ui_save_config_cb_t)(const ui_display_config_t *config);
|
||||
|
||||
/* All calls run on the LVGL task or while its lock is held. */
|
||||
void ui_dashboard_init(ui_display_config_t config, ui_brightness_cb_t brightness,
|
||||
ui_save_config_cb_t save);
|
||||
void ui_dashboard_tick(uint64_t now_ms, const ui_device_status_t *status);
|
||||
/* Wrap the touch read callback, so the wake-up touch cannot activate controls. */
|
||||
void ui_dashboard_filter_touch(lv_indev_data_t *data);
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "ui_model.h"
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#ifdef ESP_PLATFORM
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/portmacro.h"
|
||||
static portMUX_TYPE model_mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
#define LOCK() portENTER_CRITICAL(&model_mux)
|
||||
#define UNLOCK() portEXIT_CRITICAL(&model_mux)
|
||||
#else
|
||||
#define LOCK() ((void)0)
|
||||
#define UNLOCK() ((void)0)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint64_t bucket;
|
||||
float sum[UI_METRIC_COUNT];
|
||||
uint16_t count[UI_METRIC_COUNT];
|
||||
bool used;
|
||||
} history_bin_t;
|
||||
static ui_sample_t latest;
|
||||
static history_bin_t bins[UI_HISTORY_POINTS];
|
||||
|
||||
void ui_model_publish(const ui_sample_t *sample)
|
||||
{
|
||||
if (!sample || !sample->available) return;
|
||||
const uint64_t bucket = sample->timestamp_ms / UI_HISTORY_BUCKET_MS;
|
||||
LOCK();
|
||||
latest = *sample;
|
||||
history_bin_t *bin = &bins[bucket % UI_HISTORY_POINTS];
|
||||
if (!bin->used || bin->bucket != bucket) {
|
||||
*bin = (history_bin_t){.bucket = bucket, .used = true};
|
||||
}
|
||||
for (unsigned i = 0; i < UI_METRIC_COUNT; ++i) {
|
||||
if (isfinite(sample->values[i]) && bin->count[i] < UINT16_MAX) {
|
||||
bin->sum[i] += sample->values[i];
|
||||
++bin->count[i];
|
||||
}
|
||||
}
|
||||
UNLOCK();
|
||||
}
|
||||
|
||||
void ui_model_snapshot(ui_sample_t *sample)
|
||||
{
|
||||
LOCK();
|
||||
*sample = latest;
|
||||
UNLOCK();
|
||||
}
|
||||
|
||||
void ui_model_history(ui_metric_t metric, uint64_t now_ms, float *values)
|
||||
{
|
||||
const uint64_t last_bucket = now_ms / UI_HISTORY_BUCKET_MS;
|
||||
LOCK();
|
||||
for (unsigned i = 0; i < UI_HISTORY_POINTS; ++i) {
|
||||
const unsigned age = UI_HISTORY_POINTS - 1 - i;
|
||||
values[i] = NAN;
|
||||
if ((unsigned)metric >= UI_METRIC_COUNT || last_bucket < age) continue;
|
||||
const uint64_t bucket = last_bucket - age;
|
||||
const history_bin_t *bin = &bins[bucket % UI_HISTORY_POINTS];
|
||||
if (bin->used && bin->bucket == bucket && bin->count[metric]) {
|
||||
values[i] = bin->sum[metric] / bin->count[metric];
|
||||
}
|
||||
}
|
||||
UNLOCK();
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define UI_HISTORY_POINTS 180
|
||||
#define UI_HISTORY_BUCKET_MS 10000
|
||||
#define UI_SENSOR_STALE_MS 5000
|
||||
|
||||
typedef enum {
|
||||
UI_METRIC_CO2, UI_METRIC_PM25, UI_METRIC_TEMP, UI_METRIC_RH,
|
||||
UI_METRIC_VOC, UI_METRIC_NOX, UI_METRIC_COUNT
|
||||
} ui_metric_t;
|
||||
typedef struct {
|
||||
uint64_t timestamp_ms;
|
||||
float values[UI_METRIC_COUNT]; /* ppm, ug/m3, degC, %, VOC index, NOx index */
|
||||
bool available;
|
||||
} ui_sample_t;
|
||||
|
||||
/* Producer submits scaled numbers, with NAN for unavailable channels. No LVGL calls. */
|
||||
void ui_model_publish(const ui_sample_t *sample);
|
||||
void ui_model_snapshot(ui_sample_t *sample);
|
||||
/* 180 fixed ten-second bins, oldest first; empty bins are NAN. RAM only. */
|
||||
void ui_model_history(ui_metric_t metric, uint64_t now_ms, float *values);
|
||||
@@ -0,0 +1,47 @@
|
||||
#include "ui_navigation.h"
|
||||
#include "esp_log.h"
|
||||
#include "screens.h"
|
||||
#include "ui.h"
|
||||
|
||||
static void screen_gesture_cb(lv_event_t *event)
|
||||
{
|
||||
lv_indev_t *input = lv_indev_get_act();
|
||||
if (!input || lv_dropdown_is_open(objects.history_metric) ||
|
||||
lv_dropdown_is_open(objects.dim_timeout)) return;
|
||||
lv_obj_t *screen = lv_event_get_current_target(event);
|
||||
lv_obj_t *screens[] = {objects.main, objects.page_2, objects.history, objects.device};
|
||||
unsigned index = 0;
|
||||
while (index < 4 && screens[index] != screen) ++index;
|
||||
if (index >= 4) return;
|
||||
lv_dir_t direction = lv_indev_get_gesture_dir(input);
|
||||
unsigned next = index;
|
||||
if (direction == LV_DIR_LEFT && index < 3) ++next;
|
||||
else if (direction == LV_DIR_RIGHT && index > 0) --next;
|
||||
if (next == index) return;
|
||||
lv_indev_wait_release(input);
|
||||
loadScreen((enum ScreensEnum)(next + 1));
|
||||
ESP_LOGI("ui_navigation", "Swipe: page %u -> %u", index + 1, next + 1);
|
||||
}
|
||||
|
||||
static void prepare_gestures(lv_obj_t *object)
|
||||
{
|
||||
lv_obj_clear_flag(object, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_add_flag(object, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||
for (uint32_t i = 0; i < lv_obj_get_child_cnt(object); ++i)
|
||||
prepare_gestures(lv_obj_get_child(object, i));
|
||||
}
|
||||
|
||||
void ui_navigation_init(void)
|
||||
{
|
||||
lv_obj_t *screens[] = {objects.main, objects.page_2, objects.history, objects.device};
|
||||
for (unsigned i = 0; i < 4; ++i) {
|
||||
prepare_gestures(screens[i]);
|
||||
lv_obj_clear_flag(screens[i], LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||
lv_obj_add_event_cb(screens[i], screen_gesture_cb, LV_EVENT_GESTURE, NULL);
|
||||
}
|
||||
/* Sliders/dropdowns own their gestures; changing brightness must not navigate. */
|
||||
lv_obj_clear_flag(objects.brightness, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||
lv_obj_clear_flag(objects.history_metric, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||
lv_obj_clear_flag(objects.dim_timeout, LV_OBJ_FLAG_GESTURE_BUBBLE);
|
||||
ESP_LOGI("ui_navigation", "Ready: 4 pages / measurements, air, history, device");
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
/* Call once after ui_init(), with the LVGL lock held. Kept outside EEZ exports. */
|
||||
void ui_navigation_init(void);
|
||||
@@ -288,6 +288,7 @@ static esp_err_t net_influx_write_line(const char* line) {
|
||||
esp_http_client_cleanup(h);
|
||||
|
||||
ok = (err == ESP_OK && status == 204);
|
||||
if (ok) sys_status_record_influx_success();
|
||||
sys_status_set_influx_ok(ok);
|
||||
return ok ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
@@ -18,4 +18,5 @@ idf_component_register(
|
||||
eez_gui
|
||||
storage
|
||||
hardware_config
|
||||
esp_timer
|
||||
)
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h> // NAN, isfinite, lround
|
||||
#include "vars.h"
|
||||
#include "ui_model.h"
|
||||
#include "esp_timer.h"
|
||||
|
||||
static const char* TAG = "air_sensor_app";
|
||||
|
||||
@@ -188,26 +190,28 @@ static void air_sensor_task_producer(void* arg) {
|
||||
// float noxf = (s.nox_idx == 0x7FFF) ? NAN : s.nox_idx / 10.0f; // bei Bedarf anzeigen
|
||||
|
||||
// Temperatur
|
||||
snprintf(buf, sizeof(buf), "%.1f", (double)s.temp_c);
|
||||
if (isfinite(s.temp_c)) snprintf(buf, sizeof(buf), "%.1f", (double)s.temp_c);
|
||||
else snprintf(buf, sizeof(buf), "--");
|
||||
set_var_temp(buf);
|
||||
|
||||
// Feuchte
|
||||
snprintf(buf, sizeof(buf), "%.1f", (double)s.rh_pct);
|
||||
if (isfinite(s.rh_pct)) snprintf(buf, sizeof(buf), "%.1f", (double)s.rh_pct);
|
||||
else snprintf(buf, sizeof(buf), "--");
|
||||
set_var_humidity(buf);
|
||||
|
||||
// VOC-Index (gerundet), falls NAN → "nan"
|
||||
if (!isfinite(vocf)) snprintf(buf, sizeof(buf), "nan");
|
||||
// VOC-Index (gerundet), nicht verfügbare Werte als "--"
|
||||
if (!isfinite(vocf)) snprintf(buf, sizeof(buf), "--");
|
||||
else snprintf(buf, sizeof(buf), "%d", (int)lround(vocf));
|
||||
set_var_voc_ind(buf);
|
||||
|
||||
// PM (µg/m³) mit einer Nachkommastelle
|
||||
if (!isfinite(pm10f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm10f);
|
||||
if (!isfinite(pm10f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm10f);
|
||||
set_var_pm10p0(buf);
|
||||
if (!isfinite(pm4f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm4f);
|
||||
if (!isfinite(pm4f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm4f);
|
||||
set_var_pm4p0(buf);
|
||||
if (!isfinite(pm2f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm2f);
|
||||
if (!isfinite(pm2f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm2f);
|
||||
set_var_pm2p5(buf);
|
||||
if (!isfinite(pm1f)) snprintf(buf, sizeof(buf), "nan"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm1f);
|
||||
if (!isfinite(pm1f)) snprintf(buf, sizeof(buf), "--"); else snprintf(buf, sizeof(buf), "%.1f", (double)pm1f);
|
||||
set_var_pm1p0(buf);
|
||||
|
||||
/* === Influx submit (generisch, variabel viele Felder) === */
|
||||
@@ -220,6 +224,15 @@ static void air_sensor_task_producer(void* arg) {
|
||||
const double temp = (double)s.temp_c;
|
||||
const double rh = (double)s.rh_pct;
|
||||
const double co2 = (co2_raw == UINT16_MAX) ? NAN : (double)co2_raw;
|
||||
#if NANOPSX_HAS_DISPLAY
|
||||
ui_sample_t display_sample = {
|
||||
.timestamp_ms = (uint64_t)(esp_timer_get_time() / 1000),
|
||||
.available = true,
|
||||
.values = {(float)co2, (float)pm2_5, (float)temp,
|
||||
(float)rh, (float)voc, (float)nox}
|
||||
};
|
||||
ui_model_publish(&display_sample);
|
||||
#endif
|
||||
static unsigned samples;
|
||||
if (++samples % 10 == 0) {
|
||||
ESP_LOGI(TAG, "%s sample: PM2.5=%.1f temp=%.2f rh=%.2f CO2=%.0f",
|
||||
|
||||
@@ -3,6 +3,6 @@ idf_component_register(
|
||||
"src/sys_status.c"
|
||||
INCLUDE_DIRS
|
||||
"include"
|
||||
REQUIRES
|
||||
REQUIRES esp_timer
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// File: firmware/components/sys_status/include/sys_status.h
|
||||
#pragma once
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
|
||||
@@ -25,6 +26,10 @@ static inline bool sys_status_get_wifi_ok(void) { return (xEventGroupGetBits(s
|
||||
static inline bool sys_status_get_influx_ok(void) { return (xEventGroupGetBits(sys_status_group()) & SYS_STATUS_INFLUX_OK) != 0; }
|
||||
static inline bool sys_status_get_mdns_ok(void) { return (xEventGroupGetBits(sys_status_group()) & SYS_STATUS_MDNS_OK) != 0; }
|
||||
|
||||
/* Monotonic timestamp of a confirmed HTTP 204, never merely a WLAN connection. */
|
||||
void sys_status_record_influx_success(void);
|
||||
uint64_t sys_status_last_influx_success_ms(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -21,3 +21,22 @@ EventGroupHandle_t sys_status_group(void)
|
||||
if (!s_status_group) sys_status_init();
|
||||
return s_status_group;
|
||||
}
|
||||
|
||||
#include "esp_timer.h"
|
||||
#include "freertos/portmacro.h"
|
||||
static portMUX_TYPE influx_time_mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
static uint64_t last_influx_success;
|
||||
void sys_status_record_influx_success(void)
|
||||
{
|
||||
uint64_t now = (uint64_t)(esp_timer_get_time() / 1000);
|
||||
portENTER_CRITICAL(&influx_time_mux);
|
||||
last_influx_success = now;
|
||||
portEXIT_CRITICAL(&influx_time_mux);
|
||||
}
|
||||
uint64_t sys_status_last_influx_success_ms(void)
|
||||
{
|
||||
portENTER_CRITICAL(&influx_time_mux);
|
||||
uint64_t result = last_influx_success;
|
||||
portEXIT_CRITICAL(&influx_time_mux);
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user