New Sensor-> Actor -> Item system (half implemented, relay support

only), new ui, Relay dehardcoeding.
This commit is contained in:
IMback
2018-11-02 22:08:49 +01:00
parent 74f117db69
commit b04fbfb5bc
66 changed files with 3905 additions and 123 deletions

41
src/actor.cpp Normal file
View File

@ -0,0 +1,41 @@
#include "actor.h"
Actor::Actor(QObject *parent): QObject(parent)
{
}
Actor::~Actor()
{
}
void Actor::performAction()
{
trigger();
if(action_ == ACTION_OFF) off();
else if(action_ == ACTION_ON) on();
else if(action_ != ACTION_TRIGGER_ONLY) toggle();
}
void Actor::setActive(int state)
{
state ? makeActive() : makeInactive();
}
bool Actor::isActive()
{
return active;
}
void Actor::setAction(uint8_t action)
{
action_ = action;
}
void Actor::onStateChanged(bool state)
{
}

45
src/actor.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef ACTOR_H
#define ACTOR_H
#include <QObject>
#include <QString>
class Actor : public QObject
{
Q_OBJECT
public:
static const uint8_t ACTION_DEFAULT = 0;
static const uint8_t ACTION_TOGGLE = 1;
static const uint8_t ACTION_ON = 2;
static const uint8_t ACTION_OFF = 3;
static const uint8_t ACTION_TRIGGER_ONLY = 4;
QString name;
protected:
uint8_t action_ = 0;
bool active = false;
void performAction();
signals:
void on();
void off();
void trigger();
void toggle();
public slots:
virtual void makeActive() = 0;
virtual void makeInactive() = 0;
virtual void setActive(int state);
virtual void onStateChanged(bool state);
public:
Actor(QObject* parent = nullptr);
virtual ~Actor();
bool isActive();
void setAction(uint8_t action);
};
#endif // ACTOR_H

33
src/alarmactions.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "alarmactions.h"
#include <QProcess>
#include <QSound>
#include <QProcess>
#include <QTime>
#include <QApplication>
AlarmActions::AlarmActions(QSettings *settings, Microcontroller* micro, QObject *parent) : QObject(parent), _micro(micro), _settings(settings)
{
}
void AlarmActions::syncoff()
{
_settings->sync();
for(unsigned int i = 0; i < _micro->getLastState().size(); i++) _micro->relayOff(i);
QProcess::execute ( "syncoff" );
}
void AlarmActions::Alarm()
{
if(_settings->value("Alarms/alarmSoundFile").toString().size() != 0)_micro->startSunrise();
if(_settings->value("Alarms/alarmSoundFile").toString().size() != 0)
{
_micro->relayOn(0);
QTime dieTime= QTime::currentTime().addSecs(10);
while (QTime::currentTime() < dieTime) QApplication::processEvents(QEventLoop::AllEvents, 100);
QSound::play(_settings->value("Alarms/alarmSoundFile").toString());
}
}

28
src/alarmactions.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef POWER_H
#define POWER_H
#include <QObject>
#include <QSettings>
#include "microcontroller.h"
class AlarmActions : public QObject
{
private:
Q_OBJECT
Microcontroller* _micro;
QSettings* _settings;
public:
explicit AlarmActions(QSettings* settings, Microcontroller* micro, QObject *parent = nullptr);
signals:
public slots:
void syncoff();
void Alarm();
};
#endif // POWER_H

51
src/alarmtime.cpp Normal file
View File

@ -0,0 +1,51 @@
#include "alarmtime.h"
AlarmTime::AlarmTime(const QTime time, QObject *parent) : Actor(parent), time_(time)
{
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
timer.setInterval(1000);
}
AlarmTime::~AlarmTime()
{
makeInactive();
}
void AlarmTime::run()
{
makeInactive();
active = true;
timer.start();
qDebug()<<"Start Alarm Time Manager\n";
}
void AlarmTime::makeActive()
{
run();
}
void AlarmTime::makeInactive()
{
timer.stop();
active = false;
}
void AlarmTime::doTick()
{
if(time_.hour() == QTime::currentTime().hour() && time_.minute() == QTime::currentTime().minute() && triggerd_==false )
{
qDebug()<<"Trigger\n";
triggerd_=true;
performAction();
}
else if( time_.hour() != QTime::currentTime().hour() ) triggerd_=false;
}
void AlarmTime::changeTime(QTime time)
{
time_=time;
qDebug()<<"Time Changed\n";
}

45
src/alarmtime.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef ALARMTIME_H
#define ALARMTIME_H
#include <QTime>
#include <QObject>
#include <QRunnable>
#include <QScopedPointer>
#include <QEventLoop>
#include <QTimer>
#include <QProcess>
#include <QDebug>
#include <stdint.h>
#include "actor.h"
class AlarmTime : public Actor, public QRunnable
{
Q_OBJECT
public:
static const uint8_t REPEAT_NEVER = 0;
static const uint8_t REPEAT_DAILY = 1;
static const uint8_t REPEAT_WEEKLY = 2;
static const uint8_t REPEAT_MONTHLY = 3;
static const uint8_t REPEAT_YEARLY = 4;
private:
bool triggerd_ = false;
QTime time_;
QTimer timer;
uint8_t repeat_ = REPEAT_NEVER;
public:
explicit AlarmTime(const QTime time = QTime::currentTime(), QObject *parent = nullptr);
~AlarmTime();
public slots:
void run();
virtual void makeActive();
virtual void makeInactive();
void doTick();
void changeTime(QTime time);
void setRepeat(uint8_t repeat);
};
#endif // ALARMTIME_H

140
src/main.cpp Normal file
View File

