mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-23 08:06:13 +01:00
make mDC a singleton static member of MotorDriverContainer
This commit is contained in:
parent
6e05de275d
commit
0e5c89df23
18
DCC.cpp
18
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("<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.
|
||||
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<MotorDriver*> 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();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -254,4 +254,13 @@ void MotorDriverContainer::loop() {
|
|||
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);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
#ifndef MotorDriver_h
|
||||
#define MotorDriver_h
|
||||
#include <vector>
|
||||
#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<MotorDriver*> getDriverType(driverType t);
|
||||
|
||||
private:
|
||||
MotorDriver *mD[8];
|
||||
|
|
Loading…
Reference in New Issue
Block a user