LCOV - code coverage report
Current view: top level - include - us_sensor.hpp (source / functions) Coverage Total Hit
Test: Ultrasonic Sensor Unified Coverage Lines: 100.0 % 1 1
Test Date: 2026-04-24 03:29:20 Functions: 100.0 % 2 2
Branches: 50.0 % 4 2

             Branch data     Line data    Source code
       1                 :             : #pragma once
       2                 :             : 
       3                 :             : #include <memory>
       4                 :             : 
       5                 :             : #include "i_us_driver.hpp"
       6                 :             : #include "i_us_processor.hpp"
       7                 :             : #include "i_us_sensor.hpp"
       8                 :             : #include "us_types.hpp"
       9                 :             : 
      10                 :             : namespace ultrasonic {
      11                 :             : 
      12                 :             : /**
      13                 :             :  * @brief Concrete implementation of IUsSensor.
      14                 :             :  *
      15                 :             :  * This class orchestrates multiple pings via IUsDriver and applies statistical
      16                 :             :  * processing via IUsProcessor to produce a final Reading.
      17                 :             :  *
      18                 :             :  * It manages the high-level measurement cycle, handling hardware failures
      19                 :             :  * immediately and logical failures (like timeouts or out-of-range pings) by
      20                 :             :  * collecting them for statistical analysis.
      21                 :             :  */
      22                 :             : class UsSensor : public IUsSensor
      23                 :             : {
      24                 :             : public:
      25                 :             :     /**
      26                 :             :      * @brief Construct a new UsSensor object.
      27                 :             :      *
      28                 :             :      * This constructor is intended for production use and automatically creates
      29                 :             :      * the necessary internal components (driver, processor, HALs).
      30                 :             :      *
      31                 :             :      * @param trig_pin GPIO number for the trigger pin.
      32                 :             :      * @param echo_pin GPIO number for the echo pin.
      33                 :             :      * @param cfg      Configuration structure for the sensor.
      34                 :             :      */
      35                 :             :     UsSensor(gpio_num_t trig_pin, gpio_num_t echo_pin, const UsConfig &cfg);
      36                 :             : 
      37                 :             :     /**
      38                 :             :      * @brief Construct a new UsSensor object with dependency injection.
      39                 :             :      *
      40                 :             :      * This constructor is primarily intended for unit testing or advanced
      41                 :             :      * customization.
      42                 :             :      *
      43                 :             :      * @param cfg       Configuration structure for the sensor.
      44                 :             :      * @param driver    Shared pointer to a driver implementation.
      45                 :             :      * @param processor Shared pointer to a processor implementation.
      46                 :             :      */
      47                 :             :     UsSensor(const UsConfig &cfg, std::shared_ptr<IUsDriver> driver, std::shared_ptr<IUsProcessor> processor);
      48                 :             : 
      49   [ +  -  +  - ]:          36 :     ~UsSensor() override = default;
      50                 :             : 
      51                 :             :     /** @copydoc IUsSensor::init() */
      52                 :             :     esp_err_t init() override;
      53                 :             : 
      54                 :             :     /** @copydoc IUsSensor::deinit() */
      55                 :             :     esp_err_t deinit() override;
      56                 :             : 
      57                 :             :     /** @copydoc IUsSensor::read_distance() */
      58                 :             :     Reading read_distance(uint8_t ping_count) override;
      59                 :             : 
      60                 :             : private:
      61                 :             :     /** @internal */
      62                 :             :     UsConfig cfg_;
      63                 :             :     /** @internal */
      64                 :             :     std::shared_ptr<IUsDriver> driver_;
      65                 :             :     /** @internal */
      66                 :             :     std::shared_ptr<IUsProcessor> processor_;
      67                 :             : 
      68                 :             :     /** @internal */
      69                 :             :     static constexpr uint8_t MAX_PINGS = 15;
      70                 :             : };
      71                 :             : 
      72                 :             : } // namespace ultrasonic
        

Generated by: LCOV version 2.0-1