get rid of particular compile-time designations by UART index. just hand out the next free index of hardware UARTs, or indicate that none is available any more. use names as keys to register and free UARTs.
35 lines
753 B
C++
35 lines
753 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;
|
|
};
|
|
|
|
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;
|