1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2025-03-14 18:13:09 +01:00

prevent driver pins to be used by sensors or outputs

This commit is contained in:
Harald Barth 2021-10-15 22:10:50 +02:00
parent f8fb08e331
commit 06f8c567bc
5 changed files with 27 additions and 0 deletions

View File

@ -107,6 +107,9 @@ class DCCWaveform {
inline void setMaxAckPulseDuration(unsigned int i) { inline void setMaxAckPulseDuration(unsigned int i) {
maxAckPulseDuration = i; maxAckPulseDuration = i;
} }
inline bool pinUsed(byte pin) {
return motorDriver->pinUsed(pin);
}
private: private:

View File

@ -84,6 +84,17 @@ bool MotorDriver::isPWMCapable() {
return (!dualSignal) && DCCTimer::isPWMPin(signalPin); return (!dualSignal) && DCCTimer::isPWMPin(signalPin);
} }
bool MotorDriver::pinUsed(byte pin) {
// order by how likely to hit
if (pin == powerPin) return true;
if (pin == signalPin) return true;
if (pin == currentPin) return true;
if (pin == faultPin) return true;
if (pin == brakePin) return true;
if (pin == signalPin2) return true;
return false;
}
void MotorDriver::setPower(bool on) { void MotorDriver::setPower(bool on) {
if (on) { if (on) {

View File

@ -53,6 +53,7 @@ class MotorDriver {
inline int getRawCurrentTripValue() { inline int getRawCurrentTripValue() {
return rawCurrentTripValue; return rawCurrentTripValue;
} }
bool pinUsed(byte pin);
bool isPWMCapable(); bool isPWMCapable();
bool canMeasureCurrent(); bool canMeasureCurrent();
static bool usePWM; static bool usePWM;

View File

@ -84,6 +84,7 @@ the state of any outputs being monitored or controlled by a separate interface o
#include "Outputs.h" #include "Outputs.h"
#include "EEStore.h" #include "EEStore.h"
#include "StringFormatter.h" #include "StringFormatter.h"
#include "DCCWaveform.h"
// print all output states to stream // print all output states to stream
void Output::printAll(Print *stream){ void Output::printAll(Print *stream){
@ -192,6 +193,11 @@ void Output::store(){
Output *Output::create(uint16_t id, uint8_t pin, uint8_t iFlag, uint8_t v){ Output *Output::create(uint16_t id, uint8_t pin, uint8_t iFlag, uint8_t v){
Output *tt; Output *tt;
if (DCCWaveform::mainTrack.pinUsed(pin) ||
DCCWaveform::progTrack.pinUsed(pin)) {
return NULL;
}
if(firstOutput==NULL){ if(firstOutput==NULL){
firstOutput=(Output *)calloc(1,sizeof(Output)); firstOutput=(Output *)calloc(1,sizeof(Output));
tt=firstOutput; tt=firstOutput;

View File

@ -68,6 +68,7 @@ decide to ignore the <q ID> return and only react to <Q ID> triggers.
#include "StringFormatter.h" #include "StringFormatter.h"
#include "Sensors.h" #include "Sensors.h"
#include "EEStore.h" #include "EEStore.h"
#include "DCCWaveform.h"
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -126,6 +127,11 @@ void Sensor::printAll(Print *stream){
Sensor *Sensor::create(int snum, int pin, int pullUp){ Sensor *Sensor::create(int snum, int pin, int pullUp){
Sensor *tt; Sensor *tt;
if (DCCWaveform::mainTrack.pinUsed(pin) ||
DCCWaveform::progTrack.pinUsed(pin)) {
return NULL;
}
if(firstSensor==NULL){ if(firstSensor==NULL){
firstSensor=(Sensor *)calloc(1,sizeof(Sensor)); firstSensor=(Sensor *)calloc(1,sizeof(Sensor));
tt=firstSensor; tt=firstSensor;