1
0
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. "dbf053858b61d5315790427adb5ed4da08e7a8ae" and "6cad794411f60f2022548cb9fb9c6272a0daafd2" have entirely different histories.

5 changed files with 52 additions and 58 deletions

View File

@ -98,7 +98,6 @@ const int16_t HASH_KEYWORD_WIFI = -5583;
const int16_t HASH_KEYWORD_ETHERNET = -30767; const int16_t HASH_KEYWORD_ETHERNET = -30767;
const int16_t HASH_KEYWORD_WIT = 31594; const int16_t HASH_KEYWORD_WIT = 31594;
const int16_t HASH_KEYWORD_EXTT = 8573; const int16_t HASH_KEYWORD_EXTT = 8573;
const int16_t HASH_KEYWORD_ADD = 3201;
int16_t DCCEXParser::stashP[MAX_COMMAND_PARAMS]; int16_t DCCEXParser::stashP[MAX_COMMAND_PARAMS];
bool DCCEXParser::stashBusy; bool DCCEXParser::stashBusy;
@ -715,7 +714,7 @@ void DCCEXParser::parseOne(Print *stream, byte *com, RingStream * ringStream)
// todesc = RMFT2::getTurntableDescription(id); // todesc = RMFT2::getTurntableDescription(id);
#endif #endif
if (todesc == NULL) todesc = F(""); if (todesc == NULL) todesc = F("");
StringFormatter::send(stream, F(" %d %d %d"), id, type, pos); StringFormatter::send(stream, F(" %d %d %d %d"), id, type, pos, posCount);
for (uint8_t p = 0; p < posCount; p++) { for (uint8_t p = 0; p < posCount; p++) {
int16_t value = tto->getPositionValue(p); int16_t value = tto->getPositionValue(p);
StringFormatter::send(stream, F(" %d"), value); StringFormatter::send(stream, F(" %d"), value);
@ -1060,12 +1059,10 @@ bool DCCEXParser::parseD(Print *stream, int16_t params, int16_t p[])
// ========================== // ==========================
// Turntable - no support if no HAL // Turntable - no support if no HAL
// <I> - list all // <I> - list all
// <I id> - broadcast type and current position
// <I id DCC> - create DCC - This is TBA
// <I id steps> - operate (DCC) // <I id steps> - operate (DCC)
// <I id steps activity> - operate (EXTT) // <I id steps activity> - operate (EXTT)
// <I id ADD position value> - add position // <I id EXTT i2caddress vpin position1 position2 ...> - create EXTT
// <I id EXTT i2caddress vpin home> - create EXTT // <I id DCC linear1 linear2 ...> - create DCC? - This TBA
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[]) bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
{ {
@ -1074,58 +1071,47 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
case 0: // <I> list turntable objects case 0: // <I> list turntable objects
return Turntable::printAll(stream); return Turntable::printAll(stream);
case 1: // <I id> broadcast type and current position case 1: // <I id> nothing here for the moment at least
return false; return false;
case 2: // <I id position> - rotate to position for DCC turntables case 2: // <I id position> - rotate to position for DCC turntables
{ {
if (p[1] == HASH_KEYWORD_DCC) { // Create a DCC turntable Turntable *tto = Turntable::get(p[0]);
DIAG(F("Create DCC turntable %d"), p[0]); if (tto) {
} else { // Otherwise move a DCC turntable if (tto->getPosition() == p[1]) return true;
Turntable *tto = Turntable::get(p[0]); uint16_t value = tto->getPositionValue(p[1]);
if (tto) { if (value) {
if (tto->getPosition() == p[1]) return true; DIAG(F("Rotate DCC turntable %d to position %d"), p[0], p[1]);
uint16_t value = tto->getPositionValue(p[1]);
if (value) {
DIAG(F("Rotate DCC turntable %d to position %d"), p[0], p[1]);
} else {
return false;
}
} else { } else {
return false; return false;
} }
} else {
return false;
} }
} }
return true; return true;
case 3: case 3: // <I id position activity> rotate to position for EX-Turntable
{ {
if (p[1] == HASH_KEYWORD_ADD) { // <I id ADD value> add position value to turntable Turntable *tto = Turntable::get(p[0]);
Turntable *tto = Turntable::get(p[0]); if (tto) {
if (tto) { if (!tto->setPosition(p[0], p[1], p[2])) return false;
tto->addPosition(p[2]); } else {
StringFormatter::send(stream, F("<i>\n")); return false;
} else {
return false;
}
} else { // <I id position activity> rotate to position for EX-Turntable
Turntable *tto = Turntable::get(p[0]);
if (tto) {
if (!tto->setPosition(p[0], p[1], p[2])) return false;
} else {
return false;
}
} }
} }
return true; return true;
case 5: // <I id EXTT vpin i2caddress home> create an EXTT turntable default: // If we're here, it must be creating a turntable object
{ {
if (p[1] == HASH_KEYWORD_EXTT) { if (params > 5 && params < 41 && p[1] == HASH_KEYWORD_EXTT) {
if (Turntable::get(p[0])) return false; if (Turntable::get(p[0])) return false;
if (!EXTTTurntable::create(p[0], (VPIN)p[2], (uint8_t)p[3])) return false; if (!EXTTTurntable::create(p[0], (VPIN)p[2], (uint8_t)p[3])) return false;
Turntable *tto = Turntable::get(p[0]); Turntable *tto = Turntable::get(p[0]);
tto->addPosition(p[4]); for (uint8_t i = params - 5; i > 0; i--) {
tto->addPosition(p[i + 4]);
}
tto->addPosition(p[4]); // Allow setting a value for the home angle for throttles to draw it
} else if (params > 3 && params < 39 && p[1] == HASH_KEYWORD_DCC) { } else if (params > 3 && params < 39 && p[1] == HASH_KEYWORD_DCC) {
DIAG(F("Create DCC turntable %d at base address %d with %d positions"), p[0], p[2], params - 2); DIAG(F("Create DCC turntable %d at base address %d with %d positions"), p[0], p[2], params - 2);
} else { } else {
@ -1133,9 +1119,6 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
} }
} }
return true; return true;
default: // Anything else is invalid
return false;
} }
} }
#endif #endif

