Ajout prise en charge ESP-Display

This commit is contained in:
Serge NOEL
2025-12-01 13:53:54 +01:00
parent bcd88909b7
commit ae375b8fe2
26 changed files with 3945 additions and 1017 deletions

View File

@@ -19,8 +19,11 @@
#include <Arduino.h>
// Pin definitions for DCC output
#define DCC_PIN_A 32 ///< DCC Signal A output pin
#define DCC_PIN_B 33 ///< DCC Signal B output pin (inverted)
// These share the same pins as the motor controller (LM18200)
// In DCC mode: GPIO 18 = DCC Signal A, GPIO 19 = DCC Signal B
// In DC mode: GPIO 18 = PWM, GPIO 19 = Direction
#define DCC_PIN_A 18 ///< DCC Signal A output pin (shared with MOTOR_PWM_PIN)
#define DCC_PIN_B 19 ///< DCC Signal B output pin (shared with MOTOR_DIR_PIN)
// DCC timing constants (microseconds) - NMRA standard
#define DCC_ONE_BIT_TOTAL_DURATION_MAX 64 ///< Max duration for '1' bit
@@ -99,6 +102,37 @@ public:
*/
bool isEnabled() { return enabled; }
// Programming Track Methods
/**
* @brief Factory reset decoder (send CV8 = 8)
* @return true if successful
*/
bool factoryReset();
/**
* @brief Set decoder address
* @param address New address (1-10239)
* @return true if successful
*/
bool setDecoderAddress(uint16_t address);
/**
* @brief Read CV value from decoder
* @param cv CV number (1-1024)
* @param value Pointer to store read value
* @return true if successful
*/
bool readCV(uint16_t cv, uint8_t* value);
/**
* @brief Write CV value to decoder
* @param cv CV number (1-1024)
* @param value Value to write (0-255)
* @return true if successful
*/
bool writeCV(uint16_t cv, uint8_t value);
private:
bool enabled; ///< DCC generator enabled flag
uint16_t currentAddress; ///< Current locomotive address
@@ -153,6 +187,40 @@ private:
* @return XOR checksum byte
*/
uint8_t calculateChecksum(uint8_t* data, uint8_t length);
// Programming track helper methods
/**
* @brief Send service mode packet (programming track)
* @param data Packet data bytes
* @param length Number of bytes
*/
void sendServiceModePacket(uint8_t* data, uint8_t length);
/**
* @brief Verify byte write on programming track
* @param cv CV number
* @param value Expected value
* @return true if ACK detected
*/
bool verifyByte(uint16_t cv, uint8_t value);
/**
* @brief Wait for ACK pulse from decoder
* @return true if ACK detected within timeout
*/
bool waitForAck();
/**
* @brief Calibrate ACS712 current sensor zero point
*
* Reads current sensor with no load to establish baseline.
* Should be called during initialization.
*/
void calibrateCurrentSensor();
};
// Programming track current sensing threshold (mA)
#define PROG_ACK_CURRENT_THRESHOLD 60 ///< Minimum ACK current (mA)
#endif