RAS refactoring
This commit is contained in:
@@ -36,23 +36,70 @@ class TelemetryValue {
|
||||
|
||||
void reset()
|
||||
{
|
||||
this->value = 0;
|
||||
set(0);
|
||||
};
|
||||
};
|
||||
|
||||
class FilteredTelemetryValue: public TelemetryValue {
|
||||
template <class T>
|
||||
class TelemetryFilterDecorator: public T {
|
||||
public:
|
||||
uint8_t value; // filtered value (average of last TELEMETRY_AVERAGE_COUNT+1 values)
|
||||
uint8_t values[TELEMETRY_AVERAGE_COUNT];
|
||||
void set(uint8_t value);
|
||||
void reset();
|
||||
void set(uint8_t value)
|
||||
{
|
||||
if (this->value == 0) {
|
||||
memset(values, value, TELEMETRY_AVERAGE_COUNT);
|
||||
this->value = value;
|
||||
}
|
||||
else {
|
||||
//calculate the average from values[] and value
|
||||
//also shift readings in values [] array
|
||||
unsigned int sum = values[0];
|
||||
for (int i=0; i<TELEMETRY_AVERAGE_COUNT-1; i++) {
|
||||
uint8_t tmp = values[i+1];
|
||||
values[i] = tmp;
|
||||
sum += tmp;
|
||||
}
|
||||
values[TELEMETRY_AVERAGE_COUNT-1] = value;
|
||||
sum += value;
|
||||
this->value = sum / (TELEMETRY_AVERAGE_COUNT+1);
|
||||
}
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
memclear(this, sizeof(*this));
|
||||
};
|
||||
};
|
||||
|
||||
class TelemetryValueWithMin: public FilteredTelemetryValue {
|
||||
template <class T>
|
||||
class TelemetryExpiringDecorator: public T {
|
||||
public:
|
||||
tmr10ms_t expirationTime;
|
||||
void set(uint8_t value)
|
||||
{
|
||||
T::set(value);
|
||||
expirationTime = get_tmr10ms();
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
memclear(this, sizeof(*this));
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class TelemetryMinDecorator: public T {
|
||||
public:
|
||||
uint8_t min;
|
||||
void set(uint8_t value);
|
||||
void reset();
|
||||
void set(uint8_t value)
|
||||
{
|
||||
T::set(value);
|
||||
if (!min || value < min) {
|
||||
min = value;
|
||||
}
|
||||
}
|
||||
void reset()
|
||||
{
|
||||
memclear(this, sizeof(*this));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _TELEMETRY_HOLDERS_H_
|
||||
|
||||
Reference in New Issue
Block a user