[modules] baro ets start delay

This commit is contained in:
Tobias Muench
2013-06-08 08:06:55 +02:00
parent 20707a0d11
commit 1c590fbb34
2 changed files with 38 additions and 5 deletions
+19 -3
View File
@@ -2,9 +2,25 @@
<module name="baro_ets" dir="sensors">
<doc>
<description>Baro ETS (I2C)</description>
<define name="BARO_ETS_I2C_DEV" value="i2cX" description="select i2c peripheral to use (default i2c0)"/>
<define name="BARO_ETS_SCALE" value="sensor scale factor"/>
<description>
Baro ETS (I2C).
Driver for the EagleTree Systems Baro Sensor.
Has only been tested with V3 of the sensor hardware.
Notes:
Connect directly to TWOG/Tiny I2C port. Multiple sensors can be chained together.
Sensor should be in the proprietary mode (default) and not in 3rd party mode.
Sensor module wire assignments:
- Red wire: 5V
- White wire: Ground
- Yellow wire: SDA
- Brown wire: SCL
</description>
<define name="BARO_ETS_I2C_DEV" value="i2cX" description="set i2c peripheral (default: i2c0)"/>
<define name="BARO_ETS_SCALE" value="scale" description="sensor scale factor (default: 1.8)"/>
<define name="BARO_ETS_START_DELAY" value="delay" description="set initial start delay in seconds"/>
<define name="BARO_ETS_TELEMETRY" description="flag to transmit the data as it is acquired"/>
</doc>
+19 -2
View File
@@ -43,6 +43,7 @@
#include "mcu_periph/i2c.h"
#include "state.h"
#include <math.h>
#include "mcu_periph/sys_time.h"
#include "subsystems/nav.h"
@@ -91,13 +92,15 @@ struct i2c_transaction baro_ets_i2c_trans;
bool_t baro_ets_offset_init;
uint32_t baro_ets_offset_tmp;
uint16_t baro_ets_cnt;
uint32_t baro_ets_delay_time;
bool_t baro_ets_delay_done;
void baro_ets_init( void ) {
baro_ets_adc = 0;
baro_ets_altitude = 0.0;
baro_ets_offset = 0;
baro_ets_offset_tmp = 0;
baro_ets_valid = TRUE;
baro_ets_valid = FALSE;
baro_ets_offset_init = FALSE;
baro_ets_enabled = TRUE;
baro_ets_cnt = BARO_ETS_OFFSET_NBSAMPLES_INIT + BARO_ETS_OFFSET_NBSAMPLES_AVRG;
@@ -105,15 +108,29 @@ void baro_ets_init( void ) {
baro_ets_sigma2 = BARO_ETS_SIGMA2;
baro_ets_i2c_trans.status = I2CTransDone;
#if defined BARO_ETS_START_DELAY && ! defined SITL
baro_ets_delay_done = FALSE;
SysTimeTimerStart(baro_ets_delay_time);
#else
baro_ets_delay_done = TRUE;
baro_ets_delay_time = 0;
#endif
}
void baro_ets_read_periodic( void ) {
// Initiate next read
#ifndef SITL
#if defined BARO_ETS_START_DELAY
if (!baro_ets_delay_done) {
if (SysTimeTimer(baro_ets_delay_time) < USEC_OF_SEC(BARO_ETS_START_DELAY)) return;
else baro_ets_delay_done = TRUE;
}
#endif
if (baro_ets_i2c_trans.status == I2CTransDone)
i2c_receive(&BARO_ETS_I2C_DEV, &baro_ets_i2c_trans, BARO_ETS_ADDR, 2);
#else // SITL
/* fake an offset so sim works for under hmsl as well */
/* fake an offset so sim works as well */
if (!baro_ets_offset_init) {
baro_ets_offset = 12400;
baro_ets_offset_init = TRUE;