change energy length

This commit is contained in:
Siwat Sirichai 2024-02-10 16:36:59 +07:00
parent 7a67732daf
commit 8378338ed8
2 changed files with 7 additions and 7 deletions

View File

@ -60,12 +60,12 @@ float CurrentTransformer::getCurrent()
return this->current;
}
long double CurrentTransformer::getEnergy()
double CurrentTransformer::getEnergy()
{
return this->energy;
}
uint8_t CurrentTransformer::registerCallback(std::function<void(float, long double)> callback) {
uint8_t CurrentTransformer::registerCallback(std::function<void(float, double)> callback) {
this->callbacks[this->handler_count] = callback;
return this->handler_count++;
}
@ -74,10 +74,10 @@ void CurrentTransformer::unregisterCallback(uint8_t handler) {
}
void CurrentTransformer::saveEnergy(){
this->fram->write(this->framAddress, (uint8_t*)&this->energy, 16);
this->fram->write(this->framAddress, (uint8_t*)&this->energy, sizeof(this->energy));
}
void CurrentTransformer::loadEnergy(){
this->fram->read(this->framAddress, (uint8_t*)&this->energy, 16);
this->fram->read(this->framAddress, (uint8_t*)&this->energy, sizeof(this->energy));
}
void CurrentTransformer::setEnergyAutoSave(bool autoSave){

View File

@ -25,7 +25,7 @@ class CurrentTransformer
void loadEnergy();
void setEnergyAutoSave(bool autoSave);
float getVoltage();
uint8_t registerCallback(std::function<void(float, long double)> callback);
uint8_t registerCallback(std::function<void(float, double)> callback);
void unregisterCallback(uint8_t handler);
private:
AnalogCard* analogCard;
@ -35,12 +35,12 @@ class CurrentTransformer
uint32_t conversionInterval;
bool autoSave;
float calibration;
long double energy;
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;
std::map<uint8_t,std::function<void(float, double)>> callbacks;
};