[fix] fix mpl3115 driver and apogee baro_board

This commit is contained in:
Gautier Hattenberger
2013-10-15 18:45:58 +02:00
parent 3c7c08d16f
commit 8f13aef998
2 changed files with 29 additions and 8 deletions
+28 -7
View File
@@ -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;
}
}
+1 -1
View File
@@ -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);
}
}
}