mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-26 09:36:13 +01:00
Add serial output for sabertooth controller
This commit is contained in:
parent
33306219c8
commit
efdbfcb030
|
@ -205,6 +205,36 @@ int16_t CommandDistributor::retClockTime() {
|
||||||
void CommandDistributor::broadcastLoco(byte slot) {
|
void CommandDistributor::broadcastLoco(byte slot) {
|
||||||
DCC::LOCO * sp=&DCC::speedTable[slot];
|
DCC::LOCO * sp=&DCC::speedTable[slot];
|
||||||
broadcastReply(COMMAND_TYPE, F("<l %d %d %d %l>\n"), sp->loco,slot,sp->speedCode,sp->functions);
|
broadcastReply(COMMAND_TYPE, F("<l %d %d %d %l>\n"), sp->loco,slot,sp->speedCode,sp->functions);
|
||||||
|
#ifdef SABERTOOTH
|
||||||
|
if (Serial2 && sp->loco == SABERTOOTH) {
|
||||||
|
static uint8_t rampingmode = 0;
|
||||||
|
bool direction = (sp->speedCode & 0x80) !=0; // true for forward
|
||||||
|
int32_t speed = sp->speedCode & 0x7f;
|
||||||
|
if (speed == 1) { // emergency stop
|
||||||
|
if (rampingmode != 1) {
|
||||||
|
rampingmode = 1;
|
||||||
|
Serial2.print("R1: 0\r\n");
|
||||||
|
Serial2.print("R2: 0\r\n");
|
||||||
|
}
|
||||||
|
Serial2.print("MD: 0\r\n");
|
||||||
|
} else {
|
||||||
|
if (speed != 0) {
|
||||||
|
// speed is here 2 to 127
|
||||||
|
speed = (speed - 1) * 1625 / 100;
|
||||||
|
speed = speed * (direction ? 1 : -1);
|
||||||
|
// speed is here -2047 to 2047
|
||||||
|
}
|
||||||
|
if (rampingmode != 2) {
|
||||||
|
rampingmode = 2;
|
||||||
|
Serial2.print("R1: 2047\r\n");
|
||||||
|
Serial2.print("R2: 2047\r\n");
|
||||||
|
}
|
||||||
|
Serial2.print("MD: ");
|
||||||
|
Serial2.print(speed);
|
||||||
|
Serial2.print("\r\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#ifdef CD_HANDLE_RING
|
#ifdef CD_HANDLE_RING
|
||||||
WiThrottle::markForBroadcast(sp->loco);
|
WiThrottle::markForBroadcast(sp->loco);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -87,6 +87,9 @@ void SerialManager::init() {
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SABERTOOTH
|
||||||
|
Serial2.begin(9600, SERIAL_8N1, 16, 17); // GPIO 16 RXD2; GPIO 17 TXD2 on ESP32
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void SerialManager::broadcast(char * stringBuffer) {
|
void SerialManager::broadcast(char * stringBuffer) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user