#ifndef CONFIG_H #define CONFIG_H #include "driver/gpio.h" #include "driver/ledc.h" // ================================ // WiFi Configuration // ================================ #define WIFI_SSID "GL-AXT1800-0c2" #define WIFI_PASS "CR7W25FM8S" #define WIFI_MAXIMUM_RETRY 5 // WiFi event group bits #define WIFI_CONNECTED_BIT BIT0 #define WIFI_FAIL_BIT BIT1 // ================================ // GPIO Pin Definitions // ================================ #define LED_PIN GPIO_NUM_13 #define MOTOR_R_EN GPIO_NUM_18 #define MOTOR_L_EN GPIO_NUM_19 #define PWM_R_PIN GPIO_NUM_21 #define PWM_L_PIN GPIO_NUM_22 // ================================ // PWM Configuration // ================================ #define PWM_FREQUENCY 20000 #define PWM_RESOLUTION LEDC_TIMER_8_BIT #define PWM_R_CHANNEL LEDC_CHANNEL_0 #define PWM_L_CHANNEL LEDC_CHANNEL_1 #define PWM_TIMER LEDC_TIMER_0 #define PWM_SPEED_MODE LEDC_LOW_SPEED_MODE // ================================ // Motor Control Configuration // ================================ #define RAMP_STEP_MS 150 // Time between ramp steps (milliseconds) #define RAMP_STEP_SIZE 5 // PWM duty change per step (0-255) #define MIN_MOTOR_SPEED 10 // Minimum speed to overcome motor inertia #define DIRECTION_CHANGE_COOLDOWN_MS 10000 // 10 seconds cooldown for direction changes // ================================ // Watchdog Configuration // ================================ #define WATCHDOG_TIMEOUT_S 10 // Watchdog timeout in seconds #define WATCHDOG_FEED_INTERVAL_MS 3000 // Feed watchdog every 3 seconds // ================================ // State Preservation Configuration // ================================ #define NVS_NAMESPACE "fan_state" #define NVS_KEY_MODE "mode" #define NVS_KEY_SPEED "speed" #define NVS_KEY_LAST_ON_MODE "last_mode" #define NVS_KEY_LAST_ON_SPEED "last_speed" #define NVS_KEY_POWER_STATE "power_state" // ================================ // HTTP Server Configuration // ================================ #define HTTP_SERVER_PORT 80 #define HTTP_MAX_URI_HANDLERS 15 #define HTTP_RECV_TIMEOUT_SEC 10 #define HTTP_SEND_TIMEOUT_SEC 10 // ================================ // Status Update Configuration // ================================ #define STATUS_UPDATE_INTERVAL_MS 1000 // Web interface status update interval // ================================ // System Configuration // ================================ #define SYSTEM_TAG "HTTP_MOTOR" // Main logging tag // ================================ // Safety Limits // ================================ #define MAX_SPEED_PERCENT 100 #define MIN_SPEED_PERCENT 0 #define MAX_JSON_BUFFER_SIZE 200 // ================================ // Motor PWM Calculation Macros // ================================ #define SPEED_TO_DUTY(speed_percent) ((speed_percent * 255) / 100) #define DUTY_TO_SPEED(duty) ((duty * 100) / 255) // ================================ // Validation Macros // ================================ #define CLAMP_SPEED(speed) ((speed) < MIN_SPEED_PERCENT ? MIN_SPEED_PERCENT : \ (speed) > MAX_SPEED_PERCENT ? MAX_SPEED_PERCENT : (speed)) // For unsigned types (uint8_t), we only need to check the upper bound since MIN_SPEED_PERCENT is 0 #define IS_VALID_SPEED(speed) ((speed) <= MAX_SPEED_PERCENT) // For signed types or when MIN_SPEED_PERCENT might be > 0, use this version: #define IS_VALID_SPEED_FULL(speed) ((speed) >= MIN_SPEED_PERCENT && (speed) <= MAX_SPEED_PERCENT) #define IS_DIRECTION_CHANGE(old_mode, new_mode) \ (((old_mode) == MOTOR_EXHAUST && (new_mode) == MOTOR_INTAKE) || \ ((old_mode) == MOTOR_INTAKE && (new_mode) == MOTOR_EXHAUST)) // ================================ // Debug Configuration // ================================ #ifdef CONFIG_LOG_DEFAULT_LEVEL_DEBUG #define MOTOR_DEBUG_ENABLED 1 #else #define MOTOR_DEBUG_ENABLED 0 #endif // Debug logging macro #if MOTOR_DEBUG_ENABLED #define MOTOR_LOGD(tag, format, ...) ESP_LOGD(tag, format, ##__VA_ARGS__) #else #define MOTOR_LOGD(tag, format, ...) #endif #endif // CONFIG_H