Vehicle Control Unit 0.01
This is the c library for controlling the car.
Loading...
Searching...
No Matches
App.c
Go to the documentation of this file.
1#include "../../../Inc/Sensors/AnalogSensors/App.h"
2
3#include <stdio.h>
4
5void initApp(App* app, int hz, int channel) {
6 initAnalogSensor(&app->base, "App", hz, channel, app);
7 app->position = 0;
9}
10
11float getAppPosition(App* app) {
12 return app->position;
13}
14
15void updateApp(App* app) {
16 // FIXME: Implement APP connection with stm
17 float rawData = getAnalogSensorData(&app->base);
18 app->position = transferFunctionApp(rawData);
19}
20
21float transferFunctionApp(float rawVal) {
22 // This is a +-45 degree sensor
23 if (rawVal < 0.5) {
24 printf("App::transfer_function rawValue is too low\r\n");
25 return -1;
26 }
27 else if (rawVal > 4.5) {
28 printf("App::transfer_function rawValue is too high\r\n");
29 return -1;
30 }
31 return (rawVal - 0.5)/4.0;
32}
float getAnalogSensorData(AnalogSensor *sensor)
Retrieves analog sensor data for a specific channel.
Definition: AnalogSensor.c:89
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
float getAppPosition(App *app)
Gets the current position of the APP.
Definition: App.c:11
void updateApp(App *app)
Updates the APP data.
Definition: App.c:15
void initApp(App *app, int hz, int channel)
Initializes the APP with the given frequency and channel.
Definition: App.c:5
float transferFunctionApp(float rawVal)
Converts raw APP data to a meaningful position value.
Definition: App.c:21
Sensor sensor
Definition: AnalogSensor.h:23
Definition: App.h:6
AnalogSensor base
Definition: App.h:7
float position
Definition: App.h:8
Updateable updateable
Definition: Sensor.h:15
int(* update)(struct Updateable *self)
Definition: Updateable.h:27