@ -0,0 +1,140 @@
#include <QtWidgets/QApplication>
#include <stdio.h>
#include <QDir>
#include <QDebug>
#include <QString>
#include <QSettings>
#include <QSignalMapper>
#include <QTcpSocket>
#include <QtSerialPort/QtSerialPort>
#include <QtSerialPort/QSerialPortInfo>
#include <QCommandLineParser>
#include "alarmtime.h"
#include "microcontroller.h"
#include "mainwindow.h"
#include "ampmanager.h"
#include "alarmactions.h"
#include "alarmsettingsdialog.h"
#define BAUD QSerialPort::Baud38400
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
//set info
QCoreApplication::setOrganizationName("UVOS");
QCoreApplication::setOrganizationDomain("uvos.xyz");
QCoreApplication::setApplicationName("SHinterface");
QCoreApplication::setApplicationVersion("0.5");
QDir::setCurrent(a.applicationDirPath());
//parse comand line
QCommandLineParser parser;
parser.setApplicationDescription("Smart Home Interface");
parser.addHelpOption();
parser.addVersionOption();
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
parser.addOption(tcpOption);
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "adress");
parser.addOption(hostOption);
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port in TCP mode or Serial port in serial mode"), "port");
parser.addOption(portOption);
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main", "Use serial connection"));
parser.addOption(serialOption);
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
parser.addOption(baudOption);
QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main", "Set if instance is not main instance"));
parser.addOption(secondaryOption);
parser.process(a);
QSettings settings;
//connect to microcontoler
Microcontroller micro;
if(parser.isSet(tcpOption))
{
QTcpSocket* microSocket = new QTcpSocket;
int port = 6856;
if(parser.isSet(portOption)) port = parser.value(portOption).toInt();
QString host("127.0.0.1");
if(parser.isSet(hostOption)) host = parser.value(hostOption);
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
if(!microSocket->waitForConnected(1000))
{
std::cout<<"Can not connect to to Server.\n";
return 1;
}
micro.setIODevice(microSocket);
}
else
{
QSerialPort* microPort = new QSerialPort;
if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
else microPort->setPortName("ttyUSB0");
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
else microPort->setBaudRate(BAUD);
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
else micro.setIODevice(microPort);
}
AlarmActions alarmActions(&settings, &micro);
AmpManager amp(&micro, 0);
//Alarms
AlarmTime almNight(settings.value("nightTime").toTime());
AlarmTime almAlarm(settings.value("alarmTime").toTime());
//mainwindow
MainWindow w(&micro, parser.isSet(secondaryOption));
QObject::connect(&micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
QObject::connect(&micro, SIGNAL(relayStateChanged(std::vector<bool>)), &w, SLOT(relayStateChanged(std::vector<bool>)));
QObject::connect(&micro, SIGNAL(auxStateChanged(int)), &w, SLOT(auxStateChanged(int)));
//dialogs
AlarmSettingsDialog alarmDialog(&almNight, &almAlarm, &settings, &w);
if(!parser.isSet(secondaryOption))
{
QObject::connect(&almNight, SIGNAL(trigger()), &alarmActions, SLOT(syncoff()));
QObject::connect(&w, SIGNAL(signalAlmNightChanged(QTime)), &almNight, SLOT(changeTime(QTime)));
QObject::connect(&w, SIGNAL(signalAlmNightStateChanged(int)), &almNight, SLOT(runOrAbort(int)));
almNight.run();
QObject::connect(&almAlarm, &AlarmTime::trigger, &micro, &Microcontroller::startSunrise);
QObject::connect(&w, SIGNAL(signalAlmAlarmChanged(QTime)), &almAlarm, SLOT(changeTime(QTime)));
QObject::connect(&w, SIGNAL(signalAlmAlarmStateChanged(int)), &almAlarm, SLOT(runOrAbort(int)));
almAlarm.run();
//Amplifyer
QObject::connect(&w, SIGNAL(signalAmpOn()), &amp, SLOT(run()));
QObject::connect(&w, SIGNAL(signalAmpOff()), &amp, SLOT(abort()));
QMetaObject::invokeMethod(&amp, "run", Qt::QueuedConnection );
}
//show dialogs
QObject::connect(&w, &MainWindow::showAlmSettingsDialog, &alarmDialog, &AlarmSettingsDialog::show);
QMetaObject::invokeMethod(&micro, "run", Qt::QueuedConnection );
w.show();
micro.requestRelayList();
micro.requestState();
micro.requestRelayList();
micro.requestState();
return a.exec();
}

229
src/microcontroller.cpp Normal file
View File

