Ajout gestion LM18220

This commit is contained in:
Serge NOEL
2026-08-05 11:51:54 +02:00
parent fd3fc380d8
commit be3dbaa824
7 changed files with 207 additions and 46 deletions
+13 -19
View File
@@ -1,26 +1,20 @@
#include "Dcc.h"
#include <Arduino.h>
std::vector<uint8_t> Dcc::generateAccessoryPacket(uint16_t addr, bool activate) {
// This produces a simple, application-level packet representation.
// For NMRA-compliant bitstreams you will need a timing-accurate generator.
std::vector<uint8_t> p;
p.push_back((uint8_t)(addr >> 8));
p.push_back((uint8_t)(addr & 0xFF));
p.push_back(activate ? 1 : 0);
return p;
void Dcc::begin(int dirPin, int pwmPin) {
DCCpp::begin();
DCCpp::beginMain(UNDEFINED_PIN, dirPin, pwmPin, UNDEFINED_PIN);
DCCpp::powerOn(true, false);
}
void Dcc::sendPacket(const std::vector<uint8_t> &packet, int pin) {
// Simple simulation: print packet and toggle pin briefly for each byte.
Serial.print("DCC packet: ");
for (size_t i = 0; i < packet.size(); ++i) {
Serial.print(packet[i], HEX);
Serial.print(' ');
digitalWrite(pin, HIGH);
delay(2);
digitalWrite(pin, LOW);
delay(2);
void Dcc::sendAccessory(uint16_t linearAddress, bool activate) {
if (linearAddress == 0) {
Serial.println("Adresse DCC invalide");
return;
}
Serial.println();
int boardAddress = ((linearAddress - 1) / 4) + 1;
int subAddress = (linearAddress - 1) % 4;
byte activateByte = activate ? 1 : 0;
DCCpp::setAccessory(boardAddress, subAddress, activateByte);
}
+7 -7
View File
@@ -1,14 +1,14 @@
#pragma once
#include <vector>
#include <stdint.h>
#include <DCCpp.h>
#ifndef UNDEFINED_PIN
#define UNDEFINED_PIN 255
#endif
class Dcc {
public:
// Generate a simplified DCC accessory packet (bytes).
// addr: accessory address (application-dependent)
// activate: true = ON, false = OFF
static std::vector<uint8_t> generateAccessoryPacket(uint16_t addr, bool activate);
// Send packet via a GPIO pin (simulation/pulse). Implementation may be hardware-specific.
static void sendPacket(const std::vector<uint8_t> &packet, int pin);
static void begin(int dirPin, int pwmPin);
static void sendAccessory(uint16_t linearAddress, bool activate);
};