Initialisation depot

This commit is contained in:
Serge NOEL
2026-08-05 09:14:31 +02:00
commit fd3fc380d8
10 changed files with 350 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
#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::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);
}
Serial.println();
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <vector>
#include <stdint.h>
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);
};