@ -0,0 +1,229 @@
#include "microcontroller.h"
//relays
void Microcontroller::relayToggle(int state, int relay)
{
char buffer[8];
int length = sprintf(buffer, "%d \n", relay);
if(_port != nullptr) state ? _port->write("relay on ", sizeof("relay on ")-1) : _port->write("relay off ", sizeof("relay off ")-1);
state ? std::cout<<"relay on " : std::cout<<"relay off ";
std::cout<<buffer;
if(_port != nullptr) _port->write(buffer, length);
}
void Microcontroller::relayOn(int relay)
{
relayToggle(true, relay);
}
void Microcontroller::relayOff(int relay)
{
relayToggle(false, relay);
}
//rgb lights
void Microcontroller::rgbOn()
{
if(_port != nullptr) _port->write("rgb on\n", sizeof("rgb on\n")-1);
}
void Microcontroller::rgbOff()
{
if(_port != nullptr) _port->write( "rgb off\n", sizeof("rgb off\n")-1);
}
void Microcontroller::changeRgbColor(const QColor color)
{
char buffer[64];
int length = sprintf(buffer, "rgb set %03d %03d %03d \n", color.red(), color.green(), color.blue() );
if(_port != nullptr) _port->write(buffer, length);
std::cout<<buffer;
}
void Microcontroller::setAuxPwm(int duty)
{
if(duty != _auxState)
{
if(duty > 1)
{
if(_auxState <= 1 && _port != nullptr) _port->write("aux on\n");
char buffer[64];
int length = sprintf(buffer, "aux set %03d \n", duty );
if(_port != nullptr) _port->write(buffer, length);
}
else if(_port != nullptr)_port->write("aux off\n");
}
_auxState = duty;
}
void Microcontroller::setPattern(int pattern)
{
if(_port != nullptr)
{
char buffer[4];
std::cout<<"pattern apply\n";
_port->write("rgb pattern ", sizeof("rgb pattern ")-1);
int length = sprintf(buffer, "%d \n", pattern);
_port->write(buffer, length);
}
}
void Microcontroller::startSunrise()
{
setPattern(4);
}
bool Microcontroller::connected()
{
if(_port != nullptr) return _port->isOpen();
else return false;
}
void Microcontroller::run()
{
abort();
loop.reset(new QEventLoop);
QTimer timer;
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
timer.setInterval(500);
timer.start();
loop->exec();
}
void Microcontroller::requestState()
{
if(_port != nullptr) _port->write("state\n", sizeof("state\n"));
}
void Microcontroller::requestRelayList()
{
if(_port != nullptr) _port->write("relay list\n", sizeof("relay list\n"));
}
void Microcontroller::abort()
{
if (!loop.isNull())
{
loop->quit();
}
}
std::vector<bool> Microcontroller::getLastState()
{
return _relayStates;
}
//housekeeping
Microcontroller::Microcontroller(QIODevice* port): _port(port)
{
}
Microcontroller::Microcontroller()
{
}
Microcontroller::~Microcontroller()
{
if(_port != nullptr) delete _port;
}
void Microcontroller::setIODevice(QIODevice *port)
{
_port = port;
}
void Microcontroller::processMicroReturn()
{
QString workbuff = _buffer;
if(listMode)
{
QStringList workbufList = workbuff.split(' ');
if(workbufList.size() >= 5 && workbufList[0] == "NUMBER:")
{
QString name;
for(int i = 5; i < workbufList.size(); i++) name.append(workbufList[i] + ' ');
name.remove(name.size()-1, 1);
relayList.push_back(RelayStore(workbufList[1].toInt(), name, workbufList[3].toInt()));
}
else if(_buffer.startsWith("EOL"))
{
listMode = false;
gotRelayList(relayList);
relayList.clear();
}
else listMode = false;
}
else
{
if(_buffer.startsWith("Relays:"))
{
listMode = true;
relayList.clear();
}
else if(_buffer.startsWith("ST"))
{
workbuff.remove(0, 2);
QStringList workbufList = workbuff.split(',');
//aux state
if(workbufList[0].toInt() != _auxState)
{
_auxState = workbufList[0].toInt();
auxStateChanged(_auxState);
}
//relay state
uint_fast8_t numberOfRelays = workbufList[1].toInt();
if(workbufList.size() >= numberOfRelays+2)
{
_relayStates.resize(numberOfRelays, false);
for(uint_fast8_t i = 0; i < numberOfRelays; i++)
{
if(_relayStates[i] != static_cast<bool>(workbufList[i+2].toInt()))
{
_relayStates[i] = static_cast<bool>(workbufList[i+2].toInt());
relayStateChanged(RelayStore(i, "", 0, _relayStates[i]));
}
}
}
}
else if(workbuff.contains("Door Open Warning"))
{
doorOpenTimeout();
}
else if(workbuff.size() > 2 && workbuff[0]=='D' && workbuff[1]=='2')
{
if(workbuff[3] == 'O') doorOpened(1);
else if(workbuff[3] == 'C') doorClosed(1);
}
}
}
void Microcontroller::doTick()
{
if(_port != nullptr)
{
char charBuf;
while(_port->getChar(&charBuf))
{
_buffer.push_back(charBuf);
if( _buffer.endsWith('\n') )
{
_buffer.remove('\n');
processMicroReturn();
textRecived(_buffer);
_buffer.clear();
}
}
}
}

79
src/microcontroller.h Normal file
View File

@ -0,0 +1,79 @@
#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:
bool listMode = false;
std::vector<RelayStore> relayList;
std::vector<bool> _relayStates; //ugh vector of bools
int _auxState = 0;
QIODevice* _port = nullptr;
QScopedPointer<QEventLoop> loop;
QString _buffer;
void processMicroReturn();
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 requestState();
void setAuxPwm(int duty);
void relayOn(int relay);
void relayOff(int relay);
void relayToggle(int state, int id);
void run();
void abort();
void doTick();
signals:
void textRecived(const QString string);
void relayStateChanged(RelayStore relay);
void auxStateChanged(int value);
void gotRelayList(std::vector<RelayStore>& relays);
void doorOpenTimeout();
void doorOpened(int id);
void doorClosed(int id);
};
#endif // MICROCONTROLLER_H

116
src/relay.cpp Normal file
View File

@ -0,0 +1,116 @@
#include "relay.h"
#include "microcontroller.h"
RelayStore::RelayStore(uint8_t id, QString name, uint16_t address, bool state): name_(name), state_(state), id_(id), address_(address)
{
}
QString RelayStore::getName() const
{
return name_;
}
void RelayStore::setName(QString name)
{
name_ = name;
}
bool RelayStore::getState() const
{
return state_;
}
bool RelayStore::actorsActive() const
{
return actorsActive_;
}
uint16_t RelayStore::getAddress() const
{
return address_;
}
uint8_t RelayStore::getId() const
{
return id_;
}
void RelayStore::setId(uint8_t id)
{
id_=id;
}
//Relay
Relay::Relay(Microcontroller* micro, uint8_t id, QString name, uint16_t address, bool state, QObject* parent): QObject(parent), RelayStore(id, name, address, state), micro_(micro)
{
}
Relay::Relay(Microcontroller* micro, const RelayStore& relayStore, QObject *parent): QObject(parent), RelayStore(relayStore), micro_(micro)
{
}
void Relay::setState(bool state)
{
state_ = state;
}
void Relay::addActor(Actor* actor)
{
actor->setParent(this);
actors_.push_back(actor);
connect(actor, &Actor::on, this, &Relay::on);
connect(actor, &Actor::off, this, &Relay::off);
connect(actor, &Actor::toggle, this, &Relay::toggle);
if(actorsActive_) actor->makeActive();
}
std::vector< Actor* > Relay::getActors()
{
return actors_;
}
bool Relay::hasActors()
{
return actors_.size() > 0;
}
Relay* Relay::copy() const
{
Relay* copy = new Relay(micro_, id_, name_, address_, parent());
copy->actors_ = actors_;
return copy;
}
void Relay::on()
{
micro_->relayOn(id_);
state_ = true;
for(unsigned i = 0; i < actors_.size(); i++) actors_[i]->onStateChanged(state_);
}
void Relay::off()
{
micro_->relayOff(id_);
state_ = false;
for(unsigned i = 0; i < actors_.size(); i++) actors_[i]->onStateChanged(state_);
}
void Relay::toggle()
{
state_ ? off() : on();
}
void Relay::moveToState(bool state)
{
state ? on() : off();
}
void Relay::setActorsActive(bool in)
{
actorsActive_ = true;
for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
}

57
src/relay.h Normal file
View File

@ -0,0 +1,57 @@
#ifndef RELAY_H
#define RELAY_H
#include<stdint.h>
#include<QObject>
#include<QString>
#include<vector>
#include<memory>
#include"actor.h"
class Microcontroller;
class RelayStore
{
protected:
QString name_;
bool state_ = false;
uint8_t id_;
uint16_t address_;
bool actorsActive_ = true;
public:
RelayStore(uint8_t id, QString name = "", uint16_t address = 0, bool state = false);
bool actorsActive() const;
QString getName() const;
void setName(QString name);
uint16_t getAddress() const;
uint8_t getId() const;
void setId(uint8_t id);
bool getState() const;
};
class Relay : public QObject, public RelayStore
{
Q_OBJECT
private:
Microcontroller* micro_;
std::vector< Actor* > actors_;
public slots:
void on();
void off();
void toggle();
void moveToState(bool state);
void setActorsActive(bool in);
public:
Relay(Microcontroller* micro, uint8_t id, QString name = "", uint16_t address = 0, bool state = false, QObject *parent = nullptr);
Relay(Microcontroller* micro, const RelayStore& relayStore, QObject *parent = nullptr);
void addActor(Actor* actor);
bool hasActors();
Relay* copy() const;
void setState(bool state);
std::vector< Actor* > getActors();
};
#endif // RELAY_H

66
src/relayscrollbox.cpp Normal file
View File

@ -0,0 +1,66 @@
#include "relayscrollbox.h"
#include "ui_relayscrollbox.h"
RelayScrollBox::RelayScrollBox(QWidget *parent) :
QWidget(parent),
ui(new Ui::RelayScrollBox)
{
ui->setupUi(this);
}
RelayScrollBox::~RelayScrollBox()
{
delete ui;
}
void RelayScrollBox::addRelay(const Relay& relay)
{
widgets_.push_back(new RelayWidget(relay.copy(), this));
ui->relayWidgetVbox->addWidget(widgets_.back());
}
void RelayScrollBox::addRelay(const RelayStore& relay)
{
RelayWidget* newWidget = new RelayWidget(new Relay(micro_, relay), this);
widgets_.push_back(newWidget);
ui->relayWidgetVbox->addWidget(widgets_.back());
}
void RelayScrollBox::setMicrocontoller(Microcontroller* micro)
{
micro_ = micro;
}
void RelayScrollBox::gotRelays(const std::vector<RelayStore>& relays)
{
for(unsigned i = 0; i < widgets_.size(); i++ )
{
bool mached = false;
for(unsigned j = 0; j < relays.size(); j++) if(widgets_[i]->getRelay()->getAddress() == relays[j].getAddress())
{
mached = true;
if(widgets_[i]->getRelay()->getId() != relays[j].getId()) widgets_[i]->getRelay()->setId(relays[j].getId());
}
if(!mached)
{
delete widgets_[i];
widgets_.erase(widgets_.begin()+i);
}
}
for(unsigned j = 0; j < relays.size(); j++)
{
bool mached = false;
for(unsigned i = 0; i < widgets_.size(); i++ ) if(widgets_[i]->getRelay()->getAddress() == relays[j].getAddress()) mached = true;
if(!mached)
{
addRelay(relays[j]);
}
}
}
void RelayScrollBox::relaySateChanged(const RelayStore& Realy)
{
}

40
src/relayscrollbox.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef RELAYSCROLLBOX_H
#define RELAYSCROLLBOX_H
#include <QWidget>
#include <vector>
#include <memory>
#include "relaywidget.h"
#include "relay.h"
#include "microcontroller.h"
namespace Ui {
class RelayScrollBox;
}
class RelayScrollBox : public QWidget
{
Q_OBJECT
private:
Microcontroller* micro_ = nullptr;
std::vector< RelayWidget* > widgets_;
public:
explicit RelayScrollBox(QWidget *parent = nullptr);
~RelayScrollBox();
public slots:
void addRelay(const Relay& relay);
void addRelay(const RelayStore& relay);
void setMicrocontoller(Microcontroller* micro);
void gotRelays(const std::vector<RelayStore>& relays);
void relaySateChanged(const RelayStore& Realy);
private:
Ui::RelayScrollBox *ui;
};
#endif // RELAYSCROLLBOX_H

67
src/serial_io.cpp Normal file
View File

@ -0,0 +1,67 @@
#include "serial_io.h"
struct termios toptions;;
void sWrite(int port, char string[], size_t length)
{
if(port != -1) write(port, string, length);
else std::cout<<string;
}
void sWrite(int port, const char string[], size_t length)
{
if(port != -1) write(port, string, length);
else std::cout<<string;
}
ssize_t sRead(int port, void *buf, size_t count)
{
return (port != -1) ? read(port, buf, count) : 0;
}
int serialport_init()
{
int fd;
system("stty -F /dev/ttyUSB0 38400 sane -echo");
fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
perror("init_serialport: Unable to open port ");
return -1;
}
if (tcgetattr(fd, &toptions) < 0)
{
perror("init_serialport: Couldn't get term attributes");
return -1;
}
speed_t brate = BAUDRATE;
cfsetispeed(&toptions, brate);
cfsetospeed(&toptions, brate);
// 8N1
toptions.c_cflag &= ~PARENB;
toptions.c_cflag &= ~CSTOPB;
toptions.c_cflag &= ~CSIZE;
toptions.c_cflag |= CS8;
// no flow control
toptions.c_cflag &= ~CRTSCTS;
toptions.c_cflag |= CREAD | CLOCAL | IGNPAR; // turn on READ & ignore ctrl lines
toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl
toptions.c_lflag &= ~(ICANON | ISIG | ECHO | ECHOE); // make raw
toptions.c_oflag &= ~OPOST; // make raw
// see: http://unixwiz.net/techtips/termios-vmin-vtime.html
toptions.c_cc[VMIN] = 0;
toptions.c_cc[VTIME] = 20;
fcntl(fd, F_SETFL, FNDELAY);
if( tcsetattr(fd, TCSANOW, &toptions) < 0)
{
perror("init_serialport: Couldn't set term attributes");
return -1;
}
return fd;
}

21
src/serial_io.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef SERIAL_H
#define SERIAL_H
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <iostream>
#define BAUDRATE B38400
#define DEVICE "/dev/ttyUSB0"
void sWrite(int port, char string[], size_t length);
void sWrite(int port, const char string[], size_t length);
ssize_t sRead(int port, void *buf, size_t count);
int serialport_init();
#endif // SERIAL_H

36
src/serialwatcher.cpp Normal file
View File

@ -0,0 +1,36 @@
#include "serialwatcher.h"
void SerialWatcher::run()
{
abort();
loop.reset(new QEventLoop);
QTimer timer;
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
timer.setInterval(500);
timer.start();
loop->exec();
}
void SerialWatcher::abort()
{
if (!loop.isNull()){
loop->quit();
}
}
void SerialWatcher::doTick()
{
char charBuf;
while(sRead(_serial, &charBuf, 1) == 1)
{
_buffer.push_back(charBuf);
if( _buffer.endsWith('\n') )
{
textRecived(_buffer);
_buffer.clear();
}
}
}

39
src/serialwatcher.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef SERIALWATCHER_H
#define SERIALWATCHER_H
#include "serial_io.h"
#define BUFFER_SIZE 128
#include<QString>
#include<QObject>
#include<QRunnable>
#include<QScopedPointer>
#include<QEventLoop>
#include<QTimer>
class SerialWatcher: public QObject, public QRunnable
{
Q_OBJECT
private:
QScopedPointer<QEventLoop> loop;
int _serial;
QString _buffer;
public:
explicit SerialWatcher(int serial, QObject *parent = 0);
~SerialWatcher();
signals:
void textRecived(const QString string);
public slots:
void run();
void abort();
void doTick();
};
#endif // SERIALWATCHER_H

65
src/speakersensor.cpp Normal file
View File

@ -0,0 +1,65 @@
#include "ampmanager.h"
AmpManager::AmpManager(Microcontroller *micro, int relayNumber, QObject *parent) : QObject(parent), _micro(micro), _relayNumber(relayNumber)
{
silenceCount = 0;
}
AmpManager::~AmpManager()
{
abort();
}
void AmpManager::run()
{
abort();
arecord.start( "arecord -D front -" );
loop.reset(new QEventLoop);
QTimer timer;
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
timer.setInterval(500);
timer.start();
qDebug()<<"Start Auto Amp Manager\n";
_micro->relayOn(_relayNumber);
relayState = true;
loop->exec();
}
void AmpManager::abort()
{
if (!loop.isNull()){
loop->quit();
}
if(arecord.state() == QProcess::Running)arecord.close();
qDebug()<<"Stop Auto Amp Manager\n";
}
void AmpManager::doTick()
{
if(arecord.state() == QProcess::Running)
{
QByteArray buffer = arecord.readAllStandardOutput();
for(long i = 0; i < buffer.size(); i++)
{
if((uint8_t) buffer.at(i) != 128)
{
silenceCount = 0;
}
}
if(silenceCount > 40 && relayState)
{
std::cout<<"Auto off Amp\n";
_micro->relayOff(_relayNumber);
relayState = false;
}
else if(silenceCount == 0 && !relayState)
{
std::cout<<"Auto on Amp\n";
_micro->relayOn(_relayNumber);
relayState = true;
}
silenceCount ++;
}
}

48
src/speakersensor.h Normal file
View File

@ -0,0 +1,48 @@
#ifndef AMPMANAGER_H
#define AMPMANAGER_H
#include <iostream>
#include <QObject>
#include <QRunnable>
#include <QScopedPointer>
#include <QEventLoop>
#include <QTimer>
#include <QProcess>
#include <QByteArray>
#include <QtDebug>
#include "microcontroller.h"
class AmpManager : public QObject
{
Q_OBJECT
public:
explicit AmpManager(Microcontroller *micro, int relayNumber, QObject *parent = nullptr);
~AmpManager();
public slots:
void run();
void abort();
private slots:
void doTick();
private:
QScopedPointer<QEventLoop> loop;
long silenceCount = 0;
Microcontroller *_micro;
int _relayNumber;
QProcess arecord;
bool relayState = false;
};
#endif // AMPMANAGER_H

View File

@ -0,0 +1,14 @@
#include "actorsettingsdialog.h"
#include "ui_actorsettingsdialog.h"
ActorSettingsDialog::ActorSettingsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::ActorSettingsDialog)
{
ui->setupUi(this);
}
ActorSettingsDialog::~ActorSettingsDialog()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef ACTORSETTINGSDIALOG_H
#define ACTORSETTINGSDIALOG_H
#include <QDialog>
namespace Ui {
class ActorSettingsDialog;
}
class ActorSettingsDialog : public QDialog
{
Q_OBJECT
public:
explicit ActorSettingsDialog(QWidget *parent = nullptr);
~ActorSettingsDialog();
private:
Ui::ActorSettingsDialog *ui;
};
#endif // ACTORSETTINGSDIALOG_H

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ActorSettingsDialog</class>
<widget class="QDialog" name="ActorSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="vertlayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Action:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_action">
<item>
<property name="text">
<string>On</string>
</property>
</item>
<item>
<property name="text">
<string>Off</string>
</property>
</item>
<item>
<property name="text">
<string>Toggle</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>ActorSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>ActorSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,50 @@
#include "alarmsettingsdialog.h"
#include "ui_alarmsettingsdialog.h"
#include <QFileDialog>
AlarmSettingsDialog::AlarmSettingsDialog(AlarmTime* almNight, AlarmTime* almAlarm, QSettings* settings, QWidget *parent): QDialog(parent), ui(new Ui::AlarmSettingsDialog), almNight_(almNight), almAlarm_(almAlarm), settings_(settings)
{
ui->setupUi(this);
//restore settings
ui->checkBox_Alarm->setChecked(settings_->value("Alarms/alarmOn").toBool());
ui->checkBox_Sunrise->setChecked(settings_->value("Alarms/sunrise").toBool());
ui->timeEdit_Shutdown->setTime(settings_->value("Alarms/shutdownTime").toTime());
ui->timeEdit_Alarm->setTime(settings_->value("Alarms/alarmTime").toTime());
ui->lineEdit->setText(settings_->value("Alarms/alarmSoundFile").toString());
connect(ui->pushButton_changeFile, SIGNAL(clicked()), this, SLOT(showFileChooser()));
}
AlarmSettingsDialog::~AlarmSettingsDialog()
{
delete ui;
}
void AlarmSettingsDialog::accept()
{
//store settings
settings_->setValue("Alarms/alarmOn", ui->checkBox_Alarm->checkState());
settings_->setValue("Alarms/sunrise", ui->checkBox_Sunrise->checkState());
settings_->setValue("Alarms/shutdownTime", ui->timeEdit_Shutdown->time());
settings_->setValue("Alarms/alarmTime", ui->timeEdit_Alarm->time());
settings_->setValue("Alarms/alarmSoundFile", ui->lineEdit->text());
//send signals
signalAlarmSoundFile(ui->lineEdit->text());
signalSunrise(ui->checkBox_Sunrise->checkState());
//modify alarm objects
almAlarm_->changeTime(ui->timeEdit_Alarm->time());
almNight_->changeTime(ui->timeEdit_Shutdown->time());
QDialog::accept();
}
void AlarmSettingsDialog::showFileChooser()
{
ui->lineEdit->setText(QFileDialog::getOpenFileName(this));
}

View File

@ -0,0 +1,43 @@
#ifndef ALARMSETTINGSDIALOG_H
#define ALARMSETTINGSDIALOG_H
#include <QDialog>
#include <QTime>
#include <QString>
#include <QSettings>
#include "alarmtime.h"
namespace Ui {
class AlarmSettingsDialog;
}
class AlarmSettingsDialog : public QDialog
{
Q_OBJECT
AlarmTime* almNight_;
AlarmTime* almAlarm_;
QSettings* settings_;
public:
explicit AlarmSettingsDialog(AlarmTime* almNight, AlarmTime* almAlarm, QSettings* settings, QWidget* parent = nullptr);
~AlarmSettingsDialog();
signals:
void signalAlarmSoundFile(QString fileName);
void signalSunrise(bool enabled);
public slots:
void accept();
private slots:
void showFileChooser();
private:
Ui::AlarmSettingsDialog *ui;
};
#endif // ALARMSETTINGSDIALOG_H

View File

@ -0,0 +1,241 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlarmSettingsDialog</class>
<widget class="QDialog" name="AlarmSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<height>406</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Alarm</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_alm">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Time</string>
</property>
</widget>
</item>
<item>
<widget class="QTimeEdit" name="timeEdit_Alarm">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_Alarm">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_snd">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sound File</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_changeFile">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Sunrise</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_Sunrise">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Auto Power off</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Time</string>
</property>
</widget>
</item>
<item>
<widget class="QTimeEdit" name="timeEdit_Shutdown"/>
</item>
<item>
<widget class="QCheckBox" name="checkBox_Shutdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlarmSettingsDialog</class>
<widget class="QDialog" name="AlarmSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>281</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Sound File:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Sunrise</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

View File

@ -0,0 +1,142 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlarmSettingsDialog</class>
<widget class="QDialog" name="AlarmSettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>281</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Sound File:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Change</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Sunrise</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -0,0 +1,71 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>AlarmSettingsDialog</class>
<widget name="AlarmSettingsDialog" class="QDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget name="buttonBox" class="QDialogButtonBox">
<property name="geometry">
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</widget>
<pixmapfunction/>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AlarmSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

14
src/ui/alarmwidget.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "alarmwidget.h"
#include "ui_alarmwidget.h"
AlarmWidget::AlarmWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::AlarmWidget)
{
ui->setupUi(this);
}
AlarmWidget::~AlarmWidget()
{
delete ui;
}

22
src/ui/alarmwidget.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef ALARMWIDGET_H
#define ALARMWIDGET_H
#include <QWidget>
namespace Ui {
class AlarmWidget;
}
class AlarmWidget : public QWidget
{
Q_OBJECT
public:
explicit AlarmWidget(QWidget *parent = nullptr);
~AlarmWidget();
private:
Ui::AlarmWidget *ui;
};
#endif // ALARMWIDGET_H

134
src/ui/alarmwidget.ui Normal file
View File

@ -0,0 +1,134 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AlarmWidget</class>
<widget class="QWidget" name="AlarmWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>357</width>
<height>166</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="rowWrapPolicy">
<enum>QFormLayout::DontWrapRows</enum>
</property>
<property name="labelAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="formAlignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="horizontalSpacing">
<number>50</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Time:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDateTimeEdit" name="dateTimeEdit">
<property name="locale">
<locale language="English" country="Germany"/>
</property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
<property name="currentSection">
<enum>QDateTimeEdit::DaySection</enum>
</property>
<property name="displayFormat">
<string>dd.mM.yyyy hh:mm</string>
</property>
<property name="calendarPopup">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Repeating:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QRadioButton" name="radioButton_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Wee&amp;kly</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QRadioButton" name="radioButton_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Monthly</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QRadioButton" name="radioButton_4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Yearly</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QRadioButton" name="radioButton">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Daily</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string> Enable</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

78
src/ui/mainwindow.cpp Normal file
View File

@ -0,0 +1,78 @@
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "relayscrollbox.h"
MainWindow::MainWindow(Microcontroller *micro , bool isRemoteMode , QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
colorChooser(this),
_micro(micro)
{
ui->setupUi(this);
if(!_micro->connected()) ui->label_serialRecive->setText("No IO Port! Debug only.");
//Relays
connect(ui->pushButton_refesh, SIGNAL(clicked()), _micro, SLOT(requestRelayList()));
ui->relayList->setMicrocontoller(_micro);
connect(_micro, &Microcontroller::gotRelayList, ui->relayList, &RelayScrollBox::gotRelays);
connect(_micro, &Microcontroller::relayStateChanged, ui->relayList, &RelayScrollBox::relaySateChanged);
//RGB Leds
connect(ui->presettApply, SIGNAL(clicked()), this, SLOT(slotApplyPreset()));
connect(&colorChooser, SIGNAL(colorSelected(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
connect(ui->button_lightsOn, SIGNAL(clicked()), _micro, SLOT(rgbOn()));
connect(ui->button_lightsOff, SIGNAL(clicked()), _micro, SLOT(rgbOff()));
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
new QListWidgetItem(tr("Pattern 0 Solid"), ui->listWidget_patern);
new QListWidgetItem(tr("Pattern 1"), ui->listWidget_patern);
new QListWidgetItem(tr("Pattern 2 Alarm"), ui->listWidget_patern);
new QListWidgetItem(tr("Pattern 3"), ui->listWidget_patern);
new QListWidgetItem(tr("Pattern 4 Sunrise"), ui->listWidget_patern);
//Desk light
connect(ui->horizontalSlider_deskLight, &QAbstractSlider::valueChanged, _micro, [this](int value){ _micro->setAuxPwm(value); });
connect(ui->pushButton_alarms, SIGNAL(clicked()), this, SIGNAL(showAlmSettingsDialog()));
}
void MainWindow::remoteMode()
{
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::slotChangedRgb(const QColor color)
{
_micro->changeRgbColor(color);
}
void MainWindow::slotApplyPreset()
{
if(ui->listWidget_patern->selectedItems().count() == 1) _micro->setPattern(ui->listWidget_patern->currentRow());
}
void MainWindow::slotDoorOpenTimeout()
{
//ui->checkBox_doorOpen->setChecked(true);
}
void MainWindow::auxStateChanged(int value)
{
ui->horizontalSlider_deskLight->blockSignals(true);
ui->horizontalSlider_deskLight->setValue(value);
ui->horizontalSlider_deskLight->blockSignals(false);
}
void MainWindow::changeHeaderLableText(const QString string)
{
ui->label_serialRecive->setText(string);
}

59
src/ui/mainwindow.h Normal file
View File

@ -0,0 +1,59 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QColorDialog>
#include <QListWidgetItem>
#include <QTime>
#include <vector>
#include "alarmtime.h"
#include "microcontroller.h"
namespace Ui
{
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(Microcontroller *micro, bool isRemoteMode = false, QWidget *parent = nullptr);
~MainWindow();
private:
Ui::MainWindow *ui;
QColorDialog colorChooser;
Microcontroller *_micro;
void remoteMode();
signals:
void signalAmpOn();
void signalAmpOff();
void showAlmSettingsDialog();
private slots:
//RGB
void slotChangedRgb(const QColor color);
void slotApplyPreset();
void changeHeaderLableText(const QString string);
//door
void slotDoorOpenTimeout();
public slots:
void auxStateChanged(int value);
};
#endif // MAINWINDOW_H

332
src/ui/mainwindow.ui Normal file
View File

@ -0,0 +1,332 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>862</width>
<height>570</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>50</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>600</width>
<height>197</height>
</size>
</property>
<property name="windowTitle">
<string>Smart Home Interface</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
</property>
<widget class="QWidget" name="centralWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<property name="topMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QLabel" name="label_serialRecive">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="frameShape">
<enum>QFrame::Box</enum>
</property>
<property name="text">
<string>SHinterface</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Relays</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="RelayScrollBox" name="relayList" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_refesh">
<property name="text">
<string>Refesh</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget_patern">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>120</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="presettApply">
<property name="minimumSize">
<size>
<width>128</width>
<height>32</height>
</size>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="button_color">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>50</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>80</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>128</height>
</size>
</property>
<property name="text">
<string>Choose Color</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="topMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item>
<widget class="QPushButton" name="button_lightsOn">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>50</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>48</height>
</size>
</property>
<property name="text">
<string>ON</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_lightsOff">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>50</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>48</height>
</size>
</property>
<property name="text">
<string>OFF</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Desk Light</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_deskLight">
<property name="maximum">
<number>254</number>
</property>
<property name="tracking">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_alarms">
<property name="text">
<string>Alarms</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_quit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Quit</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>RelayScrollBox</class>
<extends>QWidget</extends>
<header>relayscrollbox.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="resources.qrc"/>
</resources>
<connections/>
</ui>

230
src/ui/relaydialog.ui Normal file
View File

@ -0,0 +1,230 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RelayDialog</class>
<widget class="QDialog" name="RelayDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>358</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>Advanced Relays</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Advanced</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>3Dator</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_R0">
<property name="text">
<string>On</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>3040</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_R1">
<property name="text">
<string>On</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>Aux</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_R2">
<property name="text">
<string>On</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Enterance Watch</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Inside</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>Watch</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RelayDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RelayDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

32
src/ui/relayscrollbox.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "relayscrollbox.h"
#include "ui_relayscrollbox.h"
RelayScrollBox::RelayScrollBox(QWidget *parent) :
QWidget(parent),
ui(new Ui::RelayScrollBox)
{
ui->setupUi(this);
QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture);
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
}
RelayScrollBox::~RelayScrollBox()
{
delete ui;
}
void RelayScrollBox::addRelay(std::weak_ptr<Relay> relay)
{
widgets_.push_back(new RelayWidget(relay));
ui->relayWidgetVbox->addWidget(widgets_.back());
}
void RelayScrollBox::removeRelay(const RelayStore& realy)
{
for(unsigned i = 0; i < widgets_.size(); i++)
{
if(widgets_[i]->controles(realy)) widgets_.erase(widgets_.begin()+i);
}
}

40
src/ui/relayscrollbox.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef RELAYSCROLLBOX_H
#define RELAYSCROLLBOX_H
#include <QWidget>
#include <vector>
#include <memory>
#include <QScroller>
#include "relaywidget.h"
#include "../relay.h"
#include "../item.h"
namespace Ui {
class RelayScrollBox;
}
class RelayScrollBox : public QWidget
{
Q_OBJECT
private:
std::vector< RelayWidget* > widgets_;
public:
explicit RelayScrollBox(QWidget *parent = nullptr);
~RelayScrollBox();
void setItemStore(ItemStore* itemStore);
public slots:
void addRelay(std::weak_ptr<Relay> relay);
void removeRelay(const RelayStore& Realy);
private:
Ui::RelayScrollBox *ui;
};
#endif // RELAYSCROLLBOX_H

56
src/ui/relayscrollbox.ui Normal file
View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RelayScrollBox</class>
<widget class="QWidget" name="RelayScrollBox">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QScrollArea" name="scrollArea">
<property name="widgetResizable">
<bool>true</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>384</width>
<height>284</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QVBoxLayout" name="relayWidgetVbox"/>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,18 @@
#include "relaysettingsdialog.h"
#include "ui_relaysettingsdialog.h"
RelaySettingsDialog::RelaySettingsDialog(RelayStore* relay, QWidget *parent) :
QDialog(parent),
relay_(relay),
ui(new Ui::RelaySettingsDialog)
{
ui->setupUi(this);
ui->label_address->setText(QString::number(relay_->getAddress(), 2));
ui->label_name->setText(relay_->getName());
ui->label_id->setText(QString::number(relay_->getId(), 10));
}
RelaySettingsDialog::~RelaySettingsDialog()
{
delete ui;
}

View File

@ -0,0 +1,24 @@
#ifndef RELAYSETTINGSDIALOG_H
#define RELAYSETTINGSDIALOG_H
#include <QDialog>
#include "relay.h"
namespace Ui {
class RelaySettingsDialog;
}
class RelaySettingsDialog : public QDialog
{
Q_OBJECT
RelayStore* relay_;
public:
explicit RelaySettingsDialog(RelayStore* relay, QWidget *parent = nullptr);
~RelaySettingsDialog();
private:
Ui::RelaySettingsDialog *ui;
};
#endif // RELAYSETTINGSDIALOG_H

View File

@ -0,0 +1,207 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RelaySettingsDialog</class>
<widget class="QDialog" name="RelaySettingsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>319</height>
</rect>
</property>
<property name="windowTitle">
<string>Relay Settings</string>
</property>
<property name="windowIcon">
<iconset resource="resources.qrc">
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>10</number>
</property>
<item row="3" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Address</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="label_address">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_name">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_id">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>ID:</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="comboBox">
<item>
<property name="text">
<string>Alarm</string>
</property>
</item>
<item>
<property name="text">
<string>Timer</string>
</property>
</item>
<item>
<property name="text">
<string>Speaker</string>
</property>
</item>
<item>
<property name="text">
<string>RGB Value</string>
</property>
</item>
<item>
<property name="text">
<string>Temperature</string>
</property>
</item>
<item>
<property name="text">
<string/>
</property>
</item>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_add">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>RelaySettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>RelaySettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

50
src/ui/relaywidget.cpp Normal file
View File

@ -0,0 +1,50 @@
#include "relaywidget.h"
#include "ui_relaywidget.h"
#include <QCheckBox>
RelayWidget::RelayWidget(Relay* relay, QWidget *parent) :
QWidget(parent),
relay_(relay),
ui(new Ui::RelayWidget)
{
ui->setupUi(this);
relay_->setParent(this);
if(!relay->hasActors())
{
ui->checkBox_auto->hide();
}
ui->checkBox_auto->setChecked(relay->actorsActive());
ui->checkBox->setChecked(relay->getState());
ui->label->setText(relay_->getName());
connect(ui->checkBox, &QCheckBox::toggled, relay_, &Relay::moveToState);
connect(ui->checkBox_auto, &QCheckBox::toggled, relay_, &Relay::setActorsActive);
connect(ui->pushButton, &QPushButton::clicked, this, &RelayWidget::showSettingsDialog);
}
void RelayWidget::showSettingsDialog()
{
RelaySettingsDialog dialog(relay_, this);
dialog.exec();
}
Relay* RelayWidget::getRelay()
{
return relay_;
}
void RelayWidget::stateChanged(bool state)
{
ui->checkBox->setChecked(state);
relay_->setState(state);
}
RelayWidget::~RelayWidget()
{
delete ui;
}

33
src/ui/relaywidget.h Normal file
View File

@ -0,0 +1,33 @@
#ifndef RELAYWIDGET_H
#define RELAYWIDGET_H
#include <QWidget>
#include "relaysettingsdialog.h"
#include "relay.h"
namespace Ui {
class RelayWidget;
}
class RelayWidget : public QWidget
{
Q_OBJECT
private:
Relay* relay_;
private slots:
void showSettingsDialog();
public:
explicit RelayWidget(Relay* relay_, QWidget *parent = nullptr);
Relay* getRelay();
~RelayWidget();
public slots:
void stateChanged(bool state);
private:
Ui::RelayWidget *ui;
};
#endif // RELAYWIDGET_H

65
src/ui/relaywidget.ui Normal file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RelayWidget</class>
<widget class="QWidget" name="RelayWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>435</width>
<height>48</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>On</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_auto">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Auto</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Settings</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,14 @@
#include "sensoractorwidget.h"
#include "ui_sensoractorwidget.h"
SensorActorWidget::SensorActorWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::SensorActorWidget)
{
ui->setupUi(this);
}
SensorActorWidget::~SensorActorWidget()
{
delete ui;
}

View File

@ -0,0 +1,22 @@
#ifndef SENSORACTORWIDGET_H
#define SENSORACTORWIDGET_H
#include <QWidget>
namespace Ui {
class SensorActorWidget;
}
class SensorActorWidget : public QWidget
{
Q_OBJECT
public:
explicit SensorActorWidget(QWidget *parent = nullptr);
~SensorActorWidget();
private:
Ui::SensorActorWidget *ui;
};
#endif // SENSORACTORWIDGET_H

View File

@ -0,0 +1,21 @@
<ui version="4.0">
<author/>
<comment/>
<exportmacro/>
<class>SensorActorWidget</class>
<widget name="SensorActorWidget" class="QWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<pixmapfunction/>
<connections/>
</ui>

View File

@ -0,0 +1,33 @@
#include "sensorlistwidget.h"
SensorListWidget::SensorListWidget(QWidget *parent): QListWidget (parent)
{}
SensorListWidget::SensorListWidget(SensorStore& sensorStore, QWidget* parent): QListWidget (parent)
{
sensorsChanged(*(sensorStore.getSensors()));
}
void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
{
clear();
for(size_t i = 0; i < sensors.size(); ++i)
{
QString itemString = sensors[i].name + ": ";
if(sensors[i].type == Sensor::TYPE_DOOR)
{
if(sensors[i].field) itemString.append("Open");
else itemString.append("Closed");
}
else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT)
{
if(sensors[i].field) itemString.append("Playing");
else itemString.append("Silent");
}
else itemString.append(QString::number(sensors[i].field));
addItem(itemString);
}
}

18
src/ui/sensorlistwidget.h Normal file
View File

@ -0,0 +1,18 @@
#pragma once
#include <QListWidget>
#include <vector>
#include "../sensor.h"
class SensorListWidget : public QListWidget
{
Q_OBJECT
public:
SensorListWidget(QWidget *parent = nullptr);
SensorListWidget(SensorStore& sensorStore, QWidget* parent = nullptr);
virtual ~SensorListWidget(){}
public slots:
void sensorsChanged(std::vector<Sensor> sensors);
};