remove most of the defines

This commit is contained in:
2023-08-18 15:34:56 +02:00
parent 4cd2b9368d
commit a82b32087c
21 changed files with 155 additions and 285 deletions
+14 -39
View File
@@ -11,18 +11,22 @@
*/
#include "speedometer.h"
Speedometer::Speedometer(uint8_t pin, double diameter, uint16_t steps, uint8_t numOfValForAvg) {
this->init(pin, diameter, steps);
this->bufSize = numOfValForAvg;
this->loopDelay = DELAY_SPEEDOMETER;
}
Speedometer::Speedometer(uint8_t pin, double diameter, uint16_t steps) {
this->init(pin, diameter, steps);
this->diameter = diameter;
this->steps = steps;
this->pulseCounter = new Counter(pin);
this->pulseCounter->setFilterValue(1000); // ignore pulses less than 1000 x 2.5ns
this->pulseCounter->clear();
this->pulseCounter->resume();
Component::loopDelay = Speedometer::loopDelay;
clearAvgBuf();
}
Speedometer::~Speedometer() {
delete[] this->buf;
delete this->pulseCounter;
}
@@ -58,7 +62,7 @@ void Speedometer::run() {
break;
}
this->addValToBuf(static_cast<int16_t>(this->speed * CONVERSION_FACTOR));
this->addValToBuf(static_cast<int16_t>(this->speed * Speedometer::conversionFactor));
}
void Speedometer::setDirection(Direction dir) {
@@ -68,11 +72,6 @@ void Speedometer::setDirection(Direction dir) {
this->clearAvgBuf();
}
void Speedometer::setNumOfValForAvg(uint8_t val) {
this->bufSize = val;
updateAvgBufSize();
}
void Speedometer::setEncFilter(uint16_t val) {
if (val > 1023)
val = 1023;
@@ -81,7 +80,7 @@ void Speedometer::setEncFilter(uint16_t val) {
double Speedometer::getAvgSpeed() const {
int16_t avg = this->calcAverage();
return (float)avg / CONVERSION_FACTOR;
return (float)avg / Speedometer::conversionFactor;
}
void Speedometer::calibrationMeasurementStart() {
@@ -101,25 +100,6 @@ uint16_t Speedometer::calibrationMeasurementStop() {
return res;
}
void Speedometer::init(uint8_t pin, double diameter, uint16_t steps) {
this->diameter = diameter;
this->steps = steps;
this->pulseCounter = new Counter(pin);
this->pulseCounter->setFilterValue(1000); // ignore pulses less than 1000 x 2.5ns
this->pulseCounter->clear();
this->pulseCounter->resume();
initAvgBuf();
}
void Speedometer::initAvgBuf() {
this->buf = new int16_t[bufSize];
for (uint8_t i = 0; i < bufSize; i++)
this->buf[i] = 0;
}
void Speedometer::clearAvgBuf() {
for (uint8_t i = 0; i < bufSize; i++)
this->buf[i] = 0;
@@ -133,11 +113,6 @@ void Speedometer::addValToBuf(int16_t val) {
bufPos = 0;
}
void Speedometer::updateAvgBufSize() {
delete[] this->buf;
initAvgBuf();
}
int16_t Speedometer::calcAverage() const {
int16_t sum = 0;
for (int i = 0; i < this->bufSize; i++)