1
0
mirror of https://github.com/DCC-EX/CommandStation-EX.git synced 2024-12-24 13:21:23 +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 "DCCTimer.h"
#include "EXRAIL2.h"
// #include "Turntables.h"
#include "Turntables.h"
// This macro can't be created easily as a portable function because the
// 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)
{
case 0: // <I> list turntable objects
StringFormatter::send(stream, F("<i all>\n"));
return true;
// return Turntable::printAll(stream);
return Turntable::printAll(stream);
case 1: // <T id> delete turntable
// if (!Turntable::remove(p[0]))
// return false;
StringFormatter::send(stream, F("<i delete>\n"));
if (!Turntable::remove(p[0]))
return false;
StringFormatter::send(stream, F("<O>\n"));
return true;
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
{
if (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);
return true;
} else if (params < 39 && p[1] == HASH_KEYWORD_DCC) {
if (params > 5 && params < 41 && p[1] == HASH_KEYWORD_EXTT) {
DIAG(F("Create EXTT turntable %d on vpin %d and address %d with %d positions"), p[0], p[2], p[3], params - 4);
if (!EXTTTurntable::create(p[0], (uint8_t)p[1], (VPIN)p[2])) return false;
} 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);
} else {
return false;
}
}
return true;
}
}
break;
}
return false;
}
// CALLBACKS must be static

View File

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

View File

@ -105,6 +105,7 @@ public:
inline Turntable *next() { return _nextTurntable; }
void printState(Print *stream);
/*
* Virtual functions
*/
@ -113,13 +114,14 @@ public:
}
virtual ~Turntable() {} // Destructor
/*
* Public static functions
*/
inline static bool exists(uint16_t id) { return get(id) != 0; }
static bool remove(uint16_t id);
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);
inline static Turntable *first() { return _firstTurntable; }
static bool printAll(Print *stream) {
@ -148,11 +150,11 @@ private:
} _exttTurntableData;
// Constructor
EXTTTurntable(uint16_t id, uint8_t i2caddress, VPIN vpin, long **positions);
EXTTTurntable(uint16_t id, uint8_t i2caddress, VPIN vpin);
public:
// 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;
protected: