diff --git a/DCC.cpp b/DCC.cpp index fe0fbb4..9f5d53e 100644 --- a/DCC.cpp +++ b/DCC.cpp @@ -28,7 +28,6 @@ #include "IODevice.h" #include "MotorDriver.h" -extern MotorDriverContainer mDC; // This module is responsible for converting API calls into // messages to be sent to the waveform generator. @@ -54,7 +53,8 @@ byte DCC::joinRelay=UNUSED_PIN; byte DCC::globalSpeedsteps=128; void DCC::begin() { - StringFormatter::send(Serial,F("\n"), F(VERSION), F(ARDUINO_TYPE), mDC.getMotorShieldName(), F(GITHUB_SHA)); + StringFormatter::send(Serial,F("\n"), F(VERSION), F(ARDUINO_TYPE), + MotorDriverContainer::mDC.getMotorShieldName(), F(GITHUB_SHA)); // Initialise HAL layer before reading EEprom. IODevice::begin(); @@ -63,13 +63,17 @@ void DCC::begin() { (void)EEPROM; // tell compiler not to warn this is unused EEStore::init(); - DCCWaveform::begin(mDC.mainTrack(),mDC.progTrack()); - DCCTrack::mainTrack.addDriver(mDC.mainTrack()); - DCCTrack::progTrack.addDriver(mDC.progTrack()); + DCCWaveform::begin(MotorDriverContainer::mDC.mainTrack(),MotorDriverContainer::mDC.progTrack()); + DCCTrack::mainTrack.addDriver(MotorDriverContainer::mDC.mainTrack()); + DCCTrack::progTrack.addDriver(MotorDriverContainer::mDC.progTrack()); MotorDriver *md; - mDC.add(2, md = new MotorDriver(16, 21, UNUSED_PIN, UNUSED_PIN, UNUSED_PIN, 2.00, 2000, UNUSED_PIN, RMT_MAIN)); + MotorDriverContainer::mDC.add(2, md = new MotorDriver(16, 21, UNUSED_PIN, UNUSED_PIN, UNUSED_PIN, 2.00, 2000, UNUSED_PIN, RMT_MAIN)); DCCTrack::mainTrack.addDriver(md); + /* + std::vector v = MotorDriverContainer::mDC.getDriverType(RMT_MAIN); + for (const auto& d: v) DCCTrack::mainTrack.addDriver(d); + */ } void DCC::setJoinRelayPin(byte joinRelayPin) { @@ -578,7 +582,7 @@ byte DCC::loopStatus=0; void DCC::loop() { DCCWaveform::loop(ackManagerProg!=NULL); // power overload checks - mDC.loop(); + MotorDriverContainer::mDC.loop(); ackManagerLoop(); // maintain prog track ack manager issueReminders(); } diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 85bf40b..92b98eb 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -27,9 +27,16 @@ #include "DIAG.h" #include "freeMemory.h" +// The two Waveforms which defines what happens when the +// interrupt driven DCC signal is generated. This is tied +// to the timer interrupts of the hardware. DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true); DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false); + +// The two different DCC _kinds_ of signals we want to be able +// to genrate at the same time. When timer interupts are used, +// these need the respective waveform DCCTrack DCCTrack::mainTrack(&DCCWaveform::mainTrack); DCCTrack DCCTrack::progTrack(&DCCWaveform::progTrack); diff --git a/MotorDriver.cpp b/MotorDriver.cpp index cb8e55d..70643e5 100644 --- a/MotorDriver.cpp +++ b/MotorDriver.cpp @@ -254,4 +254,13 @@ void MotorDriverContainer::loop() { if(i > 7) i=0; } -MotorDriverContainer mDC(MOTOR_SHIELD_TYPE); +std::vector MotorDriverContainer::getDriverType(driverType t) { + std::vector v; + for(byte i=0; i<8; i++) { + if (mD[i] && mD[i]->type() == t) + v.push_back(mD[i]); + } + return v; +} + +MotorDriverContainer MotorDriverContainer::mDC(MOTOR_SHIELD_TYPE); diff --git a/MotorDriver.h b/MotorDriver.h index 77f645a..c84bdca 100644 --- a/MotorDriver.h +++ b/MotorDriver.h @@ -19,6 +19,7 @@ #ifndef MotorDriver_h #define MotorDriver_h +#include #include "defines.h" #include "FSH.h" @@ -127,6 +128,7 @@ public: MotorDriver *m5=NULL, MotorDriver *m6=NULL, MotorDriver *m7=NULL); + static MotorDriverContainer mDC; inline void add(byte n, MotorDriver *m) { if (n>8) return; mD[n] = m; @@ -136,6 +138,7 @@ public: inline MotorDriver *mainTrack() { return mD[0]; }; //start fixed inline MotorDriver *progTrack() { return mD[1]; }; void loop(); + std::vector getDriverType(driverType t); private: MotorDriver *mD[8];