Vehicle Control Unit 0.01
This is the c library for controlling the car.
|
#include "../../Inc/Sensors/AnalogSensor.h"
#include <stdio.h>
#include <string.h>
#include "stm32f7xx_hal.h"
Go to the source code of this file.
Functions | |
void | initAnalogSensor (AnalogSensor *analogSensor, const char *name, int hz, int channel) |
Initializes an analog sensor and configures the corresponding GPIO pin. More... | |
static void | addSampleToBuffer (ADCSample sample) |
Adds a sample to the circular buffer. More... | |
void | ProcessADCData (uint16_t *adc1_data, uint16_t *adc2_data, uint16_t *adc3_data) |
Processes ADC data from all three ADCs and stores it in the circular buffer. More... | |
ADCSample | getLatestSample (void) |
Retrieves the latest ADC sample from the buffer. More... | |
uint32_t | getRecentSamples (ADCSample *samples, uint32_t num_samples) |
Retrieves a specified number of recent samples from the buffer. More... | |
int | getAnalogSensorData (AnalogSensor *sensor) |
Retrieves analog sensor data for a specific channel. More... | |
Variables | |
static ADCSample | adc_circular_buffer [BUFFER_SIZE] |
static uint32_t | buffer_head = 0 |
static uint32_t | buffer_tail = 0 |
static uint32_t | buffer_count = 0 |
|
static |
Adds a sample to the circular buffer.
sample | ADCSample to be added to the buffer |
This function adds a new sample to the circular buffer. If the buffer is full, it overwrites the oldest data.
Definition at line 92 of file AnalogSensor.c.
int getAnalogSensorData | ( | AnalogSensor * | sensor | ) |
Retrieves analog sensor data for a specific channel.
sensor | Pointer to the AnalogSensor structure |
This function returns the latest ADC value for the channel specified in the AnalogSensor structure. If an invalid channel is specified, it returns 0.
Definition at line 193 of file AnalogSensor.c.
ADCSample getLatestSample | ( | void | ) |
Retrieves the latest ADC sample from the buffer.
If the buffer is empty, this function returns a sample with all channels set to 0.
Definition at line 152 of file AnalogSensor.c.
uint32_t getRecentSamples | ( | ADCSample * | samples, |
uint32_t | num_samples | ||
) |
Retrieves a specified number of recent samples from the buffer.
samples | Pointer to an array to store the retrieved samples |
num_samples | Number of samples to retrieve |
This function copies the most recent samples from the circular buffer to the provided array. It returns the actual number of samples copied, which may be less than requested if the buffer is not full.
Definition at line 173 of file AnalogSensor.c.
void initAnalogSensor | ( | AnalogSensor * | analogSensor, |
const char * | name, | ||
int | hz, | ||
int | channel | ||
) |
Initializes an analog sensor and configures the corresponding GPIO pin.
sensor | Pointer to the AnalogSensor structure to initialize |
name | Name of the sensor (string) |
hz | Sampling frequency in Hertz |
channel | ADC channel number for the sensor (0-16) |
This function initializes the base sensor properties, sets the ADC channel, and configures the corresponding GPIO pin based on the channel number.
Definition at line 44 of file AnalogSensor.c.
void ProcessADCData | ( | uint16_t * | adc1_data, |
uint16_t * | adc2_data, | ||
uint16_t * | adc3_data | ||
) |
Processes ADC data from all three ADCs and stores it in the circular buffer.
adc1_data | Pointer to ADC1 data buffer (channels 0-5) |
adc2_data | Pointer to ADC2 data buffer (channels 6-11) |
adc3_data | Pointer to ADC3 data buffer (channels 12-15) |
This function combines data from all three ADCs into a single ADCSample and adds it to the circular buffer. It also sends debug information via UART.
Definition at line 114 of file AnalogSensor.c.
|
static |
Definition at line 12 of file AnalogSensor.c.
|
static |
Definition at line 15 of file AnalogSensor.c.
|
static |
Definition at line 13 of file AnalogSensor.c.
|
static |
Definition at line 14 of file AnalogSensor.c.