From 257a81f969b891ae09b85f52d105c8185289c9c1 Mon Sep 17 00:00:00 2001 From: Asbelos Date: Fri, 29 May 2020 15:44:57 +0100 Subject: [PATCH] Throttle fix --- DCC.cpp | 10 +++------- Hardware.cpp | 2 ++ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/DCC.cpp b/DCC.cpp index cd8f635..439faab 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -26,6 +26,7 @@ void DCC::setThrottle( uint16_t cab, uint8_t tSpeed, bool tDirection) { } void DCC::setThrottle2( uint16_t cab, uint8_t tSpeed, bool tDirection) { + uint8_t b[5]; uint8_t nB = 0; @@ -34,13 +35,8 @@ void DCC::setThrottle2( uint16_t cab, uint8_t tSpeed, bool tDirection) { b[nB++] = lowByte(cab); b[nB++] = 0x3F; // 128-step speed control byte - if (tSpeed > 0) - b[nB++] = tSpeed + (tSpeed > 0) + tDirection * 128; // max speed is 126, but speed codes range from 2-127 (0=stop, 1=emergency stop) - else { - b[nB++] = 1; - tSpeed = 0; - } - + b[nB++] = tSpeed + (tSpeed > 0) + tDirection * 128; // max speed is 126, but speed codes range from 2-127 (0=stop, 1=emergency stop) + DCCWaveform::mainTrack.schedulePacket(b, nB, 0); } diff --git a/Hardware.cpp b/Hardware.cpp index d5a6f51..bca0e66 100644 --- a/Hardware.cpp +++ b/Hardware.cpp @@ -4,6 +4,7 @@ #include "Hardware.h" #include "Config.h" +#include "DIAG.h" void Hardware::init() { pinMode(MAIN_POWER_PIN, OUTPUT); @@ -35,6 +36,7 @@ int Hardware::getCurrentMilliamps(bool isMainTrack) { int pin = isMainTrack ? MAIN_SENSE_PIN : PROG_SENSE_PIN; float factor = isMainTrack ? MAIN_SENSE_FACTOR : PROG_SENSE_FACTOR; int rawCurrent = analogRead(pin); + // DIAG(F("\nCurrent on %d pin %d = %d"),isMainTrack,pin,rawCurrent); return (int)(rawCurrent * factor); }