CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Baro/AP_Baro_MSP.cpp
Views: 1798
1
#include "AP_Baro_MSP.h"
2
3
#if AP_BARO_MSP_ENABLED
4
5
AP_Baro_MSP::AP_Baro_MSP(AP_Baro &baro, uint8_t _msp_instance) :
6
AP_Baro_Backend(baro)
7
{
8
msp_instance = _msp_instance;
9
instance = _frontend.register_sensor();
10
set_bus_id(instance, AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_MSP,0,msp_instance,0));
11
}
12
13
// Read the sensor
14
void AP_Baro_MSP::update(void)
15
{
16
if (count) {
17
WITH_SEMAPHORE(_sem);
18
_copy_to_frontend(instance, sum_pressure/count, sum_temp/count);
19
sum_pressure = sum_temp = 0;
20
count = 0;
21
}
22
}
23
24
void AP_Baro_MSP::handle_msp(const MSP::msp_baro_data_message_t &pkt)
25
{
26
if (pkt.instance != msp_instance) {
27
// not for us
28
return;
29
}
30
WITH_SEMAPHORE(_sem);
31
sum_pressure += pkt.pressure_pa;
32
sum_temp += pkt.temp*0.01;
33
count++;
34
}
35
36
#endif // AP_BARO_MSP_ENABLED
37
38