Initialisation depot
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user