aboutsummaryrefslogtreecommitdiff
path: root/data_manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'data_manager.c')
-rw-r--r--data_manager.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/data_manager.c b/data_manager.c
index 17abdda..b77ba81 100644
--- a/data_manager.c
+++ b/data_manager.c
@@ -4,6 +4,7 @@
#include "data_manager.h"
#include "barometer.h"
+#include "timer.h"
/* utility functions */
@@ -12,21 +13,20 @@ 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)
+void data_manager_init(struct data_ctx *ctx, struct timer *timer, struct barometer *barometer)
{
ctx->setting = 1013.25;
- barometer_init();
+ ctx->timer = timer;
+ ctx->barometer = barometer;
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
- */
+ /* 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);
}