cleaning
refactore all components now have a base class compnent for loop functions
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "counter.h"
|
||||
#include "component.h"
|
||||
|
||||
/**
|
||||
* @brief The default size of numbers to be taken in account for the average.
|
||||
@@ -38,7 +39,7 @@
|
||||
* The calculated speed is the average of an amount of last measurements.
|
||||
*
|
||||
*/
|
||||
class Speedometer {
|
||||
class Speedometer : public Component {
|
||||
public:
|
||||
/**
|
||||
* @brief Enum to control the direction.
|
||||
@@ -66,24 +67,6 @@ class Speedometer {
|
||||
|
||||
~Speedometer();
|
||||
|
||||
/**
|
||||
* @brief Calls runSpeedometer() to update all Values.
|
||||
*
|
||||
* This function should be called every mainloop. If the delayLoop is not reached, than the
|
||||
* functions returns immediately.
|
||||
* @see runSpeedometer()
|
||||
* @see DELAY_SPEEDOMETER
|
||||
* @return time since the last call in Milliseconds
|
||||
*/
|
||||
uint16_t loop();
|
||||
|
||||
/**
|
||||
* @brief Normally called repeatedly by loop() to calculate new values.
|
||||
*
|
||||
* Add a new Value to the average and update the speed.
|
||||
*/
|
||||
void runSpeedometer();
|
||||
|
||||
/**
|
||||
* @brief Set the direction
|
||||
*
|
||||
@@ -107,13 +90,6 @@ class Speedometer {
|
||||
*/
|
||||
void setEncFilter(uint16_t val);
|
||||
|
||||
/**
|
||||
* @brief Set the min delayLoop between each loop
|
||||
*
|
||||
* @param delayLoop time in Milliseconds
|
||||
*/
|
||||
void setDelay(uint8_t delayLoop) { this->delayLoop = delayLoop; }
|
||||
|
||||
/**
|
||||
* @brief Get the Direction
|
||||
*
|
||||
@@ -149,6 +125,7 @@ class Speedometer {
|
||||
|
||||
|
||||
private:
|
||||
void run() override;
|
||||
void init(uint8_t pin, double diameter, uint16_t steps);
|
||||
void initAvgBuf();
|
||||
void clearAvgBuf();
|
||||
@@ -166,13 +143,11 @@ class Speedometer {
|
||||
|
||||
uint8_t printCounter = 0;
|
||||
uint8_t bufSize = BUFSIZE;
|
||||
uint8_t delayLoop = DELAY_SPEEDOMETER;
|
||||
uint8_t bufPos = 0;
|
||||
uint16_t steps;
|
||||
|
||||
int16_t *buf = nullptr;
|
||||
|
||||
uint32_t lastMillisLoop = 0;
|
||||
uint32_t lastMillisCalc = 0;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user