From efdbfcb03053ff88db13198520a01ecbaba80115 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Mon, 1 May 2023 20:18:32 +0200 Subject: [PATCH 1/3] Add serial output for sabertooth controller --- CommandDistributor.cpp | 30 ++++++++++++++++++++++++++++++ SerialManager.cpp | 3 +++ 2 files changed, 33 insertions(+) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index 4b4159d..f788034 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -205,6 +205,36 @@ int16_t CommandDistributor::retClockTime() { void CommandDistributor::broadcastLoco(byte slot) { DCC::LOCO * sp=&DCC::speedTable[slot]; broadcastReply(COMMAND_TYPE, F("\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 WiThrottle::markForBroadcast(sp->loco); #endif diff --git a/SerialManager.cpp b/SerialManager.cpp index 0ac567d..bacfceb 100644 --- a/SerialManager.cpp +++ b/SerialManager.cpp @@ -87,6 +87,9 @@ void SerialManager::init() { delay(1000); } #endif +#ifdef SABERTOOTH + Serial2.begin(9600, SERIAL_8N1, 16, 17); // GPIO 16 RXD2; GPIO 17 TXD2 on ESP32 +#endif } void SerialManager::broadcast(char * stringBuffer) { From 9d953c70b8a4df5b205c75e1f48588aef8c23f87 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Tue, 2 May 2023 23:51:17 +0200 Subject: [PATCH 2/3] use M1 and M2 instead of MD for motor control --- CommandDistributor.cpp | 5 ++++- GITHUB_SHA.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CommandDistributor.cpp b/CommandDistributor.cpp index f788034..9b61f78 100644 --- a/CommandDistributor.cpp +++ b/CommandDistributor.cpp @@ -229,7 +229,10 @@ void CommandDistributor::broadcastLoco(byte slot) { Serial2.print("R1: 2047\r\n"); Serial2.print("R2: 2047\r\n"); } - Serial2.print("MD: "); + Serial2.print("M1: "); + Serial2.print(speed); + Serial2.print("\r\n"); + Serial2.print("M2: "); Serial2.print(speed); Serial2.print("\r\n"); } diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index f3e8efd..9564209 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202304172140Z" +#define GITHUB_SHA "devel-202305022149Z" From c472f48d9303633433948bbd07451e3aa48e62b0 Mon Sep 17 00:00:00 2001 From: Harald Barth Date: Sat, 20 May 2023 14:57:00 +0200 Subject: [PATCH 3/3] Experimental support for sabertooth motor controller on ESP32 --- GITHUB_SHA.h | 2 +- config.example.h | 10 ++++++++++ version.h | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/GITHUB_SHA.h b/GITHUB_SHA.h index 9564209..355e2e9 100644 --- a/GITHUB_SHA.h +++ b/GITHUB_SHA.h @@ -1 +1 @@ -#define GITHUB_SHA "devel-202305022149Z" +#define GITHUB_SHA "devel-202305201256Z" diff --git a/config.example.h b/config.example.h index 2a8a11a..058bc7a 100644 --- a/config.example.h +++ b/config.example.h @@ -224,5 +224,15 @@ The configuration file for DCC-EX Command Station // //#define SERIAL_BT_COMMANDS +// SABERTOOTH +// +// This is a very special option and only useful if you happen to have a +// sabertooth motor controller from dimension engineering configured to +// take commands from and ESP32 via serial at 9600 baud from GPIO17 (TX) +// and GPIO16 (RX, currently unused). +// The number defined is the DCC address for which speed controls are sent +// to the sabertooth controller _as_well_. Default: Undefined. +// +//#define SABERTOOTH 1 ///////////////////////////////////////////////////////////////////////////////////// diff --git a/version.h b/version.h index f168477..030cff6 100644 --- a/version.h +++ b/version.h @@ -4,7 +4,8 @@ #include "StringFormatter.h" -#define VERSION "4.2.47" +#define VERSION "4.2.52" +// 4.2.52 - Experimental support for sabertooth motor controller on ESP32 // 4.2.47 - Correct response to // 4.2.46 - Support boards with inverted fault pin // 4.2.45 - Add ONCLOCKMINS to FastClock to allow hourly repeat events