Midnight Sun Firmware
Loading...
Searching...
No Matches
pedal_calib.h
1#pragma once
2
3/************************************************************************************************
4 * @file pedal_calib.h
5 *
6 * @brief Header file to define the pedal calibration data
7 *
8 * @date 2025-05-15
9 * @author Midnight Sun Team #24 - MSXVI
10 ************************************************************************************************/
11
12/* Standard library Headers */
13#include <stdbool.h>
14
15/* Inter-component Headers */
16#include "gpio.h"
17
18/* Intra-component Headers */
19
27#define NUM_SAMPLES 1000
28
33typedef enum {
34 PEDAL_PRESSED = 0,
35 PEDAL_UNPRESSED,
36 NUM_PEDAL_STATES,
38
43typedef struct PedalCalibrationData {
44 // When the pedal is considered fully unpressed
45 int16_t lower_value;
46 // When the pedal is considered fully pressed
47 int16_t upper_value;
49
51typedef struct PedalCalibBlob {
52 PedalCalibrationData throttle_calib;
53 PedalCalibrationData brake_calib;
55
58 int16_t min_reading;
59 int16_t max_reading;
60 volatile uint32_t sample_counter;
62
65
66/* @brief Reads data from ADC and calculates appropriate pedal calibration values
67 *
68 * @param calib_storage - A struct for storing the max and min reading while looping through adc reading for a given number of samples
69 * @param data - A struct that stores the final calculated values for the upper and lower values for the pedal
70 * @param state - An enum that describes the current state that he pedal is in when calling the function
71 * @param address - The GPIO address for the adc of the pedal
72 * @return STATUS_CODE_OK on success
73 */
74StatusCode pedal_calib_sample(PedalCalibrationStorage *calib_storage, PedalCalibrationData *data, PedalState state, GpioAddress *address);
75
PedalCalibBlob global_calib_blob
A global struct that stores the throttle pedal and calibration data.
PedalState
Stores the possible pedal states that the pedal could be in.
Definition: pedal_calib.h:33
StatusCode
StatusCodes for various errors.
Definition: status.h:27
Port and pin data.
Definition: network.h:62
Stores pedal calibration data for the break and the throttle pedals.
Definition: pedal.h:40
Stores data that defines when the pedal is full pressed or unpressed.
Definition: pedal.h:33
A struct that stores the max and min reading along with a sample counter for the data that is being p...
Definition: pedal_calib.h:57