add doxygen and header guards

This commit is contained in:
HendrikRauh 2026-03-20 22:44:33 +01:00
parent f30fa4f130
commit 472b478afe
8 changed files with 126 additions and 21 deletions

View file

@ -1,4 +1,3 @@
/**
* @file logger.h
* @brief Project-wide logging macros based on ESP-IDF's logging library.
@ -27,8 +26,12 @@
#include "esp_log.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef LOG_TAG
#define LOG_TAG "CHAOS"
#define LOG_TAG "CHAOS" ///< Default log tag
#endif
/** @brief Log a message at Error level. */
@ -41,3 +44,7 @@
#define LOGD(...) ESP_LOGD(LOG_TAG, __VA_ARGS__)
/** @brief Log a message at Verbose level. */
#define LOGV(...) ESP_LOGV(LOG_TAG, __VA_ARGS__)
#ifdef __cplusplus
}
#endif

View file

@ -1,5 +1,4 @@
#ifndef STORAGE_H
#define STORAGE_H
#pragma once
#include "esp_err.h"
@ -24,5 +23,3 @@ const char *storage_get_mount_point(void);
#ifdef __cplusplus
}
#endif
#endif /* STORAGE_H */

View file

@ -1,11 +1,12 @@
#define LOG_TAG "STORE"
#define LOG_TAG "STORE" ///< "STORE" log tag for this file
#include "storage.h"
#include "esp_littlefs.h"
#include "esp_vfs.h"
#include "logger.h"
static const char *LITTLEFS_MOUNT_POINT = "/data";
static const char *LITTLEFS_MOUNT_POINT =
"/data"; ///< Mount point for LittleFS filesystem
esp_err_t storage_init(void) {
esp_vfs_littlefs_conf_t conf = {

View file

@ -6,8 +6,26 @@
extern "C" {
#endif
/**
* @brief Start WiFi Access Point (AP) mode.
*
* Initializes and starts the WiFi AP with the given SSID and password.
*
* @param ssid SSID for the AP (1-32 characters)
* @param password Password for the AP (min. 8 characters, optional)
* @param channel WiFi channel to use
* @param max_connections Maximum number of client connections
* @return ESP_OK on success, ESP_ERR_INVALID_ARG or other error codes on
* failure
*/
esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
uint8_t max_connections);
/**
* @brief Stop WiFi Access Point (AP) mode.
*
* Deinitializes and stops the WiFi AP.
*/
void wifi_stop_ap(void);
#ifdef __cplusplus

View file

@ -1,5 +1,10 @@
#define LOG_TAG "WEBSRV"
/**
* @def LOG_TAG
* @brief Tag used for web server logging.
*/
#include "web_server.h"
#include <ctype.h>
@ -14,12 +19,34 @@
#include "storage.h"
// Default configuration values
/**
* @brief Default port for the web server.
*/
#define WEBSERVER_DEFAULT_PORT 80
/**
* @brief Default port for the web server.
*/
#define WEBSERVER_DEFAULT_MAX_HANDLERS 32
/**
* @brief Default maximum number of URI handlers.
*/
#define WEBSERVER_DEFAULT_STACK_SIZE (8 * 1024)
/**
* @brief Default stack size for the web server task.
*/
#define WEBSERVER_DEFAULT_TASK_PRIORITY 5
/**
* @brief Default task priority for the web server task.
*/
/**
* @brief Handle for the HTTP server instance.
*/
static httpd_handle_t s_server_handle = NULL;
/**
* @brief Handle for the FreeRTOS web server task.
*/
static TaskHandle_t s_server_task_handle = NULL;
/**
@ -127,6 +154,15 @@ static void webserver_task(void *arg) {
vTaskDelete(NULL);
}
/**
* @brief Start the web server with the given configuration.
*
* Initializes storage, configures the HTTP server, registers default handlers,
* and starts the FreeRTOS task for async operation.
*
* @param config Pointer to webserver configuration struct (optional)
* @return Handle to the running HTTP server, or NULL on failure
*/
httpd_handle_t webserver_start(const webserver_config_t *config) {
if (s_server_handle != NULL) {
LOGW("Web server already running");
@ -207,6 +243,13 @@ httpd_handle_t webserver_start(const webserver_config_t *config) {
return s_server_handle;
}
/**
* @brief Stop the web server and clean up resources.
*
* Stops the HTTP server and deletes the FreeRTOS task.
*
* @param server Handle to the HTTP server instance
*/
void webserver_stop(httpd_handle_t server) {
if (server == NULL) {
return;
@ -224,6 +267,14 @@ void webserver_stop(httpd_handle_t server) {
LOGI("Web server stopped");
}
/**
* @brief Register a URI handler with the web server.
*
* @param server Handle to the HTTP server instance
* @param uri_handler Pointer to the URI handler struct
* @return ESP_OK on success, ESP_ERR_INVALID_ARG or other error codes on
* failure
*/
esp_err_t webserver_register_handler(httpd_handle_t server,
const httpd_uri_t *uri_handler) {
if (server == NULL || uri_handler == NULL) {

View file

@ -1,6 +1,4 @@
#define LOG_TAG "WIFI"
#include "wifi.h"
#define LOG_TAG "WIFI" ///< "WIFI" log tag for this file
#include <string.h>
@ -9,9 +7,25 @@
#include "esp_wifi.h"
#include "logger.h"
#include "nvs_flash.h"
#include "wifi.h"
/**
* @brief Indicates whether the WiFi AP is started.
*/
static bool s_wifi_started = false;
/**
* @brief Start WiFi Access Point (AP) mode.
*
* Initializes and starts the WiFi AP with the given SSID and password.
*
* @param ssid SSID for the AP (1-32 characters)
* @param password Password for the AP (min. 8 characters, optional)
* @param channel WiFi channel to use
* @param max_connections Maximum number of client connections
* @return ESP_OK on success, ESP_ERR_INVALID_ARG or other error codes on
* failure
*/
esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
uint8_t max_connections) {
if (s_wifi_started) {
@ -74,6 +88,11 @@ esp_err_t wifi_start_ap(const char *ssid, const char *password, uint8_t channel,
return ESP_OK;
}
/**
* @brief Stop WiFi Access Point (AP) mode.
*
* Deinitializes and stops the WiFi AP.
*/
void wifi_stop_ap(void) {
if (!s_wifi_started) {
return;

View file

@ -1,2 +1,8 @@
idf_component_register(SRCS "dmx-interface.c" INCLUDE_DIRS "." REQUIRES
web_server)
idf_component_register(
SRCS
"dmx-interface.c"
INCLUDE_DIRS
"."
REQUIRES
web_server
logger)

View file

@ -1,32 +1,38 @@
#define LOG_TAG "MAIN" ///< "MAIN" log tag for this file
#include <stdio.h>
#include "esp_err.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "logger.h"
#include "web_server.h"
#include "wifi.h"
static const char *TAG = "MAIN";
/**
* @brief Main entry point for the DMX Interface application.
*
* Initializes WiFi Access Point and starts the web server.
* Keeps the application running indefinitely.
*/
void app_main(void) {
ESP_LOGI(TAG, "DMX Interface starting...");
LOGI("DMX Interface starting...");
esp_err_t wifi_err = wifi_start_ap("DMX", "mbgmbgmbg", 1, 4);
if (wifi_err != ESP_OK) {
ESP_LOGE(TAG, "Failed to start WiFi AP: %s", esp_err_to_name(wifi_err));
LOGE("Failed to start WiFi AP: %s", esp_err_to_name(wifi_err));
return;
}
// Start HTTP web server
httpd_handle_t server = webserver_start(NULL);
if (server == NULL) {
ESP_LOGE(TAG, "Failed to start web server!");
LOGE("Failed to start web server!");
return;
}
ESP_LOGI(TAG, "Web server started successfully");
ESP_LOGI(TAG, "Open http://192.168.4.1 in your browser");
LOGI("Web server started successfully");
LOGI("Open http://192.168.4.1 in your browser");
// Keep the app running
while (1) {