From b04fbfb5bca332a06bf5e5783625588da5370a14 Mon Sep 17 00:00:00 2001 From: IMback Date: Fri, 2 Nov 2018 22:08:49 +0100 Subject: [PATCH] New Sensor-> Actor -> Item system (half implemented, relay support only), new ui, Relay dehardcoeding. --- actorsettingsdialog.cpp | 14 + actorsettingsdialog.h | 22 ++ actorsettingsdialog.ui | 71 +++++ alarmwidget.cpp | 14 + alarmwidget.h | 22 ++ alarmwidget.ui | 21 ++ relaydialog.cpp | 52 ---- relaydialog.h | 39 --- relaymanager.cpp | 6 - relaymanager.h | 26 -- relayscrollbox.cpp | 14 + relayscrollbox.h | 22 ++ relayscrollbox.ui | 21 ++ relaysettingsdialog.cpp | 14 + relaysettingsdialog.h | 22 ++ relaysettingsdialog.ui | 71 +++++ src/actor.cpp | 41 +++ src/actor.h | 45 +++ src/alarmactions.cpp | 33 ++ src/alarmactions.h | 28 ++ src/alarmtime.cpp | 51 ++++ src/alarmtime.h | 45 +++ src/main.cpp | 140 +++++++++ src/microcontroller.cpp | 229 ++++++++++++++ src/microcontroller.h | 79 +++++ src/relay.cpp | 116 +++++++ src/relay.h | 57 ++++ src/relayscrollbox.cpp | 66 ++++ src/relayscrollbox.h | 40 +++ src/serial_io.cpp | 67 +++++ src/serial_io.h | 21 ++ src/serialwatcher.cpp | 36 +++ src/serialwatcher.h | 39 +++ src/speakersensor.cpp | 65 ++++ src/speakersensor.h | 48 +++ src/ui/actorsettingsdialog.cpp | 14 + src/ui/actorsettingsdialog.h | 22 ++ src/ui/actorsettingsdialog.ui | 104 +++++++ src/ui/alarmsettingsdialog.cpp | 50 ++++ src/ui/alarmsettingsdialog.h | 43 +++ src/ui/alarmsettingsdialog.ui | 241 +++++++++++++++ src/ui/alarmsettingsdialog.ui.orig | 142 +++++++++ src/ui/alarmsettingsdialog_BASE_22257.ui | 0 src/ui/alarmsettingsdialog_LOCAL_22257.ui | 142 +++++++++ src/ui/alarmsettingsdialog_REMOTE_22257.ui | 71 +++++ src/ui/alarmwidget.cpp | 14 + src/ui/alarmwidget.h | 22 ++ src/ui/alarmwidget.ui | 134 +++++++++ src/ui/mainwindow.cpp | 78 +++++ src/ui/mainwindow.h | 59 ++++ src/ui/mainwindow.ui | 332 +++++++++++++++++++++ src/ui/relaydialog.ui | 230 ++++++++++++++ src/ui/relayscrollbox.cpp | 32 ++ src/ui/relayscrollbox.h | 40 +++ src/ui/relayscrollbox.ui | 56 ++++ src/ui/relaysettingsdialog.cpp | 18 ++ src/ui/relaysettingsdialog.h | 24 ++ src/ui/relaysettingsdialog.ui | 207 +++++++++++++ src/ui/relaywidget.cpp | 50 ++++ src/ui/relaywidget.h | 33 ++ src/ui/relaywidget.ui | 65 ++++ src/ui/sensoractorwidget.cpp | 14 + src/ui/sensoractorwidget.h | 22 ++ src/ui/sensoractorwidget.ui | 21 ++ src/ui/sensorlistwidget.cpp | 33 ++ src/ui/sensorlistwidget.h | 18 ++ 66 files changed, 3905 insertions(+), 123 deletions(-) create mode 100644 actorsettingsdialog.cpp create mode 100644 actorsettingsdialog.h create mode 100644 actorsettingsdialog.ui create mode 100644 alarmwidget.cpp create mode 100644 alarmwidget.h create mode 100644 alarmwidget.ui delete mode 100644 relaydialog.cpp delete mode 100644 relaydialog.h delete mode 100644 relaymanager.cpp delete mode 100644 relaymanager.h create mode 100644 relayscrollbox.cpp create mode 100644 relayscrollbox.h create mode 100644 relayscrollbox.ui create mode 100644 relaysettingsdialog.cpp create mode 100644 relaysettingsdialog.h create mode 100644 relaysettingsdialog.ui create mode 100644 src/actor.cpp create mode 100644 src/actor.h create mode 100644 src/alarmactions.cpp create mode 100644 src/alarmactions.h create mode 100644 src/alarmtime.cpp create mode 100644 src/alarmtime.h create mode 100644 src/main.cpp create mode 100644 src/microcontroller.cpp create mode 100644 src/microcontroller.h create mode 100644 src/relay.cpp create mode 100644 src/relay.h create mode 100644 src/relayscrollbox.cpp create mode 100644 src/relayscrollbox.h create mode 100644 src/serial_io.cpp create mode 100644 src/serial_io.h create mode 100644 src/serialwatcher.cpp create mode 100644 src/serialwatcher.h create mode 100644 src/speakersensor.cpp create mode 100644 src/speakersensor.h create mode 100644 src/ui/actorsettingsdialog.cpp create mode 100644 src/ui/actorsettingsdialog.h create mode 100644 src/ui/actorsettingsdialog.ui create mode 100644 src/ui/alarmsettingsdialog.cpp create mode 100644 src/ui/alarmsettingsdialog.h create mode 100644 src/ui/alarmsettingsdialog.ui create mode 100644 src/ui/alarmsettingsdialog.ui.orig create mode 100644 src/ui/alarmsettingsdialog_BASE_22257.ui create mode 100644 src/ui/alarmsettingsdialog_LOCAL_22257.ui create mode 100644 src/ui/alarmsettingsdialog_REMOTE_22257.ui create mode 100644 src/ui/alarmwidget.cpp create mode 100644 src/ui/alarmwidget.h create mode 100644 src/ui/alarmwidget.ui create mode 100644 src/ui/mainwindow.cpp create mode 100644 src/ui/mainwindow.h create mode 100644 src/ui/mainwindow.ui create mode 100644 src/ui/relaydialog.ui create mode 100644 src/ui/relayscrollbox.cpp create mode 100644 src/ui/relayscrollbox.h create mode 100644 src/ui/relayscrollbox.ui create mode 100644 src/ui/relaysettingsdialog.cpp create mode 100644 src/ui/relaysettingsdialog.h create mode 100644 src/ui/relaysettingsdialog.ui create mode 100644 src/ui/relaywidget.cpp create mode 100644 src/ui/relaywidget.h create mode 100644 src/ui/relaywidget.ui create mode 100644 src/ui/sensoractorwidget.cpp create mode 100644 src/ui/sensoractorwidget.h create mode 100644 src/ui/sensoractorwidget.ui create mode 100644 src/ui/sensorlistwidget.cpp create mode 100644 src/ui/sensorlistwidget.h diff --git a/actorsettingsdialog.cpp b/actorsettingsdialog.cpp new file mode 100644 index 0000000..becfc2d --- /dev/null +++ b/actorsettingsdialog.cpp @@ -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; +} diff --git a/actorsettingsdialog.h b/actorsettingsdialog.h new file mode 100644 index 0000000..0854572 --- /dev/null +++ b/actorsettingsdialog.h @@ -0,0 +1,22 @@ +#ifndef ACTORSETTINGSDIALOG_H +#define ACTORSETTINGSDIALOG_H + +#include + +namespace Ui { +class ActorSettingsDialog; +} + +class ActorSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ActorSettingsDialog(QWidget *parent = nullptr); + ~ActorSettingsDialog(); + +private: + Ui::ActorSettingsDialog *ui; +}; + +#endif // ACTORSETTINGSDIALOG_H diff --git a/actorsettingsdialog.ui b/actorsettingsdialog.ui new file mode 100644 index 0000000..222c9d3 --- /dev/null +++ b/actorsettingsdialog.ui @@ -0,0 +1,71 @@ + + + + + ActorSettingsDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + buttonBox + accepted() + ActorSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ActorSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/alarmwidget.cpp b/alarmwidget.cpp new file mode 100644 index 0000000..c8f5a06 --- /dev/null +++ b/alarmwidget.cpp @@ -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; +} diff --git a/alarmwidget.h b/alarmwidget.h new file mode 100644 index 0000000..afd841f --- /dev/null +++ b/alarmwidget.h @@ -0,0 +1,22 @@ +#ifndef ALARMWIDGET_H +#define ALARMWIDGET_H + +#include + +namespace Ui { +class AlarmWidget; +} + +class AlarmWidget : public QWidget +{ + Q_OBJECT + +public: + explicit AlarmWidget(QWidget *parent = nullptr); + ~AlarmWidget(); + +private: + Ui::AlarmWidget *ui; +}; + +#endif // ALARMWIDGET_H diff --git a/alarmwidget.ui b/alarmwidget.ui new file mode 100644 index 0000000..bf4389c --- /dev/null +++ b/alarmwidget.ui @@ -0,0 +1,21 @@ + + + + + AlarmWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/relaydialog.cpp b/relaydialog.cpp deleted file mode 100644 index 4022210..0000000 --- a/relaydialog.cpp +++ /dev/null @@ -1,52 +0,0 @@ -#include "relaydialog.h" -#include "ui_relaydialog.h" - -RelayDialog::RelayDialog(Microcontroller *micro, QWidget *parent) : - QDialog(parent), - ui(new Ui::RelayDialog), - _micro(micro) -{ - ui->setupUi(this); - - _relayCheckBoxes.push_back(ui->checkBox_R0); - _relayCheckBoxes.push_back(ui->checkBox_R1); - - for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) connect(_relayCheckBoxes[i], SIGNAL(stateChanged(int)), this, SLOT(relayCheckBoxToggeled(int))); - - _micro->relayOn(STARTING_RELAY); - -} - -RelayDialog::~RelayDialog() -{ - delete ui; -} - - -void RelayDialog::relayCheckBoxToggeled(int state) -{ - for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) - { - - if(_relayCheckBoxes[i] == sender()) - { - std::cerr<relayOff(STARTING_RELAY); _relayCheckBoxes[0]->setChecked(false);}); - } - _micro->relayToggle(state, i+STARTING_RELAY); - } - } -} - -void RelayDialog::relayStateChanged(std::vector relayStates) -{ - if(relayStates.size() > STARTING_RELAY) for(unsigned int i = 0; i < relayStates.size()-STARTING_RELAY; i++) - { - _relayCheckBoxes[i]->blockSignals(true); - _relayCheckBoxes[i]->setChecked(relayStates[i+STARTING_RELAY]); - _relayCheckBoxes[i]->blockSignals(false); - } -} diff --git a/relaydialog.h b/relaydialog.h deleted file mode 100644 index 85d10d5..0000000 --- a/relaydialog.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef RELAYDIALOG_H -#define RELAYDIALOG_H - -#include -#include -#include -#include -#include "microcontroller.h" - -#define STARTING_RELAY 5 - -namespace Ui { -class RelayDialog; -} - -class RelayDialog : public QDialog -{ - Q_OBJECT - -public: - explicit RelayDialog(Microcontroller *micro, QWidget *parent = 0); - ~RelayDialog(); - -private: - - std::vector _relayCheckBoxes; - - Ui::RelayDialog *ui; - - Microcontroller *_micro; - -private slots: - void relayCheckBoxToggeled(int state); - -public slots: - void relayStateChanged(std::vector relayStates); -}; - -#endif // RELAYDIALOG_H diff --git a/relaymanager.cpp b/relaymanager.cpp deleted file mode 100644 index c5a7a03..0000000 --- a/relaymanager.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "relaymanager.h" - -RelayManager::RelayManager(QObject *parent) : QObject(parent) -{ - -} diff --git a/relaymanager.h b/relaymanager.h deleted file mode 100644 index 24f8446..0000000 --- a/relaymanager.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef RELAYMANAGER_H -#define RELAYMANAGER_H - -#include -#include -#include "relay.h" -#include "microcontroller.h" - -class RelayManager : public QObject -{ - Q_OBJECT -private: - std::vector relays; - - Microcontroller* micro_; - -public: - explicit RelayManager(QObject *parent = nullptr); - -signals: - -public slots: - void -}; - -#endif // RELAYMANAGER_H diff --git a/relayscrollbox.cpp b/relayscrollbox.cpp new file mode 100644 index 0000000..3f619c8 --- /dev/null +++ b/relayscrollbox.cpp @@ -0,0 +1,14 @@ +#include "relayscrollbox.h" +#include "ui_relayscrollbox.h" + +RelayScrollBox::RelayScrollBox(QWidget *parent) : + QWidget(parent), + ui(new Ui::RelayScrollBox) +{ + ui->setupUi(this); +} + +RelayScrollBox::~RelayScrollBox() +{ + delete ui; +} diff --git a/relayscrollbox.h b/relayscrollbox.h new file mode 100644 index 0000000..43ea6ab --- /dev/null +++ b/relayscrollbox.h @@ -0,0 +1,22 @@ +#ifndef RELAYSCROLLBOX_H +#define RELAYSCROLLBOX_H + +#include + +namespace Ui { +class RelayScrollBox; +} + +class RelayScrollBox : public QWidget +{ + Q_OBJECT + +public: + explicit RelayScrollBox(QWidget *parent = nullptr); + ~RelayScrollBox(); + +private: + Ui::RelayScrollBox *ui; +}; + +#endif // RELAYSCROLLBOX_H diff --git a/relayscrollbox.ui b/relayscrollbox.ui new file mode 100644 index 0000000..e35a0c6 --- /dev/null +++ b/relayscrollbox.ui @@ -0,0 +1,21 @@ + + + + + RelayScrollBox + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/relaysettingsdialog.cpp b/relaysettingsdialog.cpp new file mode 100644 index 0000000..b0d58f1 --- /dev/null +++ b/relaysettingsdialog.cpp @@ -0,0 +1,14 @@ +#include "relaysettingsdialog.h" +#include "ui_relaysettingsdialog.h" + +RelaySettingsDialog::RelaySettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::RelaySettingsDialog) +{ + ui->setupUi(this); +} + +RelaySettingsDialog::~RelaySettingsDialog() +{ + delete ui; +} diff --git a/relaysettingsdialog.h b/relaysettingsdialog.h new file mode 100644 index 0000000..424d5f8 --- /dev/null +++ b/relaysettingsdialog.h @@ -0,0 +1,22 @@ +#ifndef RELAYSETTINGSDIALOG_H +#define RELAYSETTINGSDIALOG_H + +#include + +namespace Ui { +class RelaySettingsDialog; +} + +class RelaySettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit RelaySettingsDialog(QWidget *parent = nullptr); + ~RelaySettingsDialog(); + +private: + Ui::RelaySettingsDialog *ui; +}; + +#endif // RELAYSETTINGSDIALOG_H diff --git a/relaysettingsdialog.ui b/relaysettingsdialog.ui new file mode 100644 index 0000000..5df8f6b --- /dev/null +++ b/relaysettingsdialog.ui @@ -0,0 +1,71 @@ + + + + + RelaySettingsDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + buttonBox + accepted() + RelaySettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RelaySettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/actor.cpp b/src/actor.cpp new file mode 100644 index 0000000..a20ca97 --- /dev/null +++ b/src/actor.cpp @@ -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) +{ + +} + diff --git a/src/actor.h b/src/actor.h new file mode 100644 index 0000000..0bca73a --- /dev/null +++ b/src/actor.h @@ -0,0 +1,45 @@ +#ifndef ACTOR_H +#define ACTOR_H + +#include +#include + +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 diff --git a/src/alarmactions.cpp b/src/alarmactions.cpp new file mode 100644 index 0000000..e49b27e --- /dev/null +++ b/src/alarmactions.cpp @@ -0,0 +1,33 @@ +#include "alarmactions.h" +#include +#include +#include +#include +#include + +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()); + } +} diff --git a/src/alarmactions.h b/src/alarmactions.h new file mode 100644 index 0000000..d8a5f67 --- /dev/null +++ b/src/alarmactions.h @@ -0,0 +1,28 @@ +#ifndef POWER_H +#define POWER_H + +#include +#include +#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 diff --git a/src/alarmtime.cpp b/src/alarmtime.cpp new file mode 100644 index 0000000..876ebe4 --- /dev/null +++ b/src/alarmtime.cpp @@ -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"; +} diff --git a/src/alarmtime.h b/src/alarmtime.h new file mode 100644 index 0000000..9e797b4 --- /dev/null +++ b/src/alarmtime.h @@ -0,0 +1,45 @@ +#ifndef ALARMTIME_H +#define ALARMTIME_H +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..b3961df --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,140 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +#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 "<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 "<portName().toStdString()<<". Continueing in demo mode"<<'\n'; + else micro.setIODevice(microPort); + } + + AlarmActions alarmActions(&settings, µ); + + AmpManager amp(µ, 0); + + //Alarms + AlarmTime almNight(settings.value("nightTime").toTime()); + AlarmTime almAlarm(settings.value("alarmTime").toTime()); + + //mainwindow + MainWindow w(µ, parser.isSet(secondaryOption)); + QObject::connect(µ, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString))); + QObject::connect(µ, SIGNAL(relayStateChanged(std::vector)), &w, SLOT(relayStateChanged(std::vector))); + QObject::connect(µ, 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, µ, &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()), &, SLOT(run())); + QObject::connect(&w, SIGNAL(signalAmpOff()), &, SLOT(abort())); + QMetaObject::invokeMethod(&, "run", Qt::QueuedConnection ); + } + + //show dialogs + QObject::connect(&w, &MainWindow::showAlmSettingsDialog, &alarmDialog, &AlarmSettingsDialog::show); + + QMetaObject::invokeMethod(µ, "run", Qt::QueuedConnection ); + + w.show(); + + micro.requestRelayList(); + micro.requestState(); + + micro.requestRelayList(); + micro.requestState(); + + return a.exec(); +} diff --git a/src/microcontroller.cpp b/src/microcontroller.cpp new file mode 100644 index 0000000..24f7469 --- /dev/null +++ b/src/microcontroller.cpp @@ -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<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< 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 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(workbufList[i+2].toInt())) + { + _relayStates[i] = static_cast(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(); + } + } + } +} diff --git a/src/microcontroller.h b/src/microcontroller.h new file mode 100644 index 0000000..cf1b294 --- /dev/null +++ b/src/microcontroller.h @@ -0,0 +1,79 @@ +#ifndef MICROCONTROLLER_H +#define MICROCONTROLLER_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "relay.h" + +class Microcontroller : public QObject +{ + + Q_OBJECT + +public: + + static constexpr char AMP_RELAY = 0; + +private: + + bool listMode = false; + std::vector relayList; + + std::vector _relayStates; //ugh vector of bools + int _auxState = 0; + QIODevice* _port = nullptr; + + QScopedPointer loop; + QString _buffer; + + void processMicroReturn(); + +public: + Microcontroller(QIODevice* port); + Microcontroller(); + ~Microcontroller(); + bool connected(); + void setIODevice(QIODevice* port); + std::vector 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& relays); + void doorOpenTimeout(); + void doorOpened(int id); + void doorClosed(int id); +}; + +#endif // MICROCONTROLLER_H diff --git a/src/relay.cpp b/src/relay.cpp new file mode 100644 index 0000000..97fe93e --- /dev/null +++ b/src/relay.cpp @@ -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(); +} diff --git a/src/relay.h b/src/relay.h new file mode 100644 index 0000000..c57c023 --- /dev/null +++ b/src/relay.h @@ -0,0 +1,57 @@ +#ifndef RELAY_H +#define RELAY_H + +#include +#include +#include +#include +#include + +#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 diff --git a/src/relayscrollbox.cpp b/src/relayscrollbox.cpp new file mode 100644 index 0000000..c5ea3e3 --- /dev/null +++ b/src/relayscrollbox.cpp @@ -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& 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) +{ + +} diff --git a/src/relayscrollbox.h b/src/relayscrollbox.h new file mode 100644 index 0000000..deab92d --- /dev/null +++ b/src/relayscrollbox.h @@ -0,0 +1,40 @@ +#ifndef RELAYSCROLLBOX_H +#define RELAYSCROLLBOX_H + +#include +#include +#include +#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& relays); + void relaySateChanged(const RelayStore& Realy); + +private: + Ui::RelayScrollBox *ui; +}; + +#endif // RELAYSCROLLBOX_H + + diff --git a/src/serial_io.cpp b/src/serial_io.cpp new file mode 100644 index 0000000..2d34100 --- /dev/null +++ b/src/serial_io.cpp @@ -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< +#include +#include +#include + +#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 diff --git a/src/serialwatcher.cpp b/src/serialwatcher.cpp new file mode 100644 index 0000000..e30185b --- /dev/null +++ b/src/serialwatcher.cpp @@ -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(); + } + } +} diff --git a/src/serialwatcher.h b/src/serialwatcher.h new file mode 100644 index 0000000..4b2f64b --- /dev/null +++ b/src/serialwatcher.h @@ -0,0 +1,39 @@ +#ifndef SERIALWATCHER_H +#define SERIALWATCHER_H +#include "serial_io.h" + +#define BUFFER_SIZE 128 + +#include +#include +#include +#include +#include +#include + +class SerialWatcher: public QObject, public QRunnable +{ + Q_OBJECT +private: + + QScopedPointer 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 diff --git a/src/speakersensor.cpp b/src/speakersensor.cpp new file mode 100644 index 0000000..777623c --- /dev/null +++ b/src/speakersensor.cpp @@ -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 ++; + } +} diff --git a/src/speakersensor.h b/src/speakersensor.h new file mode 100644 index 0000000..634836d --- /dev/null +++ b/src/speakersensor.h @@ -0,0 +1,48 @@ +#ifndef AMPMANAGER_H +#define AMPMANAGER_H + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#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 loop; + + long silenceCount = 0; + Microcontroller *_micro; + int _relayNumber; + + + QProcess arecord; + + bool relayState = false; + +}; + +#endif // AMPMANAGER_H diff --git a/src/ui/actorsettingsdialog.cpp b/src/ui/actorsettingsdialog.cpp new file mode 100644 index 0000000..becfc2d --- /dev/null +++ b/src/ui/actorsettingsdialog.cpp @@ -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; +} diff --git a/src/ui/actorsettingsdialog.h b/src/ui/actorsettingsdialog.h new file mode 100644 index 0000000..0854572 --- /dev/null +++ b/src/ui/actorsettingsdialog.h @@ -0,0 +1,22 @@ +#ifndef ACTORSETTINGSDIALOG_H +#define ACTORSETTINGSDIALOG_H + +#include + +namespace Ui { +class ActorSettingsDialog; +} + +class ActorSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit ActorSettingsDialog(QWidget *parent = nullptr); + ~ActorSettingsDialog(); + +private: + Ui::ActorSettingsDialog *ui; +}; + +#endif // ACTORSETTINGSDIALOG_H diff --git a/src/ui/actorsettingsdialog.ui b/src/ui/actorsettingsdialog.ui new file mode 100644 index 0000000..6dc5832 --- /dev/null +++ b/src/ui/actorsettingsdialog.ui @@ -0,0 +1,104 @@ + + + ActorSettingsDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + + + + + + + 0 + 0 + + + + Action: + + + + + + + + On + + + + + Off + + + + + Toggle + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + ActorSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ActorSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/alarmsettingsdialog.cpp b/src/ui/alarmsettingsdialog.cpp new file mode 100644 index 0000000..54471db --- /dev/null +++ b/src/ui/alarmsettingsdialog.cpp @@ -0,0 +1,50 @@ +#include "alarmsettingsdialog.h" +#include "ui_alarmsettingsdialog.h" + +#include + +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)); +} + + diff --git a/src/ui/alarmsettingsdialog.h b/src/ui/alarmsettingsdialog.h new file mode 100644 index 0000000..1e2997d --- /dev/null +++ b/src/ui/alarmsettingsdialog.h @@ -0,0 +1,43 @@ +#ifndef ALARMSETTINGSDIALOG_H +#define ALARMSETTINGSDIALOG_H + +#include +#include +#include +#include + +#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 diff --git a/src/ui/alarmsettingsdialog.ui b/src/ui/alarmsettingsdialog.ui new file mode 100644 index 0000000..f46d2e0 --- /dev/null +++ b/src/ui/alarmsettingsdialog.ui @@ -0,0 +1,241 @@ + + + AlarmSettingsDialog + + + + 0 + 0 + 462 + 406 + + + + Dialog + + + + + + Alarm + + + + + + + + + 0 + 0 + + + + Time + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Enable + + + + + + + + + 0 + + + 0 + + + + + + 0 + 0 + + + + Sound File + + + + + + + true + + + + + + + + 0 + 0 + + + + Change + + + + + + + + + 0 + + + + + Sunrise + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Enable + + + + + + + + + + + + + 0 + 0 + + + + Auto Power off + + + + + + + + Time + + + + + + + + + + + 0 + 0 + + + + Enable + + + true + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AlarmSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AlarmSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/alarmsettingsdialog.ui.orig b/src/ui/alarmsettingsdialog.ui.orig new file mode 100644 index 0000000..55297a9 --- /dev/null +++ b/src/ui/alarmsettingsdialog.ui.orig @@ -0,0 +1,142 @@ + + + AlarmSettingsDialog + + + + 0 + 0 + 423 + 281 + + + + Dialog + + + + + + Sound File: + + + + + + + 0 + + + 0 + + + + + false + + + + + + + Change + + + + + + + + + 0 + + + + + Sunrise + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Enable + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AlarmSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AlarmSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/alarmsettingsdialog_BASE_22257.ui b/src/ui/alarmsettingsdialog_BASE_22257.ui new file mode 100644 index 0000000..e69de29 diff --git a/src/ui/alarmsettingsdialog_LOCAL_22257.ui b/src/ui/alarmsettingsdialog_LOCAL_22257.ui new file mode 100644 index 0000000..55297a9 --- /dev/null +++ b/src/ui/alarmsettingsdialog_LOCAL_22257.ui @@ -0,0 +1,142 @@ + + + AlarmSettingsDialog + + + + 0 + 0 + 423 + 281 + + + + Dialog + + + + + + Sound File: + + + + + + + 0 + + + 0 + + + + + false + + + + + + + Change + + + + + + + + + 0 + + + + + Sunrise + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Enable + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + AlarmSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AlarmSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/alarmsettingsdialog_REMOTE_22257.ui b/src/ui/alarmsettingsdialog_REMOTE_22257.ui new file mode 100644 index 0000000..f721017 --- /dev/null +++ b/src/ui/alarmsettingsdialog_REMOTE_22257.ui @@ -0,0 +1,71 @@ + + + + + AlarmSettingsDialog + + + + 0 + 0 + 400 + 300 + + + + Dialog + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + buttonBox + accepted() + AlarmSettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + AlarmSettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/alarmwidget.cpp b/src/ui/alarmwidget.cpp new file mode 100644 index 0000000..c8f5a06 --- /dev/null +++ b/src/ui/alarmwidget.cpp @@ -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; +} diff --git a/src/ui/alarmwidget.h b/src/ui/alarmwidget.h new file mode 100644 index 0000000..afd841f --- /dev/null +++ b/src/ui/alarmwidget.h @@ -0,0 +1,22 @@ +#ifndef ALARMWIDGET_H +#define ALARMWIDGET_H + +#include + +namespace Ui { +class AlarmWidget; +} + +class AlarmWidget : public QWidget +{ + Q_OBJECT + +public: + explicit AlarmWidget(QWidget *parent = nullptr); + ~AlarmWidget(); + +private: + Ui::AlarmWidget *ui; +}; + +#endif // ALARMWIDGET_H diff --git a/src/ui/alarmwidget.ui b/src/ui/alarmwidget.ui new file mode 100644 index 0000000..6699c31 --- /dev/null +++ b/src/ui/alarmwidget.ui @@ -0,0 +1,134 @@ + + + AlarmWidget + + + + 0 + 0 + 357 + 166 + + + + + 0 + 0 + + + + Form + + + false + + + + QFormLayout::AllNonFixedFieldsGrow + + + QFormLayout::DontWrapRows + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + 50 + + + 6 + + + + + Time: + + + + + + + + + + false + + + QDateTimeEdit::DaySection + + + dd.mM.yyyy hh:mm + + + true + + + + + + + Repeating: + + + + + + + false + + + Wee&kly + + + + + + + false + + + Monthly + + + + + + + false + + + Yearly + + + + + + + false + + + Daily + + + true + + + true + + + + + + + Enable + + + + + + + + diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp new file mode 100644 index 0000000..4cf3c07 --- /dev/null +++ b/src/ui/mainwindow.cpp @@ -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); +} diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h new file mode 100644 index 0000000..7d410f8 --- /dev/null +++ b/src/ui/mainwindow.h @@ -0,0 +1,59 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include +#include +#include +#include +#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 diff --git a/src/ui/mainwindow.ui b/src/ui/mainwindow.ui new file mode 100644 index 0000000..04515e1 --- /dev/null +++ b/src/ui/mainwindow.ui @@ -0,0 +1,332 @@ + + + MainWindow + + + + 0 + 0 + 862 + 570 + + + + + 0 + 50 + + + + + 600 + 197 + + + + Smart Home Interface + + + + :/images/UVOSicon.bmp:/images/UVOSicon.bmp + + + + + 0 + 0 + + + + Qt::LeftToRight + + + false + + + + + + + + + + 0 + + + 10 + + + + + + 0 + 0 + + + + QFrame::Box + + + SHinterface + + + + + + + + + + 0 + 0 + + + + Relays + + + + + + + 0 + 0 + + + + + + + + Refesh + + + + + + + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 120 + + + + + 0 + 50 + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 128 + 32 + + + + Apply + + + + + + + + + + 0 + 50 + + + + + 0 + 0 + + + + + 16777215 + 80 + + + + + 0 + 128 + + + + Choose Color + + + + + + + 10 + + + 10 + + + + + + 0 + 50 + + + + + 0 + 48 + + + + ON + + + + + + + + 0 + 50 + + + + + 0 + 48 + + + + OFF + + + + + + + + + + + Desk Light + + + + + + + 254 + + + false + + + Qt::Horizontal + + + + + + + + + Qt::Vertical + + + QSizePolicy::Preferred + + + + 20 + 20 + + + + + + + + Alarms + + + + + + + + 0 + 0 + + + + Qt::RightToLeft + + + Quit + + + + + + + + + + + + RelayScrollBox + QWidget +
relayscrollbox.h
+ 1 +
+
+ + + + +
diff --git a/src/ui/relaydialog.ui b/src/ui/relaydialog.ui new file mode 100644 index 0000000..c1c4cd1 --- /dev/null +++ b/src/ui/relaydialog.ui @@ -0,0 +1,230 @@ + + + RelayDialog + + + + 0 + 0 + 358 + 320 + + + + Advanced Relays + + + + + + Advanced + + + + + + + + 3Dator + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + On + + + + + + + + + Qt::Horizontal + + + + + + + + + 3040 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + On + + + + + + + + + Qt::Horizontal + + + + + + + + + Aux + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + On + + + + + + + + + + + + 0 + + + 0 + + + + + Enterance Watch + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Inside + + + true + + + + + + + Watch + + + true + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + RelayDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RelayDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/relayscrollbox.cpp b/src/ui/relayscrollbox.cpp new file mode 100644 index 0000000..1f14496 --- /dev/null +++ b/src/ui/relayscrollbox.cpp @@ -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) +{ + 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); + } +} + + diff --git a/src/ui/relayscrollbox.h b/src/ui/relayscrollbox.h new file mode 100644 index 0000000..e5ddd13 --- /dev/null +++ b/src/ui/relayscrollbox.h @@ -0,0 +1,40 @@ +#ifndef RELAYSCROLLBOX_H +#define RELAYSCROLLBOX_H + +#include +#include +#include +#include +#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); + void removeRelay(const RelayStore& Realy); + +private: + Ui::RelayScrollBox *ui; +}; + +#endif // RELAYSCROLLBOX_H + + diff --git a/src/ui/relayscrollbox.ui b/src/ui/relayscrollbox.ui new file mode 100644 index 0000000..46e0d44 --- /dev/null +++ b/src/ui/relayscrollbox.ui @@ -0,0 +1,56 @@ + + + RelayScrollBox + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + true + + + + + 0 + 0 + 384 + 284 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + diff --git a/src/ui/relaysettingsdialog.cpp b/src/ui/relaysettingsdialog.cpp new file mode 100644 index 0000000..4c8588d --- /dev/null +++ b/src/ui/relaysettingsdialog.cpp @@ -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; +} diff --git a/src/ui/relaysettingsdialog.h b/src/ui/relaysettingsdialog.h new file mode 100644 index 0000000..ca62dbe --- /dev/null +++ b/src/ui/relaysettingsdialog.h @@ -0,0 +1,24 @@ +#ifndef RELAYSETTINGSDIALOG_H +#define RELAYSETTINGSDIALOG_H + +#include +#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 diff --git a/src/ui/relaysettingsdialog.ui b/src/ui/relaysettingsdialog.ui new file mode 100644 index 0000000..d3b37b5 --- /dev/null +++ b/src/ui/relaysettingsdialog.ui @@ -0,0 +1,207 @@ + + + RelaySettingsDialog + + + + 0 + 0 + 400 + 319 + + + + Relay Settings + + + + :/images/UVOSicon.bmp:/images/UVOSicon.bmp + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + 0 + + + 10 + + + + + Address + + + + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 5 + 0 + + + + Qt::LeftToRight + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Name: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + TextLabel + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + ID: + + + + + + + + + + + + Remove + + + + + + + + + + Alarm + + + + + Timer + + + + + Speaker + + + + + RGB Value + + + + + Temperature + + + + + + + + + + + + + + 0 + 0 + + + + Add + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Ok + + + + + + + + + + + buttonBox + accepted() + RelaySettingsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + RelaySettingsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/ui/relaywidget.cpp b/src/ui/relaywidget.cpp new file mode 100644 index 0000000..458f812 --- /dev/null +++ b/src/ui/relaywidget.cpp @@ -0,0 +1,50 @@ +#include "relaywidget.h" +#include "ui_relaywidget.h" + +#include + +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; +} diff --git a/src/ui/relaywidget.h b/src/ui/relaywidget.h new file mode 100644 index 0000000..44df6ea --- /dev/null +++ b/src/ui/relaywidget.h @@ -0,0 +1,33 @@ +#ifndef RELAYWIDGET_H +#define RELAYWIDGET_H + +#include +#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 diff --git a/src/ui/relaywidget.ui b/src/ui/relaywidget.ui new file mode 100644 index 0000000..f4bbad2 --- /dev/null +++ b/src/ui/relaywidget.ui @@ -0,0 +1,65 @@ + + + RelayWidget + + + + 0 + 0 + 435 + 48 + + + + Form + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + On + + + + + + + true + + + Auto + + + + + + + Settings + + + + + + + + diff --git a/src/ui/sensoractorwidget.cpp b/src/ui/sensoractorwidget.cpp new file mode 100644 index 0000000..506ae7f --- /dev/null +++ b/src/ui/sensoractorwidget.cpp @@ -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; +} diff --git a/src/ui/sensoractorwidget.h b/src/ui/sensoractorwidget.h new file mode 100644 index 0000000..1d0ef66 --- /dev/null +++ b/src/ui/sensoractorwidget.h @@ -0,0 +1,22 @@ +#ifndef SENSORACTORWIDGET_H +#define SENSORACTORWIDGET_H + +#include + +namespace Ui { +class SensorActorWidget; +} + +class SensorActorWidget : public QWidget +{ + Q_OBJECT + +public: + explicit SensorActorWidget(QWidget *parent = nullptr); + ~SensorActorWidget(); + +private: + Ui::SensorActorWidget *ui; +}; + +#endif // SENSORACTORWIDGET_H diff --git a/src/ui/sensoractorwidget.ui b/src/ui/sensoractorwidget.ui new file mode 100644 index 0000000..4e16e0f --- /dev/null +++ b/src/ui/sensoractorwidget.ui @@ -0,0 +1,21 @@ + + + + + SensorActorWidget + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + diff --git a/src/ui/sensorlistwidget.cpp b/src/ui/sensorlistwidget.cpp new file mode 100644 index 0000000..248732f --- /dev/null +++ b/src/ui/sensorlistwidget.cpp @@ -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 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); + } +} + diff --git a/src/ui/sensorlistwidget.h b/src/ui/sensorlistwidget.h new file mode 100644 index 0000000..04bc330 --- /dev/null +++ b/src/ui/sensorlistwidget.h @@ -0,0 +1,18 @@ +#pragma once +#include +#include +#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 sensors); +};