documentation checked and edit

for all files in lib folder
This commit is contained in:
2023-10-12 18:45:12 +02:00
parent 61a95e4601
commit db74898b72
41 changed files with 1030 additions and 569 deletions
+5 -5
View File
@@ -37,12 +37,12 @@ void Battery::run()
this->readAdcToBuf();
this->loopCounter++;
if (this->loopCounter >= this->calulationDelayMultiplier)
if (this->loopCounter >= this->calculateDelayMultiplier)
{
this->calculateBatteryVoltage();
this->calculateBatteryPercent();
this->loopCounter = 0;
this->calculatetNewValues = true;
this->calculatedNewValues = true;
}
}
@@ -89,12 +89,12 @@ bool Battery::isBatteryLow(double voltage) const
bool Battery::isNewValue()
{
if (!this->calculatetNewValues)
if (!this->calculatedNewValues)
{
return false;
}
this->calculatetNewValues = false;
this->calculatedNewValues = false;
return true;
}
@@ -136,7 +136,7 @@ double Battery::calculateInputVoltage()
return 0;
}
return -this->adcCurveCoeficient[0] * pow(reading, 4) + this->adcCurveCoeficient[1] * pow(reading, 3) - this->adcCurveCoeficient[2] * pow(reading, 2) + this->adcCurveCoeficient[3] * reading + this->adcCurveCoeficient[4];
return -this->adcCurveCoefficient[0] * pow(reading, 4) + this->adcCurveCoefficient[1] * pow(reading, 3) - this->adcCurveCoefficient[2] * pow(reading, 2) + this->adcCurveCoefficient[3] * reading + this->adcCurveCoefficient[4];
}
void Battery::calculateBatteryVoltage()
+66 -11
View File
@@ -24,12 +24,20 @@
*
* This class reads the voltage from an analog pin to calculate the
* charge level of a 3 Cell Li-Poly battery pack. The battery pack have
* to be after a voltage diveder, so that maximum voltage for the
* to be after a voltage divider, so that maximum voltage for the
* microcontroller is 3.3 Volt.
*/
class Battery : public Component
{
public:
/**
* @brief States when the calibration modes is active
*
* - None means that no calibration is running
* - Reading means that the adc takes multiple values to calculate an average
* - Waiting means that the user has to set the new wanted voltage
* - Finished means that all measurements was taken
*/
enum CalibrationState
{
None,
@@ -41,15 +49,25 @@ public:
/**
* @brief Construct a new Battery object
*
* The voltage devider have to be calculated, so that the input
* The voltage divider have to be calculated, so that the input
* voltage from 3.3 Volt is never exceeded. It is assumed that
* the microcontroller is connected to the second resistor.
*
* @param pin The analog to read from.
* @param firstResistor First resistor of the voltage devider.
* @param secondResistor Second resistor of the voltage devider.
* @param firstResistor First resistor of the voltage divider.
* @param secondResistor Second resistor of the voltage divider.
*/
Battery(uint8_t pin, uint32_t firstResistor, uint32_t secondResistor);
/**
* @brief Construct a new Battery object
*
* With this constructor the real voltage is not calculated with the
* voltage divider but with a table which contains the raw reading from
* the adc mapped to a specific voltage
*
* @param pin
*/
Battery(uint8_t pin);
/**
@@ -79,13 +97,50 @@ public:
*/
bool isBatteryLow(double voltage) const;
/**
* @brief Check if a new voltage was been calculated
*
* @return true
* @return false
*/
bool isNewValue();
// Calibration
CalibrationState getCalibrationState() const { return this->calibrationState; }
/**
* @brief Get the current calibration voltage target
*
* The returned value stand for the index of the table for this reason
* the real value have to be calculated. After the returned voltage has been set
* you have to call nextVoltageIsReady().
*
* @return uint8_t voltage multiply with 0,1 and add 7
*/
uint8_t getCurrentCalibrationVoltage() const { return this->currentCalibrationVoltage; }
/**
* @brief Read next wanted voltage
*
* If this function is called, the calibration mode reads the new voltage
* and save the value in the table.
*/
void nextVoltageIsReady();
/**
* @brief Calibrate the battery readings
*
* This calibration has only an effect if the Component
* uses the table with the raw adc values. The calibration gives
* the user different voltages that have to be set with a
* laboratory power supply. The power supply have to be connected
* instead of the battery.
*/
void startCalibration();
/**
* @brief abort the calibration
*/
void finishCalibration();
private:
@@ -109,14 +164,14 @@ private:
uint8_t batteryPercent = 0;
uint8_t batteryLowPercent = 10;
uint8_t bufferPos = 0;
uint8_t calulationDelayMultiplier = 5;
uint8_t calculateDelayMultiplier = 5;
uint8_t loopCounter = 0;
uint8_t currentCalibrationVoltage = 0; // *0.1 + 7
uint16_t adcBuffer[bufferSize];
uint16_t *newRawAdcVoltages = nullptr;
uint32_t firstResistor = 0;
uint32_t secondResistor = 0;
bool calculatetNewValues = false;
bool calculatedNewValues = false;
double batteryVoltage = 0;
double batteryVoltageFactor;
@@ -137,11 +192,11 @@ private:
2920, 2956, 2983, 3019, 3054, 3088, 3121, 3158, 3189, 3226,
3264, 3300, 3339, 3379, 3414, 3453, 3500, 3544, 3598, 3636,
3682, 3730, 3781, 3837, 3887, 3943, 3997, 4054, 4093, 4095};
const double adcCurveCoeficient[5] = {0.000000000000016,
0.000000000118171,
0.000000301211691,
0.001109019271794,
0.034143524634089};
const double adcCurveCoefficient[5] = {0.000000000000016,
0.000000000118171,
0.000000301211691,
0.001109019271794,
0.034143524634089};
};
#endif // BATTERY_H