aboutsummaryrefslogtreecommitdiff
path: root/data_manager.c
blob: 17abdda2b290115c5a89543f454c875f6d5cdd96 (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"


/* 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)
{
	ctx->setting = 1013.25;
	barometer_init();
	data_manager_tick(ctx);
}

void data_manager_tick(struct data_ctx *ctx)
{
	/* FIXME alt rate */
	/* FIXME calculate on demand? */
	ctx->pressure = barometer_read();

	/* FIXME we need atomic access to alt setting once user can set it. Check
	 * if AVR allows multiple/nested ISRs to run concurrently, pretty sure not
	 */
	ctx->altitude = pressure_to_metres_asl(ctx->pressure, ctx->setting);
}