62 lines
1.2 KiB
C++
62 lines
1.2 KiB
C++
#ifndef MICROCONTROLLER_H
|
|
#define MICROCONTROLLER_H
|
|
|
|
#include <iostream>
|
|
|
|
#include <QObject>
|
|
#include <QColor>
|
|
#include <QIODevice>
|
|
#include <QString>
|
|
#include <QRunnable>
|
|
#include <QScopedPointer>
|
|
#include <QEventLoop>
|
|
#include <QTimer>
|
|
#include <QAbstractButton>
|
|
#include <vector>
|
|
|
|
class Microcontroller: public QObject
|
|
{
|
|
Q_OBJECT
|
|
private:
|
|
|
|
std::vector<bool> _relayStates; //ugh vector of bools
|
|
QIODevice* _port = nullptr;
|
|
|
|
QScopedPointer<QEventLoop> loop;
|
|
QString _buffer;
|
|
|
|
void processMicroReturn();
|
|
void requestState();
|
|
|
|
public:
|
|
Microcontroller(QIODevice* port);
|
|
Microcontroller();
|
|
~Microcontroller();
|
|
bool connected();
|
|
void setIODevice(QIODevice* port);
|
|
std::vector<bool> getLastState();
|
|
|
|
public slots:
|
|
void rgbOn();
|
|
void rgbOff();
|
|
void changeRgbColor(const QColor color);
|
|
void setPattern(int pattern);
|
|
|
|
void relayToggle(int state, int id);
|
|
void relayOn(int relay);
|
|
void relayOff(int relay);
|
|
|
|
void run();
|
|
void abort();
|
|
void doTick();
|
|
|
|
signals:
|
|
void textRecived(const QString string);
|
|
void relayStateChanged(std::vector<bool> relayStates);
|
|
void doorOpenTimeout();
|
|
void doorOpened(int id);
|
|
void doorClosed(int id);
|
|
};
|
|
|
|
#endif // MICROCONTROLLER_H
|