blob: b77ba81d59f6067ac4a74833a2a824441324ea7b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <stdbool.h>
#include <stdlib.h>
#include <math.h>
#include "data_manager.h"
#include "barometer.h"
#include "timer.h"
/* utility functions */
static float pressure_to_metres_asl(float real, float setting)
{
return 44330.f*(1.f-powf(real/setting, 1/5.255));
}
void data_manager_init(struct data_ctx *ctx, struct timer *timer, struct barometer *barometer)
{
ctx->setting = 1013.25;
ctx->timer = timer;
ctx->barometer = barometer;
data_manager_tick(ctx);
}
void data_manager_tick(struct data_ctx *ctx)
{
/* FIXME altitude rate */
// struct data_ctx previous_ctx = *ctx;
if (ctx->timer)
ctx->timestamp = ctx->timer->get_time();
ctx->pressure = ctx->barometer->read_pressure();
ctx->altitude = pressure_to_metres_asl(ctx->pressure, ctx->setting);
}
|