Add Pylontech battery to device pin manager
This commit is contained in:
parent
43436e19b7
commit
06fbdf1f12
@ -31,6 +31,8 @@ struct PinMapping_t {
|
||||
uint8_t display_reset;
|
||||
uint8_t victron_tx;
|
||||
uint8_t victron_rx;
|
||||
uint8_t battery_rx;
|
||||
uint8_t battery_tx;
|
||||
};
|
||||
|
||||
class PinMappingClass {
|
||||
@ -42,6 +44,7 @@ public:
|
||||
bool isValidNrf24Config();
|
||||
bool isValidEthConfig();
|
||||
bool isValidVictronConfig();
|
||||
bool isValidBatteryConfig();
|
||||
|
||||
private:
|
||||
PinMapping_t _pinMapping;
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
|
||||
class PylontechCanReceiverClass {
|
||||
public:
|
||||
void init();
|
||||
void init(int8_t rx, int8_t tx);
|
||||
void enable();
|
||||
void loop();
|
||||
void parseCanPackets();
|
||||
void mqtt();
|
||||
|
||||
@ -64,6 +64,8 @@ PinMappingClass::PinMappingClass()
|
||||
_pinMapping.victron_tx = VICTRON_PIN_TX;
|
||||
_pinMapping.victron_rx = VICTRON_PIN_RX;
|
||||
|
||||
_pinMapping.battery_rx = PYLONTECH_PIN_RX;
|
||||
_pinMapping.battery_tx = PYLONTECH_PIN_TX;
|
||||
}
|
||||
|
||||
PinMapping_t& PinMappingClass::get()
|
||||
@ -119,6 +121,9 @@ bool PinMappingClass::init(const String& deviceMapping)
|
||||
_pinMapping.victron_rx = doc[i]["victron"]["rx"] | VICTRON_PIN_RX;
|
||||
_pinMapping.victron_tx = doc[i]["victron"]["tx"] | VICTRON_PIN_TX;
|
||||
|
||||
_pinMapping.battery_rx = doc[i]["battery"]["rx"] | PYLONTECH_PIN_RX;
|
||||
_pinMapping.battery_tx = doc[i]["battery"]["tx"] | PYLONTECH_PIN_TX;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -146,3 +151,9 @@ bool PinMappingClass::isValidVictronConfig()
|
||||
return _pinMapping.victron_rx > 0
|
||||
&& _pinMapping.victron_tx > 0;
|
||||
}
|
||||
|
||||
bool PinMappingClass::isValidBatteryConfig()
|
||||
{
|
||||
return _pinMapping.battery_rx > 0
|
||||
&& _pinMapping.battery_tx > 0;
|
||||
}
|
||||
|
||||
@ -9,16 +9,21 @@
|
||||
|
||||
PylontechCanReceiverClass PylontechCanReceiver;
|
||||
|
||||
void PylontechCanReceiverClass::init()
|
||||
void PylontechCanReceiverClass::init(int8_t rx, int8_t tx)
|
||||
{
|
||||
CAN.setPins(rx, tx);
|
||||
|
||||
CONFIG_T& config = Configuration.get();
|
||||
|
||||
if (!config.Battery_Enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
CAN.setPins(PYLONTECH_PIN_RX, PYLONTECH_PIN_TX);
|
||||
enable();
|
||||
}
|
||||
|
||||
void PylontechCanReceiverClass::enable()
|
||||
{
|
||||
if (!CAN.begin(500E3)) {
|
||||
Hoymiles.getMessageOutput()->println("Starting CAN failed!");
|
||||
}
|
||||
|
||||
@ -108,6 +108,6 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
|
||||
request->send(response);
|
||||
|
||||
if (config.Battery_Enabled) {
|
||||
PylontechCanReceiver.init();
|
||||
PylontechCanReceiver.enable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +73,10 @@ void WebApiDeviceClass::onDeviceAdminGet(AsyncWebServerRequest* request)
|
||||
victronPinObj[F("rx")] = pin.victron_rx;
|
||||
victronPinObj[F("tx")] = pin.victron_tx;
|
||||
|
||||
JsonObject batteryPinObj = curPin.createNestedObject("battery");
|
||||
batteryPinObj[F("rx")] = pin.battery_rx;
|
||||
batteryPinObj[F("tx")] = pin.battery_tx;
|
||||
|
||||
response->setLength();
|
||||
request->send(response);
|
||||
}
|
||||
|
||||
11
src/main.cpp
11
src/main.cpp
@ -149,8 +149,15 @@ void setup()
|
||||
// Dynamic power limiter
|
||||
PowerLimiter.init();
|
||||
|
||||
// Pylontech / CAN bus
|
||||
PylontechCanReceiver.init();
|
||||
// Initialize Pylontech Battery / CAN bus
|
||||
MessageOutput.println(F("Initialize Pylontech battery interface... "));
|
||||
if (PinMapping.isValidBatteryConfig()) {
|
||||
MessageOutput.printf("Pylontech Battery rx = %d, tx = %d\r\n", pin.battery_rx, pin.battery_tx);
|
||||
PylontechCanReceiver.init(pin.battery_rx, pin.battery_tx);
|
||||
MessageOutput.println(F("done"));
|
||||
} else {
|
||||
MessageOutput.println(F("Invalid pin config"));
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user