Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Dec 29, 2024
1 parent 787448e commit 5335789
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 541 deletions.
5 changes: 2 additions & 3 deletions include/YaSolR.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <MycilaTaskMonitor.h>
#include <MycilaTime.h>
#include <MycilaTrafficLight.h>
#include <MycilaUtilities.h>

#ifdef APP_MODEL_TRIAL
#include <MycilaTrial.h>
Expand Down Expand Up @@ -149,7 +150,6 @@ extern float yasolr_frequency();
extern void yasolr_boot();
extern void yasolr_configure();
extern void yasolr_divert();
extern void yasolr_event_listeners();

extern void yasolr_start_config();
extern void yasolr_start_display();
Expand All @@ -162,10 +162,9 @@ extern void yasolr_start_logging();
extern void yasolr_start_mqtt();
extern void yasolr_start_network();
extern void yasolr_start_pzem();
extern void yasolr_start_rest_api();
extern void yasolr_start_system();
extern void yasolr_start_trial();
extern void yasolr_start_website();
extern void yasolr_start_web_server();
extern void yasolr_start_zcd();

extern void yasolr_configure_logging();
39 changes: 39 additions & 0 deletions src/fn/yasolr_configure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,27 @@
* Copyright (C) 2023-2024 Mathieu Carbou
*/
#include <YaSolR.h>
#include <YaSolRWebsite.h>

#include <string>

void yasolr_divert() {
if (router.isCalibrationRunning())
return;

if (!output1.isAutoDimmerEnabled() && !output2.isAutoDimmerEnabled())
return;

std::optional<float> voltage = grid.getVoltage();

if (voltage.has_value() && grid.getPower().isPresent()) {
router.divert(voltage.value(), grid.getPower().get());
if (website.pidCharts()) {
dashboardUpdateTask.requestEarlyRun();
}
}
}

void yasolr_configure() {
logger.info(TAG, "Configuring %s", Mycila::AppInfo.nameModelVersion.c_str());

Expand Down Expand Up @@ -85,4 +103,25 @@ void yasolr_configure() {
// Router
router.addOutput(output1);
router.addOutput(output2);

bypassRelayO1.listen([](bool state) {
logger.info(TAG, "Output 1 Relay changed to %s", state ? "ON" : "OFF");
if (mqttPublishTask)
mqttPublishTask->requestEarlyRun();
});
bypassRelayO2.listen([](bool state) {
logger.info(TAG, "Output 2 Relay changed to %s", state ? "ON" : "OFF");
if (mqttPublishTask)
mqttPublishTask->requestEarlyRun();
});
relay1.listen([](bool state) {
logger.info(TAG, "Relay 1 changed to %s", state ? "ON" : "OFF");
if (mqttPublishTask)
mqttPublishTask->requestEarlyRun();
});
relay2.listen([](bool state) {
logger.info(TAG, "Relay 2 changed to %s", state ? "ON" : "OFF");
if (mqttPublishTask)
mqttPublishTask->requestEarlyRun();
});
}
23 changes: 0 additions & 23 deletions src/fn/yasolr_divert.cpp

This file was deleted.

33 changes: 0 additions & 33 deletions src/fn/yasolr_event_listeners.cpp

This file was deleted.

35 changes: 0 additions & 35 deletions src/fn/yasolr_frequency.cpp

This file was deleted.

30 changes: 30 additions & 0 deletions src/fn/yasolr_start_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@

Mycila::Grid grid;

float yasolr_frequency() {
float frequency = round(grid.getFrequency().value_or(NAN));
if (frequency > 0)
return frequency;

if (pzemO1) {
frequency = round(pzemO1->data.frequency);
if (frequency > 0)
return frequency;
}

if (pzemO2) {
frequency = round(pzemO2->data.frequency);
if (frequency > 0)
return frequency;
}

frequency = config.getFloat(KEY_GRID_FREQUENCY);
if (frequency)
return frequency;

if (pulseAnalyzer) {
frequency = pulseAnalyzer->getNominalGridFrequency();
if (frequency)
return frequency;
}

return 0;
}

void yasolr_start_grid() {
grid.localMetrics().setExpiration(10000); // local is fast
grid.remoteMetrics().setExpiration(10000); // remote JSY is fast
Expand Down
Loading

0 comments on commit 5335789

Please sign in to comment.