1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-11-30 03:26:13 +01:00

Basic hardware and railcom abstraction

This commit is contained in:
Asbelos 2020-05-26 17:06:15 +01:00
parent 22406b44ed
commit c16358facc
5 changed files with 51 additions and 1 deletions

View File

@ -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();
}
}
}

View File

@ -1,4 +1,5 @@
#include <Arduino.h>
#include <TimerOne.h>
#include <TimerThree.h>
#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);
}

View File

@ -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);
};

25
Railcom.cpp Normal file
View File

@ -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];

11
Railcom.h Normal file
View File

@ -0,0 +1,11 @@
#include <Arduino.h>
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];
};