2011-12-28 05:32:21 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-10-13 11:22:03 -03:00
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
// AVR LibC Includes
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <avr/interrupt.h>
|
|
|
|
}
|
2012-01-27 23:25:47 -04:00
|
|
|
#if defined(ARDUINO) && ARDUINO >= 100
|
|
|
|
#include "Arduino.h"
|
|
|
|
#else
|
|
|
|
#include "WConstants.h"
|
|
|
|
#endif
|
2011-10-13 11:22:03 -03:00
|
|
|
|
2011-11-27 01:34:26 -04:00
|
|
|
#include "AP_Baro_BMP085_hil.h"
|
2011-10-13 11:22:03 -03:00
|
|
|
|
|
|
|
// Constructors ////////////////////////////////////////////////////////////////
|
2011-11-27 01:34:26 -04:00
|
|
|
AP_Baro_BMP085_HIL::AP_Baro_BMP085_HIL()
|
2011-10-13 11:22:03 -03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public Methods //////////////////////////////////////////////////////////////
|
2011-12-28 05:32:21 -04:00
|
|
|
bool AP_Baro_BMP085_HIL::init(AP_PeriodicProcess * scheduler)
|
2011-10-13 11:22:03 -03:00
|
|
|
{
|
2011-12-28 05:32:21 -04:00
|
|
|
BMP085_State=1;
|
|
|
|
return true;
|
2011-10-13 11:22:03 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Read the sensor. This is a state machine
|
|
|
|
// We read one time Temperature (state = 1) and then 4 times Pressure (states 2-5)
|
2011-12-11 00:30:24 -04:00
|
|
|
uint8_t AP_Baro_BMP085_HIL::read()
|
2011-10-13 11:22:03 -03:00
|
|
|
{
|
|
|
|
uint8_t result = 0;
|
|
|
|
|
|
|
|
if (BMP085_State == 1){
|
|
|
|
BMP085_State++;
|
|
|
|
}else{
|
|
|
|
|
|
|
|
if (BMP085_State == 5){
|
|
|
|
BMP085_State = 1; // Start again from state = 1
|
|
|
|
result = 1; // New pressure reading
|
|
|
|
}else{
|
|
|
|
BMP085_State++;
|
|
|
|
result = 1; // New pressure reading
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return(result);
|
|
|
|
}
|
|
|
|
|
2011-11-27 01:34:26 -04:00
|
|
|
void AP_Baro_BMP085_HIL::setHIL(float _Temp, float _Press)
|
2011-10-13 11:22:03 -03:00
|
|
|
{
|
|
|
|
// TODO: map floats to raw
|
|
|
|
Temp = _Temp;
|
|
|
|
Press = _Press;
|
2011-12-28 05:32:21 -04:00
|
|
|
healthy = true;
|
2012-06-19 23:25:19 -03:00
|
|
|
_last_update = millis();
|
2011-10-13 11:22:03 -03:00
|
|
|
}
|
2011-12-11 00:30:24 -04:00
|
|
|
|
|
|
|
int32_t AP_Baro_BMP085_HIL::get_pressure() {
|
|
|
|
return Press;
|
|
|
|
}
|
|
|
|
|
|
|
|
int16_t AP_Baro_BMP085_HIL::get_temperature() {
|
|
|
|
return Temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t AP_Baro_BMP085_HIL::get_raw_pressure() {
|
|
|
|
return Press;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t AP_Baro_BMP085_HIL::get_raw_temp() {
|
|
|
|
return Temp;
|
|
|
|
}
|