this change adds support for a second Victron MPPT charge controller using a second serial connection. * Add device configuration for a second victron mppt * Update VedirectView for second victron mppt * Update MqttHandleVedirect for second victron mppt * Update MqttHandleVedirectHass for second victron mppt * Handle nonexisting victron controllers with optionals * Add bool-function to Battery and inherited classes, if uart port 2 is being used * Introduced a serial port manager. In order to prevent the battery and the Victron MPPT to use the same hw serial ports, this class keeps track of the used ports and their owners.
36 lines
789 B
C++
36 lines
789 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <TaskSchedulerDeclarations.h>
|
|
|
|
#include "BatteryStats.h"
|
|
|
|
class BatteryProvider {
|
|
public:
|
|
// returns true if the provider is ready for use, false otherwise
|
|
virtual bool init(bool verboseLogging) = 0;
|
|
virtual void deinit() = 0;
|
|
virtual void loop() = 0;
|
|
virtual std::shared_ptr<BatteryStats> getStats() const = 0;
|
|
virtual bool usesHwPort2() = 0;
|
|
};
|
|
|
|
class BatteryClass {
|
|
public:
|
|
void init(Scheduler&);
|
|
void updateSettings();
|
|
|
|
std::shared_ptr<BatteryStats const> getStats() const;
|
|
|
|
private:
|
|
void loop();
|
|
|
|
Task _loopTask;
|
|
mutable std::mutex _mutex;
|
|
std::unique_ptr<BatteryProvider> _upProvider = nullptr;
|
|
};
|
|
|
|
extern BatteryClass Battery;
|