From 402096798a0b10ce97e654c75f66ed9b4c4c503b Mon Sep 17 00:00:00 2001 From: cpq Date: Tue, 21 Apr 2026 16:50:45 +0100 Subject: [PATCH] Remove points --- mongoose.h | 6 ++---- src/dash.h | 6 ++---- tutorials/device-dashboard/mongoose_app.c | 10 +++++----- tutorials/device-dashboard/web_root/index.html | 2 +- tutorials/device-dashboard/web_root/style.css | 6 ++++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/mongoose.h b/mongoose.h index e9ccef9c..fb6ebb17 100644 --- a/mongoose.h +++ b/mongoose.h @@ -3255,12 +3255,9 @@ static inline size_t mg_print_field(mg_pfn_t fn, void *arg, va_list *ap) { } else if (f->type == MG_VAL_INT) { n += mg_xprintf(fn, arg, "%d", *(int *) f->value); } else if (f->type == MG_VAL_DBL) { - n += mg_xprintf(fn, arg, "%g", *(double *) f->value); + n += mg_xprintf(fn, arg, "%.2f", *(double *) f->value); } else if (f->type == MG_VAL_STR) { - // struct mg_str *s = * (struct mg_str *) f->value; n += mg_xprintf(fn, arg, "%m", MG_ESC(f->value)); - // } else if (f->type == MG_VAL_FN) { - // n += mg_xprintf(fn, arg, val.fn ? "%M" : "null", val.fn); } else { n += mg_xprintf(fn, arg, "null"); } @@ -3313,6 +3310,7 @@ static inline void mg_dash_send_change(struct mg_mgr *mgr, struct mg_dash *dash, const char *name) { struct mg_field_set *set = mg_dash_find_field_set(dash, mg_str(name)); if (set != NULL) { + if (set->sync) set->sync(false); mg_dash_broadcast(mgr, "{%m:%m,%m:{%m:%M}}", MG_ESC("method"), MG_ESC("change"), MG_ESC("params"), MG_ESC(set->name), mg_print_field_set, set); diff --git a/src/dash.h b/src/dash.h index 3a50f863..3fdd4f4d 100644 --- a/src/dash.h +++ b/src/dash.h @@ -110,12 +110,9 @@ static inline size_t mg_print_field(mg_pfn_t fn, void *arg, va_list *ap) { } else if (f->type == MG_VAL_INT) { n += mg_xprintf(fn, arg, "%d", *(int *) f->value); } else if (f->type == MG_VAL_DBL) { - n += mg_xprintf(fn, arg, "%g", *(double *) f->value); + n += mg_xprintf(fn, arg, "%.2f", *(double *) f->value); } else if (f->type == MG_VAL_STR) { - // struct mg_str *s = * (struct mg_str *) f->value; n += mg_xprintf(fn, arg, "%m", MG_ESC(f->value)); - // } else if (f->type == MG_VAL_FN) { - // n += mg_xprintf(fn, arg, val.fn ? "%M" : "null", val.fn); } else { n += mg_xprintf(fn, arg, "null"); } @@ -168,6 +165,7 @@ static inline void mg_dash_send_change(struct mg_mgr *mgr, struct mg_dash *dash, const char *name) { struct mg_field_set *set = mg_dash_find_field_set(dash, mg_str(name)); if (set != NULL) { + if (set->sync) set->sync(false); mg_dash_broadcast(mgr, "{%m:%m,%m:{%m:%M}}", MG_ESC("method"), MG_ESC("change"), MG_ESC("params"), MG_ESC(set->name), mg_print_field_set, set); diff --git a/tutorials/device-dashboard/mongoose_app.c b/tutorials/device-dashboard/mongoose_app.c index f493fac8..308905fc 100644 --- a/tutorials/device-dashboard/mongoose_app.c +++ b/tutorials/device-dashboard/mongoose_app.c @@ -32,7 +32,7 @@ static void sync_control(bool is_write) { } // Read-only device Metrics -static int s_ram = 32, s_cpu = 37, s_humidity = 59; +static int s_ram = 32, s_cpu = 7, s_humidity = 59; static double s_temperature = 24.8; static struct mg_field fields_metrics[] = { @@ -45,8 +45,9 @@ static struct mg_field fields_metrics[] = { static void sync_metrics(bool is_write) { if (is_write) return; - // Read values from hardware into the state variables - // s_ram = calculate_current_free_ram(); + s_ram = 25 + (rand() % 16); // Sumulate metric change + s_cpu = 7 + (rand() % 21); + s_temperature = 14.8 + ((double)rand() / RAND_MAX) * 20.0; } // Read-write device settings @@ -127,8 +128,7 @@ void mongoose_poll(void) { { // Send metrics change periodically static uint64_t timer = 0; - if (mg_timer_expired(&timer, 30000, mg_now())) { - sync_metrics(false); + if (mg_timer_expired(&timer, 300, mg_now())) { mg_dash_send_change(&s_mgr, &s_dashboard, "metrics"); } } diff --git a/tutorials/device-dashboard/web_root/index.html b/tutorials/device-dashboard/web_root/index.html index 84a32ea8..3828f872 100644 --- a/tutorials/device-dashboard/web_root/index.html +++ b/tutorials/device-dashboard/web_root/index.html @@ -9,7 +9,7 @@ Dashboard.init({ debug: true, data: { - points: [], + chart1: {data: ''}, controls: { fan: true, relay1: false, diff --git a/tutorials/device-dashboard/web_root/style.css b/tutorials/device-dashboard/web_root/style.css index edaa5b92..049ffcb4 100644 --- a/tutorials/device-dashboard/web_root/style.css +++ b/tutorials/device-dashboard/web_root/style.css @@ -15,6 +15,8 @@ --spacing-2: 0.5rem; --spacing-3: 0.75rem; --spacing-4: 1rem; + --spacing-5: 1.25rem; + --spacing-6: 1.5rem; } * { @@ -46,7 +48,7 @@ body { align-items: center; justify-content: space-between; gap: var(--spacing-4); - padding: var(--spacing-2) var(--spacing-3); + padding: var(--spacing-2) var(--spacing-4); } .header-left { @@ -134,7 +136,7 @@ body { .tab-stage { max-width: var(--max-width); margin: 0 auto; - padding: 5.5rem var(--spacing-3) var(--spacing-3); + padding: 5.5rem var(--spacing-4) var(--spacing-4); } .tab-panel {