158 lines
4.8 KiB
C++
158 lines
4.8 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.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.");
|
|
|
|
|
|
//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); });
|
|
|
|
//Relays
|
|
_relayCheckBoxes.push_back(ui->checkBox_amp);
|
|
_relayCheckBoxes.push_back(ui->checkBox_bspeaker);
|
|
_relayCheckBoxes.push_back(ui->checkBox_inf);
|
|
_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)));
|
|
|
|
//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)));
|
|
else remoteMode();
|
|
|
|
//dialogs
|
|
connect(ui->button_advRelay, SIGNAL(clicked()), this, SIGNAL(showAdvRelayDialog()));
|
|
connect(ui->pushButton_alarms, SIGNAL(clicked()), this, SIGNAL(showAlmSettingsDialog()));
|
|
}
|
|
|
|
void MainWindow::remoteMode()
|
|
{
|
|
|
|
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);
|
|
}
|
|
|
|
MainWindow::~MainWindow()
|
|
{
|
|
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::auxStateChanged(int value)
|
|
{
|
|
ui->horizontalSlider_deskLight->blockSignals(true);
|
|
ui->horizontalSlider_deskLight->setValue(value);
|
|
ui->horizontalSlider_deskLight->blockSignals(false);
|
|
}
|
|
|
|
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);
|
|
}
|