Skip to content

Commit

Permalink
refactor: optimize data type
Browse files Browse the repository at this point in the history
  • Loading branch information
jhon-p16 committed Aug 22, 2022
1 parent 4ea615d commit 1c97465
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/BslibEnergyMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ float voltage;
* @param _inPinCurrentRef pin analógico Vref del sensor
* @param _factorCurrent factor de sensiblidad del sensor
*/
void BslibEnergyMeter::SetSensorCurrent(int _inPinCurrent, int _inPinCurrentRef, float _factorCurrent) {
void BslibEnergyMeter::SetSensorCurrent(unsigned int _inPinCurrent, unsigned int _inPinCurrentRef, float _factorCurrent) {
inPinCurrent = _inPinCurrent;
inPinCurrentRef = _inPinCurrentRef;
factorCurrent = _factorCurrent;
Expand All @@ -43,7 +43,7 @@ void BslibEnergyMeter::SetSensorCurrent(int _inPinCurrent, int _inPinCurrentRef,
* @param _factorVoltage factor de sensiblidad del sensor
* @param _offsetVoltage compensacion para obtener voltaje real
*/
void BslibEnergyMeter::SetSensorVoltage(int _inPinVoltage, float _factorVoltage, float _offsetVoltage = 0) {
void BslibEnergyMeter::SetSensorVoltage(unsigned int _inPinVoltage, float _factorVoltage, float _offsetVoltage = 0) {
inPinVoltage = _inPinVoltage;
factorVoltage = _factorVoltage;
offsetVoltage = _offsetVoltage;
Expand All @@ -55,7 +55,7 @@ void BslibEnergyMeter::SetSensorVoltage(int _inPinVoltage, float _factorVoltage,
* @param _inPinVoltage pin analógico de sensor de voltaje
* @param _factorVoltage factor de sensiblidad del sensor
*/
void BslibEnergyMeter::SetSensorVoltage(int _inPinVoltage, float _factorVoltage) {
void BslibEnergyMeter::SetSensorVoltage(unsigned int _inPinVoltage, float _factorVoltage) {
inPinVoltage = _inPinVoltage;
factorVoltage = _factorVoltage;
}
Expand All @@ -78,7 +78,7 @@ void BslibEnergyMeter::SetAnalogReference(float _analogReference) {
analogReference = _analogReference;
}

void BslibEnergyMeter::SetFilterSamples(int _numberOfSamples) {
void BslibEnergyMeter::SetFilterSamples(unsigned int _numberOfSamples) {
numberOfSamples = _numberOfSamples;
}

Expand All @@ -88,7 +88,7 @@ void BslibEnergyMeter::SetFilterSamples(int _numberOfSamples) {
* @param pinADC pin analógico al cual leer
* @return int
*/
int BslibEnergyMeter::FilterValueADC(int pinADC) {
int BslibEnergyMeter::FilterValueADC(unsigned int pinADC) {
unsigned long valueADC = 0;
int filteredValueADC = 0;
for (int i = 0; i < numberOfSamples; i++) {
Expand Down
18 changes: 9 additions & 9 deletions src/BslibEnergyMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

class BslibEnergyMeter {
public:
void SetSensorCurrent(int _inPinCurrent, int _inPinCurrentRef, float _factorCurrent);
void SetSensorVoltage(int _inPinVoltage, float _factorVoltage, float _offsetVoltage);
void SetSensorVoltage(int _inPinVoltage, float _factorVoltage);
void SetSensorCurrent(unsigned int _inPinCurrent, unsigned int _inPinCurrentRef, float _factorCurrent);
void SetSensorVoltage(unsigned int _inPinVoltage, float _factorVoltage, float _offsetVoltage);
void SetSensorVoltage(unsigned int _inPinVoltage, float _factorVoltage);

void SetCurrentReference(int _currentReference);
void SetAnalogReference(float _analogReference);
void SetFilterSamples(int _numberOfSamples);
void SetFilterSamples(unsigned int _numberOfSamples);

int FilterValueADC(int pinADC);
int FilterValueADC(unsigned int pinADC);
float SoftwareDAC(int digitalValue);

int AutoCalibrationCurrent(int lastVRef);
Expand All @@ -54,11 +54,11 @@ class BslibEnergyMeter {
float ReadVcc();

private:
int inPinCurrent;
int inPinCurrentRef;
int inPinVoltage;
unsigned int inPinCurrent;
unsigned int inPinCurrentRef;
unsigned int inPinVoltage;

int numberOfSamples;
unsigned int numberOfSamples;
float analogReference;
float factorCurrent;
float factorVoltage;
Expand Down

0 comments on commit 1c97465

Please sign in to comment.