Initialisation depot
This commit is contained in:
101
ESP32/DCC-Loco/include/AccessoryOutputs.h
Normal file
101
ESP32/DCC-Loco/include/AccessoryOutputs.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* @file AccessoryOutputs.h
|
||||
* @brief Accessory Output Controller (N-channel MOSFETs)
|
||||
*
|
||||
* Controls 2 N-channel MOSFET outputs for accessories like smoke generators,
|
||||
* sound modules, or other low-side switched loads.
|
||||
*/
|
||||
|
||||
#ifndef ACCESSORY_OUTPUTS_H
|
||||
#define ACCESSORY_OUTPUTS_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
enum AccessoryMode {
|
||||
ACC_OFF = 0, // Always off
|
||||
ACC_ON = 1, // Always on
|
||||
ACC_FUNCTION = 2, // Controlled by DCC function
|
||||
ACC_PWM = 3, // PWM control
|
||||
ACC_BLINK = 4, // Blinking mode
|
||||
ACC_SPEED_DEPENDENT = 5 // Output follows speed
|
||||
};
|
||||
|
||||
class AccessoryOutputs {
|
||||
public:
|
||||
AccessoryOutputs();
|
||||
|
||||
/**
|
||||
* @brief Initialize accessory outputs
|
||||
* @param output1Pin GPIO for accessory output 1 (N-FET gate)
|
||||
* @param output2Pin GPIO for accessory output 2 (N-FET gate)
|
||||
* @return true if successful
|
||||
*/
|
||||
bool begin(uint8_t output1Pin, uint8_t output2Pin);
|
||||
|
||||
/**
|
||||
* @brief Set output mode
|
||||
* @param outputNum Output number (1 or 2)
|
||||
* @param mode Accessory mode
|
||||
*/
|
||||
void setMode(uint8_t outputNum, AccessoryMode mode);
|
||||
|
||||
/**
|
||||
* @brief Set PWM duty cycle for output
|
||||
* @param outputNum Output number (1 or 2)
|
||||
* @param dutyCycle Duty cycle (0-255)
|
||||
*/
|
||||
void setPWM(uint8_t outputNum, uint8_t dutyCycle);
|
||||
|
||||
/**
|
||||
* @brief Map DCC function to output
|
||||
* @param outputNum Output number (1 or 2)
|
||||
* @param functionNum DCC function number (0-28)
|
||||
*/
|
||||
void mapFunction(uint8_t outputNum, uint8_t functionNum);
|
||||
|
||||
/**
|
||||
* @brief Update function state
|
||||
* @param functionNum Function number (0-28)
|
||||
* @param state Function state (true = on)
|
||||
*/
|
||||
void setFunctionState(uint8_t functionNum, bool state);
|
||||
|
||||
/**
|
||||
* @brief Set speed for speed-dependent mode
|
||||
* @param speed Speed value (0-126)
|
||||
*/
|
||||
void setSpeed(uint8_t speed);
|
||||
|
||||
/**
|
||||
* @brief Update outputs (call regularly from loop)
|
||||
*/
|
||||
void update();
|
||||
|
||||
/**
|
||||
* @brief Direct output control
|
||||
* @param outputNum Output number (1 or 2)
|
||||
* @param state Output state (true = on)
|
||||
*/
|
||||
void setOutput(uint8_t outputNum, bool state);
|
||||
|
||||
private:
|
||||
uint8_t pins[2];
|
||||
AccessoryMode modes[2];
|
||||
uint8_t pwmValues[2];
|
||||
uint8_t mappedFunctions[2];
|
||||
bool functionStates[29]; // F0-F28
|
||||
uint8_t currentSpeed;
|
||||
|
||||
// PWM channels
|
||||
const uint8_t pwmChannels[2] = {2, 3};
|
||||
const uint32_t pwmFrequency = 1000; // 1 kHz
|
||||
const uint8_t pwmResolution = 8;
|
||||
|
||||
// Blink timing
|
||||
unsigned long lastBlinkUpdate;
|
||||
bool blinkState;
|
||||
|
||||
void updateOutput(uint8_t outputNum);
|
||||
};
|
||||
|
||||
#endif // ACCESSORY_OUTPUTS_H
|
||||
Reference in New Issue
Block a user