diff --git a/sw/airborne/boards/apogee/baro_board.c b/sw/airborne/boards/apogee/baro_board.c index 27aabe4bfe..c337bdf627 100644 --- a/sw/airborne/boards/apogee/baro_board.c +++ b/sw/airborne/boards/apogee/baro_board.c @@ -36,8 +36,31 @@ #include "subsystems/abi.h" #include "led.h" +/** Normal frequency with the default settings + * + * the baro read function should be called at 5 Hz + */ +#ifndef BARO_BOARD_APOGEE_FREQ +#define BARO_BOARD_APOGEE_FREQ 5 +#endif + +/** Baro periodic prescaler + * + * different for fixedwing and rotorcraft... + */ +#ifdef BARO_PERIODIC_FREQUENCY +#define MPL_PRESCALER ((BARO_PERIODIC_FREQUENCY)/BARO_BOARD_APOGEE_FREQ) +#else +#ifdef PERIODIC_FREQUENCY +#define MPL_PRESCALER ((PERIODIC_FREQUENCY)/BARO_BOARD_APOGEE_FREQ) +#else +// default: assuming 60Hz for a 5Hz baro update +#define MPL_PRESCALER 12 +#endif +#endif + /** Counter to init ads1114 at startup */ -#define BARO_STARTUP_COUNTER 200 +#define BARO_STARTUP_COUNTER (200/(MPL_PRESCALER)) uint16_t startup_cnt; struct Mpl3115 apogee_baro; @@ -67,17 +90,15 @@ void baro_periodic( void ) { #endif } // Read the sensor - mpl3115_periodic(&apogee_baro); + RunOnceEvery(MPL_PRESCALER, mpl3115_periodic(&apogee_baro)); } } void apogee_baro_event(void) { mpl3115_event(&apogee_baro); - if (apogee_baro.data_available) { - if (startup_cnt == 0) { - float pressure = ((float)apogee_baro.pressure/(1<<2)); - AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, &pressure); - } + if (apogee_baro.data_available && startup_cnt == 0) { + float pressure = ((float)apogee_baro.pressure/(1<<2)); + AbiSendMsgBARO_ABS(BARO_BOARD_SENDER_ID, &pressure); apogee_baro.data_available = FALSE; } } diff --git a/sw/airborne/peripherals/mpl3115.c b/sw/airborne/peripherals/mpl3115.c index bfac2abad1..1ca95a416c 100644 --- a/sw/airborne/peripherals/mpl3115.c +++ b/sw/airborne/peripherals/mpl3115.c @@ -99,7 +99,7 @@ void mpl3115_read(struct Mpl3115 *mpl) mpl->req_trans.buf[0] = MPL3115_REG_CTRL_REG1; mpl->req_trans.buf[1] = ((MPL3115_OVERSAMPLING<<3) | (mpl->raw_mode<<6) | (mpl->alt_mode<<7) | MPL3115_OST_BIT); - i2c_transmit(mpl->i2c_p, &mpl->trans, mpl->trans.slave_addr, 2); + i2c_transmit(mpl->i2c_p, &mpl->req_trans, mpl->trans.slave_addr, 2); } } }