LCOV - code coverage report
Current view: top level - AP_Airspeed - AP_Airspeed_Scripting.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 3 100.0 %
Date: 2026-09-09 11:02:08 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :   airspeed backend for airspeed data supplied by a lua script, either
       3             :   as a differential pressure or as a direct airspeed reading
       4             :  */
       5             : #pragma once
       6             : 
       7             : #include "AP_Airspeed_config.h"
       8             : 
       9             : #if AP_AIRSPEED_SCRIPTING_ENABLED
      10             : 
      11             : #include "AP_Airspeed_Backend.h"
      12             : 
      13             : // data timeout
      14             : #define AP_AIRSPEED_SCRIPTING_TIMEOUT_MS 500
      15             : 
      16             : class AP_Airspeed_Scripting : public AP_Airspeed_Backend
      17             : {
      18             : public:
      19             :     using AP_Airspeed_Backend::AP_Airspeed_Backend;
      20             : 
      21           1 :     bool init() override {
      22           1 :         set_bus_id(AP_HAL::Device::make_bus_id(
      23             :             AP_HAL::Device::BUS_TYPE_UNKNOWN,
      24             :             0,
      25             :             0,
      26             :             uint8_t(DevType::SCRIPTING)
      27             :         ));
      28           1 :         return true;
      29             :     }
      30             : 
      31             :     // handle a differential pressure reading, in Pascal, from a lua script
      32             :     bool handle_script_differential_pressure(float press_pa) override;
      33             : 
      34             :     // handle an airspeed reading, in m/s, from a lua script
      35             :     bool handle_script_airspeed(float airspeed_ms) override;
      36             : 
      37             :     // handle a temperature reading, in degrees C, from a lua script
      38             :     bool handle_script_temperature(float temperature_c) override;
      39             : 
      40             :     // return the current differential_pressure in Pascal
      41             :     bool get_differential_pressure(float &pressure) override;
      42             : 
      43             :     // return the current temperature in degrees C, if available
      44             :     bool get_temperature(float &temperature) override;
      45             : 
      46             :     // true once the script has ever provided an airspeed reading directly. Latches on
      47             :     // permanently so that we never fall back to differential pressure once a script
      48             :     // has chosen to provide airspeed directly
      49             :     bool has_airspeed() override;
      50             : 
      51             :     // return airspeed in m/s
      52             :     bool get_airspeed(float &airspeed) override;
      53             : 
      54             : private:
      55             :     float last_pressure;
      56             :     uint32_t last_pressure_ms;
      57             : 
      58             :     float last_airspeed;
      59             :     uint32_t last_airspeed_ms;
      60             :     bool have_received_airspeed;
      61             : 
      62             :     float last_temperature;
      63             :     uint32_t last_temperature_ms;
      64             : };
      65             : 
      66             : #endif  // AP_AIRSPEED_SCRIPTING_ENABLED

Generated by: LCOV version 1.14