Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
Functions
App.c File Reference
#include "../../../Inc/Sensors/AnalogSensors/App.h"
#include "../../../Inc/Utils/MessageFormat.h"
#include <stdio.h>
Include dependency graph for App.c:

Go to the source code of this file.

Functions

void initApp (App *app, int hz, int channel, char *name)
 Initializes the APP with the given frequency and channel. More...
 
float getAppPosition (App *app)
 Gets the current position of the APP. More...
 
void updateApp (App *app)
 Updates the APP data. More...
 
float transferFunctionApp (float rawVal)
 Converts raw APP data to a meaningful position value. More...
 

Function Documentation

◆ getAppPosition()

float getAppPosition ( App app)

Gets the current position of the APP.

Parameters
appPointer to the App structure to query.
Returns
The current position of the APP.

Definition at line 17 of file App.c.

17 {
18 return app->position;
19}
float position
Definition: App.h:9
Here is the caller graph for this function:

◆ initApp()

void initApp ( App app,
int  hz,
int  channel,
char *  name 
)

Initializes the APP with the given frequency and channel.

Parameters
appPointer to the App structure to initialize.
hzThe frequency in Hertz at which the APP operates.
channelThe analog channel the APP is connected to.
nameThe name of the sensor (default is "App").

Definition at line 6 of file App.c.

6 {
7 initAnalogSensor(&app->base, name, hz, channel, app);
8 app->position = 0;
10
11 // Register telemetry signal
12 app->telem_raw = registerTelemetrySignal(name, TELEMETRY_SENSOR, UNIT_VOLTS, 1000/hz, 0.4f, 4.7f);
13 app->telem_position = registerTelemetrySignal(name, TELEMETRY_SENSOR, UNIT_PERCENT, 1000/hz, 0.0f, 100.0f);
14
15}
void initAnalogSensor(AnalogSensor *analogSensor, const char *name, int hz, int channel, void *child)
Initializes an analog sensor and configures the corresponding GPIO pin.
Definition: AnalogSensor.c:42
void updateApp(App *app)
Updates the APP data.
Definition: App.c:21
@ TELEMETRY_SENSOR
Definition: Telemetry.h:9
TelemetrySignal * registerTelemetrySignal(const char *name, TelemetryType type, UnitId unit_id, uint32_t expected_rate_ms, float custom_min, float custom_max)
Definition: Telemetry.c:23
@ UNIT_PERCENT
Definition: Units.h:55
@ UNIT_VOLTS
Definition: Units.h:45
Sensor sensor
Definition: AnalogSensor.h:23
TelemetrySignal * telem_raw
Definition: App.h:10
AnalogSensor base
Definition: App.h:8
TelemetrySignal * telem_position
Definition: App.h:11
Updateable updateable
Definition: Sensor.h:15
int(* update)(struct Updateable *self)
Definition: Updateable.h:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transferFunctionApp()

float transferFunctionApp ( float  rawVal)

Converts raw APP data to a meaningful position value.

Parameters
rawValThe raw data from the APP.
Returns
The converted APP position value.

Definition at line 41 of file App.c.

41 {
42 // This is a +-45 degree sensor
43 if (rawVal < 0.5) {
44 return -1;
45 }
46 else if (rawVal > 4.5) {
47 return -2;
48 }
49 return (rawVal - 0.5)/4.0;
50}
Here is the caller graph for this function:

◆ updateApp()

void updateApp ( App app)

Updates the APP data.

Parameters
appPointer to the App structure to update.

Definition at line 21 of file App.c.

21 {
22 // FIXME: Implement APP connection with stm
23 float rawData = getAnalogSensorData(&app->base);
24 // Send Telemetry float
25 sendTelemetryValue(app->telem_raw, rawData);
26 app->position = transferFunctionApp(rawData);
27
28 // Send diagnostic info to the debugger
29 if (app->position == -1) {
31 "APP reading below sensor minimum (%.3f V)", rawData);
32 } else if (app->position == -2) {
34 "APP reading above sensor maximum (%.3f V)", rawData);
35 }
36
37 sendTelemetryValue(app->telem_position, app->position * 100); // Convert from 1-scale to percentage
38
39}
float getAnalogSensorData(AnalogSensor *sensor)
Retrieves analog sensor data for a specific channel.
Definition: AnalogSensor.c:89
float transferFunctionApp(float rawVal)
Converts raw APP data to a meaningful position value.
Definition: App.c:41
@ MSG_WARNING
Definition: MessageFormat.h:12
void sendMessage(const char *sender, MessageType type, const char *format,...)
Definition: MessageFormat.c:5
void sendTelemetryValue(TelemetrySignal *signal, float value)
Definition: Telemetry.c:59
char name[MAX_NAME_LENGTH]
Definition: Updateable.h:24
Here is the call graph for this function:
Here is the caller graph for this function: