Line data Source code
1 : #include "AP_Airspeed_Scripting.h" 2 : 3 : #if AP_AIRSPEED_SCRIPTING_ENABLED 4 : 5 : #include <AP_HAL/AP_HAL.h> 6 : 7 : // return the current differential_pressure in Pascal 8 0 : bool AP_Airspeed_Scripting::get_differential_pressure(float &pressure) 9 : { 10 0 : WITH_SEMAPHORE(sem); 11 0 : if (last_pressure_ms == 0 || AP_HAL::millis() - last_pressure_ms > AP_AIRSPEED_SCRIPTING_TIMEOUT_MS) { 12 0 : return false; 13 : } 14 0 : pressure = last_pressure; 15 0 : return true; 16 0 : } 17 : 18 : // get last temperature 19 138 : bool AP_Airspeed_Scripting::get_temperature(float &temperature) 20 : { 21 138 : WITH_SEMAPHORE(sem); 22 138 : if (last_temperature_ms == 0 || AP_HAL::millis() - last_temperature_ms > AP_AIRSPEED_SCRIPTING_TIMEOUT_MS) { 23 2 : return false; 24 : } 25 136 : temperature = last_temperature; 26 136 : return true; 27 138 : } 28 : 29 : // true once the script has ever provided an airspeed reading directly 30 55 : bool AP_Airspeed_Scripting::has_airspeed() 31 : { 32 55 : WITH_SEMAPHORE(sem); 33 110 : return have_received_airspeed; 34 55 : } 35 : 36 : // return airspeed in m/s 37 55 : bool AP_Airspeed_Scripting::get_airspeed(float &airspeed) 38 : { 39 55 : WITH_SEMAPHORE(sem); 40 55 : if (last_airspeed_ms == 0 || AP_HAL::millis() - last_airspeed_ms > AP_AIRSPEED_SCRIPTING_TIMEOUT_MS) { 41 0 : return false; 42 : } 43 55 : airspeed = last_airspeed; 44 55 : return true; 45 55 : } 46 : 47 0 : bool AP_Airspeed_Scripting::handle_script_differential_pressure(float press_pa) 48 : { 49 0 : WITH_SEMAPHORE(sem); 50 0 : if (have_received_airspeed) { 51 0 : return false; 52 : } 53 0 : last_pressure = press_pa; 54 0 : last_pressure_ms = AP_HAL::millis(); 55 0 : return true; 56 0 : } 57 : 58 55 : bool AP_Airspeed_Scripting::handle_script_airspeed(float airspeed_ms) 59 : { 60 55 : WITH_SEMAPHORE(sem); 61 55 : last_airspeed = airspeed_ms; 62 55 : last_airspeed_ms = AP_HAL::millis(); 63 : 64 : // Once an airspeed reading has been received reject pressure readings and skip calibration 65 55 : have_received_airspeed = true; 66 55 : set_use_zero_offset(); 67 110 : return true; 68 55 : } 69 : 70 55 : bool AP_Airspeed_Scripting::handle_script_temperature(float temperature_c) 71 : { 72 55 : WITH_SEMAPHORE(sem); 73 55 : last_temperature = temperature_c; 74 55 : last_temperature_ms = AP_HAL::millis(); 75 110 : return true; 76 55 : } 77 : 78 : #endif // AP_AIRSPEED_SCRIPTING_ENABLED