init branch 2

This commit is contained in:
IMback
2018-10-09 18:41:49 +02:00
parent 2801671ced
commit 74f117db69
15 changed files with 532 additions and 318 deletions

View File

@ -21,20 +21,28 @@ SOURCES += main.cpp mainwindow.cpp ampmanager.cpp alarmtime.cpp \
microcontroller.cpp \
relaydialog.cpp \
alarmsettingsdialog.cpp \
power.cpp
alarmactions.cpp \
relaywidget.cpp \
actor.cpp \
relay.cpp \
relaymanager.cpp
HEADERS += mainwindow.h \
ampmanager.h \
relay.h \
alarmtime.h \
microcontroller.h \
relaydialog.h \
alarmsettingsdialog.h \
power.h
alarmactions.h \
relaywidget.h \
actor.h \
relay.h \
relaymanager.h
FORMS += mainwindow.ui \
relaydialog.ui \
alarmsettingsdialog.ui
alarmsettingsdialog.ui \
relaywidget.ui
RESOURCES += \
resources.qrc

6
actor.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "actor.h"
Actor::Actor()
{
}

46
actor.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef ACTOR_H
#define ACTOR_H
#include <QObject>
#include <QString>
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;
void performAction();
private:
bool active = false;
signals:
void on();
void off();
void trigger();
void toggle();
public slots:
public:
Actor();
virtual ~Actor();
virtual bool isActive();
virtual bool makeActive();
virtual bool makeInactive();
void setAction(uint8_t action);
};
#endif // ACTOR_H

33
alarmactions.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "alarmactions.h"
#include <QProcess>
#include <QSound>
#include <QProcess>
#include <QTime>
#include <QApplication>
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());
}
}

View File

@ -5,7 +5,7 @@
#include <QSettings>
#include "microcontroller.h"
class Power : public QObject
class AlarmActions : public QObject
{
private:
Q_OBJECT
@ -13,7 +13,7 @@ private:
QSettings* _settings;
public:
explicit Power(QSettings* settings, Microcontroller* micro, QObject *parent = nullptr);
explicit AlarmActions(QSettings* settings, Microcontroller* micro, QObject *parent = nullptr);
signals:
@ -21,6 +21,8 @@ public slots:
void syncoff();
void Alarm();
};
#endif // POWER_H

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>423</width>
<height>281</height>
<width>462</width>
<height>406</height>
</rect>
</property>
<property name="windowTitle">
@ -15,14 +15,53 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Alarm</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_alm">
<item>
<widget class="QLabel" name="label_3">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sound File:</string>
<string>Time</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<widget class="QTimeEdit" name="timeEdit_Alarm">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_Alarm">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_snd">
<property name="leftMargin">
<number>0</number>
</property>
@ -30,14 +69,33 @@
<number>0</number>
</property>
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>false</bool>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sound File</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<widget class="QLineEdit" name="lineEdit">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_changeFile">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Change</string>
</property>
@ -71,7 +129,13 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<widget class="QCheckBox" name="checkBox_Sunrise">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
@ -79,18 +143,53 @@
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
<widget class="QGroupBox" name="groupBox_2">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<property name="title">
<string>Auto Power off</string>
</property>
</spacer>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Time</string>
</property>
</widget>
</item>
<item>
<widget class="QTimeEdit" name="timeEdit_Shutdown"/>
</item>
<item>
<widget class="QCheckBox" name="checkBox_Shutdown">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">

View File

@ -246,7 +246,7 @@
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Airconditioner</string>
<string>Soldering iron</string>
</property>
</widget>
</item>
@ -264,7 +264,45 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_aircon">
<widget class="QCheckBox" name="checkBox_SolderingIorn">
<property name="text">
<string>On</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Test Equitment</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_testEquitmpent">
<property name="text">
<string>On</string>
</property>
@ -282,67 +320,6 @@
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="label_nightTime">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Shut Down Time:</string>
</property>
</widget>
</item>
<item>
<widget class="QTimeEdit" name="nightTime">
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="showGroupSeparator" stdset="0">
<bool>false</bool>
</property>
<property name="currentSection">
<enum>QDateTimeEdit::HourSection</enum>
</property>
<property name="displayFormat">
<string notr="true">hh:mm</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_nightTime">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
@ -486,6 +463,30 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Desk Light</string>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_deskLight">
<property name="maximum">
<number>254</number>
</property>
<property name="tracking">
<bool>false</bool>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
@ -503,78 +504,12 @@
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QCheckBox" name="checkBox_doorOpen">
<widget class="QPushButton" name="pushButton_alarms">
<property name="text">
<string>CheckBox</string>
</property>
<property name="checkable">
<bool>false</bool>
<string>Alarms</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QPushButton" name="pushButton_alarm">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Alarm</string>
</property>
</widget>
</item>
<item>
<widget class="QTimeEdit" name="alarmTime">
<property name="enabled">
<bool>true</bool>
</property>
<property name="correctionMode">
<enum>QAbstractSpinBox::CorrectToNearestValue</enum>
</property>
<property name="dateTime">
<datetime>
<hour>0</hour>
<minute>0</minute>
<second>0</second>
<year>2000</year>
<month>1</month>
<day>1</day>
</datetime>
</property>
<property name="currentSection">
<enum>QDateTimeEdit::HourSection</enum>
</property>
<property name="displayFormat">
<string>hh:mm</string>
</property>
<property name="calendarPopup">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_alarm">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="button_quit">
<property name="sizePolicy">

