replace Arecord with Qtmultimedia (requiers pulse?)
This commit is contained in:
parent
a82a9459bc
commit
1dd7aca03b
@ -4,9 +4,7 @@
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui widgets network serialport
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT +=
|
||||
QT += core gui widgets network serialport multimedia
|
||||
|
||||
TARGET = SHinterface
|
||||
TEMPLATE = app
|
||||
@ -21,14 +19,22 @@ DEFINES += QT_DEPRECATED_WARNINGS
|
||||
|
||||
SOURCES += main.cpp mainwindow.cpp ampmanager.cpp alarmtime.cpp \
|
||||
microcontroller.cpp \
|
||||
relaydialog.cpp
|
||||
relaydialog.cpp \
|
||||
alarmsettingsdialog.cpp \
|
||||
power.cpp
|
||||
|
||||
HEADERS += mainwindow.h \
|
||||
ampmanager.h \
|
||||
relay.h \
|
||||
alarmtime.h \
|
||||
microcontroller.h \
|
||||
relaydialog.h
|
||||
relaydialog.h \
|
||||
alarmsettingsdialog.h \
|
||||
power.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
relaydialog.ui
|
||||
relaydialog.ui \
|
||||
alarmsettingsdialog.ui
|
||||
|
||||
RESOURCES += \
|
||||
resources.qrc
|
||||
|
@ -1,38 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<author/>
|
||||
<comment/>
|
||||
<exportmacro/>
|
||||
<class>AlarmSettingsDialog</class>
|
||||
<widget name="AlarmSettingsDialog" class="QDialog">
|
||||
<widget class="QDialog" name="AlarmSettingsDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>423</width>
|
||||
<height>281</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<widget name="buttonBox" class="QDialogButtonBox">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>240</y>
|
||||
<width>341</width>
|
||||
<height>32</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Sound File:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Change</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Sunrise</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox">
|
||||
<property name="text">
|
||||
<string>Enable</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<pixmapfunction/>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
@ -1,19 +1,28 @@
|
||||
#include "ampmanager.h"
|
||||
|
||||
AmpManager::AmpManager(Microcontroller *micro, int relayNumber, QObject *parent) : QObject(parent), _micro(micro), _relayNumber(relayNumber)
|
||||
AmpManager::AmpManager(Microcontroller *micro, int relayNumber, QAudioDeviceInfo device, QObject *parent) : QObject(parent), _micro(micro), _relayNumber(relayNumber)
|
||||
{
|
||||
silenceCount = 0;
|
||||
QAudioFormat format;
|
||||
format.setSampleRate(8000);
|
||||
format.setChannelCount(1);
|
||||
format.setSampleSize(8);
|
||||
format.setCodec("audio/pcm");
|
||||
format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
format.setSampleType(QAudioFormat::UnSignedInt);
|
||||
|
||||
_audioDevice = new QAudioInput(device/*, format*/);
|
||||
}
|
||||
|
||||
AmpManager::~AmpManager()
|
||||
{
|
||||
abort();
|
||||
delete _audioDevice;
|
||||
}
|
||||
|
||||
void AmpManager::run()
|
||||
{
|
||||
abort();
|
||||
arecord.start( "arecord -D front -" );
|
||||
_ioDevice = _audioDevice->start();
|
||||
loop.reset(new QEventLoop);
|
||||
QTimer timer;
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||
@ -29,18 +38,17 @@ void AmpManager::run()
|
||||
|
||||
void AmpManager::abort()
|
||||
{
|
||||
if (!loop.isNull()){
|
||||
loop->quit();
|
||||
}
|
||||
if(arecord.state() == QProcess::Running)arecord.close();
|
||||
if (!loop.isNull())loop->quit();
|
||||
if(_audioDevice->error() == 0)_audioDevice->stop();
|
||||
if(_ioDevice != nullptr)delete _ioDevice;
|
||||
qDebug()<<"Stop Auto Amp Manager\n";
|
||||
}
|
||||
|
||||
void AmpManager::doTick()
|
||||
{
|
||||
if(arecord.state() == QProcess::Running)
|
||||
if(_audioDevice->error() == 0 && _ioDevice != nullptr)
|
||||
{
|
||||
QByteArray buffer = arecord.readAllStandardOutput();
|
||||
QByteArray buffer = _ioDevice->readAll();
|
||||
for(long i = 0; i < buffer.size(); i++)
|
||||
{
|
||||
if((uint8_t) buffer.at(i) != 128)
|
||||
@ -60,6 +68,6 @@ void AmpManager::doTick()
|
||||
_micro->relayOn(_relayNumber);
|
||||
relayState = true;
|
||||
}
|
||||
silenceCount ++;
|
||||
silenceCount++;
|
||||
}
|
||||
}
|
||||
|
10
ampmanager.h
10
ampmanager.h
@ -8,9 +8,11 @@
|
||||
#include <QScopedPointer>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <QProcess>
|
||||
#include <QByteArray>
|
||||
#include <QtDebug>
|
||||
#include <QAudioInput>
|
||||
#include <QAudioDeviceInfo>
|
||||
#include <QIODevice>
|
||||
|
||||
#include "microcontroller.h"
|
||||
|
||||
@ -19,7 +21,7 @@ class AmpManager : public QObject, public QRunnable
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AmpManager(Microcontroller *micro, int relayNumber, QObject *parent = 0);
|
||||
explicit AmpManager(Microcontroller *micro, int relayNumber, QAudioDeviceInfo device, QObject *parent = 0);
|
||||
~AmpManager();
|
||||
|
||||
|
||||
@ -36,8 +38,8 @@ private:
|
||||
Microcontroller *_micro;
|
||||
int _relayNumber;
|
||||
|
||||
|
||||
QProcess arecord;
|
||||
QAudioInput* _audioDevice;
|
||||
QIODevice* _ioDevice = nullptr;
|
||||
|
||||
bool relayState = false;
|
||||
|
||||
|
36
main.cpp
36
main.cpp
@ -11,11 +11,13 @@
|
||||
#include <QCommandLineParser>
|
||||
|
||||
|
||||
|
||||
#include "alarmtime.h"
|
||||
#include "microcontroller.h"
|
||||
#include "mainwindow.h"
|
||||
#include "relaydialog.h"
|
||||
#include "ampmanager.h"
|
||||
#include "power.h"
|
||||
|
||||
#define BAUD QSerialPort::Baud38400
|
||||
|
||||
@ -46,12 +48,14 @@ int main(int argc, char *argv[])
|
||||
parser.addOption(serialOption);
|
||||
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
|
||||
parser.addOption(baudOption);
|
||||
QCommandLineOption secondaryOption(QStringList() << "s" << "secondary", QCoreApplication::translate("main", "Set if instance is not main instance"));
|
||||
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))
|
||||
@ -85,23 +89,35 @@ int main(int argc, char *argv[])
|
||||
else micro.setIODevice(microPort);
|
||||
}
|
||||
|
||||
AmpManager amp(µ, 0);
|
||||
Power power(&settings, µ);
|
||||
|
||||
|
||||
|
||||
|
||||
AmpManager amp(µ, 0, QAudioDeviceInfo::defaultInputDevice());
|
||||
|
||||
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
|
||||
AlarmTime almNight(settings.value("nightTime").toTime());
|
||||
|
||||
AlarmTime *almAlarm = new AlarmTime(settings.value("alarmTime").toTime());
|
||||
QSignalMapper signalMapper;
|
||||
|
||||
if(!parser.isSet(secondaryOption))
|
||||
{
|
||||
//Alarms
|
||||
AlarmTime almNight(settings.value("nightTime").toTime());
|
||||
QObject::connect(&almNight, SIGNAL(trigger()), &w, SLOT(slotSyncoff()));
|
||||
|
||||
QObject::connect(&almNight, SIGNAL(trigger()), &power, SLOT(syncoff()));
|
||||
QObject::connect(&w, SIGNAL(signalAlmNightChanged(QTime)), &almNight, SLOT(changeTime(QTime)));
|
||||
QObject::connect(&w, SIGNAL(signalAlmNightStateChanged(int)), &almNight, SLOT(runOrAbort(int)));
|
||||
//QMetaObject::invokeMethod(&almNight, "run", Qt::QueuedConnection );
|
||||
|
||||
AlarmTime *almAlarm = new AlarmTime(settings.value("alarmTime").toTime());
|
||||
QSignalMapper signalMapper;
|
||||
|
||||
QObject::connect(almAlarm, SIGNAL(trigger()), &signalMapper, SLOT(map()));
|
||||
signalMapper.setMapping(almAlarm, 4);
|
||||
QObject::connect(&signalMapper, SIGNAL(mapped(int)), µ, SLOT(setPattern(int)));
|
||||
@ -115,13 +131,11 @@ int main(int argc, char *argv[])
|
||||
QMetaObject::invokeMethod(&, "run", Qt::QueuedConnection );
|
||||
}
|
||||
|
||||
//serial display
|
||||
QObject::connect(µ, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
||||
QMetaObject::invokeMethod(µ, "run", Qt::QueuedConnection );
|
||||
|
||||
//Advanced Relays
|
||||
QObject::connect(&w, SIGNAL(showAdvRelayDialog()), &relayDialog, SLOT(show()));
|
||||
|
||||
QMetaObject::invokeMethod(µ, "run", Qt::QueuedConnection );
|
||||
|
||||
QMetaObject::invokeMethod(&w, "postActivate", Qt::QueuedConnection );
|
||||
w.show();
|
||||
|
||||
|
@ -19,7 +19,7 @@ MainWindow::MainWindow(QSettings *settings, Microcontroller *micro , bool isRemo
|
||||
|
||||
//RGB Leds
|
||||
connect(ui->presettApply, SIGNAL(clicked()), this, SLOT(slotApplyPreset()));
|
||||
connect(&colorChooser, SIGNAL(currentColorChanged(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
|
||||
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()));
|
||||
@ -32,24 +32,25 @@ MainWindow::MainWindow(QSettings *settings, Microcontroller *micro , bool isRemo
|
||||
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(slotAmpChkbtn(int)));
|
||||
connect(ui->checkBox_amp, SIGNAL(stateChanged(int)), this, SLOT(slotAmpToggle(int)));
|
||||
if(!isRemoteMode)connect(ui->checkBox_ampAuto, SIGNAL(stateChanged(int)), this, SLOT(slotAmpAutoToggle(int)));
|
||||
|
||||
|
||||
//Bedroom Speakers
|
||||
connect(ui->checkBox_bspeaker, SIGNAL(stateChanged(int)), this, SLOT(slotBSpeakerToggle(int)));
|
||||
if(!isRemoteMode)connect(ui->checkBox_bspeakerAuto, SIGNAL(stateChanged(int)), this, SLOT(slotBSpeakerAutoToggle(int)));
|
||||
|
||||
|
||||
//Infinity Mirror
|
||||
connect(ui->checkBox_inf, SIGNAL(stateChanged(int)), this, SLOT(slotInfMirrorToggle(int)));
|
||||
if(!isRemoteMode)connect(ui->checkBox_infAuto, SIGNAL(stateChanged(int)), this, SLOT(slotInfMirrorAutoToggle(int)));
|
||||
|
||||
|
||||
//Airconditioner
|
||||
connect(ui->checkBox_aircon, SIGNAL(stateChanged(int)), this, SLOT(slotAirconToggle(int)));
|
||||
|
||||
if(!isRemoteMode)
|
||||
{
|
||||
//Alarm
|
||||
@ -72,18 +73,21 @@ void MainWindow::remoteMode()
|
||||
{
|
||||
ui->alarmTime->setEnabled(false);
|
||||
ui->checkBox_alarm->setEnabled(false);
|
||||
ui->label_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()
|
||||
@ -106,9 +110,9 @@ void MainWindow::slotChangedRgb(const QColor color)
|
||||
if( color.redF() < 0.2 && color.greenF() < 0.2 && color.blueF() > 0.8 )
|
||||
{
|
||||
qDebug()<<"Auto turn on inf mirror\n";
|
||||
slotInfMirrorToggle(true);
|
||||
_micro->relayOn(2);
|
||||
}
|
||||
else slotInfMirrorToggle(false);
|
||||
else _micro->relayOff(2);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,14 +122,20 @@ void MainWindow::slotApplyPreset()
|
||||
if(ui->listWidget_patern->selectedItems().count() == 1) _micro->setPattern(ui->listWidget_patern->currentRow());
|
||||
}
|
||||
|
||||
void MainWindow::slotAmpToggle(int state)
|
||||
void MainWindow::relayCheckBoxToggeled(int state)
|
||||
{
|
||||
_micro->relayToggle(state, 0);
|
||||
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
||||
if(_relayCheckBoxes[i] == sender()) _micro->relayToggle(state, i);
|
||||
}
|
||||
|
||||
void MainWindow::slotBSpeakerToggle(int state)
|
||||
void MainWindow::relayStateChanged(std::vector<bool> relayStates)
|
||||
{
|
||||
_micro->relayToggle(state, 1);
|
||||
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)
|
||||
@ -133,26 +143,15 @@ void MainWindow::slotBSpeakerAutoToggle(int state)
|
||||
ui->checkBox_bspeaker->setEnabled(!state);
|
||||
}
|
||||
|
||||
void MainWindow::slotInfMirrorToggle(int state)
|
||||
{
|
||||
_micro->relayToggle(state, 2);
|
||||
}
|
||||
|
||||
void MainWindow::slotInfMirrorAutoToggle(int state)
|
||||
{
|
||||
ui->checkBox_inf->setEnabled(!state);
|
||||
if(!state)
|
||||
{
|
||||
slotInfMirrorToggle(ui->checkBox_inf->isChecked());
|
||||
_micro->relayToggle(ui->checkBox_inf->isChecked(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::slotAirconToggle(int state)
|
||||
{
|
||||
_micro->relayToggle(state, 3);
|
||||
}
|
||||
|
||||
void MainWindow::slotChangedAlarmTime(const QTime time)
|
||||
{
|
||||
_settings->setValue("alarmTime", time);
|
||||
@ -170,7 +169,7 @@ void MainWindow::slotChangedNightTime(const QTime time)
|
||||
signalAlmNightChanged(time);
|
||||
}
|
||||
|
||||
void MainWindow::slotAmpChkbtn(int state)
|
||||
void MainWindow::slotAmpAutoToggle(int state)
|
||||
{
|
||||
ui->checkBox_amp->setEnabled(!state);
|
||||
if(state)
|
||||
@ -180,7 +179,7 @@ void MainWindow::slotAmpChkbtn(int state)
|
||||
else
|
||||
{
|
||||
signalAmpOff();
|
||||
slotAmpToggle(ui->checkBox_amp->checkState());
|
||||
_micro->relayToggle(ui->checkBox_amp->checkState(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,15 +187,3 @@ void MainWindow::changeHeaderLableText(const QString string)
|
||||
{
|
||||
ui->label_serialRecive->setText(string);
|
||||
}
|
||||
|
||||
void MainWindow::slotSyncoff()
|
||||
{
|
||||
qDebug()<<"Power Off on alarm\n";
|
||||
_settings->sync();
|
||||
slotAmpToggle(false);
|
||||
slotBSpeakerToggle(false);
|
||||
slotInfMirrorToggle(false);
|
||||
slotAirconToggle(false);
|
||||
|
||||
QProcess::execute ( "syncoff" );
|
||||
}
|
||||
|
25
mainwindow.h
25
mainwindow.h
@ -3,15 +3,10 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QColorDialog>
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <QListWidgetItem>
|
||||
#include <QSettings>
|
||||
#include <QTime>
|
||||
#include <QProcess>
|
||||
#include <QSignalMapper>
|
||||
#include <vector>
|
||||
#include "alarmtime.h"
|
||||
#include "microcontroller.h"
|
||||
|
||||
@ -40,6 +35,8 @@ private:
|
||||
|
||||
Microcontroller *_micro;
|
||||
|
||||
std::vector<QAbstractButton*> _relayCheckBoxes;
|
||||
|
||||
void remoteMode();
|
||||
|
||||
signals:
|
||||
@ -62,17 +59,16 @@ private slots:
|
||||
//RGB
|
||||
void slotChangedRgb(const QColor color);
|
||||
void slotApplyPreset();
|
||||
void slotAmpChkbtn(int state);
|
||||
|
||||
void changeHeaderLableText(const QString string);
|
||||
|
||||
//Relays
|
||||
void slotAmpToggle(int state);
|
||||
void slotBSpeakerToggle(int state);
|
||||
//relays
|
||||
void relayCheckBoxToggeled(int state);
|
||||
|
||||
//Automation
|
||||
void slotAmpAutoToggle(int state);
|
||||
void slotBSpeakerAutoToggle(int state);
|
||||
void slotInfMirrorToggle(int state);
|
||||
void slotInfMirrorAutoToggle(int state);
|
||||
void slotAirconToggle(int state);
|
||||
|
||||
//Alarm
|
||||
void slotChangedAlarmTime(const QTime time);
|
||||
@ -81,9 +77,10 @@ private slots:
|
||||
//Night
|
||||
void slotChangedNightTime(const QTime time);
|
||||
|
||||
//syncoff
|
||||
|
||||
void slotSyncoff();
|
||||
public slots:
|
||||
|
||||
void relayStateChanged(std::vector<bool> relayStates);
|
||||
|
||||
};
|
||||
|
||||
|
@ -23,11 +23,11 @@
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>SHinterface</string>
|
||||
<string>Smart Home Interface</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset>
|
||||
<normaloff>UVOSicon.bmp</normaloff>UVOSicon.bmp</iconset>
|
||||
<iconset resource="resources.qrc">
|
||||
<normaloff>:/images/UVOSicon.bmp</normaloff>:/images/UVOSicon.bmp</iconset>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<property name="sizePolicy">
|
||||
@ -421,6 +421,12 @@
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>16777215</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="baseSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
@ -499,12 +505,9 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_12">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_alarm">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
<widget class="QPushButton" name="pushButton_alarm">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Alarm</string>
|
||||
@ -580,6 +583,8 @@
|
||||
</widget>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources/>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -1,24 +1,6 @@
|
||||
#include "microcontroller.h"
|
||||
|
||||
Microcontroller::Microcontroller(QIODevice* port): _port(port)
|
||||
{
|
||||
getState();
|
||||
}
|
||||
|
||||
Microcontroller::Microcontroller()
|
||||
{
|
||||
}
|
||||
|
||||
Microcontroller::~Microcontroller()
|
||||
{
|
||||
if(_port != nullptr) delete _port;
|
||||
}
|
||||
|
||||
void Microcontroller::setIODevice(QIODevice *port)
|
||||
{
|
||||
_port = port;
|
||||
getState();
|
||||
}
|
||||
//relays
|
||||
|
||||
void Microcontroller::relayToggle(int state, int relay)
|
||||
{
|
||||
@ -30,6 +12,18 @@ void Microcontroller::relayToggle(int state, int relay)
|
||||
if(_port != nullptr) _port->write(buffer, length);
|
||||
}
|
||||
|
||||
void Microcontroller::relayOn(int relay)
|
||||
{
|
||||
relayToggle(true, relay);
|
||||
}
|
||||
|
||||
void Microcontroller::relayOff(int relay)
|
||||
{
|
||||
relayToggle(false, relay);
|
||||
}
|
||||
|
||||
//rgb lights
|
||||
|
||||
void Microcontroller::rgbOn()
|
||||
{
|
||||
if(_port != nullptr) _port->write("rgb on\n", sizeof("rgb on\n")-1);
|
||||
@ -57,16 +51,6 @@ void Microcontroller::setPattern(int pattern)
|
||||
_port->write(buffer, length);
|
||||
}
|
||||
|
||||
void Microcontroller::relayOn(int relay)
|
||||
{
|
||||
relayToggle(true, relay);
|
||||
}
|
||||
|
||||
void Microcontroller::relayOff(int relay)
|
||||
{
|
||||
relayToggle(false, relay);
|
||||
}
|
||||
|
||||
bool Microcontroller::connected()
|
||||
{
|
||||
if(_port != nullptr) return _port->isOpen();
|
||||
@ -86,7 +70,7 @@ void Microcontroller::run()
|
||||
loop->exec();
|
||||
}
|
||||
|
||||
void Microcontroller::getState()
|
||||
void Microcontroller::requestState()
|
||||
{
|
||||
if(_port != nullptr) _port->write("relay state\n", sizeof("relay state\n"));
|
||||
}
|
||||
@ -100,6 +84,34 @@ void Microcontroller::abort()
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<bool> Microcontroller::getLastState()
|
||||
{
|
||||
return _relayStates;
|
||||
}
|
||||
|
||||
//housekeeping
|
||||
|
||||
Microcontroller::Microcontroller(QIODevice* port): _port(port)
|
||||
{
|
||||
requestState();
|
||||
}
|
||||
|
||||
Microcontroller::Microcontroller()
|
||||
{
|
||||
}
|
||||
|
||||
Microcontroller::~Microcontroller()
|
||||
{
|
||||
if(_port != nullptr) delete _port;
|
||||
}
|
||||
|
||||
void Microcontroller::setIODevice(QIODevice *port)
|
||||
{
|
||||
_port = port;
|
||||
requestState();
|
||||
}
|
||||
|
||||
|
||||
void Microcontroller::processMicroReturn()
|
||||
{
|
||||
QString workbuff = _buffer;
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <QScopedPointer>
|
||||
#include <QEventLoop>
|
||||
#include <QTimer>
|
||||
#include <QAbstractButton>
|
||||
#include <vector>
|
||||
|
||||
class Microcontroller: public QObject
|
||||
@ -25,7 +26,7 @@ private:
|
||||
QString _buffer;
|
||||
|
||||
void processMicroReturn();
|
||||
void getState();
|
||||
void requestState();
|
||||
|
||||
public:
|
||||
Microcontroller(QIODevice* port);
|
||||
@ -33,6 +34,7 @@ public:
|
||||
~Microcontroller();
|
||||
bool connected();
|
||||
void setIODevice(QIODevice* port);
|
||||
std::vector<bool> getLastState();
|
||||
|
||||
public slots:
|
||||
void rgbOn();
|
||||
|
10
power.cpp
10
power.cpp
@ -1,6 +1,14 @@
|
||||
#include "power.h"
|
||||
#include <QProcess>
|
||||
|
||||
Power::Power(QObject *parent) : QObject(parent)
|
||||
Power::Power(QSettings *settings, Microcontroller* micro, QObject *parent) : QObject(parent), _micro(micro), _settings(settings)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Power::syncoff()
|
||||
{
|
||||
_settings->sync();
|
||||
for(unsigned int i = 0; i < _micro->getLastState().size(); i++) _micro->relayOff(i);
|
||||
QProcess::execute ( "syncoff" );
|
||||
}
|
||||
|
13
power.h
13
power.h
@ -2,16 +2,25 @@
|
||||
#define POWER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include "microcontroller.h"
|
||||
|
||||
class Power : public QObject
|
||||
{
|
||||
private:
|
||||
Q_OBJECT
|
||||
Microcontroller* _micro;
|
||||
QSettings* _settings;
|
||||
|
||||
public:
|
||||
explicit Power(QObject *parent = nullptr);
|
||||
explicit Power(QSettings* settings, Microcontroller* micro, QObject *parent = nullptr);
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
||||
void syncoff();
|
||||
|
||||
};
|
||||
|
||||
#endif // POWER_H
|
||||
#endif // POWER_H
|
||||
|
@ -13,7 +13,7 @@ RelayDialog::RelayDialog(Microcontroller *micro, QWidget *parent) :
|
||||
_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(toggled(bool)), this, SLOT(relayCheckBoxToggeled(bool)));
|
||||
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+1);
|
||||
@ -26,18 +26,18 @@ RelayDialog::~RelayDialog()
|
||||
}
|
||||
|
||||
|
||||
void RelayDialog::relayCheckBoxToggeled(bool checked)
|
||||
void RelayDialog::relayCheckBoxToggeled(int state)
|
||||
{
|
||||
for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
||||
{
|
||||
if(_relayCheckBoxes[i] == sender())
|
||||
{
|
||||
checked ? _micro->relayOn(i+4) : _micro->relayOff(i+4);
|
||||
}
|
||||
}
|
||||
if(_relayCheckBoxes[i] == sender())_micro->relayToggle(state, i+STARTING_RELAY);
|
||||
}
|
||||
|
||||
void RelayDialog::relayStateChanged(std::vector<bool> relayStates)
|
||||
{
|
||||
if(relayStates.size() >= 8) for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++) _relayCheckBoxes[i]->setChecked(relayStates[i+4]);
|
||||
if(relayStates.size() >= STARTING_RELAY+4) for(unsigned int i = 0; i < _relayCheckBoxes.size(); i++)
|
||||
{
|
||||
_relayCheckBoxes[i]->blockSignals(true);
|
||||
_relayCheckBoxes[i]->setChecked(relayStates[i+STARTING_RELAY]);
|
||||
_relayCheckBoxes[i]->blockSignals(false);
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ private:
|
||||
Microcontroller *_micro;
|
||||
|
||||
private slots:
|
||||
void relayCheckBoxToggeled(bool checked);
|
||||
void relayCheckBoxToggeled(int state);
|
||||
|
||||
public slots:
|
||||
void relayStateChanged(std::vector<bool> relayStates);
|
||||
|
@ -152,7 +152,7 @@
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Aux 1</string>
|
||||
<string>3040</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -178,6 +178,44 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Aux</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_3">
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -1,2 +1,5 @@
|
||||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0"/>
|
||||
<RCC>
|
||||
<qresource prefix="/images">
|
||||
<file>UVOSicon.bmp</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
Loading…
x
Reference in New Issue
Block a user