beta current transformer card
This commit is contained in:
parent
8232bce927
commit
8244ad1c8a
2 changed files with 139 additions and 0 deletions
46
ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CurrentTransformer.hpp
Normal file
46
ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/CurrentTransformer.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
#include <AnalogCard.hpp>
|
||||
#include <FRAM.h>
|
||||
#include <map>
|
||||
|
||||
/**
|
||||
* @brief The CurrentTransformer class is a class for reading the current and energy from a current transformer that's connected to the AnalogCard.
|
||||
* Also supports storing energy to FRAM.
|
||||
*/
|
||||
|
||||
class CurrentTransformer
|
||||
{
|
||||
public:
|
||||
CurrentTransformer(AnalogCard* analogCard, uint8_t pin, float *voltage, std::function<float(uint16_t)> adcToCurrent, uint32_t conversionInterval);
|
||||
void bindFRAM(FRAM *fram, uint8_t framAddress); // Takes 16 bytes of FRAM (long double energy)
|
||||
void begin();
|
||||
void loop();
|
||||
void beginConversion();
|
||||
void setEnergy(float energy);
|
||||
void resetEnergy();
|
||||
float getCurrent();
|
||||
long double getEnergy();
|
||||
float getPower();
|
||||
void saveEnergy();
|
||||
void loadEnergy();
|
||||
void setEnergyAutoSave(bool autoSave);
|
||||
float getVoltage();
|
||||
uint8_t registerCallback(std::function<void(float, long double)> callback);
|
||||
void unregisterCallback(uint8_t handler);
|
||||
private:
|
||||
AnalogCard* analogCard;
|
||||
uint8_t pin;
|
||||
uint8_t framAddress;
|
||||
FRAM *fram;
|
||||
uint32_t conversionInterval;
|
||||
bool autoSave;
|
||||
float calibration;
|
||||
long double energy;
|
||||
float current;
|
||||
float *voltage;
|
||||
uint32_t lastConversionTime;
|
||||
std::function<float(uint16_t)> adcToCurrent; // std::function that convert adc value to current in amps
|
||||
uint8_t handler_count = 0;
|
||||
std::map<uint8_t,std::function<void(float, long double)>> callbacks;
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue