Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion EXRAIL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,24 @@ void RMFT2::loop2() {
case OPCODE_INVERT_DIRECTION:
invert= !invert;
break;


case OPCODE_SAVESPEED:
if (loco) {
auto slot=LocoSlot::getSlot(loco,false);
if (slot) {
slot->saveSpeed();
}
}
break;

case OPCODE_RESTORESPEED:
if (loco) {
auto slot=LocoSlot::getSlot(loco,false);

if (slot) DCC::setThrottle(loco,slot->getSavedSpeed() & 0x7F,DCC::getThrottleDirection(loco));
}
break;

case OPCODE_RESERVE:
if (getFlag(operand,SECTION_FLAG)) {
if (loco) DCC::setThrottle(loco,1,DCC::getThrottleDirection(loco));
Expand Down
2 changes: 1 addition & 1 deletion EXRAIL2.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
// searching easier as a parameter can never be confused with an opcode.
//
enum OPCODE : byte {OPCODE_THROW,OPCODE_CLOSE,OPCODE_TOGGLE_TURNOUT,
OPCODE_FWD,OPCODE_REV,OPCODE_SPEED,OPCODE_INVERT_DIRECTION,
OPCODE_FWD,OPCODE_REV,OPCODE_SPEED,OPCODE_INVERT_DIRECTION,OPCODE_SAVESPEED,OPCODE_RESTORESPEED,
OPCODE_MOMENTUM,
OPCODE_RESERVE,OPCODE_FREE,
OPCODE_AT,OPCODE_AFTER,
Expand Down
14 changes: 14 additions & 0 deletions EXRAIL2MacroReset.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
#undef RED
#undef RESERVE
#undef RESET
#undef RESTORESPEED
#undef RESUME
#undef RETURN
#undef REV
Expand All @@ -165,6 +166,7 @@
#undef ROUTE_HIDDEN
#undef ROUTE_DISABLED
#undef ROUTE_CAPTION
#undef SAVESPEED
#undef SENDLOCO
#undef SEQUENCE
#undef SERIAL
Expand Down Expand Up @@ -1049,6 +1051,12 @@
* @param count... Number of consecutive pins, default 1
*/
#define RESET(vpin,count...)
/**
* @def RESTORESPEED
* @brief Restore current loco speed
* @see SAVESPEED
*/
#define RESTORESPEED
/**
* @def RESUME
* @brief Resumes PAUSEd tasks
Expand Down Expand Up @@ -1140,6 +1148,12 @@
* @param caption
*/
#define ROUTE_CAPTION(sequence_id,caption)
/**
* @def SAVESPEED
* @brief Save current loco speed
* @see RESTORESPEED
*/
#define SAVESPEED
/**
* @def SENDLOCO(cab,sequence_id)
* @brief Start a new task to drive the loco
Expand Down
2 changes: 2 additions & 0 deletions EXRAILMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,8 @@ int RMFT2::onLCCLookup[RMFT2::countLCCLookup];
#define ROUTE_HIDDEN(id) OPCODE_ROUTE_HIDDEN,V(id),
#define ROUTE_DISABLED(id) OPCODE_ROUTE_DISABLED,V(id),
#define ROUTE_CAPTION(id,caption) PRINT(caption)
#define SAVESPEED OPCODE_SAVESPEED,0,0,
#define RESTORESPEED OPCODE_RESTORESPEED,0,0,
#define SENDLOCO(cab,route) OPCODE_SENDLOCO,V(cab),OPCODE_PAD,V(route),
#define SEQUENCE(id) OPCODE_SEQUENCE, V(id),
#define SERIAL(msg) PRINT(msg)
Expand Down
6 changes: 6 additions & 0 deletions LocoSlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void LocoSlot::prepare(uint16_t locoId) {
momentumA=MOMENTUM_USE_DEFAULT;
momentumD=MOMENTUM_USE_DEFAULT;
targetSpeed=128;
savedSpeed=128;
blockOccupied=0;

snifferSpeedCode=128; // default direction forward
Expand Down Expand Up @@ -80,6 +81,11 @@ void LocoSlot::forget() {
chainModified=true;
}

void LocoSlot::saveSpeed() {
// targetSpeed should eventually to be the speed we want to reach and save
savedSpeed=targetSpeed;
}

/* static */ void LocoSlot::forgetAll() {
// remove entire list
LocoSlot * killnext=nullptr;
Expand Down
4 changes: 4 additions & 0 deletions LocoSlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class LocoSlot {
uint16_t blockOccupied; // railcom detected block

byte targetSpeed; // speed set by throttle
byte savedSpeed;
byte speedCode; // current DCC speed and direction
byte snifferSpeedCode; // sniffer speed and direction
byte momentumA; // momentum accelerating
Expand Down Expand Up @@ -82,6 +83,8 @@ class LocoSlot {
void setMomentumBase(uint32_t v) { momentum_base=v; }
byte getTargetSpeed() { return targetSpeed; }
void setTargetSpeed(byte v) { targetSpeed=v; }
byte getSavedSpeed() { return savedSpeed; }
void setSavedSpeed(byte v) { savedSpeed=v; }

byte getSpeedCode() { return speedCode; }
void setSpeedCode(byte v) { speedCode=v; }
Expand All @@ -92,6 +95,7 @@ class LocoSlot {
uint16_t getBlockOccupied() { return blockOccupied; }
void setBlockOccupied(uint16_t v) { blockOccupied=v; }
void forget();
void saveSpeed();

};
#endif