aboutsummaryrefslogtreecommitdiff
path: root/data_manager.c
blob: 8202216d9f9c250930d5d7371c826ee3830f2800 (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
#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; /* FIXME don't hardcode, at least not here */
	ctx->timer = timer;
	ctx->barometer = barometer;
	data_manager_tick(ctx);
}

void data_manager_tick(struct data_ctx *ctx)
{
	/* FIXME altitude rate */
	ctx->timestamp = ctx->timer->get_time();
	ctx->pressure = ctx->barometer->read_pressure();
	ctx->altitude = pressure_to_metres_asl(ctx->pressure, ctx->setting);
}