1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00

Throttle fix

This commit is contained in:
Asbelos 2020-05-29 15:44:57 +01:00
parent 54ef92085b
commit 257a81f969
2 changed files with 5 additions and 7 deletions

View File

@ -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,12 +35,7 @@ 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);
}

View File

@ -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);
}