View File

@ -38,7 +38,7 @@ struct DCCEXParser
static void setFilter(FILTER_CALLBACK filter); static void setFilter(FILTER_CALLBACK filter);
static void setRMFTFilter(FILTER_CALLBACK filter); static void setRMFTFilter(FILTER_CALLBACK filter);
static void setAtCommandCallback(AT_COMMAND_CALLBACK filter); static void setAtCommandCallback(AT_COMMAND_CALLBACK filter);
static const int MAX_COMMAND_PARAMS=10; // Must not exceed this static const int MAX_COMMAND_PARAMS=MAX_PARSER_PARAMS; // Must not exceed this
private: private:

View File

@ -70,15 +70,17 @@ void Turntable::addPosition(uint16_t value) {
} }
// Get value for position // Get value for position
uint16_t Turntable::getPositionValue(uint8_t position) { uint16_t Turntable::getPositionValue(size_t position) {
TurntablePosition* currentPosition = _turntablePositions.getHead(); TurntablePosition* currentPosition = _turntablePositions.getHead();
while (currentPosition) { for (size_t i = 0; i < position && currentPosition; i++) {
if (currentPosition->index == position) {
return currentPosition->data;
}
currentPosition = currentPosition->next; currentPosition = currentPosition->next;
} }
return false;
if (currentPosition) {
return currentPosition->data;
} else {
return false;
}
} }
// Get the count of positions associated with the turntable // Get the count of positions associated with the turntable

View File

@ -32,8 +32,8 @@
// EXTT = EX-Turntable // EXTT = EX-Turntable
// DCC = DCC accessory turntables - to be added later // DCC = DCC accessory turntables - to be added later
enum { enum {
TURNTABLE_EXTT = 0, TURNTABLE_EXTT = 1,
TURNTABLE_DCC = 1, // TURNTABLE_DCC = 2,
}; };
/************************************************************************************* /*************************************************************************************
@ -41,19 +41,18 @@ enum {
* *
*************************************************************************************/ *************************************************************************************/
struct TurntablePosition { struct TurntablePosition {
uint8_t index;
uint16_t data; uint16_t data;
TurntablePosition* next; TurntablePosition* next;
TurntablePosition(uint8_t idx, uint16_t value) : index(idx), data(value), next(nullptr) {} TurntablePosition(uint16_t value) : data(value), next(nullptr) {}
}; };
class TurntablePositionList { class TurntablePositionList {
public: public:
TurntablePositionList() : head(nullptr), currentIndex(0) {} TurntablePositionList() : head(nullptr) {}
void insert(uint16_t value) { void insert(uint16_t value) {
TurntablePosition* newPosition = new TurntablePosition(currentIndex++, value); TurntablePosition* newPosition = new TurntablePosition(value);
if(!head) { if(!head) {
head = newPosition; head = newPosition;
} else { } else {
@ -68,7 +67,6 @@ public:
private: private:
TurntablePosition* head; TurntablePosition* head;
uint8_t currentIndex;
}; };
@ -89,8 +87,8 @@ protected:
union { union {
struct { struct {
bool hidden : 1; bool hidden : 1;
bool turntableType : 1; uint8_t turntableType : 2;
uint8_t position : 6; // Allows up to 63 positions including 0/home uint8_t position : 5; // Allows up to 38 positions including 0/home
}; };
uint8_t flags; uint8_t flags;
}; };
@ -150,7 +148,7 @@ public:
inline Turntable *next() { return _nextTurntable; } inline Turntable *next() { return _nextTurntable; }
void printState(Print *stream); void printState(Print *stream);
void addPosition(uint16_t value); void addPosition(uint16_t value);
uint16_t getPositionValue(uint8_t position); uint16_t getPositionValue(size_t position);
uint8_t getPositionCount(); uint8_t getPositionCount();
/* /*

View File

@ -222,6 +222,17 @@
#define IO_NO_HAL #define IO_NO_HAL
#endif #endif
////////////////////////////////////////////////////////////////////////////////
//
// This defines the maximum number of parameters DCCEXParser will accept.
// The increase is required to allow for a sufficient number of turntable positions.
//
#ifdef IO_NO_HAL
#define MAX_PARSER_PARAMS 10
#else
#define MAX_PARSER_PARAMS 20
#endif
#if __has_include ( "myAutomation.h") #if __has_include ( "myAutomation.h")
#if defined(HAS_ENOUGH_MEMORY) || defined(DISABLE_EEPROM) || defined(DISABLE_PROG) #if defined(HAS_ENOUGH_MEMORY) || defined(DISABLE_EEPROM) || defined(DISABLE_PROG)
#define EXRAIL_ACTIVE #define EXRAIL_ACTIVE