87 lines
1.9 KiB
C++
87 lines
1.9 KiB
C++
#ifndef MICROCONTROLLER_H
|
|
#define MICROCONTROLLER_H
|
|
|
|
#include <iostream>
|
|
|
|
#include <QObject>
|
|
#include <QColor>
|
|
#include <QIODevice>
|
|
#include <QString>
|
|
#include <QRunnable>
|
|
#include <QDebug>
|
|
#include <QEventLoop>
|
|
#include <QTimer>
|
|
#include <QAbstractButton>
|
|
#include <vector>
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include "items/item.h"
|
|
|
|
class Microcontroller : public QObject
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static constexpr char AMP_RELAY = 0;
|
|
static constexpr char SENSOR_TEMPERATURE = 1;
|
|
static constexpr char SENSOR_DOOR = 0 ;
|
|
|
|
private:
|
|
|
|
static constexpr int TRAIN_LIST = 1;
|
|
static constexpr int TURNOUT_LIST = 2;
|
|
static constexpr int SIGNAL_LIST = 3;
|
|
|
|
int listMode = 0;
|
|
|
|
//uint8_t _auxState = 0;
|
|
|
|
QIODevice* _port = nullptr;
|
|
|
|
std::vector< std::shared_ptr<Item> > itemList;
|
|
|
|
QScopedPointer<QEventLoop> loop;
|
|
QString _buffer;
|
|
|
|
void processMicroReturn();
|
|
void processList(const QString& buffer);
|
|
void processItemState(const QString& buffer);
|
|
std::shared_ptr<Item> processTrainLine(const QString& buffer);
|
|
std::shared_ptr<Item> processTurnoutLine(const QString& buffer);
|
|
std::shared_ptr<Item> processSignalLine(const QString& buffer);
|
|
|
|
void write(char *buffer, const size_t length);
|
|
void write(const QByteArray& buffer);
|
|
|
|
public:
|
|
Microcontroller(QIODevice* port);
|
|
Microcontroller();
|
|
~Microcontroller();
|
|
bool connected();
|
|
void setIODevice(QIODevice* port);
|
|
|
|
public slots:
|
|
void requestState();
|
|
|
|
void trainSetSpeed(uint8_t id, int8_t speed);
|
|
void trainReverse(uint8_t id);
|
|
void trainSetFunction(uint8_t id, uint8_t function, bool on);
|
|
void tunoutSetDirection(uint8_t id, bool direction);
|
|
void signalSetValue(uint8_t id, uint8_t state);
|
|
void estop();
|
|
void setPower(bool on);
|
|
|
|
private slots:
|
|
void isReadyRead();
|
|
|
|
signals:
|
|
void textRecived(const QString string);
|
|
void itemChanged(ItemData relay);
|
|
void auxStateChanged(int value);
|
|
void gotItemList(std::vector< std::shared_ptr<Item> >&);
|
|
};
|
|
|
|
#endif // MICROCONTROLLER_H
|