Skip to content

Commit

Permalink
Added SETFREQ command
Browse files Browse the repository at this point in the history
Added SETFREQ command to EXRAIL
  • Loading branch information
ColinHMurdoch committed Jan 20, 2024
1 parent 8036ba1 commit a5b73c8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DCCTimerAVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void DCCTimer::DCCEXanalogWriteFrequencyInternal(uint8_t pin, uint32_t fbits) {

TCCR2A = (TCCR2A & B11111100) | abits; // set WGM0 and WGM1
TCCR2B = (TCCR2B & B11110000) | bbits; // set WGM2 and 3 bits of prescaler
//DIAG(F("Timer 2 A=%x B=%x"), TCCR2A, TCCR2B);
DIAG(F("Timer 2 A=%x B=%x"), TCCR2A, TCCR2B);

} else { // not timer 9 or 10
abits = B01;
Expand Down
37 changes: 37 additions & 0 deletions EXRAIL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,43 @@ void RMFT2::loop2() {
}
break;

case OPCODE_SETFREQ:
// Frequency is default 0, or 1, 2,3
//if (loco) DCC::setFn(loco,operand,true);
switch (operand) {
case 0: // default - all F-s off
if (loco) {
DCC::setFn(loco,29,false);
DCC::setFn(loco,30,false);
DCC::setFn(loco,31,false);
}
break;
case 1:
//if (loco) DCC::setFn(loco,29,true);
if (loco) {
DCC::setFn(loco,30,true);
DCC::setFn(loco,31,false);
}
break;
case 2:
//if (loco) DCC::setFn(loco,30,true);
if (loco) {
DCC::setFn(loco,30,false);
DCC::setFn(loco,31,true);
}
break;
case 3:
//if (loco) DCC::setFn(loco,31,true);
if (loco) {
DCC::setFn(loco,30,true);
DCC::setFn(loco,31,true);
}
break;

}

break;

case OPCODE_RESUME:
pausingTask=NULL;
driveLoco(speedo);
Expand Down
2 changes: 1 addition & 1 deletion EXRAIL2.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,
OPCODE_JOIN,OPCODE_UNJOIN,OPCODE_READ_LOCO1,OPCODE_READ_LOCO2,
#endif
OPCODE_POM,
OPCODE_START,OPCODE_SETLOCO,OPCODE_SENDLOCO,OPCODE_FORGET,
OPCODE_START,OPCODE_SETLOCO,OPCODE_SETFREQ,OPCODE_SENDLOCO,OPCODE_FORGET,
OPCODE_PAUSE, OPCODE_RESUME,OPCODE_POWEROFF,OPCODE_POWERON,
OPCODE_ONCLOSE, OPCODE_ONTHROW, OPCODE_SERVOTURNOUT, OPCODE_PINTURNOUT,
OPCODE_PRINT,OPCODE_DCCACTIVATE,
Expand Down
2 changes: 2 additions & 0 deletions EXRAIL2MacroReset.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
#undef SET_TRACK
#undef SET_POWER
#undef SETLOCO
#undef SETFREQ
#undef SIGNAL
#undef SIGNALH
#undef SPEED
Expand Down Expand Up @@ -302,6 +303,7 @@
#define SET_TRACK(track,mode)
#define SET_POWER(track,onoff)
#define SETLOCO(loco)
#define SETFREQ(loco,freq)
#define SIGNAL(redpin,amberpin,greenpin)
#define SIGNALH(redpin,amberpin,greenpin)
#define SPEED(speed)
Expand Down
1 change: 1 addition & 0 deletions EXRAILMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
#define SET_TRACK(track,mode) OPCODE_SET_TRACK,V(TRACK_MODE_##mode <<8 | TRACK_NUMBER_##track),
#define SET_POWER(track,onoff) OPCODE_SET_POWER,V(TRACK_POWER_##onoff),OPCODE_PAD, V(TRACK_NUMBER_##track),
#define SETLOCO(loco) OPCODE_SETLOCO,V(loco),
#define SETFREQ(loco,freq) OPCODE_SETLOCO,V(loco), OPCODE_SETFREQ,V(freq),
#define SIGNAL(redpin,amberpin,greenpin)
#define SIGNALH(redpin,amberpin,greenpin)
#define SPEED(speed) OPCODE_SPEED,V(speed),
Expand Down

0 comments on commit a5b73c8

Please sign in to comment.