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);
7 app->position = 0;
9}
10
11float getAppPosition(App* app) {
12 return app->position;
13}
14
15void updateApp(void* app) {
16 App *myApp = (App *)app;
17 // FIXME: Implement APP connection with stm
18 float rawData = 1.0f;
19 myApp->position = transferFunctionApp(rawData);
20}
21
22float transferFunctionApp(float rawVal) {
23 // This is a +-45 degree sensor
24 if (rawVal < 0.5) {
25 printf("App::transfer_function rawValue is too low\n");
26 return -1;
27 }
28 else if (rawVal > 4.5) {
29 printf("App::transfer_function rawValue is too high\n");
30 return -1;
31 }
32 return (22.5 * rawVal) - 56.25;
33}
34
35void setAppPos(App* app, float pos) {
36 app->position = pos;
37}
void initAnalogSensor(AnalogSensor *analogSensor, const char *name, int hz, int channel)
Initializes an analog sensor and configures the corresponding GPIO pin.
Definition: AnalogSensor.c:44
float getAppPosition(App *app)
Gets the current position of the APP.
Definition: App.c:11
void initApp(App *app, int hz, int channel)
Initializes the APP with the given frequency and channel.
Definition: App.c:5
void setAppPos(App *app, float pos)
Sets pedal position in app sensor.
Definition: App.c:35
float transferFunctionApp(float rawVal)
Converts raw APP data to a meaningful position value.
Definition: App.c:22
void updateApp(void *app)
Updates the APP data.
Definition: App.c:15
Sensor sensor
Definition: AnalogSensor.h:28
Definition: App.h:6
AnalogSensor base
Definition: App.h:7
float position
Definition: App.h:8
Updateable updateable
Definition: Sensor.h:15
void(* update)(void *self)
Definition: Updateable.h:26