Modular ringbuffer and graph display
This commit is contained in:
parent
5c58a1fa8a
commit
847c8e16ba
3 changed files with 14 additions and 14 deletions
|
@ -244,7 +244,7 @@ void display_screen_grid(float grid_power, float consum, float inv_power, float
|
|||
}
|
||||
|
||||
//Graph last 100 values
|
||||
void display_screen_graph(float values[100])
|
||||
void display_screen_graph(float values[100], char* key, int buffersize)
|
||||
{
|
||||
logPrintD("Display graph...");
|
||||
display.firstPage();
|
||||
|
@ -263,7 +263,8 @@ void display_screen_graph(float values[100])
|
|||
display.drawLine(i, 60, i, 62); //marker X
|
||||
}
|
||||
|
||||
for (int i = 0; i<126; i++)
|
||||
//Data display
|
||||
for (int i = 0; i<buffersize; i++)
|
||||
{
|
||||
display.drawLine((10+i), 60, (10+i), map(values[i], 0, 1000, 60, 10));
|
||||
}
|
||||
|
|
|
@ -35,4 +35,4 @@ void display_header(char* TEXT);
|
|||
void display_screen_pv(float pv_voltage, float pv_wattage, float battery_voltage, float pv_amps, float pv_kwh);
|
||||
void display_screen_battery(float battery_voltage, float battery_amps, float battery_wattage, float battery_soc, float batt_cell_v_min, float batt_cell_v_max);
|
||||
void display_screen_grid(float grid_power, float consum, float inv_power, float inv_current, float pv_wattage);
|
||||
void display_screen_graph(float values[100]);
|
||||
void display_screen_graph(float values[100], char* key, int buffersize);
|
||||
|
|
21
src/main.cpp
21
src/main.cpp
|
@ -94,8 +94,11 @@ bool display_conf_time_present = false;
|
|||
bool display_conf_dc_pvcharger_present = false;
|
||||
bool display_conf_graph_pv_present = false;
|
||||
bool display_conf_statistics_present = false;
|
||||
float display_graph_ringbuffer[126] = { 0 };
|
||||
int display_graph_ringbuffer_index = 0;
|
||||
float display_graph_ringbuffer_load_1h[100] = { 0 };
|
||||
float display_graph_ringbuffer_load_24h[100] = { 0 };
|
||||
float display_graph_ringbuffer_pv_1h[100] = { 0 };
|
||||
float display_graph_ringbuffer_pv_24h[100] = { 0 };
|
||||
const int display_graph_buffersize = 100;
|
||||
int display_refresh_counter = 0;
|
||||
int display_refresh_time;
|
||||
|
||||
|
@ -128,11 +131,10 @@ static unsigned long lastScreenChangeTime = 0;
|
|||
int display_screen = 0;
|
||||
|
||||
//Display graph ringbuffer
|
||||
void display_graph_ringbuffer_add(float value) {
|
||||
float tmp = value;
|
||||
display_graph_ringbuffer[0] = value;
|
||||
memmove(display_graph_ringbuffer,display_graph_ringbuffer+1,sizeof(int)*(125));
|
||||
display_graph_ringbuffer[125] = tmp;
|
||||
void display_graph_ringbuffer_add(float ringbuffer [display_graph_buffersize], float value) {
|
||||
ringbuffer[0] = value;
|
||||
memmove(ringbuffer, ringbuffer + 1, sizeof(int)*(display_graph_buffersize - 1));
|
||||
ringbuffer[display_graph_buffersize - 1] = value;
|
||||
}
|
||||
|
||||
//MQTT topics
|
||||
|
@ -181,9 +183,6 @@ void callback(char* topic, byte* message, unsigned int length) {
|
|||
DynamicJsonDocument json(512);
|
||||
deserializeJson(json, messageTemp);
|
||||
grid_p = json["value"];
|
||||
|
||||
//add every measurement to rbuffer
|
||||
display_graph_ringbuffer_add(grid_p);
|
||||
}
|
||||
|
||||
//Inverter - power
|
||||
|
@ -648,7 +647,7 @@ void loop() {
|
|||
{
|
||||
if (display_conf_graph_pv_present)
|
||||
{
|
||||
display_screen_graph(display_graph_ringbuffer);
|
||||
display_screen_graph(display_graph_ringbuffer_load_1h, (char*)"1h", display_graph_buffersize);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue