1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-25 05:31:24 +01:00

Progress!

This commit is contained in:
peteGSX 2023-08-22 19:30:22 +10:00
parent c4febd1d0f
commit b277d204f0
3 changed files with 30 additions and 32 deletions

View File

@ -41,7 +41,7 @@
#include "TrackManager.h" #include "TrackManager.h"
#include "DCCTimer.h" #include "DCCTimer.h"
#include "EXRAIL2.h" #include "EXRAIL2.h"
// #include "Turntables.h" #include "Turntables.h"
// This macro can't be created easily as a portable function because the // This macro can't be created easily as a portable function because the
// flashlist requires a far pointer for high flash access. // flashlist requires a far pointer for high flash access.
@ -1033,14 +1033,12 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
switch (params) switch (params)
{ {
case 0: // <I> list turntable objects case 0: // <I> list turntable objects
StringFormatter::send(stream, F("<i all>\n")); return Turntable::printAll(stream);
return true;
// return Turntable::printAll(stream);
case 1: // <T id> delete turntable case 1: // <T id> delete turntable
// if (!Turntable::remove(p[0])) if (!Turntable::remove(p[0]))
// return false; return false;
StringFormatter::send(stream, F("<i delete>\n")); StringFormatter::send(stream, F("<O>\n"));
return true; return true;
case 2: // <T id position> - rotate to position for DCC turntables case 2: // <T id position> - rotate to position for DCC turntables
@ -1053,19 +1051,17 @@ bool DCCEXParser::parseI(Print *stream, int16_t params, int16_t p[])
default: // If we're here, it must be creating a turntable object default: // If we're here, it must be creating a turntable object
{ {
if (params < 41 && p[1] == HASH_KEYWORD_EXTT) { if (params > 5 && params < 41 && p[1] == HASH_KEYWORD_EXTT) {
DIAG(F("Create EXTT turntable %d on vpin %d and address %s with %d positions"), p[0], p[2], p[3], params - 4); DIAG(F("Create EXTT turntable %d on vpin %d and address %d with %d positions"), p[0], p[2], p[3], params - 4);
return true; if (!EXTTTurntable::create(p[0], (uint8_t)p[1], (VPIN)p[2])) return false;
} else if (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 {
return false;
}
}
return true; return true;
} }
}
break;
}
return false;
} }
// CALLBACKS must be static // CALLBACKS must be static

View File

@ -36,13 +36,14 @@ Turntable *Turntable::_firstTurntable = 0;
/* /*
* Public static data * Public static data
*/ */
int Turntable::_turntablelistHash = 0; int Turntable::turntablelistHash = 0;
/* /*
* Protected static functions * Protected static functions
*/ */
// Add new turntable to end of list // Add new turntable to end of list
void Turntable::add(Turntable *tto) { void Turntable::add(Turntable *tto) {
if (!_firstTurntable) { if (!_firstTurntable) {
_firstTurntable = tto; _firstTurntable = tto;
@ -73,25 +74,25 @@ bool Turntable::remove(uint16_t id) {
pp->_nextTurntable = tto->_nextTurntable; pp->_nextTurntable = tto->_nextTurntable;
} }
delete (EXTTTurntable *)tto; // delete (EXTTTurntable *)tto;
turntablelistHash++; turntablelistHash++;
return true; return true;
} }
/* /*
* Public static functions * Public static functions
*/ */
bool Turntable::isPosition(uint16_t id, uint8_t position) { bool Turntable::isPosition(uint16_t id, uint8_t position) {
Turntable *tto = get(id); Turntable *tto = get(id);
if (!tto) return false;
if (tto) { if (tto) {
if (tto->getPosition() == position) { if (tto->getPosition() == position) {
return true; return true;
} else { } else {
return false; return false;
} }
} else {
return false;
} }
} }
@ -102,15 +103,16 @@ bool Turntable::setPositionStateOnly(uint16_t id, uint8_t position) {
#if defined(EXRAIL_ACTIVE) #if defined(EXRAIL_ACTIVE)
// RMFT2::turntableEvent(id, position); // RMFT2::turntableEvent(id, position);
#endif #endif
return true;
} }
bool Turntable::setPosition(uint16_t id, uint8_t position) { bool Turntable::setPosition(uint16_t id, uint8_t position, uint8_t activity) {
#if defined(DIAG_IO) #if defined(DIAG_IO)
DIAG(F("Turntable(%d, %d)"), id, position); DIAG(F("Turntable(%d, %d)"), id, position);
#endif #endif
Turntable *tto = Turntable::get(id); Turntable *tto = Turntable::get(id);
if (!tto) return false; if (!tto) return false;
bool ok = tto->setPositionInternal(position); bool ok = tto->setPositionInternal(position, activity);
if (ok) { if (ok) {
tto->setPositionStateOnly(id, position); tto->setPositionStateOnly(id, position);
@ -123,30 +125,28 @@ bool Turntable::setPosition(uint16_t id, uint8_t position) {
* *
*************************************************************************************/ *************************************************************************************/
// Private constructor // Private constructor
EXTTTurntable::EXTTTurntable(uint16_t id, uint8_t i2caddress, VPIN vpin, long **positions) : EXTTTurntable::EXTTTurntable(uint16_t id, uint8_t i2caddress, VPIN vpin) :
Turntable(id, TURNTABLE_EXTT) Turntable(id, TURNTABLE_EXTT)
{ {
_exttTurntableData.i2caddress = i2caddress; _exttTurntableData.i2caddress = i2caddress;
_exttTurntableData.vpin = vpin; _exttTurntableData.vpin = vpin;
_exttTurntableData.positions = **positions;
} }
// Create function // Create function
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
Turntable *EXTTTurntable::create(uint16_t id, uint8_t i2caddress, VPIN vpin, long **positions) { Turntable *EXTTTurntable::create(uint16_t id, uint8_t i2caddress, VPIN vpin) {
Turntable *tto = get(id); Turntable *tto = get(id);
if (tto) { if (tto) {
if (tto->isType(TURNTABLE_EXTT)) { if (tto->isType(TURNTABLE_EXTT)) {
EXTTTurntable *extt = (EXTTTurntable *)tto; EXTTTurntable *extt = (EXTTTurntable *)tto;
extt->_exttTurntableData.i2caddress = i2caddress; extt->_exttTurntableData.i2caddress = i2caddress;
extt->_exttTurntableData.vpin = vpin; extt->_exttTurntableData.vpin = vpin;
extt->_exttTurntableData.positions = positions;
return tto; return tto;
} else { } else {
remove(id); remove(id);
} }
} }
tto = (Turntable *)new EXTTTurntable(id, i2caddress, vpin, **positions); tto = (Turntable *)new EXTTTurntable(id, i2caddress, vpin);
DIAG(F("Turntable 0x%x"), tto); DIAG(F("Turntable 0x%x"), tto);
return tto; return tto;
#else #else
@ -166,9 +166,9 @@ EXTTTurntable::EXTTTurntable(uint16_t id, uint8_t i2caddress, VPIN vpin, long **
bool EXTTTurntable::setPositionInternal(uint8_t position, uint8_t activity) { bool EXTTTurntable::setPositionInternal(uint8_t position, uint8_t activity) {
#ifndef IO_NO_HAL #ifndef IO_NO_HAL
// Get step value from positions // Get step value from positions
int value = _exttTurntableData.positions[position]; // int value = _exttTurntableData.positions[position];
// Set position via device driver // Set position via device driver
EXTurntable::_writeAnalogue(vpin, value, activity, 0); // EXTurntable::_writeAnalogue(vpin, value, activity, 0);
#else #else
(void)position; (void)position;
#endif #endif

View File

@ -105,6 +105,7 @@ public:
inline Turntable *next() { return _nextTurntable; } inline Turntable *next() { return _nextTurntable; }
void printState(Print *stream); void printState(Print *stream);
/* /*
* Virtual functions * Virtual functions
*/ */
@ -113,13 +114,14 @@ public:
} }
virtual ~Turntable() {} // Destructor virtual ~Turntable() {} // Destructor
/* /*
* Public static functions * Public static functions
*/ */
inline static bool exists(uint16_t id) { return get(id) != 0; } inline static bool exists(uint16_t id) { return get(id) != 0; }
static bool remove(uint16_t id); static bool remove(uint16_t id);
static bool isPosition(uint16_t id, uint8_t position); static bool isPosition(uint16_t id, uint8_t position);
static bool setPosition(uint16_t id, uint8_t position); static bool setPosition(uint16_t id, uint8_t position, uint8_t activity=0);
static bool setPositionStateOnly(uint16_t id, uint8_t position); static bool setPositionStateOnly(uint16_t id, uint8_t position);
inline static Turntable *first() { return _firstTurntable; } inline static Turntable *first() { return _firstTurntable; }
static bool printAll(Print *stream) { static bool printAll(Print *stream) {
@ -148,11 +150,11 @@ private:
} _exttTurntableData; } _exttTurntableData;
// Constructor // Constructor
EXTTTurntable(uint16_t id, uint8_t i2caddress, VPIN vpin, long **positions); EXTTTurntable(uint16_t id, uint8_t i2caddress, VPIN vpin);
public: public:
// Create function // Create function
static Turntable *create(uint16_t id, uint8_t i2caddress, VPIN vpin, long **positions); static Turntable *create(uint16_t id, uint8_t i2caddress, VPIN vpin);
void print(Print *stream) override; void print(Print *stream) override;
protected: protected: