diff --git a/conf/modules/baro_ets.xml b/conf/modules/baro_ets.xml
index 9a8003de05..161637c126 100644
--- a/conf/modules/baro_ets.xml
+++ b/conf/modules/baro_ets.xml
@@ -11,11 +11,10 @@
-
+
-
+
-
diff --git a/sw/airborne/modules/sensors/baro_ets.c b/sw/airborne/modules/sensors/baro_ets.c
index 0d3064b11e..328b1e71f2 100644
--- a/sw/airborne/modules/sensors/baro_ets.c
+++ b/sw/airborne/modules/sensors/baro_ets.c
@@ -81,62 +81,65 @@ void baro_ets_init( void ) {
baro_ets_cnt = BARO_ETS_OFFSET_NBSAMPLES_INIT + BARO_ETS_OFFSET_NBSAMPLES_AVRG;
baro_ets_r = BARO_ETS_R;
baro_ets_sigma2 = BARO_ETS_SIGMA2;
+
+ baro_ets_i2c_trans.status = I2CTransDone;
}
void baro_ets_read_periodic( void ) {
// Initiate next read
#ifndef SITL
- I2CReceive(i2c0, baro_ets_i2c_trans, BARO_ETS_ADDR, 2);
+ if (baro_ets_i2c_trans.status == I2CTransDone)
+ I2CReceive(i2c0, baro_ets_i2c_trans, BARO_ETS_ADDR, 2);
#else // SITL
baro_ets_adc = 0;
baro_ets_altitude = gps_alt / 100.0;
baro_ets_valid = TRUE;
EstimatorSetAlt(baro_ets_altitude);
#endif
-}
-
-void baro_ets_read_event( void ) {
- // Get raw altimeter from buffer
- baro_ets_adc = ((uint16_t)(baro_ets_i2c_trans.buf[1]) << 8) | (uint16_t)(baro_ets_i2c_trans.buf[0]);
- // Check if this is valid altimeter
- if (baro_ets_adc == 0)
- baro_ets_valid = FALSE;
- else
- baro_ets_valid = TRUE;
-
- // Continue only if a new altimeter value was received
- if (baro_ets_valid) {
- // Calculate offset average if not done already
- if (!baro_ets_offset_init) {
- --baro_ets_cnt;
- // Check if averaging completed
- if (baro_ets_cnt == 0) {
- // Calculate average
- baro_ets_offset = (uint16_t)(baro_ets_offset_tmp / BARO_ETS_OFFSET_NBSAMPLES_AVRG);
- // Limit offset
- if (baro_ets_offset < BARO_ETS_OFFSET_MIN)
- baro_ets_offset = BARO_ETS_OFFSET_MIN;
- if (baro_ets_offset > BARO_ETS_OFFSET_MAX)
- baro_ets_offset = BARO_ETS_OFFSET_MAX;
- baro_ets_offset_init = TRUE;
- }
- // Check if averaging needs to continue
- else if (baro_ets_cnt <= BARO_ETS_OFFSET_NBSAMPLES_AVRG)
- baro_ets_offset_tmp += baro_ets_adc;
- }
- // Convert raw to m/s
- if (baro_ets_offset_init)
- baro_ets_altitude = BARO_ETS_SCALE * (float)(baro_ets_offset-baro_ets_adc);
- else
- baro_ets_altitude = 0.0;
- // New value available
- EstimatorSetAlt(baro_ets_altitude);
- } else {
- baro_ets_altitude = 0.0;
- }
-
- // Transaction has been read
- baro_ets_i2c_trans.status = I2CTransDone;
-
}
+void baro_ets_event( void ) {
+ if (baro_ets_i2c_trans.status == I2CTransSuccess) {
+ // Get raw altimeter from buffer
+ baro_ets_adc = ((uint16_t)(baro_ets_i2c_trans.buf[1]) << 8) | (uint16_t)(baro_ets_i2c_trans.buf[0]);
+ // Check if this is valid altimeter
+ if (baro_ets_adc == 0)
+ baro_ets_valid = FALSE;
+ else
+ baro_ets_valid = TRUE;
+
+ // Continue only if a new altimeter value was received
+ if (baro_ets_valid) {
+ // Calculate offset average if not done already
+ if (!baro_ets_offset_init) {
+ --baro_ets_cnt;
+ // Check if averaging completed
+ if (baro_ets_cnt == 0) {
+ // Calculate average
+ baro_ets_offset = (uint16_t)(baro_ets_offset_tmp / BARO_ETS_OFFSET_NBSAMPLES_AVRG);
+ // Limit offset
+ if (baro_ets_offset < BARO_ETS_OFFSET_MIN)
+ baro_ets_offset = BARO_ETS_OFFSET_MIN;
+ if (baro_ets_offset > BARO_ETS_OFFSET_MAX)
+ baro_ets_offset = BARO_ETS_OFFSET_MAX;
+ baro_ets_offset_init = TRUE;
+ }
+ // Check if averaging needs to continue
+ else if (baro_ets_cnt <= BARO_ETS_OFFSET_NBSAMPLES_AVRG)
+ baro_ets_offset_tmp += baro_ets_adc;
+ }
+ // Convert raw to m/s
+ if (baro_ets_offset_init)
+ baro_ets_altitude = BARO_ETS_SCALE * (float)(baro_ets_offset-baro_ets_adc);
+ else
+ baro_ets_altitude = 0.0;
+ // New value available
+ EstimatorSetAlt(baro_ets_altitude);
+ } else {
+ baro_ets_altitude = 0.0;
+ }
+
+ // Transaction has been read
+ baro_ets_i2c_trans.status = I2CTransDone;
+ }
+}
diff --git a/sw/airborne/modules/sensors/baro_ets.h b/sw/airborne/modules/sensors/baro_ets.h
index 337c4c041c..a288bcfbdf 100644
--- a/sw/airborne/modules/sensors/baro_ets.h
+++ b/sw/airborne/modules/sensors/baro_ets.h
@@ -56,8 +56,6 @@ extern struct i2c_transaction baro_ets_i2c_trans;
extern void baro_ets_init( void );
extern void baro_ets_read_periodic( void );
-extern void baro_ets_read_event( void );
-
-#define BaroEtsEvent() { if (baro_ets_i2c_trans.status == I2CTransSuccess) baro_ets_read_event(); }
+extern void baro_ets_event( void );
#endif // BARO_ETS_H