#include <stdio.h>
#include <signal.h>
#define OVERSAMPLE BMP_OVERSAMPLE_16
#define INTERNAL_FILTER BMP_FILTER_OFF
#define ORDER 2
#define CUTOFF_FREQ 2.0f
#define BMP_CHECK_HZ 25
#define DT 1.0f/BMP_CHECK_HZ
static int running = 0;
static void signal_handler(__attribute__ ((unused)) int dummy)
{
running=0;
return;
}
int main()
{
double filtered_alt;
signal(SIGINT, signal_handler);
running = 1;
if(
rc_bmp_init(OVERSAMPLE, INTERNAL_FILTER))
return -1;
printf("\n");
printf(" temp |");
printf(" pressure |");
printf(" altitude |");
printf(" filtered |");
printf("\n");
while(running){
printf("\r");
printf(
"%6.2lfC |", data.
temp_c);
printf(
"%8.2lfm |", data.
alt_m);
printf("%8.2lfm |", filtered_alt);
fflush(stdout);
}
printf("\n");
return 0;
}
int rc_bmp_read(rc_bmp_data_t *data)
Reads the newest temperature and pressure measurments from the barometer over the I2C bus.
int rc_bmp_power_off(void)
Puts the barometer into a low power state, should be called at the end of your program before close.
int rc_bmp_init(rc_bmp_oversample_t oversample, rc_bmp_filter_t filter)
powers on the barometer and initializes it with the given oversample and filter settings.
int rc_filter_prefill_outputs(rc_filter_t *f, double out)
Fills all previous outputs of the filter as if they had been equal to 'out'.
double rc_filter_march(rc_filter_t *f, double new_input)
March a filter forward one step with new input provided as an argument.
int rc_filter_prefill_inputs(rc_filter_t *f, double in)
Fills all previous inputs to the filter as if they had been equal to 'in'.
#define RC_FILTER_INITIALIZER
Definition: filter.h:82
int rc_filter_butterworth_lowpass(rc_filter_t *f, int order, double dt, double wc)
Creates a Butterworth low pass filter of specified order and cutoff frequency.
void rc_usleep(unsigned int us)
Sleep in microseconds.
double alt_m
altitude in meters
Definition: bmp.h:58
double temp_c
temperature in degrees celcius
Definition: bmp.h:57
double pressure_pa
current pressure in pascals
Definition: bmp.h:59
Struct containing configuration and state of a SISO filter.
Definition: filter.h:43