used ChatGPT to add comments and proper Headers to all SourceFiles

This commit is contained in:
2024-01-09 12:54:05 +01:00
parent 62cc2bf982
commit f52f4103f6
21 changed files with 945 additions and 99 deletions

View File

@@ -1,3 +1,16 @@
/**
* @file can.h
*
* @brief Header file for Controller Area Network (CAN) functionality in the ChainLube application.
*
* This file provides functions and structures related to Controller Area Network (CAN)
* communication for the ChainLube project. It includes functions for initializing CAN,
* processing CAN messages, and retrieving wheel speed from CAN data.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _CAN_H_
#define _CAN_H_
@@ -9,6 +22,7 @@
#include "dtc.h"
#include "debugger.h"
// CAN frame structure definition
struct can_frame
{
unsigned long can_id;
@@ -16,8 +30,9 @@ struct can_frame
uint8_t data[8] __attribute__((aligned(8)));
};
// Function prototypes
void Init_CAN();
void CAN_Process();
uint32_t Process_CAN_WheelSpeed();
#endif
#endif

View File

@@ -1,3 +1,16 @@
/**
* @file common.h
*
* @brief Header file for common definitions and macros in the ChainLube application.
*
* This file defines common macros, GPIO configurations, and other shared constants
* for the ChainLube project. It includes definitions for GPIO pins, OTA delays, pulse lengths,
* and other common settings used across the project.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _COMMON_H_
#define _COMMON_H_
@@ -5,6 +18,7 @@
#define QUOTE(x) Q(x)
#define SET_BIT(value, bitPosition) ((value) |= (1U << (bitPosition)))
// Conditional compilation based on PCB revision
#if PCB_REV == 1
#define GPIO_BUTTON D7
#define GPIO_LED D8
@@ -40,17 +54,17 @@
#define LUBE_PULSE_LENGHT_MS 160
#define LUBE_PULSE_PAUSE_MS 340
// Pump pulse parameters
// -> 2Hz PumpPulse
// -> 49,7cc / h @ 2Hz
// -> 49,7 ml / h @ 2Hz
// -> 828,4µl / min @ 2Hz
// -> 828,3µl / 60s
// -> 13,81µl / 1s
// -> 6,90µl / Pulse
// -> 49.7cc / h @ 2Hz
// -> 49.7 ml / h @ 2Hz
// -> 828.4µl / min @ 2Hz
// -> 828.3µl / 60s
// -> 13.81µl / 1s
// -> 6.90µl / Pulse
#define DEFAULT_PUMP_DOSE 7
#define STARTUP_DELAY 5000
#define SHUTDOWN_DELAY_MS 5000
#endif
#endif

View File

@@ -1,3 +1,17 @@
/**
* @file config.h
*
* @brief Header file for configuration settings and EEPROM operations in the ChainLube application.
*
* This file defines configuration settings for the ChainLube project, including default values,
* EEPROM structures, and functions for EEPROM operations. It also defines enums for different sources
* of speed input, GPS baud rates, and CAN bus sources. Additionally, it includes functions for EEPROM handling
* such as storing, retrieving, and formatting configuration data.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
@@ -14,6 +28,7 @@
#define EEPROM_SIZE_BYTES I2C_DEVICESIZE_24LC256
#endif
// Enum for different sources of speed input
typedef enum SpeedSource_e
{
#ifdef FEATURE_ENABLE_TIMER
@@ -24,6 +39,7 @@ typedef enum SpeedSource_e
SOURCE_CAN
} SpeedSource_t;
// String representation of SpeedSource enum
const char SpeedSourceString[][8] = {
#ifdef FEATURE_ENABLE_TIMER
"Timer",
@@ -33,32 +49,37 @@ const char SpeedSourceString[][8] = {
"CAN-Bus"
};
const size_t SpeedSourceString_Elements = sizeof(SpeedSourceString) / sizeof(SpeedSourceString[0]);
// Enum for GPS baud rates
typedef enum GPSBaudRate_e
{
BAUD_9600,
BAUD_115200
} GPSBaudRate_t;
// String representation of GPSBaudRate enum
const char GPSBaudRateString[][7] = {
"9600",
"115200"};
const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPSBaudRateString[0]);
// Enum for CAN bus sources
typedef enum CANSource_e
{
KTM_890_ADV_R_2021,
KTM_1290_SD_R_2023
} CANSource_t;
// String representation of CANSource enum
const char CANSourceString[][30] = {
"KTM 890 Adventure R (2021)",
"KTM 1290 Superduke R (2023)"};
const size_t CANSourceString_Elements = sizeof(CANSourceString) / sizeof(CANSourceString[0]);
const size_t SpeedSourceString_Elements = sizeof(SpeedSourceString) / sizeof(SpeedSourceString[0]);
// Structure for persistence data stored in EEPROM
typedef struct
{
uint16_t writeCycleCounter = 0;
@@ -69,6 +90,7 @@ typedef struct
uint32_t checksum = 0;
} persistenceData_t;
// Structure for configuration settings stored in EEPROM
typedef struct
{
uint8_t EEPROM_Version = 0;
@@ -92,6 +114,7 @@ typedef struct
uint32_t checksum = 0;
} LubeConfig_t;
// Default configuration settings
const LubeConfig_t LubeConfig_defaults = {
0, 8000, 4000, 320, DEFAULT_PUMP_DOSE, 30, 1, 150, 70, 18, 2000, 25, SOURCE_IMPULSE,
BAUD_115200,
@@ -117,4 +140,4 @@ uint32_t ConfigSanityCheck(bool autocorrect = false);
extern LubeConfig_t LubeConfig;
extern persistenceData_t PersistenceData;
extern uint16_t eePersistenceMarker;
#endif // _CONFIG_H_
#endif // _CONFIG_H_

View File

@@ -1,9 +1,21 @@
/**
* @file debugger.h
*
* @brief Header file for debugging functions and status in the ChainLube application.
*
* This file declares functions and status definitions for debugging purposes in the ChainLube project.
* It includes functions to print system information, WiFi information, format EEPROM data,
* handle debug messages, and manage the status of different debug ports.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _DEBUGGER_H_
#define _DEBUGGER_H_
#include <Arduino.h>
#include "webui.h"
const char PROGMEM helpCmd[] = "sysinfo - System Info\n"
"netinfo - WiFi Info\n"
"formatPDS - Format Persistence EEPROM Data\n"

View File

@@ -1,3 +1,16 @@
/**
* @file dtc.h
*
* @brief Header file for handling Diagnostic Trouble Codes (DTC) in the ChainLube application.
*
* This file provides definitions and functions for handling Diagnostic Trouble Codes (DTC)
* in the ChainLube project. It includes structures for DTC entries, severity levels,
* and functions for DTC maintenance and processing. DTCs are used to track system errors and issues.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _DTC_H_
#define _DTC_H_

View File

@@ -1,4 +1,18 @@
// Auto-generated by script on 2023-12-04 02:10:49
/**
* @file dtc_defs.h
*
* @brief Header file for Diagnostic Trouble Code (DTC) definitions in the ChainLube application.
*
* This file contains definitions for Diagnostic Trouble Codes (DTC) in the ChainLube project.
* It includes enums for DTC active status, severity levels, and specific DTC codes.
* The file also defines an array of DTC definitions and a timestamp indicating the generation time.
*
* @note This file is auto-generated by a script on 2024-01-09 12:08:43.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef DTC_DEFS_H
#define DTC_DEFS_H
@@ -66,6 +80,6 @@ const DTC_t dtc_definitions[] = {
{ DTC_LAST_DTC , DTC_NONE } // Last Error
};
const uint32_t dtc_generation_timestamp = 1701652249;
const uint32_t dtc_generation_timestamp = 1704798523;
#endif // DTC_DEFS_H

View File

@@ -1,4 +1,18 @@
// Auto-generated by script on {{ timestamp }}
/**
* @file dtc_defs.h
*
* @brief Header file for Diagnostic Trouble Code (DTC) definitions in the ChainLube application.
*
* This file contains definitions for Diagnostic Trouble Codes (DTC) in the ChainLube project.
* It includes enums for DTC active status, severity levels, and specific DTC codes.
* The file also defines an array of DTC definitions and a timestamp indicating the generation time.
*
* @note This file is auto-generated by a script on {{ timestamp }}.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef DTC_DEFS_H
#define DTC_DEFS_H

View File

@@ -1,3 +1,16 @@
/**
* @file globals.h
*
* @brief Header file for global variables and enums in the ChainLube application.
*
* This file contains declarations for global variables and enums used in the ChainLube application.
* It includes enums for system status and EEPROM-related requests, as well as a struct for global variables.
* The file also defines a struct for constants and initializes it with firmware and required flash version information.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
@@ -29,29 +42,29 @@ typedef enum eEERequest
typedef struct Globals_s
{
tSystem_Status systemStatus = sysStat_Startup;
tSystem_Status resumeStatus = sysStat_Startup;
char systemStatustxt[16] = "";
uint16_t purgePulses = 0;
eEERequest requestEEAction = EE_IDLE;
char DeviceName[33];
char FlashVersion[10];
uint16_t eePersistanceAdress;
uint8_t TankPercentage;
bool hasDTC;
bool measurementActive;
uint32_t measuredPulses;
tSystem_Status systemStatus = sysStat_Startup; /**< Current system status */
tSystem_Status resumeStatus = sysStat_Startup; /**< Status to resume after rain mode */
char systemStatustxt[16] = ""; /**< Text representation of system status */
uint16_t purgePulses = 0; /**< Number of purge pulses */
eEERequest requestEEAction = EE_IDLE;; /**< EEPROM-related request */
char DeviceName[33]; /**< Device name */
char FlashVersion[10]; /**< Flash version */
uint16_t eePersistanceAdress; /**< EEPROM persistence address */
uint8_t TankPercentage; /**< Tank percentage */
bool hasDTC; /**< Flag indicating the presence of Diagnostic Trouble Codes (DTC) */
bool measurementActive; /**< Flag indicating active measurement */
uint32_t measuredPulses; /**< Number of measured pulses */
} Globals_t;
extern Globals_t globals;
extern Globals_t globals; /**< Global variable struct */
typedef struct Constants_s
{
uint8_t FW_Version_major;
uint8_t FW_Version_minor;
uint8_t Required_Flash_Version_major;
uint8_t Required_Flash_Version_minor;
char GitHash[11];
uint8_t FW_Version_major; /**< Firmware version major number */
uint8_t FW_Version_minor; /**< Firmware version minor number */
uint8_t Required_Flash_Version_major; /**< Required flash version major number */
uint8_t Required_Flash_Version_minor; /**< Required flash version minor number */
char GitHash[11]; /**< Git hash string */
} Constants_t;
const Constants_t constants PROGMEM = {
@@ -60,6 +73,9 @@ const Constants_t constants PROGMEM = {
GIT_REV // Git-Hash-String
};
/**
* @brief Initializes global variables.
*/
void initGlobals();
#endif
#endif // _GLOBALS_H_

View File

@@ -1,3 +1,17 @@
/**
* @file gps.h
*
* @brief Header file for GPS-related functions in the ChainLube application.
*
* This file contains declarations for functions related to GPS (Global Positioning System) functionality
* within the ChainLube application. It includes the initialization of the GPS module and processing of GPS
* data to calculate wheel speed. Additionally, it references other necessary header files for configuration,
* common definitions, diagnostics, and debugging.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _GPS_H_
#define _GPS_H_
@@ -7,7 +21,16 @@
#include "dtc.h"
#include "debugger.h"
/**
* @brief Initializes the GPS module.
*/
void Init_GPS();
/**
* @brief Processes GPS data to calculate wheel speed.
*
* @return Calculated wheel speed in millimeters per second.
*/
uint32_t Process_GPS_WheelSpeed();
#endif
#endif // _GPS_H_

View File

@@ -1,3 +1,16 @@
/**
* @file led_colors.h
*
* @brief Header file defining color values for LEDs in the ChainLube application.
*
* This file contains color definitions in hexadecimal format for various states and events of LEDs
* used in the ChainLube application. It provides a convenient way to reference specific colors for
* different visual indications in the system.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _LED_COLORS_H_
#define _LED_COLORS_H_
@@ -19,17 +32,14 @@
#define COLOR_AMBER 0xFF6400
#define COLOR_WARM_WHITE 0xFDF5E6
#define LED_DEFAULT_COLOR COLOR_WARM_WHITE
#define LED_STARTUP_NORMAL COLOR_WARM_WHITE
#define LED_STARTUP_TANKWARN COLOR_AMBER
#define LED_NORMAL_COLOR COLOR_GREEN
#define LED_RAIN_COLOR COLOR_BLUE
#define LED_NORMAL_COLOR COLOR_GREEN
#define LED_RAIN_COLOR COLOR_BLUE
#define LED_WIFI_BLINK COLOR_YELLOW
#define LED_PURGE_COLOR COLOR_MAGENTA
#define LED_ERROR_BLINK COLOR_RED
#define LED_SHUTDOWN_BLINK COLOR_CYAN
#endif /* _LED_COLORS_H_ */

View File

@@ -1,3 +1,15 @@
/**
* @file lubeapp.h
*
* @brief Header file for the ChainLube application functions.
*
* This file contains function declarations related to the main functionality of the ChainLube
* application. It includes functions for running the application and generating lubrication pulses.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _LUBEAPP_H_
#define _LUBEAPP_H_
@@ -12,4 +24,4 @@
void RunLubeApp(uint32_t add_milimeters);
void LubePulse();
#endif
#endif /* _LUBEAPP_H_ */

View File

@@ -1,3 +1,15 @@
/**
* @file sanitycheck.h
*
* @brief Header file for sanity checks and configuration validation in the ChainLube application.
*
* This file contains checks and validations to ensure that the configuration and features of the
* ChainLube application are compatible with the selected PCB revision and defined parameters.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _SANITYCHECK_H_
#define _SANITYCHECK_H_
@@ -34,4 +46,4 @@
#error "You must define an WIFI_AP_PASSWORD for Standalone AP-Mode"
#endif
#endif //_SANITYCHECK_H_
#endif // _SANITYCHECK_H_

View File

@@ -1,3 +1,16 @@
/**
* @file webui.h
*
* @brief Header file for the web-based user interface (WebUI) in the ChainLube application.
*
* This file contains declarations for functions related to the initialization and processing of the
* web-based user interface (WebUI). It includes the necessary libraries and dependencies for handling
* web server functionality, asynchronous JSON operations, and live debugging through WebSockets.
*
* @author Marcel Peterkau
* @date 09.01.2024
*/
#ifndef _WEBUI_H_
#define _WEBUI_H_
@@ -22,4 +35,4 @@ void Webserver_Process();
void Websocket_PushLiveDebug(String Message);
#endif
#endif // _WEBUI_H_