LCOV - code coverage report
Current view: top level - AP_Param - AP_ParamT.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 35 46 76.1 %
Date: 2026-09-09 11:02:08 Functions: 24 31 77.4 %

          Line data    Source code
       1             : /*
       2             :    This program is free software: you can redistribute it and/or modify
       3             :    it under the terms of the GNU General Public License as published by
       4             :    the Free Software Foundation, either version 3 of the License, or
       5             :    (at your option) any later version.
       6             : 
       7             :    This program is distributed in the hope that it will be useful,
       8             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10             :    GNU General Public License for more details.
      11             : 
      12             :    You should have received a copy of the GNU General Public License
      13             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      14             :  */
      15             : 
      16             : #include "AP_Param.h"
      17             : #include <AP_Math/AP_Math.h>
      18             : 
      19             : // Param type template functions
      20             : 
      21             : // set a parameter that is an ENABLE param
      22             : template<typename T, ap_var_type PT>
      23           0 : void AP_ParamTBase<T, PT>::set_enable(const T &v) {
      24             : #pragma GCC diagnostic push
      25             : #pragma GCC diagnostic ignored "-Wfloat-equal"
      26           0 :     if (v != _value) {
      27             : #pragma GCC diagnostic pop
      28           0 :         invalidate_count();
      29             :     }
      30           0 :     _value = v;
      31           0 : }
      32             : 
      33             : // Sets if the parameter is unconfigured
      34             : template<typename T, ap_var_type PT>
      35      147395 : void AP_ParamTBase<T, PT>::set_default(const T &v) {
      36             : #if AP_PARAM_DEFAULTS_ENABLED
      37      147395 :     add_default(this, (float)v);
      38             : #endif
      39      147395 :     if (!configured()) {
      40      140024 :         set(v);
      41             :     }
      42      147395 : }
      43             : 
      44             : // Sets parameter and default
      45             : template<typename T, ap_var_type PT>
      46       11178 : void AP_ParamTBase<T, PT>::set_and_default(const T &v) {
      47             : #if AP_PARAM_DEFAULTS_ENABLED
      48       11178 :     add_default(this, (float)v);
      49             : #endif
      50       11178 :     set(v);
      51       11178 : }
      52             : 
      53             : // Value setter - set value, tell GCS
      54             : template<typename T, ap_var_type PT>
      55       11081 : void AP_ParamTBase<T, PT>::set_and_notify(const T &v) {
      56             : // We do want to compare each value, even floats, since it being the same here
      57             : // is the result of previously setting it.
      58             : #pragma GCC diagnostic push
      59             : #pragma GCC diagnostic ignored "-Wfloat-equal"
      60       11081 :     if (v != _value) {
      61             : #pragma GCC diagnostic pop
      62        3596 :         set(v);
      63        3596 :         notify();
      64             :     }
      65       11081 : }
      66             : 
      67             : // Combined set and save
      68             : template<typename T, ap_var_type PT>
      69       25789 : void AP_ParamTBase<T, PT>::set_and_save(const T &v) {
      70       25789 :     bool force = fabsf((float)(_value - v)) < FLT_EPSILON;
      71       25789 :     set(v);
      72       25789 :     save(force);
      73       25789 : }
      74             : 
      75             : // Combined set and save, but only does the save if the value if
      76             : // different from the current ram value, thus saving us a
      77             : // scan(). This should only be used where we have not set() the
      78             : // value separately, as otherwise the value in EEPROM won't be
      79             : // updated correctly.
      80             : template<typename T, ap_var_type PT>
      81       61947 : void AP_ParamTBase<T, PT>::set_and_save_ifchanged(const T &v) {
      82             : #pragma GCC diagnostic push
      83             : #pragma GCC diagnostic ignored "-Wfloat-equal"
      84       61947 :     if (v == _value) {
      85             : #pragma GCC diagnostic pop
      86       47413 :         return;
      87             :     }
      88       14534 :     set(v);
      89       14534 :     save(true);
      90             : }
      91             : 
      92             : // AP_ParamTBase types can implement AP_Param::cast_to_float
      93             : template<typename T, ap_var_type PT>
      94     4470649 : float AP_ParamTBase<T, PT>::cast_to_float(void) const {
      95     4470649 :     return (float)_value;
      96             : }
      97             : 
      98             : template class AP_ParamTBase<float, AP_PARAM_FLOAT>;
      99             : template class AP_ParamTBase<int8_t, AP_PARAM_INT8>;
     100             : template class AP_ParamTBase<int16_t, AP_PARAM_INT16>;
     101             : template class AP_ParamTBase<int32_t, AP_PARAM_INT32>;
     102             : 
     103             : // Value setter - set value, tell GCS
     104             : template<typename T, ap_var_type PT>
     105           0 : void AP_ParamV<T, PT>::set_and_notify(const T &v) {
     106           0 :     if (v != _value) {
     107           0 :         set(v);
     108           0 :         notify();
     109             :     }
     110           0 : }
     111             : 
     112             :     /// Combined set and save
     113             : template<typename T, ap_var_type PT>
     114        1573 : void AP_ParamV<T, PT>::set_and_save(const T &v) {
     115        1573 :     bool force = (_value != v);
     116        1573 :     set(v);
     117        1573 :     save(force);
     118        1573 : }
     119             : 
     120             : // Combined set and save, but only does the save if the value is
     121             : // different from the current ram value, thus saving us a
     122             : // scan(). This should only be used where we have not set() the
     123             : // value separately, as otherwise the value in EEPROM won't be
     124             : // updated correctly.
     125             : template<typename T, ap_var_type PT>
     126         216 : void AP_ParamV<T, PT>::set_and_save_ifchanged(const T &v) {
     127             : #pragma GCC diagnostic push
     128             : #pragma GCC diagnostic ignored "-Wfloat-equal"
     129         216 :     if (_value == v) {
     130             : #pragma GCC diagnostic pop
     131           0 :         return;
     132             :     }
     133         216 :     set(v);
     134         216 :     save(true);
     135             : }
     136             : 
     137             : template class AP_ParamV<Vector3f, AP_PARAM_VECTOR3F>;

Generated by: LCOV version 1.14