Eliminate some preprocessor define usage

This commit is contained in:
Jaakko Haakana 2025-05-15 16:31:04 +03:00
parent 24fff70984
commit c58d7a2b67
8 changed files with 14 additions and 22 deletions

View file

@ -102,10 +102,7 @@ void setup() {
#endif // PRECHARGE_CONTROL
setup_charger();
#if defined(CAN_INVERTER_SELECTED) || defined(MODBUS_INVERTER_SELECTED) || defined(RS485_INVERTER_SELECTED)
setup_inverter();
#endif
setup_battery();
init_rs485();
@ -512,15 +509,9 @@ void update_calculated_values() {
}
void update_values_inverter() {
#ifdef SELECTED_INVERTER_CLASS
if (inverter) {
inverter->update_values();
}
#else
#ifdef CAN_INVERTER_SELECTED
update_values_can_inverter();
#endif // CAN_INVERTER_SELECTED
#endif
}
void check_reset_reason() {

View file

@ -39,13 +39,10 @@ String settings_processor(const String& var) {
String(getCANInterfaceName(can_config.battery_double)) + "</span></h4>";
#endif // DOUBLE_BATTERY
#ifdef CAN_INVERTER_SELECTED
if (inverter) {
content += "<h4 style='color: white;'>Inverter interface: <span id='Inverter'>" +
String(getCANInterfaceName(can_config.inverter)) + "</span></h4>";
#endif //CAN_INVERTER_SELECTED
#ifdef MODBUS_INVERTER_SELECTED
content += "<h4 style='color: white;'>Inverter interface: RS485<span id='Inverter'></span></h4>";
#endif
String(inverter->interface_name()) + "</span></h4>";
}
#ifdef CAN_SHUNT_SELECTED
content += "<h4 style='color: white;'>Shunt Interface: <span id='Shunt'>" +

View file

@ -7,6 +7,7 @@
class CanInverterProtocol : public InverterProtocol {
public:
virtual const char* interface_name() { return getCANInterfaceName(can_config.inverter); }
virtual void transmit_can(unsigned long currentMillis) = 0;
virtual void map_can_frame_to_variable(CAN_frame rx_frame) = 0;
};

View file

@ -3,9 +3,7 @@
// These functions adapt the old C-style global functions inverter-API to the
// object-oriented inverter protocol API.
#ifdef SELECTED_INVERTER_CLASS
InverterProtocol* inverter;
InverterProtocol* inverter = nullptr;
#ifdef CAN_INVERTER_SELECTED
CanInverterProtocol* can_inverter;
@ -30,7 +28,9 @@ void setup_inverter() {
inverter = new SELECTED_INVERTER_CLASS();
#endif
if (inverter) {
inverter->setup();
}
}
#ifdef CAN_INVERTER_SELECTED
@ -52,5 +52,3 @@ void receive_RS485() {
((Rs485InverterProtocol*)inverter)->receive_RS485();
}
#endif
#endif

View file

@ -30,6 +30,7 @@ extern InverterProtocol* inverter;
#include "SOLAX-CAN.h"
#include "SUNGROW-CAN.h"
// Call to initialize the build-time selected inverter. Safe to call even though inverter was not selected.
void setup_inverter();
#ifdef CAN_INVERTER_SELECTED

View file

@ -5,6 +5,7 @@
class InverterProtocol {
public:
virtual void setup() = 0;
virtual const char* interface_name() = 0;
// This function maps all the values fetched from battery to the correct battery emulator data structures
virtual void update_values() = 0;

View file

@ -10,6 +10,8 @@ extern uint16_t mbPV[];
// The abstract base class for all Modbus inverter protocols
class ModbusInverterProtocol : public InverterProtocol {
virtual const char* interface_name() { return "RS485 / Modbus"; }
protected:
// Create a ModbusRTU server instance with 2000ms timeout
ModbusInverterProtocol() : MBserver(2000) { mbPV = ::mbPV; }

View file

@ -5,6 +5,7 @@
class Rs485InverterProtocol : public InverterProtocol {
public:
virtual const char* interface_name() { return "RS485"; }
virtual void receive_RS485() = 0;
virtual int baud_rate() = 0;
};