View File

@ -1,14 +0,0 @@
#include "power.h"
#include <QProcess>
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" );
}

58
relay.cpp Normal file
View File

@ -0,0 +1,58 @@
#include "relay.h"
#include "microcontroller.h"
Relay::Relay(Microcontroller* micro, uint8_t id, QString name, uint16_t address, QObject* parent): QObject(parent), micro_(micro), name_(name), id_(id), address_(address)
{
}
QString Relay::getName()
{
return name_;
}
void Relay::setName(QString name)
{
name_ = name;
}
void Relay::addActor(std::unique_ptr<Actor> actor)
{
actors_.push_back(actor);
connect(actor.get(), &Actor::on, this, &Relay::on);
connect(actor.get(), &Actor::off, this, &Relay::off);
connect(actor.get(), &Actor::toggle, this, &Relay::toggle);
}
std::vector< std::unique_ptr<Actor> >* Relay::getActors()
{
return &actors_;
}
bool Relay::hasActors()
{
return actors_.size() > 0;
}
void Relay::on()
{
micro_->relayOn(id_);
state_ = true;
}
void Relay::off()
{
micro_->relayOn(id_);
state_ = false;
}
void Relay::setState(bool state)
{
state_ = state;
}
void Relay::setActorsActive(bool in)
{
actorsActive_ = true;
for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
}

View File

@ -20,95 +20,6 @@
<string>Advanced</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Soldering iron</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</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_R0">
<property name="text">
<string>On</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_R2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Test Equitment</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<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_R1">
<property name="text">
<string>On</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
@ -132,7 +43,7 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_R2">
<widget class="QCheckBox" name="checkBox_R0">
<property name="text">
<string>On</string>
</property>
@ -170,7 +81,7 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_R3">
<widget class="QCheckBox" name="checkBox_R1">
<property name="text">
<string>On</string>
</property>
@ -208,7 +119,7 @@
</spacer>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<widget class="QCheckBox" name="checkBox_R2">
<property name="text">
<string>On</string>
</property>

6
relaymanager.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "relaymanager.h"
RelayManager::RelayManager(QObject *parent) : QObject(parent)
{
}

26
relaymanager.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef RELAYMANAGER_H
#define RELAYMANAGER_H
#include <QObject>
#include <vector>
#include "relay.h"
#include "microcontroller.h"
class RelayManager : public QObject
{
Q_OBJECT
private:
std::vector<Relay> relays;
Microcontroller* micro_;
public:
explicit RelayManager(QObject *parent = nullptr);
signals:
public slots:
void
};
#endif // RELAYMANAGER_H

14
relaywidget.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "relaywidget.h"
#include "ui_relaywidget.h"
RelayWidget::RelayWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::RelayWidget)
{
ui->setupUi(this);
}
RelayWidget::~RelayWidget()
{
delete ui;
}

22
relaywidget.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef RELAYWIDGET_H
#define RELAYWIDGET_H
#include <QWidget>
namespace Ui {
class RelayWidget;
}
class RelayWidget : public QWidget
{
Q_OBJECT
public:
explicit RelayWidget(QWidget *parent = nullptr);
~RelayWidget();
private:
Ui::RelayWidget *ui;
};
#endif // RELAYWIDGET_H

62
relaywidget.ui Normal file
View File

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>RelayWidget</class>
<widget class="QWidget" name="RelayWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>751</width>
<height>58</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>TextLabel</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>On</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_auto">
<property name="text">
<string>Auto</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Settings</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>