Initialisation depot
This commit is contained in:
100
ESP32/DCC-Loco/include/CVManager.h
Normal file
100
ESP32/DCC-Loco/include/CVManager.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/**
|
||||
* @file CVManager.h
|
||||
* @brief Configuration Variable (CV) Manager
|
||||
*
|
||||
* Manages NMRA-compliant Configuration Variables stored in non-volatile memory.
|
||||
* Supports programming track operations and service mode programming.
|
||||
*/
|
||||
|
||||
#ifndef CV_MANAGER_H
|
||||
#define CV_MANAGER_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Preferences.h>
|
||||
|
||||
// Standard DCC CVs
|
||||
#define CV_PRIMARY_ADDRESS 1 // Short address (1-127)
|
||||
#define CV_VSTART 2 // Start voltage
|
||||
#define CV_ACCEL_RATE 3 // Acceleration rate
|
||||
#define CV_DECEL_RATE 4 // Deceleration rate
|
||||
#define CV_VHIGH 5 // Max voltage
|
||||
#define CV_VMID 6 // Mid voltage
|
||||
#define CV_VERSION_ID 7 // Manufacturer version
|
||||
#define CV_MANUFACTURER_ID 8 // Manufacturer ID
|
||||
#define CV_TOTAL_PWM_PERIOD 9 // PWM period
|
||||
#define CV_EMF_FEEDBACK_CUTOUT 10 // EMF feedback cutout
|
||||
#define CV_PACKET_TIMEOUT 11 // Packet timeout
|
||||
#define CV_EXTENDED_ADDRESS_HIGH 17 // Long address high byte
|
||||
#define CV_EXTENDED_ADDRESS_LOW 18 // Long address low byte
|
||||
#define CV_CONSIST_ADDRESS 19 // Consist address
|
||||
#define CV_CONFIG_DATA_1 29 // Configuration data
|
||||
|
||||
// Custom CVs for this decoder
|
||||
#define CV_MOTOR_KP 50 // Motor PID Kp
|
||||
#define CV_MOTOR_KI 51 // Motor PID Ki
|
||||
#define CV_MOTOR_KD 52 // Motor PID Kd
|
||||
#define CV_RAILCOM_ENABLE 53 // RailCom enable
|
||||
#define CV_LOAD_COMP_ENABLE 54 // Load compensation enable
|
||||
#define CV_LED_BRIGHTNESS 55 // LED brightness
|
||||
#define CV_ACCESSORY_1_MODE 56 // Accessory output 1 mode
|
||||
#define CV_ACCESSORY_2_MODE 57 // Accessory output 2 mode
|
||||
|
||||
#define MAX_CV_NUMBER 1024
|
||||
|
||||
class CVManager {
|
||||
public:
|
||||
CVManager();
|
||||
|
||||
/**
|
||||
* @brief Initialize CV manager and load from NVS
|
||||
* @return true if successful
|
||||
*/
|
||||
bool begin();
|
||||
|
||||
/**
|
||||
* @brief Read CV value
|
||||
* @param cvNumber CV number (1-1024)
|
||||
* @param defaultValue Default value if CV not set
|
||||
* @return CV value
|
||||
*/
|
||||
uint8_t readCV(uint16_t cvNumber, uint8_t defaultValue = 0);
|
||||
|
||||
/**
|
||||
* @brief Write CV value
|
||||
* @param cvNumber CV number (1-1024)
|
||||
* @param value Value to write
|
||||
* @return true if successful
|
||||
*/
|
||||
bool writeCV(uint16_t cvNumber, uint8_t value);
|
||||
|
||||
/**
|
||||
* @brief Reset all CVs to factory defaults
|
||||
*/
|
||||
void resetToDefaults();
|
||||
|
||||
/**
|
||||
* @brief Get locomotive address from CVs
|
||||
* @return Locomotive address (1-10239)
|
||||
*/
|
||||
uint16_t getLocoAddress();
|
||||
|
||||
/**
|
||||
* @brief Set locomotive address in CVs
|
||||
* @param address Address to set (1-10239)
|
||||
*/
|
||||
void setLocoAddress(uint16_t address);
|
||||
|
||||
/**
|
||||
* @brief Check if using extended (long) address
|
||||
* @return true if using long address
|
||||
*/
|
||||
bool isLongAddress();
|
||||
|
||||
private:
|
||||
Preferences preferences;
|
||||
|
||||
void setDefaultCVs();
|
||||
String getCVKey(uint16_t cvNumber);
|
||||
};
|
||||
|
||||
#endif // CV_MANAGER_H
|
||||
Reference in New Issue
Block a user