195 lines
6.0 KiB
C++
195 lines
6.0 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
MainWindow::MainWindow(QSettings *settings, Microcontroller *micro , bool isRemoteMode , QWidget *parent) :
|
|
QMainWindow(parent),
|
|
ui(new Ui::MainWindow),
|
|
colorChooser(this),
|
|
_settings(settings),
|
|
_micro(micro)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
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
|
|
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);
|
|
|
|
|
|
//Relays
|
|
_relayCheckBoxes.push_back(ui->checkBox_amp);
|
|
_relayCheckBoxes.push_back(ui->checkBox_bspeaker);
|
|
_relayCheckBoxes.push_back(ui->checkBox_inf);
|
|
_relayCheckBoxes.push_back(ui->checkBox_aircon);
|
|
|
|
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) connect(_relayCheckBoxes[i], SIGNAL(stateChanged(int)), this, SLOT(relayCheckBoxToggeled(int)));
|
|
|
|
//Amp
|
|
if(!isRemoteMode)connect(ui->checkBox_ampAuto, SIGNAL(stateChanged(int)), this, SLOT(slotAmpAutoToggle(int)));
|
|
|
|
|
|
//Bedroom Speakers
|
|
if(!isRemoteMode)connect(ui->checkBox_bspeakerAuto, SIGNAL(stateChanged(int)), this, SLOT(slotBSpeakerAutoToggle(int)));
|
|
|
|
|
|
//Infinity Mirror
|
|
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();
|
|
//adv relays
|
|
connect(ui->button_advRelay, SIGNAL(clicked()), this, SIGNAL(showAdvRelayDialog()));
|
|
}
|
|
|
|
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->setChecked(false);
|
|
ui->checkBox_bspeakerAuto->setEnabled(false);
|
|
ui->checkBox_amp->setEnabled(true);
|
|
ui->checkBox_bspeaker->setEnabled(true);
|
|
ui->checkBox_inf->setEnabled(true);
|
|
ui->checkBox_inf->setChecked(false);
|
|
ui->checkBox_infAuto->setEnabled(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()
|
|
{
|
|
_settings->sync();
|
|
delete ui;
|
|
}
|
|
|
|
void MainWindow::slotChangedRgb(const QColor color)
|
|
{
|
|
_micro->changeRgbColor(color);
|
|
if( ui->checkBox_infAuto->isChecked() )
|
|
{
|
|
if( color.redF() < 0.2 && color.greenF() < 0.2 && color.blueF() > 0.8 )
|
|
{
|
|
qDebug()<<"Auto turn on inf mirror\n";
|
|
_micro->relayOn(2);
|
|
}
|
|
else _micro->relayOff(2);
|
|
}
|
|
}
|
|
|
|
|
|
void MainWindow::slotApplyPreset()
|
|
{
|
|
if(ui->listWidget_patern->selectedItems().count() == 1) _micro->setPattern(ui->listWidget_patern->currentRow());
|
|
}
|
|
|
|
void MainWindow::relayCheckBoxToggeled(int state)
|
|
{
|
|
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
|
if(_relayCheckBoxes[i] == sender()) _micro->relayToggle(state, i);
|
|
}
|
|
|
|
void MainWindow::relayStateChanged(std::vector<bool> relayStates)
|
|
{
|
|
if(relayStates.size() >= 4) for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
|
{
|
|
_relayCheckBoxes[i]->blockSignals(true);
|
|
_relayCheckBoxes[i]->setChecked(relayStates[i]);
|
|
_relayCheckBoxes[i]->blockSignals(false);
|
|
}
|
|
}
|
|
|
|
void MainWindow::slotBSpeakerAutoToggle(int state)
|
|
{
|
|
ui->checkBox_bspeaker->setEnabled(!state);
|
|
}
|
|
|
|
void MainWindow::slotDoorOpenTimeout()
|
|
{
|
|
ui->checkBox_doorOpen->setChecked(true);
|
|
}
|
|
|
|
void MainWindow::slotInfMirrorAutoToggle(int state)
|
|
{
|
|
ui->checkBox_inf->setEnabled(!state);
|
|
if(!state)
|
|
{
|
|
_micro->relayToggle(ui->checkBox_inf->isChecked(), 2);
|
|
}
|
|
}
|
|
|
|
void MainWindow::slotChangedAlarmTime(const QTime time)
|
|
{
|
|
_settings->setValue("alarmTime", time);
|
|
signalAlmAlarmChanged(time);
|
|
}
|
|
|
|
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)
|
|
{
|
|
ui->checkBox_amp->setEnabled(!state);
|
|
if(state)
|
|
{
|
|
signalAmpOn();
|
|
}
|
|
else
|
|
{
|
|
signalAmpOff();
|
|
_micro->relayToggle(ui->checkBox_amp->checkState(), 0);
|
|
}
|
|
}
|
|
|
|
void MainWindow::changeHeaderLableText(const QString string)
|
|
{
|
|
ui->label_serialRecive->setText(string);
|
|
}
|