Loading...
Searching...
No Matches
debug_barometer.c
1/***********************************************************************************
2 * @file launch.c *
3 * @author Matt Ricci *
4 * @addtogroup Shell *
5 * *
6 * @{ *
7 ***********************************************************************************/
8
9#include "string.h"
10#include "stdio.h"
11
12#include "shell.h"
13#include "parser.h"
14#include "devicelist.h"
15#include "barometer.h"
16
17static void Baro_exec(UART_t *uart, char *);
18
19DEFINE_PROGRAM_HANDLE("baro", Baro_exec, NULL)
20
21char str[50];
22
23/* =============================================================================== */
30static void Baro_exec(UART_t *uart, char *flags) {
31
32 // Initialise parser
33 ArgParser parser = ArgParser_init();
34 int SHELL_BARO_READ = parser.addArg(
35 &parser, "read", 'r', ARG_TYPE_BOOL, false
36 );
37
38 char *tokens[MAX_ARGS];
39 int numTokens = 0;
40
41 // Tokenize the input string
42 char *token = strtok(flags, " ");
43 while (token != NULL && numTokens < MAX_ARGS) {
44 tokens[numTokens++] = token;
45 token = strtok(NULL, " ");
46 }
47
48 // Parse input tokens
49 parser.parseArgs(&parser, numTokens, tokens);
50
51 Baro_t *baro = DeviceList_getDeviceHandle(DEVICE_BARO).device;
52 if (parser.error.status == PARSER_STATUS_OK && parser.args[SHELL_BARO_READ].provided) {
53 baro->update(baro);
54 snprintf(str, 50, "Ground pressure: %f", baro->groundPress);
55 uart->println(uart, str);
56 snprintf(str, 50, "Current pressure: %f", baro->press);
57 uart->println(uart, str);
58 snprintf(str, 50, "Current temperature: %f", baro->temp);
59 uart->println(uart, str);
60 } else {
61 uart->println(uart, parser.error.msg);
62 }
63}
64
Defines the API for the Barometer sensor.
float temp
Last read processed temperature value.
Definition barometer.h:115
float press
Last read processed pressure value.
Definition barometer.h:114
float groundPress
Stored ground pressure reading.
Definition barometer.h:113
void(* update)(struct Baro *baro)
Pointer to update method.
Definition barometer.h:25
DeviceHandle_t DeviceList_getDeviceHandle(DeviceKey)
Retrieve device handle from list by key.
Definition devicelist.c:36
Struct definition for UART interface.
Definition uart.h:132