add ringbuffer func
This commit is contained in:
parent
165831bac6
commit
e55a1b5fef
21
src/main.cpp
21
src/main.cpp
|
@ -120,13 +120,21 @@ tm tm;
|
|||
//Globals
|
||||
long lastMsg = 0;
|
||||
char msg[50];
|
||||
float pv_v = 0, pv_w = 0, pv_i = 0, pv_kwh = 0, inv_p = 0, inv_i = 0, batt_v = 0, batt_i = 0, batt_p = 0, batt_c_min = 0, batt_c_max = 0, grid_p = 0, batt_soc = 0, load_ph1 = 0, load_ph2 = 0, load_ph3 = 0;
|
||||
float pv_v = 0, pv_w = 0, pv_i = 0, pv_kwh = 0, inv_p = 0, inv_i = 0, batt_v = 0, batt_i = 0, batt_p = 0, batt_c_min = 0, batt_c_max = 0, grid_p = 0, consum_p = 0, batt_soc = 0, load_ph1 = 0, load_ph2 = 0, load_ph3 = 0;
|
||||
bool lastButtonRotationState = HIGH, lastButtonSetupState = HIGH;
|
||||
bool currentButtonRotationState, currentButtonSetupState;
|
||||
static unsigned long lastDispRefreshTime = 0;
|
||||
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;
|
||||
}
|
||||
|
||||
//MQTT topics
|
||||
void callback(char* topic, byte* message, unsigned int length) {
|
||||
logPrintlnD("Message arrived on topic: ");
|
||||
|
@ -174,10 +182,8 @@ void callback(char* topic, byte* message, unsigned int length) {
|
|||
deserializeJson(json, messageTemp);
|
||||
grid_p = json["value"];
|
||||
|
||||
//add to ringbuffer for testing
|
||||
display_graph_ringbuffer[display_graph_ringbuffer_index++] = grid_p;
|
||||
if (display_graph_ringbuffer_index == 126)
|
||||
display_graph_ringbuffer_index = 0;
|
||||
//add every measurement to rbuffer
|
||||
display_graph_ringbuffer_add(grid_p);
|
||||
}
|
||||
|
||||
//Inverter - power
|
||||
|
@ -242,18 +248,21 @@ void callback(char* topic, byte* message, unsigned int length) {
|
|||
DynamicJsonDocument json(512);
|
||||
deserializeJson(json, messageTemp);
|
||||
load_ph1 = json["value"];
|
||||
consum_p = load_ph1 + load_ph2 + load_ph3; //calc consumption on each msg for precision
|
||||
}
|
||||
//System - AC Load Phase 2
|
||||
if (String(topic) == mqtt_grid_power_l2) {
|
||||
DynamicJsonDocument json(512);
|
||||
deserializeJson(json, messageTemp);
|
||||
load_ph2 = json["value"];
|
||||
consum_p = load_ph1 + load_ph2 + load_ph3; //calc consumption on each msg for precision
|
||||
}
|
||||
//System - AC Load Phase 3
|
||||
if (String(topic) == mqtt_grid_power_l3) {
|
||||
DynamicJsonDocument json(512);
|
||||
deserializeJson(json, messageTemp);
|
||||
load_ph3 = json["value"];
|
||||
consum_p = load_ph1 + load_ph2 + load_ph3; //calc consumption on each msg for precision
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -618,7 +627,7 @@ void loop() {
|
|||
|
||||
if (display_refresh_counter <= display_refresh_time)
|
||||
{
|
||||
display_screen_grid(grid_p, inv_p, inv_i, pv_w);
|
||||
display_screen_grid(grid_p, consum_p, inv_p, inv_i, pv_w);
|
||||
}
|
||||
if (display_refresh_counter >= display_refresh_time && display_refresh_counter <= (display_refresh_time*2))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue