77 lines
1.5 KiB
C++
77 lines
1.5 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>
|
|
#include "relay.h"
|
|
|
|
class Microcontroller : public QObject
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
static constexpr char AMP_RELAY = 0;
|
|
|
|
private:
|
|
|
|
std::vector<bool> _relayStates; //ugh vector of bools
|
|
int _auxState = 0;
|
|
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 startSunrise();
|
|
|
|
void requestRelayList();
|
|
|
|
void setAuxPwm(int duty);
|
|
|
|
void relayOn(int relay);
|
|
void relayOff(int relay);
|
|
void relayToggle(bool state, int id);
|
|
|
|
void run();
|
|
void abort();
|
|
void doTick();
|
|
|
|
signals:
|
|
void textRecived(const QString string);
|
|
void relayStateChanged(Relay relay);
|
|
void auxStateChanged(int value);
|
|
void gotRelayList(std::vector<Relay> relays);
|
|
void doorOpenTimeout();
|
|
void doorOpened(int id);
|
|
void doorClosed(int id);
|
|
};
|
|
|
|
#endif // MICROCONTROLLER_H
|