Add Rate class for running the code at fixed rate

This commit is contained in:
Oleg Kalachev
2025-11-06 13:41:33 +03:00
parent 1a017ccb97
commit 0e6651ab82
4 changed files with 29 additions and 20 deletions

View File

@@ -4,6 +4,7 @@
// Parameters storage in flash memory
#include <Preferences.h>
#include "util.h"
extern float channelZero[16];
extern float channelMax[16];
@@ -118,10 +119,9 @@ bool setParameter(const char *name, const float value) {
}
void syncParameters() {
static float lastSync = 0;
if (t - lastSync < 1) return; // sync once per second
static Rate rate(1);
if (!rate) return; // sync once per second
if (motorsActive()) return; // don't use flash while flying, it may cause a delay
lastSync = t;
for (auto &parameter : parameters) {
if (parameter.value == *parameter.variable) continue;