LCOV - code coverage report
Current view: top level - AP_WheelEncoder - WheelEncoder_Backend.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 13 21 61.9 %
Date: 2026-09-09 11:02:08 Functions: 2 4 50.0 %

          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_Common/AP_Common.h>
      17             : #include "AP_WheelEncoder.h"
      18             : #include "WheelEncoder_Backend.h"
      19             : 
      20             : // base class constructor.
      21           6 : AP_WheelEncoder_Backend::AP_WheelEncoder_Backend(AP_WheelEncoder &frontend, uint8_t instance, AP_WheelEncoder::WheelEncoder_State &state) :
      22           6 :         _frontend(frontend),
      23           6 :         _state(state) 
      24             : {
      25           6 :     state.instance = instance;
      26           6 : }
      27             : 
      28             : // return pin.  returns -1 if pin is not defined for this instance
      29           0 : int8_t AP_WheelEncoder_Backend::get_pin_a() const
      30             : {
      31           0 :     if (_state.instance >= WHEELENCODER_MAX_INSTANCES) {
      32           0 :         return -1;
      33             :     }
      34           0 :     return _frontend._pina[_state.instance].get();
      35             : }
      36             : 
      37             : // return pin.  returns -1 if pin is not defined for this instance
      38           0 : int8_t AP_WheelEncoder_Backend::get_pin_b() const
      39             : {
      40           0 :     if (_state.instance >= WHEELENCODER_MAX_INSTANCES) {
      41           0 :         return -1;
      42             :     }
      43           0 :     return _frontend._pinb[_state.instance].get();
      44             : }
      45             : 
      46             : // copy state to front end helper function
      47        5535 : void AP_WheelEncoder_Backend::copy_state_to_frontend(int32_t distance_count, uint32_t total_count, uint32_t error_count, uint32_t last_reading_ms)
      48             : {
      49             :     // record distance and time change for calculating rate before previous state is overwritten
      50        5535 :     _state.dt_ms = last_reading_ms - _state.last_reading_ms;
      51        5535 :     _state.dist_count_change = distance_count - _state.distance_count;
      52             : 
      53             :     // copy distance and error count so it is accessible to front end
      54        5535 :     _state.distance_count = distance_count;
      55        5535 :     _state.total_count = total_count;
      56        5535 :     _state.error_count = error_count;
      57        5535 :     _state.last_reading_ms = last_reading_ms;
      58        5535 : }

Generated by: LCOV version 1.14