param: add commit_no_notification(T val) API

This commit is contained in:
Beat Küng 2021-02-05 10:06:51 +01:00 committed by Lorenz Meier
parent 3ef93823f4
commit 2a0a82fd90
1 changed files with 62 additions and 0 deletions

View File

@ -40,6 +40,8 @@
#pragma once
#include "param_macros.h"
#include <float.h>
#include <math.h>
#include <parameters/px4_parameters.hpp>
@ -130,6 +132,18 @@ public:
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
/// Set and commit a new value. Returns true if the value changed.
bool commit_no_notification(float val)
{
if (fabsf(val - _val) > FLT_EPSILON) {
set(val);
commit_no_notification();
return true;
}
return false;
}
void set(float val) { _val = val; }
void reset()
@ -170,6 +184,18 @@ public:
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
/// Set and commit a new value. Returns true if the value changed.
bool commit_no_notification(float val)
{
if (fabsf(val - _val) > FLT_EPSILON) {
set(val);
commit_no_notification();
return true;
}
return false;
}
void set(float val) { _val = val; }
void reset()
@ -208,6 +234,18 @@ public:
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
/// Set and commit a new value. Returns true if the value changed.
bool commit_no_notification(int32_t val)
{
if (val != _val) {
set(val);
commit_no_notification();
return true;
}
return false;
}
void set(int32_t val) { _val = val; }
void reset()
@ -248,6 +286,18 @@ public:
/// Store the parameter value to the parameter storage, w/o notifying the system (@see param_set_no_notification())
bool commit_no_notification() const { return param_set_no_notification(handle(), &_val) == 0; }
/// Set and commit a new value. Returns true if the value changed.
bool commit_no_notification(int32_t val)
{
if (val != _val) {
set(val);
commit_no_notification();
return true;
}
return false;
}
void set(int32_t val) { _val = val; }
void reset()
@ -294,6 +344,18 @@ public:
return param_set_no_notification(handle(), &value_int) == 0;
}
/// Set and commit a new value. Returns true if the value changed.
bool commit_no_notification(bool val)
{
if (val != _val) {
set(val);
commit_no_notification();
return true;
}
return false;
}
void set(bool val) { _val = val; }
void reset()