Files
nanopsx_sen66/firmware/components/eez_gui/vars.c
T

48 lines
2.0 KiB
C

// File: components/vars.c
#include <string.h>
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/portmacro.h"
#include "vars.h" // der von EEZ generierte Header
// Kurzer Spinlock gegen tearing zwischen GUI-Thread und Producer
static portMUX_TYPE s_vars_mux = portMUX_INITIALIZER_UNLOCKED;
// Feste Puffer (persistente Speicherorte für get_var_* Rückgaben)
static char s_pm1p0[16] = "-";
static char s_pm2p5[16] = "-";
static char s_pm4p0[16] = "-";
static char s_pm10p0[16] = "-";
static char s_voc_ind[16] = "-";
static char s_humidity[16]= "-";
static char s_temp[16] = "-";
// interne Helfer: sichere Kopie in den Zielpuffer (nullterminiert)
static inline void copy_in(char *dst, size_t dst_size, const char *src) {
taskENTER_CRITICAL(&s_vars_mux);
if (src && *src) {
snprintf(dst, dst_size, "%s", src);
} else {
dst[0] = '-'; dst[1] = '\0';
}
taskEXIT_CRITICAL(&s_vars_mux);
}
/* ---------- Setter ---------- */
void set_var_pm1p0(const char *value) { copy_in(s_pm1p0, sizeof(s_pm1p0), value); }
void set_var_pm2p5(const char *value) { copy_in(s_pm2p5, sizeof(s_pm2p5), value); }
void set_var_pm4p0(const char *value) { copy_in(s_pm4p0, sizeof(s_pm4p0), value); }
void set_var_pm10p0(const char *value) { copy_in(s_pm10p0, sizeof(s_pm10p0), value); }
void set_var_voc_ind(const char *value) { copy_in(s_voc_ind, sizeof(s_voc_ind), value); }
void set_var_humidity(const char *value){ copy_in(s_humidity, sizeof(s_humidity), value); }
void set_var_temp(const char *value) { copy_in(s_temp, sizeof(s_temp), value); }
/* ---------- Getter (geben persistenten Zeiger zurück) ---------- */
const char *get_var_pm1p0(void) { return s_pm1p0; }
const char *get_var_pm2p5(void) { return s_pm2p5; }
const char *get_var_pm4p0(void) { return s_pm4p0; }
const char *get_var_pm10p0(void) { return s_pm10p0; }
const char *get_var_voc_ind(void) { return s_voc_ind; }
const char *get_var_humidity(void){ return s_humidity; }
const char *get_var_temp(void) { return s_temp; }