add support for turnouts
This commit is contained in:
@ -3,8 +3,9 @@
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include "items/train.h"
|
||||
#include "items/turnout.h"
|
||||
|
||||
void Microcontroller::itemSetSpeed(uint8_t id, uint8_t speed)
|
||||
void Microcontroller::trainSetSpeed(uint8_t id, uint8_t speed)
|
||||
{
|
||||
qDebug()<<__func__;
|
||||
std::stringstream ss;
|
||||
@ -12,20 +13,27 @@ void Microcontroller::itemSetSpeed(uint8_t id, uint8_t speed)
|
||||
write(ss.str().c_str());
|
||||
}
|
||||
|
||||
void Microcontroller::itemReverse(uint8_t id)
|
||||
void Microcontroller::trainReverse(uint8_t id)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<"train "<<(unsigned)id<<" reverse\n";
|
||||
write(ss.str().c_str());
|
||||
}
|
||||
|
||||
void Microcontroller::itemSetFunction(uint8_t id, uint8_t function, bool on)
|
||||
void Microcontroller::trainSetFunction(uint8_t id, uint8_t function, bool on)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<"train "<<(unsigned)id<<" function "<<(unsigned)function<<' '<<(on ? "on" : "off")<<'\n';
|
||||
write(ss.str().c_str());
|
||||
}
|
||||
|
||||
void Microcontroller::tunoutSetDirection(uint8_t id, bool direction)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss<<"turnout "<<(unsigned)id<<" set "<<(!direction ? "left" : "right")<<'\n';
|
||||
write(ss.str().c_str());
|
||||
}
|
||||
|
||||
void Microcontroller::setPower(bool on)
|
||||
{
|
||||
write(on ? "power on\n" : "power off\n");
|
||||
@ -68,6 +76,7 @@ bool Microcontroller::connected()
|
||||
void Microcontroller::requestState()
|
||||
{
|
||||
write("train list\n");
|
||||
write("turnout list\n");
|
||||
}
|
||||
|
||||
//housekeeping
|
||||
@ -94,19 +103,34 @@ void Microcontroller::setIODevice(QIODevice *port)
|
||||
std::shared_ptr<Item> Microcontroller::processTrainLine(const QString& buffer)
|
||||
{
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 9 && buffer.startsWith("NUMBER:"))
|
||||
if(bufferList.size() >= 13 && buffer.startsWith("NUMBER:"))
|
||||
{
|
||||
return std::shared_ptr<Item>(new Train(bufferList[1].toInt(), bufferList[3].toInt(), bufferList[12].toInt()));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::shared_ptr<Item> Microcontroller::processTurnoutLine(const QString& buffer)
|
||||
{
|
||||
qDebug()<<__func__<<" :"<<buffer;
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 6 && buffer.startsWith("NUMBER:"))
|
||||
{
|
||||
return std::shared_ptr<Item>(new Turnout(bufferList[1].toInt(), bufferList[5].toInt()));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Microcontroller::processList(const QString& buffer)
|
||||
{
|
||||
QStringList bufferList = buffer.split(' ');
|
||||
if(bufferList.size() >= 13 && buffer.startsWith("NUMBER:"))
|
||||
qDebug()<<__func__<<" :"<<buffer<<" list mode: "<<listMode;
|
||||
if(bufferList.size() >= 10 && buffer.startsWith("NUMBER:"))
|
||||
{
|
||||
itemList.push_back(processTrainLine(buffer));
|
||||
if(listMode == TRAIN_LIST)
|
||||
itemList.push_back(processTrainLine(buffer));
|
||||
else if(listMode == TURNOUT_LIST)
|
||||
itemList.push_back(processTurnoutLine(buffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -134,9 +158,13 @@ void Microcontroller::processMicroReturn()
|
||||
{
|
||||
if(_buffer.startsWith("Trains:"))
|
||||
{
|
||||
listMode = true;
|
||||
listMode = TRAIN_LIST;
|
||||
itemList.clear();
|
||||
}
|
||||
else if(_buffer.startsWith("Turnouts:"))
|
||||
{
|
||||
listMode = TURNOUT_LIST;
|
||||
}
|
||||
else if(_buffer.startsWith("NUMBER:"))
|
||||
{
|
||||
processItemState(_buffer);
|
||||
|
Reference in New Issue
Block a user