init branch
This commit is contained in:
@ -1,14 +1,50 @@
|
|||||||
#include "alarmsettingsdialog.h"
|
#include "alarmsettingsdialog.h"
|
||||||
#include "ui_alarmsettingsdialog.h"
|
#include "ui_alarmsettingsdialog.h"
|
||||||
|
|
||||||
AlarmSettingsDialog::AlarmSettingsDialog(QWidget *parent) :
|
#include <QFileDialog>
|
||||||
QDialog(parent),
|
|
||||||
ui(new Ui::AlarmSettingsDialog)
|
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);
|
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()
|
AlarmSettingsDialog::~AlarmSettingsDialog()
|
||||||
{
|
{
|
||||||
delete ui;
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,11 @@
|
|||||||
#define ALARMSETTINGSDIALOG_H
|
#define ALARMSETTINGSDIALOG_H
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QTime>
|
||||||
|
#include <QString>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "alarmtime.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class AlarmSettingsDialog;
|
class AlarmSettingsDialog;
|
||||||
@ -11,10 +16,26 @@ class AlarmSettingsDialog : public QDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
AlarmTime* almNight_;
|
||||||
|
AlarmTime* almAlarm_;
|
||||||
|
QSettings* settings_;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AlarmSettingsDialog(QWidget *parent = 0);
|
explicit AlarmSettingsDialog(AlarmTime* almNight, AlarmTime* almAlarm, QSettings* settings, QWidget* parent = nullptr);
|
||||||
~AlarmSettingsDialog();
|
~AlarmSettingsDialog();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void signalAlarmSoundFile(QString fileName);
|
||||||
|
void signalSunrise(bool enabled);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void accept();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void showFileChooser();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::AlarmSettingsDialog *ui;
|
Ui::AlarmSettingsDialog *ui;
|
||||||
};
|
};
|
||||||
|
@ -3,8 +3,7 @@
|
|||||||
AlarmTime::AlarmTime(const QTime time, QObject *parent) : QObject(parent), time_(time)
|
AlarmTime::AlarmTime(const QTime time, QObject *parent) : QObject(parent), time_(time)
|
||||||
{
|
{
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||||
timer.setInterval(500);
|
timer.setInterval(1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AlarmTime::~AlarmTime()
|
AlarmTime::~AlarmTime()
|
||||||
@ -15,21 +14,16 @@ AlarmTime::~AlarmTime()
|
|||||||
void AlarmTime::run()
|
void AlarmTime::run()
|
||||||
{
|
{
|
||||||
abort();
|
abort();
|
||||||
loop.reset(new QEventLoop);
|
|
||||||
|
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
qDebug()<<"Start Alarm Time Manager\n";
|
qDebug()<<"Start Alarm Time Manager\n";
|
||||||
loop->exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AlarmTime::abort()
|
void AlarmTime::abort()
|
||||||
{
|
{
|
||||||
timer.stop();
|
timer.stop();
|
||||||
if (!loop.isNull()){
|
|
||||||
loop->quit();
|
|
||||||
}
|
|
||||||
qDebug()<<"Stop Alarm Time Manager\n";
|
qDebug()<<"Stop Alarm Time Manager\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,10 +17,9 @@ private:
|
|||||||
bool triggerd_ = false;
|
bool triggerd_ = false;
|
||||||
QTime time_;
|
QTime time_;
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
QScopedPointer<QEventLoop> loop;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit AlarmTime(const QTime time = QTime::currentTime(), QObject *parent = 0);
|
explicit AlarmTime(const QTime time = QTime::currentTime(), QObject *parent = nullptr);
|
||||||
~AlarmTime();
|
~AlarmTime();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
#include "microcontroller.h"
|
#include "microcontroller.h"
|
||||||
|
|
||||||
|
|
||||||
class AmpManager : public QObject, public QRunnable
|
class AmpManager : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit AmpManager(Microcontroller *micro, int relayNumber, QObject *parent = 0);
|
explicit AmpManager(Microcontroller *micro, int relayNumber, QObject *parent = nullptr);
|
||||||
~AmpManager();
|
~AmpManager();
|
||||||
|
|
||||||
|
|
||||||
@ -27,6 +27,8 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void run();
|
void run();
|
||||||
void abort();
|
void abort();
|
||||||
|
|
||||||
|
private slots:
|
||||||
void doTick();
|
void doTick();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
52
main.cpp
52
main.cpp
@ -17,7 +17,8 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "relaydialog.h"
|
#include "relaydialog.h"
|
||||||
#include "ampmanager.h"
|
#include "ampmanager.h"
|
||||||
#include "power.h"
|
#include "alarmactions.h"
|
||||||
|
#include "alarmsettingsdialog.h"
|
||||||
|
|
||||||
#define BAUD QSerialPort::Baud38400
|
#define BAUD QSerialPort::Baud38400
|
||||||
|
|
||||||
@ -29,7 +30,7 @@ int main(int argc, char *argv[])
|
|||||||
QCoreApplication::setOrganizationName("UVOS");
|
QCoreApplication::setOrganizationName("UVOS");
|
||||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||||
QCoreApplication::setApplicationName("SHinterface");
|
QCoreApplication::setApplicationName("SHinterface");
|
||||||
QCoreApplication::setApplicationVersion("0.2");
|
QCoreApplication::setApplicationVersion("0.5");
|
||||||
|
|
||||||
QDir::setCurrent(a.applicationDirPath());
|
QDir::setCurrent(a.applicationDirPath());
|
||||||
|
|
||||||
@ -54,8 +55,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//connect to microcontoler
|
//connect to microcontoler
|
||||||
Microcontroller micro;
|
Microcontroller micro;
|
||||||
if(parser.isSet(tcpOption))
|
if(parser.isSet(tcpOption))
|
||||||
@ -89,41 +88,38 @@ int main(int argc, char *argv[])
|
|||||||
else micro.setIODevice(microPort);
|
else micro.setIODevice(microPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
Power power(&settings, µ);
|
AlarmActions alarmActions(&settings, µ);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
AmpManager amp(µ, 0);
|
AmpManager amp(µ, 0);
|
||||||
|
|
||||||
MainWindow w(&settings, µ, parser.isSet(secondaryOption));
|
|
||||||
QObject::connect(µ, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
|
||||||
QObject::connect(µ, SIGNAL(relayStateChanged(std::vector<bool>)), &w, SLOT(relayStateChanged(std::vector<bool>)));
|
|
||||||
|
|
||||||
RelayDialog relayDialog(µ);
|
|
||||||
QObject::connect(µ, SIGNAL(relayStateChanged(std::vector<bool>)), &relayDialog, SLOT(relayStateChanged(std::vector<bool>)));
|
|
||||||
|
|
||||||
//Alarms
|
//Alarms
|
||||||
AlarmTime almNight(settings.value("nightTime").toTime());
|
AlarmTime almNight(settings.value("nightTime").toTime());
|
||||||
|
AlarmTime almAlarm(settings.value("alarmTime").toTime());
|
||||||
|
|
||||||
AlarmTime *almAlarm = new AlarmTime(settings.value("alarmTime").toTime());
|
//mainwindow
|
||||||
QSignalMapper signalMapper;
|
MainWindow w(µ, parser.isSet(secondaryOption));
|
||||||
|
QObject::connect(µ, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
||||||
|
QObject::connect(µ, SIGNAL(relayStateChanged(std::vector<bool>)), &w, SLOT(relayStateChanged(std::vector<bool>)));
|
||||||
|
QObject::connect(µ, SIGNAL(auxStateChanged(int)), &w, SLOT(auxStateChanged(int)));
|
||||||
|
|
||||||
|
//dialogs
|
||||||
|
AlarmSettingsDialog alarmDialog(&almNight, &almAlarm, &settings, &w);
|
||||||
|
|
||||||
|
RelayDialog relayDialog(µ, &w);
|
||||||
|
QObject::connect(µ, SIGNAL(relayStateChanged(std::vector<bool>)), &relayDialog, SLOT(relayStateChanged(std::vector<bool>)));
|
||||||
|
|
||||||
if(!parser.isSet(secondaryOption))
|
if(!parser.isSet(secondaryOption))
|
||||||
{
|
{
|
||||||
|
|
||||||
QObject::connect(&almNight, SIGNAL(trigger()), &power, SLOT(syncoff()));
|
QObject::connect(&almNight, SIGNAL(trigger()), &alarmActions, SLOT(syncoff()));
|
||||||
QObject::connect(&w, SIGNAL(signalAlmNightChanged(QTime)), &almNight, SLOT(changeTime(QTime)));
|
QObject::connect(&w, SIGNAL(signalAlmNightChanged(QTime)), &almNight, SLOT(changeTime(QTime)));
|
||||||
QObject::connect(&w, SIGNAL(signalAlmNightStateChanged(int)), &almNight, SLOT(runOrAbort(int)));
|
QObject::connect(&w, SIGNAL(signalAlmNightStateChanged(int)), &almNight, SLOT(runOrAbort(int)));
|
||||||
//QMetaObject::invokeMethod(&almNight, "run", Qt::QueuedConnection );
|
almNight.run();
|
||||||
|
|
||||||
|
QObject::connect(&almAlarm, &AlarmTime::trigger, µ, &Microcontroller::startSunrise);
|
||||||
QObject::connect(almAlarm, SIGNAL(trigger()), &signalMapper, SLOT(map()));
|
QObject::connect(&w, SIGNAL(signalAlmAlarmChanged(QTime)), &almAlarm, SLOT(changeTime(QTime)));
|
||||||
signalMapper.setMapping(almAlarm, 4);
|
QObject::connect(&w, SIGNAL(signalAlmAlarmStateChanged(int)), &almAlarm, SLOT(runOrAbort(int)));
|
||||||
QObject::connect(&signalMapper, SIGNAL(mapped(int)), µ, SLOT(setPattern(int)));
|
almAlarm.run();
|
||||||
QObject::connect(&w, SIGNAL(signalAlmAlarmChanged(QTime)), almAlarm, SLOT(changeTime(QTime)));
|
|
||||||
QObject::connect(&w, SIGNAL(signalAlmAlarmStateChanged(int)), almAlarm, SLOT(runOrAbort(int)));
|
|
||||||
//QMetaObject::invokeMethod(almAlarm, "run", Qt::QueuedConnection );
|
|
||||||
|
|
||||||
//Amplifyer
|
//Amplifyer
|
||||||
QObject::connect(&w, SIGNAL(signalAmpOn()), &, SLOT(run()));
|
QObject::connect(&w, SIGNAL(signalAmpOn()), &, SLOT(run()));
|
||||||
@ -131,12 +127,12 @@ int main(int argc, char *argv[])
|
|||||||
QMetaObject::invokeMethod(&, "run", Qt::QueuedConnection );
|
QMetaObject::invokeMethod(&, "run", Qt::QueuedConnection );
|
||||||
}
|
}
|
||||||
|
|
||||||
//Advanced Relays
|
//show dialogs
|
||||||
QObject::connect(&w, SIGNAL(showAdvRelayDialog()), &relayDialog, SLOT(show()));
|
QObject::connect(&w, SIGNAL(showAdvRelayDialog()), &relayDialog, SLOT(show()));
|
||||||
|
QObject::connect(&w, &MainWindow::showAlmSettingsDialog, &alarmDialog, &AlarmSettingsDialog::show);
|
||||||
|
|
||||||
QMetaObject::invokeMethod(µ, "run", Qt::QueuedConnection );
|
QMetaObject::invokeMethod(µ, "run", Qt::QueuedConnection );
|
||||||
|
|
||||||
QMetaObject::invokeMethod(&w, "postActivate", Qt::QueuedConnection );
|
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
@ -1,21 +1,16 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(QSettings *settings, Microcontroller *micro , bool isRemoteMode , QWidget *parent) :
|
MainWindow::MainWindow(Microcontroller *micro , bool isRemoteMode , QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
colorChooser(this),
|
colorChooser(this),
|
||||||
_settings(settings),
|
|
||||||
_micro(micro)
|
_micro(micro)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
if(!_micro->connected()) ui->label_serialRecive->setText("No IO Port! Debug only.");
|
if(!_micro->connected()) ui->label_serialRecive->setText("No IO Port! Debug only.");
|
||||||
|
|
||||||
//Settings
|
|
||||||
ui->alarmTime->setTime(_settings->value("alarmTime").toTime());
|
|
||||||
ui->nightTime->setTime(_settings->value("nightTime").toTime());
|
|
||||||
ui->checkBox_alarm->setChecked(_settings->value("alarmOn").toBool());
|
|
||||||
|
|
||||||
//RGB Leds
|
//RGB Leds
|
||||||
connect(ui->presettApply, SIGNAL(clicked()), this, SLOT(slotApplyPreset()));
|
connect(ui->presettApply, SIGNAL(clicked()), this, SLOT(slotApplyPreset()));
|
||||||
@ -32,11 +27,16 @@ MainWindow::MainWindow(QSettings *settings, Microcontroller *micro , bool isRemo
|
|||||||
new QListWidgetItem(tr("Pattern 4 Sunrise"), 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); });
|
||||||
|
|
||||||
//Relays
|
//Relays
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_amp);
|
_relayCheckBoxes.push_back(ui->checkBox_amp);
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_bspeaker);
|
_relayCheckBoxes.push_back(ui->checkBox_bspeaker);
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_inf);
|
_relayCheckBoxes.push_back(ui->checkBox_inf);
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_aircon);
|
_relayCheckBoxes.push_back(ui->checkBox_SolderingIorn);
|
||||||
|
_relayCheckBoxes.push_back(ui->checkBox_testEquitmpent);
|
||||||
|
|
||||||
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) connect(_relayCheckBoxes[i], SIGNAL(stateChanged(int)), this, SLOT(relayCheckBoxToggeled(int)));
|
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) connect(_relayCheckBoxes[i], SIGNAL(stateChanged(int)), this, SLOT(relayCheckBoxToggeled(int)));
|
||||||
|
|
||||||
@ -47,37 +47,17 @@ MainWindow::MainWindow(QSettings *settings, Microcontroller *micro , bool isRemo
|
|||||||
//Bedroom Speakers
|
//Bedroom Speakers
|
||||||
if(!isRemoteMode)connect(ui->checkBox_bspeakerAuto, SIGNAL(stateChanged(int)), this, SLOT(slotBSpeakerAutoToggle(int)));
|
if(!isRemoteMode)connect(ui->checkBox_bspeakerAuto, SIGNAL(stateChanged(int)), this, SLOT(slotBSpeakerAutoToggle(int)));
|
||||||
|
|
||||||
|
|
||||||
//Infinity Mirror
|
//Infinity Mirror
|
||||||
if(!isRemoteMode)connect(ui->checkBox_infAuto, SIGNAL(stateChanged(int)), this, SLOT(slotInfMirrorAutoToggle(int)));
|
if(!isRemoteMode)connect(ui->checkBox_infAuto, SIGNAL(stateChanged(int)), this, SLOT(slotInfMirrorAutoToggle(int)));
|
||||||
|
|
||||||
if(!isRemoteMode)
|
|
||||||
{
|
|
||||||
//Alarm
|
|
||||||
connect(ui->alarmTime, SIGNAL(timeChanged(QTime)), this, SLOT(slotChangedAlarmTime(QTime)));
|
|
||||||
connect(ui->checkBox_alarm, SIGNAL(stateChanged(int)), this, SIGNAL(signalAlmAlarmStateChanged(int)));
|
|
||||||
connect(ui->checkBox_alarm, SIGNAL(stateChanged(int)), this, SLOT(saveAlarmState(int)));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Night Time
|
|
||||||
connect(ui->nightTime, SIGNAL(timeChanged(QTime)), this, SLOT(slotChangedNightTime(QTime)));
|
|
||||||
connect(ui->checkBox_nightTime, SIGNAL(stateChanged(int)), this, SIGNAL(signalAlmNightStateChanged(int)));
|
|
||||||
}
|
|
||||||
else remoteMode();
|
else remoteMode();
|
||||||
//adv relays
|
|
||||||
|
//dialogs
|
||||||
connect(ui->button_advRelay, SIGNAL(clicked()), this, SIGNAL(showAdvRelayDialog()));
|
connect(ui->button_advRelay, SIGNAL(clicked()), this, SIGNAL(showAdvRelayDialog()));
|
||||||
|
connect(ui->pushButton_alarms, SIGNAL(clicked()), this, SIGNAL(showAlmSettingsDialog()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::remoteMode()
|
void MainWindow::remoteMode()
|
||||||
{
|
{
|
||||||
ui->alarmTime->setEnabled(false);
|
|
||||||
ui->checkBox_alarm->setEnabled(false);
|
|
||||||
ui->pushButton_alarm->setEnabled(false);
|
|
||||||
|
|
||||||
ui->nightTime->setEnabled(false);
|
|
||||||
ui->checkBox_nightTime->setEnabled(false);
|
|
||||||
ui->label_nightTime->setEnabled(false);
|
|
||||||
|
|
||||||
ui->checkBox_ampAuto->setEnabled(false);
|
ui->checkBox_ampAuto->setEnabled(false);
|
||||||
ui->checkBox_ampAuto->setChecked(false);
|
ui->checkBox_ampAuto->setChecked(false);
|
||||||
@ -90,15 +70,8 @@ void MainWindow::remoteMode()
|
|||||||
ui->checkBox_infAuto->setChecked(false);
|
ui->checkBox_infAuto->setChecked(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::postActivate()
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod( this, "signalAlmNightStateChanged", Qt::QueuedConnection, Q_ARG(int, ui->checkBox_nightTime->checkState()) );
|
|
||||||
signalAlmAlarmStateChanged(ui->checkBox_alarm->checkState());
|
|
||||||
}
|
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
{
|
{
|
||||||
_settings->sync();
|
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +118,7 @@ void MainWindow::slotBSpeakerAutoToggle(int state)
|
|||||||
|
|
||||||
void MainWindow::slotDoorOpenTimeout()
|
void MainWindow::slotDoorOpenTimeout()
|
||||||
{
|
{
|
||||||
ui->checkBox_doorOpen->setChecked(true);
|
//ui->checkBox_doorOpen->setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::slotInfMirrorAutoToggle(int state)
|
void MainWindow::slotInfMirrorAutoToggle(int state)
|
||||||
@ -157,21 +130,11 @@ void MainWindow::slotInfMirrorAutoToggle(int state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::slotChangedAlarmTime(const QTime time)
|
void MainWindow::auxStateChanged(int value)
|
||||||
{
|
{
|
||||||
_settings->setValue("alarmTime", time);
|
ui->horizontalSlider_deskLight->blockSignals(true);
|
||||||
signalAlmAlarmChanged(time);
|
ui->horizontalSlider_deskLight->setValue(value);
|
||||||
}
|
ui->horizontalSlider_deskLight->blockSignals(false);
|
||||||
|
|
||||||
void MainWindow::saveAlarmState(int state)
|
|
||||||
{
|
|
||||||
_settings->setValue("alarmOn", state);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::slotChangedNightTime(const QTime time)
|
|
||||||
{
|
|
||||||
_settings->setValue("nightTime", time);
|
|
||||||
signalAlmNightChanged(time);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::slotAmpAutoToggle(int state)
|
void MainWindow::slotAmpAutoToggle(int state)
|
||||||
|
21
mainwindow.h
21
mainwindow.h
@ -4,7 +4,6 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QSettings>
|
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "alarmtime.h"
|
#include "alarmtime.h"
|
||||||
@ -21,7 +20,7 @@ class MainWindow : public QMainWindow
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindow(QSettings *settings, Microcontroller *micro, bool isRemoteMode = false, QWidget *parent = 0);
|
explicit MainWindow(Microcontroller *micro, bool isRemoteMode = false, QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
|
||||||
@ -31,8 +30,6 @@ private:
|
|||||||
|
|
||||||
QColorDialog colorChooser;
|
QColorDialog colorChooser;
|
||||||
|
|
||||||
QSettings *_settings;
|
|
||||||
|
|
||||||
Microcontroller *_micro;
|
Microcontroller *_micro;
|
||||||
|
|
||||||
std::vector<QAbstractButton*> _relayCheckBoxes;
|
std::vector<QAbstractButton*> _relayCheckBoxes;
|
||||||
@ -44,18 +41,12 @@ signals:
|
|||||||
void signalAmpOn();
|
void signalAmpOn();
|
||||||
void signalAmpOff();
|
void signalAmpOff();
|
||||||
|
|
||||||
void signalAlmNightStateChanged(int state);
|
void showAlmSettingsDialog();
|
||||||
void signalAlmNightChanged(const QTime time);
|
|
||||||
|
|
||||||
void signalAlmAlarmStateChanged(int state);
|
|
||||||
void signalAlmAlarmChanged(const QTime time);
|
|
||||||
|
|
||||||
void showAdvRelayDialog();
|
void showAdvRelayDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void postActivate();
|
|
||||||
|
|
||||||
//RGB
|
//RGB
|
||||||
void slotChangedRgb(const QColor color);
|
void slotChangedRgb(const QColor color);
|
||||||
void slotApplyPreset();
|
void slotApplyPreset();
|
||||||
@ -70,19 +61,13 @@ private slots:
|
|||||||
void slotBSpeakerAutoToggle(int state);
|
void slotBSpeakerAutoToggle(int state);
|
||||||
void slotInfMirrorAutoToggle(int state);
|
void slotInfMirrorAutoToggle(int state);
|
||||||
|
|
||||||
//Alarm
|
|
||||||
void slotChangedAlarmTime(const QTime time);
|
|
||||||
void saveAlarmState(int state);
|
|
||||||
|
|
||||||
//Night
|
|
||||||
void slotChangedNightTime(const QTime time);
|
|
||||||
|
|
||||||
//door
|
//door
|
||||||
void slotDoorOpenTimeout();
|
void slotDoorOpenTimeout();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void relayStateChanged(std::vector<bool> relayStates);
|
void relayStateChanged(std::vector<bool> relayStates);
|
||||||
|
void auxStateChanged(int value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,7 +42,25 @@ void Microcontroller::changeRgbColor(const QColor color)
|
|||||||
std::cout<<buffer;
|
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)
|
void Microcontroller::setPattern(int pattern)
|
||||||
|
{
|
||||||
|
if(_port != nullptr)
|
||||||
{
|
{
|
||||||
char buffer[4];
|
char buffer[4];
|
||||||
std::cout<<"pattern apply\n";
|
std::cout<<"pattern apply\n";
|
||||||
@ -50,6 +68,12 @@ void Microcontroller::setPattern(int pattern)
|
|||||||
int length = sprintf(buffer, "%d \n", pattern);
|
int length = sprintf(buffer, "%d \n", pattern);
|
||||||
_port->write(buffer, length);
|
_port->write(buffer, length);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Microcontroller::startSunrise()
|
||||||
|
{
|
||||||
|
setPattern(4);
|
||||||
|
}
|
||||||
|
|
||||||
bool Microcontroller::connected()
|
bool Microcontroller::connected()
|
||||||
{
|
{
|
||||||
@ -72,9 +96,13 @@ void Microcontroller::run()
|
|||||||
|
|
||||||
void Microcontroller::requestState()
|
void Microcontroller::requestState()
|
||||||
{
|
{
|
||||||
if(_port != nullptr) _port->write("relay state\n", sizeof("relay state\n"));
|
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()
|
void Microcontroller::abort()
|
||||||
{
|
{
|
||||||
@ -121,20 +149,27 @@ void Microcontroller::processMicroReturn()
|
|||||||
|
|
||||||
workbuff.remove(0, 2);
|
workbuff.remove(0, 2);
|
||||||
QStringList workbufList = workbuff.split(',');
|
QStringList workbufList = workbuff.split(',');
|
||||||
int numberOfRelays = workbufList[0].toInt();
|
|
||||||
if(workbufList.size() >= numberOfRelays+1)
|
//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)
|
||||||
{
|
{
|
||||||
bool hasChanged = false;
|
|
||||||
_relayStates.resize(numberOfRelays, false);
|
_relayStates.resize(numberOfRelays, false);
|
||||||
for(int i = 0; i < numberOfRelays; i++)
|
for(uint_fast8_t i = 0; i < numberOfRelays; i++)
|
||||||
{
|
{
|
||||||
if(_relayStates[i] != (bool)workbufList[i+1].toInt())
|
if(_relayStates[i] != static_cast<bool>(workbufList[i+2].toInt()))
|
||||||
{
|
{
|
||||||
_relayStates[i] = (bool)workbufList[i+1].toInt();
|
_relayStates[i] = static_cast<bool>(workbufList[i+2].toInt());
|
||||||
hasChanged = true;
|
relayStateChanged(Relay(this, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(hasChanged)relayStateChanged(_relayStates);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(workbuff.contains("Door Open Warning"))
|
else if(workbuff.contains("Door Open Warning"))
|
||||||
@ -143,7 +178,7 @@ void Microcontroller::processMicroReturn()
|
|||||||
}
|
}
|
||||||
else if(workbuff.size() > 2 && workbuff[0]=='D' && workbuff[1]=='2')
|
else if(workbuff.size() > 2 && workbuff[0]=='D' && workbuff[1]=='2')
|
||||||
{
|
{
|
||||||
if(workbuff[3] == 'O') doorOpen(1);
|
if(workbuff[3] == 'O') doorOpened(1);
|
||||||
else if(workbuff[3] == 'C') doorClosed(1);
|
else if(workbuff[3] == 'C') doorClosed(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,21 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "relay.h"
|
||||||
|
|
||||||
class Microcontroller : public QObject
|
class Microcontroller : public QObject
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static constexpr char AMP_RELAY = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<bool> _relayStates; //ugh vector of bools
|
std::vector<bool> _relayStates; //ugh vector of bools
|
||||||
|
int _auxState = 0;
|
||||||
QIODevice* _port = nullptr;
|
QIODevice* _port = nullptr;
|
||||||
|
|
||||||
QScopedPointer<QEventLoop> loop;
|
QScopedPointer<QEventLoop> loop;
|
||||||
@ -41,10 +49,15 @@ public slots:
|
|||||||
void rgbOff();
|
void rgbOff();
|
||||||
void changeRgbColor(const QColor color);
|
void changeRgbColor(const QColor color);
|
||||||
void setPattern(int pattern);
|
void setPattern(int pattern);
|
||||||
|
void startSunrise();
|
||||||
|
|
||||||
|
void requestRelayList();
|
||||||
|
|
||||||
|
void setAuxPwm(int duty);
|
||||||
|
|
||||||
void relayToggle(int state, int id);
|
|
||||||
void relayOn(int relay);
|
void relayOn(int relay);
|
||||||
void relayOff(int relay);
|
void relayOff(int relay);
|
||||||
|
void relayToggle(bool state, int id);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
void abort();
|
void abort();
|
||||||
@ -52,7 +65,9 @@ public slots:
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void textRecived(const QString string);
|
void textRecived(const QString string);
|
||||||
void relayStateChanged(std::vector<bool> relayStates);
|
void relayStateChanged(Relay relay);
|
||||||
|
void auxStateChanged(int value);
|
||||||
|
void gotRelayList(std::vector<Relay> relays);
|
||||||
void doorOpenTimeout();
|
void doorOpenTimeout();
|
||||||
void doorOpened(int id);
|
void doorOpened(int id);
|
||||||
void doorClosed(int id);
|
void doorClosed(int id);
|
||||||
|
48
relay.h
48
relay.h
@ -1,14 +1,42 @@
|
|||||||
#pragma once
|
#ifndef RELAY_H
|
||||||
|
#define RELAY_H
|
||||||
|
|
||||||
#include "serial_io.h"
|
#include<stdint.h>
|
||||||
|
#include<QObject>
|
||||||
|
#include<QString>
|
||||||
|
#include<vector>
|
||||||
|
#include<memory>
|
||||||
|
|
||||||
static void relay_toggle(bool state, int id, int serial)
|
#include"actor.h"
|
||||||
|
|
||||||
|
class Microcontroller;
|
||||||
|
|
||||||
|
class Relay : public QObject
|
||||||
{
|
{
|
||||||
char buffer[8];
|
Q_OBJECT
|
||||||
int length = sprintf(buffer, "%d \n", id);
|
private:
|
||||||
state ? write(serial, "relay on ", sizeof("relay on ")-1) : write(serial, "relay off ", sizeof("relay off ")-1);
|
Microcontroller* micro_;
|
||||||
state ? std::cout<<"relay on " : std::cout<<"relay off ";
|
QString name_;
|
||||||
std::cout<<buffer;
|
bool state_ = false;
|
||||||
sWrite(serial, buffer, length);
|
uint8_t id_;
|
||||||
}
|
uint16_t address_;
|
||||||
|
std::vector< std::unique_ptr<Actor> > actors_;
|
||||||
|
bool actorsActive_ = true;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void on();
|
||||||
|
void off();
|
||||||
|
void toggle();
|
||||||
|
|
||||||
|
public:
|
||||||
|
Relay(Microcontroller* micro, uint8_t id, QString name = "", uint16_t address = 0, QObject *parent = nullptr);
|
||||||
|
void addActor(std::unique_ptr<Actor> actor);
|
||||||
|
void setState(bool state);
|
||||||
|
bool hasActors();
|
||||||
|
void setActorsActive(bool in);
|
||||||
|
QString getName();
|
||||||
|
void setName(QString name);
|
||||||
|
std::vector< std::unique_ptr<Actor> >* getActors();
|
||||||
|
~Relay();
|
||||||
|
};
|
||||||
|
#endif // RELAY_H
|
||||||
|
@ -10,13 +10,10 @@ RelayDialog::RelayDialog(Microcontroller *micro, QWidget *parent) :
|
|||||||
|
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_R0);
|
_relayCheckBoxes.push_back(ui->checkBox_R0);
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_R1);
|
_relayCheckBoxes.push_back(ui->checkBox_R1);
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_R2);
|
|
||||||
_relayCheckBoxes.push_back(ui->checkBox_R3);
|
|
||||||
|
|
||||||
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) connect(_relayCheckBoxes[i], SIGNAL(stateChanged(int)), this, SLOT(relayCheckBoxToggeled(int)));
|
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) connect(_relayCheckBoxes[i], SIGNAL(stateChanged(int)), this, SLOT(relayCheckBoxToggeled(int)));
|
||||||
|
|
||||||
_micro->relayOn(STARTING_RELAY);
|
_micro->relayOn(STARTING_RELAY);
|
||||||
_micro->relayOn(STARTING_RELAY+1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,12 +26,24 @@ RelayDialog::~RelayDialog()
|
|||||||
void RelayDialog::relayCheckBoxToggeled(int state)
|
void RelayDialog::relayCheckBoxToggeled(int state)
|
||||||
{
|
{
|
||||||
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
||||||
if(_relayCheckBoxes[i] == sender())_micro->relayToggle(state, i+STARTING_RELAY);
|
{
|
||||||
|
|
||||||
|
if(_relayCheckBoxes[i] == sender())
|
||||||
|
{
|
||||||
|
std::cerr<<state<<" "<<i<<std::endl;
|
||||||
|
if(state == 2 && i == 0)
|
||||||
|
{
|
||||||
|
std::cerr<<"primeing lambda\n";
|
||||||
|
QTimer::singleShot(3600000, _micro, [this](){ _micro->relayOff(STARTING_RELAY); _relayCheckBoxes[0]->setChecked(false);});
|
||||||
|
}
|
||||||
|
_micro->relayToggle(state, i+STARTING_RELAY);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RelayDialog::relayStateChanged(std::vector<bool> relayStates)
|
void RelayDialog::relayStateChanged(std::vector<bool> relayStates)
|
||||||
{
|
{
|
||||||
if(relayStates.size() >= STARTING_RELAY+4) for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
if(relayStates.size() > STARTING_RELAY) for(unsigned int i = 0; i < relayStates.size()-STARTING_RELAY; i++)
|
||||||
{
|
{
|
||||||
_relayCheckBoxes[i]->blockSignals(true);
|
_relayCheckBoxes[i]->blockSignals(true);
|
||||||
_relayCheckBoxes[i]->setChecked(relayStates[i+STARTING_RELAY]);
|
_relayCheckBoxes[i]->setChecked(relayStates[i+STARTING_RELAY]);
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
#include "microcontroller.h"
|
#include "microcontroller.h"
|
||||||
|
|
||||||
#define STARTING_RELAY 4
|
#define STARTING_RELAY 5
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class RelayDialog;
|
class RelayDialog;
|
||||||
|
Reference in New Issue
Block a user