diff --git a/DCCWaveform.cpp b/DCCWaveform.cpp index 28b7838..a395e77 100644 --- a/DCCWaveform.cpp +++ b/DCCWaveform.cpp @@ -2,6 +2,7 @@ #include "Hardware.h" #include "DCCWaveform.h" #include "DIAG.h" +#include "Railcom.h" DCCWaveform DCCWaveform::mainTrack(PREAMBLE_BITS_MAIN, true); DCCWaveform DCCWaveform::progTrack(PREAMBLE_BITS_PROG, false); @@ -185,7 +186,7 @@ void DCCWaveform::checkRailcom() { if (isMainTrack && RAILCOM_CUTOUT) { byte preamble = PREAMBLE_BITS_MAIN - remainingPreambles; if (preamble == RAILCOM_PREAMBLES_BEFORE_CUTOUT) { - // TODO Railcom::startCutout(); + Railcom::startCutout(); } } } diff --git a/Hardware.cpp b/Hardware.cpp index 0aa856a..81dd021 100644 --- a/Hardware.cpp +++ b/Hardware.cpp @@ -1,4 +1,5 @@ #include +#include #include #include "Hardware.h" @@ -40,3 +41,13 @@ void Hardware::setCallback(int duration, void (*isr)()) { Timer3.disablePwm(TIMER3_B_PIN); Timer3.attachInterrupt(isr); } +void Hardware::setSingleCallback(int duration, void (*isr)()) { + Timer1.initialize(duration); + Timer1.disablePwm(TIMER1_A_PIN); + Timer1.disablePwm(TIMER1_B_PIN); + Timer1.attachInterrupt(isr); +} +void Hardware::resetSingleCallback(int duration) { + if (duration==0) Timer1.stop(); + else Timer1.initialize(duration); +} diff --git a/Hardware.h b/Hardware.h index efd5eec..f66b2df 100644 --- a/Hardware.h +++ b/Hardware.h @@ -7,4 +7,6 @@ class Hardware { static void setSignal(bool isMainTrack, bool high); static int getCurrentMilliamps(bool isMainTrack); static void setCallback(int duration, void (*isr)()); + static void setSingleCallback(int duration, void (*isr)()); + static void resetSingleCallback(int duration); }; diff --git a/Railcom.cpp b/Railcom.cpp new file mode 100644 index 0000000..72c5ade --- /dev/null +++ b/Railcom.cpp @@ -0,0 +1,25 @@ +#include "Railcom.h" +#include "Hardware.h" + + void Railcom::startCutout() { + return; + /*** todo when ready *** + interruptState=0; + Hardware::setSingleCallback(RAILCOM_T0,interrupt); + *************/ + } + + void Railcom::interrupt() { + /*** TODO when ready .. railcom state machine + switch (interruptState) { + case 0: // + Hardware::setPower(true,false); + state=1; + nextInterrupt=RAILCOM_T1; + break; + } + **********************/ + } + byte Railcom::interruptState; + byte Railcom::bitsReceived; + byte Railcom::buffer[MAX_BUFFER]; diff --git a/Railcom.h b/Railcom.h new file mode 100644 index 0000000..aa85c6b --- /dev/null +++ b/Railcom.h @@ -0,0 +1,11 @@ +#include +class Railcom { + public: + static void startCutout(); + static void interrupt(); + private: + static byte interruptState; + static byte bitsReceived; + static const byte MAX_BUFFER=20; + static byte buffer[MAX_BUFFER]; +};