1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-27 01:56:14 +01:00

make mDC a singleton static member of MotorDriverContainer

This commit is contained in:
Harald Barth 2021-11-28 17:07:21 +01:00
parent 6e05de275d
commit 0e5c89df23
4 changed files with 31 additions and 8 deletions

18
DCC.cpp
View File

@ -28,7 +28,6 @@
#include "IODevice.h" #include "IODevice.h"
#include "MotorDriver.h" #include "MotorDriver.h"
extern MotorDriverContainer mDC;
// This module is responsible for converting API calls into // This module is responsible for converting API calls into
// messages to be sent to the waveform generator. // messages to be sent to the waveform generator.
@ -54,7 +53,8 @@ byte DCC::joinRelay=UNUSED_PIN;
byte DCC::globalSpeedsteps=128; byte DCC::globalSpeedsteps=128;
void DCC::begin() { void DCC::begin() {
StringFormatter::send(Serial,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE), mDC.getMotorShieldName(), F(GITHUB_SHA)); StringFormatter::send(Serial,F("<iDCC-EX V-%S / %S / %S G-%S>\n"), F(VERSION), F(ARDUINO_TYPE),
MotorDriverContainer::mDC.getMotorShieldName(), F(GITHUB_SHA));
// Initialise HAL layer before reading EEprom. // Initialise HAL layer before reading EEprom.
IODevice::begin(); IODevice::begin();
@ -63,13 +63,17 @@ void DCC::begin() {
(void)EEPROM; // tell compiler not to warn this is unused (void)EEPROM; // tell compiler not to warn this is unused
EEStore::init(); EEStore::init();
DCCWaveform::begin(mDC.mainTrack(),mDC.progTrack()); DCCWaveform::begin(MotorDriverContainer::mDC.mainTrack(),MotorDriverContainer::mDC.progTrack());
DCCTrack::mainTrack.addDriver(mDC.mainTrack()); DCCTrack::mainTrack.addDriver(MotorDriverContainer::mDC.mainTrack());
DCCTrack::progTrack.addDriver(mDC.progTrack()); DCCTrack::progTrack.addDriver(MotorDriverContainer::mDC.progTrack());
MotorDriver *md; 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); DCCTrack::mainTrack.addDriver(md);
/*
std::vector<MotorDriver*> v = MotorDriverContainer::mDC.getDriverType(RMT_MAIN);
for (const auto& d: v) DCCTrack::mainTrack.addDriver(d);
*/
} }
void DCC::setJoinRelayPin(byte joinRelayPin) { void DCC::setJoinRelayPin(byte joinRelayPin) {
@ -578,7 +582,7 @@ byte DCC::loopStatus=0;
void DCC::loop() { void DCC::loop() {
DCCWaveform::loop(ackManagerProg!=NULL); // power overload checks DCCWaveform::loop(ackManagerProg!=NULL); // power overload checks
mDC.loop(); MotorDriverContainer::mDC.loop();
ackManagerLoop(); // maintain prog track ack manager ackManagerLoop(); // maintain prog track ack manager
issueReminders(); issueReminders();
} }

View File

@ -27,9 +27,16 @@
#include "DIAG.h" #include "DIAG.h"
#include "freeMemory.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::mainTrack(PREAMBLE_BITS_MAIN, true);
DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false); 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::mainTrack(&DCCWaveform::mainTrack);
DCCTrack DCCTrack::progTrack(&DCCWaveform::progTrack); DCCTrack DCCTrack::progTrack(&DCCWaveform::progTrack);

View File

@ -254,4 +254,13 @@ void MotorDriverContainer::loop() {
if(i > 7) i=0; if(i > 7) i=0;
} }
MotorDriverContainer mDC(MOTOR_SHIELD_TYPE); std::vector<MotorDriver*> MotorDriverContainer::getDriverType(driverType t) {
std::vector<MotorDriver*> 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);

View File

@ -19,6 +19,7 @@
#ifndef MotorDriver_h #ifndef MotorDriver_h
#define MotorDriver_h #define MotorDriver_h
#include <vector>
#include "defines.h" #include "defines.h"
#include "FSH.h" #include "FSH.h"
@ -127,6 +128,7 @@ public:
MotorDriver *m5=NULL, MotorDriver *m5=NULL,
MotorDriver *m6=NULL, MotorDriver *m6=NULL,
MotorDriver *m7=NULL); MotorDriver *m7=NULL);
static MotorDriverContainer mDC;
inline void add(byte n, MotorDriver *m) { inline void add(byte n, MotorDriver *m) {
if (n>8) return; if (n>8) return;
mD[n] = m; mD[n] = m;
@ -136,6 +138,7 @@ public:
inline MotorDriver *mainTrack() { return mD[0]; }; //start fixed inline MotorDriver *mainTrack() { return mD[0]; }; //start fixed
inline MotorDriver *progTrack() { return mD[1]; }; inline MotorDriver *progTrack() { return mD[1]; };
void loop(); void loop();
std::vector<MotorDriver*> getDriverType(driverType t);
private: private:
MotorDriver *mD[8]; MotorDriver *mD[8];