mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-11-25 00:56:13 +01:00
Compare commits
No commits in common. "dba5d35aa231ebbe732a755462f8b95043554c64" and "bd02d1c15bf4cc35848d07b15c5630dcc352ebd8" have entirely different histories.
dba5d35aa2
...
bd02d1c15b
|
@ -732,12 +732,11 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
|
|||
for (uint8_t p = 0; p < posCount; p++) {
|
||||
StringFormatter::send(stream, F("<jP"));
|
||||
int16_t value = tto->getPositionValue(p);
|
||||
int16_t angle = tto->getPositionAngle(p);
|
||||
#ifdef EXRAIL_ACTIVE
|
||||
tpdesc = RMFT2::getTurntablePositionDescription(id, p);
|
||||
#endif
|
||||
if (tpdesc == NULL) tpdesc = F("");
|
||||
StringFormatter::send(stream, F(" %d %d %d %d \"%S\""), id, p, value, angle, tpdesc);
|
||||
StringFormatter::send(stream, F(" %d %d %d \"%S\""), id, p, value, tpdesc);
|
||||
StringFormatter::send(stream, F(">\n"));
|
||||
}
|
||||
}
|
||||
|
@ -1108,56 +1107,44 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
|
|||
}
|
||||
return true;
|
||||
|
||||
case 2: // <I id position> - rotate a DCC turntable
|
||||
case 2: // <I id DCC> | <I id position> - rotate or create DCC turntable
|
||||
{
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
if (tto && !tto->isEXTT()) {
|
||||
if (!tto->setPosition(p[0], p[1])) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case 3: // <I id position activity> | <I id DCC home> - rotate to position for EX-Turntable or create DCC turntable
|
||||
{
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
if (p[1] == HASH_KEYWORD_DCC) {
|
||||
if (tto || p[2] < 0 || p[2] > 3600) return false;
|
||||
if (p[1] == HASH_KEYWORD_DCC) { // Create a DCC turntable
|
||||
if (tto) return false;
|
||||
if (!DCCTurntable::create(p[0])) return false;
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
tto->addPosition(0, 0, p[2]);
|
||||
StringFormatter::send(stream, F("<i>\n"));
|
||||
} else {
|
||||
if (!tto) return false;
|
||||
if (!tto->isEXTT()) return false;
|
||||
if (!tto->setPosition(p[0], p[1], p[2])) return false;
|
||||
tto->addPosition(0, 0);
|
||||
} else { // Otherwise move a DCC turntable
|
||||
if (tto && !tto->isEXTT()) {
|
||||
if (!tto->setPosition(p[0], p[1])) return false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case 4: // <I id EXTT vpin home> create an EXTT turntable
|
||||
case 3: // <I id position activity> rotate to position for EX-Turntable
|
||||
{
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
if (!tto) return false;
|
||||
if (!tto->isEXTT()) return false;
|
||||
if (!tto->setPosition(p[0], p[1], p[2])) return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
case 4: // <I id EXTT vpin home> | <I id ADD position value> create an EXTT turntable or add position
|
||||
{
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
if (p[1] == HASH_KEYWORD_EXTT) {
|
||||
if (tto || p[3] < 0 || p[3] > 3600) return false;
|
||||
if (tto) return false;
|
||||
if (!EXTTTurntable::create(p[0], (VPIN)p[2])) return false;
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
tto->addPosition(0, 0, p[3]);
|
||||
StringFormatter::send(stream, F("<i>\n"));
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
case 5: // <I id ADD position value angle> add a position
|
||||
{
|
||||
Turntable *tto = Turntable::get(p[0]);
|
||||
if (p[1] == HASH_KEYWORD_ADD) {
|
||||
// tto must exist, no more than 48 positions, angle 0 - 3600
|
||||
if (!tto || p[2] > 48 || p[4] < 0 || p[4] > 3600) return false;
|
||||
tto->addPosition(p[2], p[3], p[4]);
|
||||
tto->addPosition(0, p[3]);
|
||||
} else if (p[1] == HASH_KEYWORD_ADD) {
|
||||
if (!tto) return false;
|
||||
tto->addPosition(p[2], p[3]);
|
||||
StringFormatter::send(stream, F("<i>\n"));
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
#include "CommandDistributor.h"
|
||||
#include "TrackManager.h"
|
||||
#include "Turntables.h"
|
||||
#include "IODevice.h"
|
||||
|
||||
// Command parsing keywords
|
||||
const int16_t HASH_KEYWORD_EXRAIL=15435;
|
||||
|
@ -249,10 +248,9 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
|||
#ifndef IO_NO_HAL
|
||||
case OPCODE_DCCTURNTABLE: {
|
||||
VPIN id=operand;
|
||||
int home=getOperand(progCounter,1);
|
||||
setTurntableHiddenState(DCCTurntable::create(id));
|
||||
Turntable *tto=Turntable::get(id);
|
||||
tto->addPosition(0,0,home);
|
||||
tto->addPosition(0,0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -262,7 +260,7 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
|||
int home=getOperand(progCounter,2);
|
||||
setTurntableHiddenState(EXTTTurntable::create(id,pin));
|
||||
Turntable *tto=Turntable::get(id);
|
||||
tto->addPosition(0,0,home);
|
||||
tto->addPosition(0,home);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -270,9 +268,8 @@ LookList* RMFT2::LookListLoader(OPCODE op1, OPCODE op2, OPCODE op3) {
|
|||
VPIN id=operand;
|
||||
int position=getOperand(progCounter,1);
|
||||
int value=getOperand(progCounter,2);
|
||||
int angle=getOperand(progCounter,3);
|
||||
Turntable *tto=Turntable::get(id);
|
||||
tto->addPosition(position,value,angle);
|
||||
tto->addPosition(position,value);
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -119,7 +119,6 @@
|
|||
#undef REV
|
||||
#undef ROSTER
|
||||
#undef ROTATE
|
||||
#undef ROTATE_DCC
|
||||
#undef ROUTE
|
||||
#undef SENDLOCO
|
||||
#undef SEQUENCE
|
||||
|
@ -175,7 +174,7 @@
|
|||
#define CALL(route)
|
||||
#define CLOSE(id)
|
||||
#define DCC_SIGNAL(id,add,subaddr)
|
||||
#define DCC_TURNTABLE(id,home,description)
|
||||
#define DCC_TURNTABLE(id,description)
|
||||
#define DEACTIVATE(addr,subaddr)
|
||||
#define DEACTIVATEL(addr)
|
||||
#define DELAY(mindelay)
|
||||
|
@ -253,7 +252,6 @@
|
|||
#define RETURN
|
||||
#define REV(speed)
|
||||
#define ROTATE(turntable_id,position,activity)
|
||||
#define ROTATE_DCC(turntable_id,position)
|
||||
#define ROSTER(cab,name,funcmap...)
|
||||
#define ROUTE(id,description)
|
||||
#define SENDLOCO(cab,route)
|
||||
|
@ -278,7 +276,7 @@
|
|||
#define START(route)
|
||||
#define STOP
|
||||
#define THROW(id)
|
||||
#define TT_ADDPOSITION(turntable_id,position,value,angle,description...)
|
||||
#define TT_ADDPOSITION(turntable_id,position,value,description)
|
||||
#define TURNOUT(id,addr,subaddr,description...)
|
||||
#define TURNOUTL(id,addr,description...)
|
||||
#define UNJOIN
|
||||
|
|
|
@ -192,7 +192,7 @@ const FSH * RMFT2::getTurnoutDescription(int16_t turnoutid) {
|
|||
// Pass to get turntable descriptions (optional)
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef DCC_TURNTABLE
|
||||
#define DCC_TURNTABLE(id,home,description...) O_DESC(id,description)
|
||||
#define DCC_TURNTABLE(id,description...) O_DESC(id,description)
|
||||
#undef EXTT_TURNTABLE
|
||||
#define EXTT_TURNTABLE(id,vpin,home,description...) O_DESC(id,description)
|
||||
|
||||
|
@ -207,7 +207,7 @@ const FSH * RMFT2::getTurntableDescription(int16_t turntableId) {
|
|||
// Pass to get turntable position descriptions (optional)
|
||||
#include "EXRAIL2MacroReset.h"
|
||||
#undef TT_ADDPOSITION
|
||||
#define TT_ADDPOSITION(turntable_id,position,value,home,description...) T_DESC(turntable_id,position,description)
|
||||
#define TT_ADDPOSITION(turntable_id,position,value,description...) T_DESC(turntable_id,position,description)
|
||||
|
||||
const FSH * RMFT2::getTurntablePositionDescription(int16_t turntableId, uint8_t positionId) {
|
||||
#include "myAutomation.h"
|
||||
|
@ -296,7 +296,7 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = {
|
|||
#define CALL(route) OPCODE_CALL,V(route),
|
||||
#define CLOSE(id) OPCODE_CLOSE,V(id),
|
||||
#ifndef IO_NO_HAL
|
||||
#define DCC_TURNTABLE(id,home,description...) OPCODE_DCCTURNTABLE,V(id),OPCODE_PAD,V(home),
|
||||
#define DCC_TURNTABLE(id,description...) OPCODE_DCCTURNTABLE,V(id),
|
||||
#endif
|
||||
#define DEACTIVATE(addr,subaddr) OPCODE_DCCACTIVATE,V(addr<<3 | subaddr<<1),
|
||||
#define DEACTIVATEL(addr) OPCODE_DCCACTIVATE,V((addr+3)<<1),
|
||||
|
@ -383,8 +383,7 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = {
|
|||
#define REV(speed) OPCODE_REV,V(speed),
|
||||
#define ROSTER(cabid,name,funcmap...)
|
||||
#ifndef IO_NO_HAL
|
||||
#define ROTATE(id,position,activity) OPCODE_ROTATE,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(EXTurntable::activity),
|
||||
#define ROTATE_DCC(id,position) OPCODE_ROTATE,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(0),
|
||||
#define ROTATE(id,position,activity) OPCODE_ROTATE,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(activity),
|
||||
#endif
|
||||
#define ROUTE(id, description) OPCODE_ROUTE, V(id),
|
||||
#define SENDLOCO(cab,route) OPCODE_SENDLOCO,V(cab),OPCODE_PAD,V(route),
|
||||
|
@ -410,7 +409,7 @@ const HIGHFLASH int16_t RMFT2::SignalDefinitions[] = {
|
|||
#define STOP OPCODE_SPEED,V(0),
|
||||
#define THROW(id) OPCODE_THROW,V(id),
|
||||
#ifndef IO_NO_HAL
|
||||
#define TT_ADDPOSITION(id,position,value,angle,description...) OPCODE_TTADDPOSITION,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(value),OPCODE_PAD,V(angle),
|
||||
#define TT_ADDPOSITION(id,position,value,description...) OPCODE_TTADDPOSITION,V(id),OPCODE_PAD,V(position),OPCODE_PAD,V(value),
|
||||
#endif
|
||||
#define TURNOUT(id,addr,subaddr,description...) OPCODE_TURNOUT,V(id),OPCODE_PAD,V(addr),OPCODE_PAD,V(subaddr),
|
||||
#define TURNOUTL(id,addr,description...) TURNOUT(id,(addr-1)/4+1,(addr-1)%4, description)
|
||||
|
|
|
@ -58,8 +58,8 @@ void Turntable::add(Turntable *tto) {
|
|||
}
|
||||
|
||||
// Add a position
|
||||
void Turntable::addPosition(uint8_t idx, uint16_t value, uint16_t angle) {
|
||||
_turntablePositions.insert(idx, value, angle);
|
||||
void Turntable::addPosition(uint8_t idx, uint16_t value) {
|
||||
_turntablePositions.insert(idx, value);
|
||||
}
|
||||
|
||||
// Get value for position
|
||||
|
@ -74,18 +74,6 @@ uint16_t Turntable::getPositionValue(uint8_t position) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Get value for position
|
||||
uint16_t Turntable::getPositionAngle(uint8_t position) {
|
||||
TurntablePosition* currentPosition = _turntablePositions.getHead();
|
||||
while (currentPosition) {
|
||||
if (currentPosition->index == position) {
|
||||
return currentPosition->angle;
|
||||
}
|
||||
currentPosition = currentPosition->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the count of positions associated with the turntable
|
||||
uint8_t Turntable::getPositionCount() {
|
||||
TurntablePosition* currentPosition = _turntablePositions.getHead();
|
||||
|
@ -127,7 +115,6 @@ uint8_t Turntable::getPosition(uint16_t id) {
|
|||
return tto->getPosition();
|
||||
}
|
||||
|
||||
// Got the moving state of the specified turntable
|
||||
bool Turntable::ttMoving(uint16_t id) {
|
||||
Turntable *tto = get(id);
|
||||
if (!tto) return false;
|
||||
|
|
13
Turntables.h
13
Turntables.h
|
@ -36,6 +36,9 @@ enum {
|
|||
TURNTABLE_DCC = 1,
|
||||
};
|
||||
|
||||
// Callback needs to return a bool: 1 = moving, 0 = stopped
|
||||
typedef void (*EXTT_CALLBACK)(bool moving);
|
||||
|
||||
/*************************************************************************************
|
||||
* Turntable positions.
|
||||
*
|
||||
|
@ -43,18 +46,17 @@ enum {
|
|||
struct TurntablePosition {
|
||||
uint8_t index;
|
||||
uint16_t data;
|
||||
uint16_t angle;
|
||||
TurntablePosition* next;
|
||||
|
||||
TurntablePosition(uint8_t idx, uint16_t value, uint16_t angle) : index(idx), data(value), angle(angle), next(nullptr) {}
|
||||
TurntablePosition(uint8_t idx, uint16_t value) : index(idx), data(value), next(nullptr) {}
|
||||
};
|
||||
|
||||
class TurntablePositionList {
|
||||
public:
|
||||
TurntablePositionList() : head(nullptr) {}
|
||||
|
||||
void insert(uint8_t idx, uint16_t value, uint16_t angle) {
|
||||
TurntablePosition* newPosition = new TurntablePosition(idx, value, angle);
|
||||
void insert(uint8_t idx, uint16_t value) {
|
||||
TurntablePosition* newPosition = new TurntablePosition(idx, value);
|
||||
if(!head) {
|
||||
head = newPosition;
|
||||
} else {
|
||||
|
@ -156,9 +158,8 @@ public:
|
|||
inline uint16_t getId() { return _turntableData.id; }
|
||||
inline Turntable *next() { return _nextTurntable; }
|
||||
void printState(Print *stream);
|
||||
void addPosition(uint8_t idx, uint16_t value, uint16_t angle);
|
||||
void addPosition(uint8_t idx, uint16_t value);
|
||||
uint16_t getPositionValue(uint8_t position);
|
||||
uint16_t getPositionAngle(uint8_t position);
|
||||
uint8_t getPositionCount();
|
||||
bool isMoving() { return _isMoving; }
|
||||
void setMoving(bool moving) { _isMoving=moving; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user