|
|
@ -80,22 +80,17 @@ AP_Baro_BMP085::AP_Baro_BMP085(AP_Baro &baro, AP_HAL::OwnPtr<AP_HAL::I2CDevice> |
|
|
|
_state = 0; |
|
|
|
_state = 0; |
|
|
|
|
|
|
|
|
|
|
|
sem->give(); |
|
|
|
sem->give(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_dev->register_periodic_callback(20000, FUNCTOR_BIND_MEMBER(&AP_Baro_BMP085::_timer, bool)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
This is a state machine. Acumulate a new sensor reading. |
|
|
|
This is a state machine. Acumulate a new sensor reading. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void AP_Baro_BMP085::accumulate(void) |
|
|
|
bool AP_Baro_BMP085::_timer(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AP_HAL::Semaphore *sem = _dev->get_semaphore(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_data_ready()) { |
|
|
|
if (!_data_ready()) { |
|
|
|
return; |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// take i2c bus sempahore
|
|
|
|
|
|
|
|
if (!sem->take(1)) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_state == 0) { |
|
|
|
if (_state == 0) { |
|
|
@ -111,8 +106,7 @@ void AP_Baro_BMP085::accumulate(void) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
_cmd_read_pressure(); |
|
|
|
_cmd_read_pressure(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
sem->give(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -120,17 +114,18 @@ void AP_Baro_BMP085::accumulate(void) |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void AP_Baro_BMP085::update(void) |
|
|
|
void AP_Baro_BMP085::update(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!_has_sample && _data_ready()) { |
|
|
|
if (_sem->take_nonblocking()) { |
|
|
|
accumulate(); |
|
|
|
if (!_has_sample) { |
|
|
|
} |
|
|
|
_sem->give(); |
|
|
|
if (!_has_sample) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float temperature = 0.1f * _temp; |
|
|
|
float temperature = 0.1f * _temp; |
|
|
|
|
|
|
|
float pressure = _pressure_filter.getf(); |
|
|
|
|
|
|
|
|
|
|
|
float pressure = _pressure_filter.getf(); |
|
|
|
_copy_to_frontend(_instance, pressure, temperature); |
|
|
|
_copy_to_frontend(_instance, pressure, temperature); |
|
|
|
_sem->give(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Send command to Read Pressure
|
|
|
|
// Send command to Read Pressure
|
|
|
@ -217,8 +212,11 @@ void AP_Baro_BMP085::_calculate() |
|
|
|
x2 = (-7357 * p) >> 16; |
|
|
|
x2 = (-7357 * p) >> 16; |
|
|
|
p += ((x1 + x2 + 3791) >> 4); |
|
|
|
p += ((x1 + x2 + 3791) >> 4); |
|
|
|
|
|
|
|
|
|
|
|
_pressure_filter.apply(p); |
|
|
|
if (_sem->take(0)) { |
|
|
|
_has_sample = true; |
|
|
|
_pressure_filter.apply(p); |
|
|
|
|
|
|
|
_has_sample = true; |
|
|
|
|
|
|
|
_sem->give(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool AP_Baro_BMP085::_data_ready() |
|
|
|
bool AP_Baro_BMP085::_data_ready() |
|
|
|