Compare commits
7 commits
d30c9546b1
...
e3b6d5c3a6
| Author | SHA1 | Date | |
|---|---|---|---|
| e3b6d5c3a6 | |||
| d6c8d799e3 | |||
| c1f6b6e90f | |||
| 913d7df56d | |||
| 6d742e60db | |||
| cbeb8d49a7 | |||
| 8fcca909de |
69 changed files with 1840 additions and 1645 deletions
169
CMakeLists.txt
Normal file
169
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,169 @@
|
||||||
|
cmake_minimum_required(VERSION 4.0)
|
||||||
|
|
||||||
|
project(SHinterface VERSION 1.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
# Set C++ standard
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Enable all warnings
|
||||||
|
add_compile_options(-Wall)
|
||||||
|
|
||||||
|
# Find Qt packages
|
||||||
|
find_package(Qt6 COMPONENTS Core Gui Widgets Network Multimedia SerialPort Mqtt REQUIRED)
|
||||||
|
|
||||||
|
# Find dependencies using pkg-config
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(PIPEWIRE REQUIRED libpipewire-0.3)
|
||||||
|
pkg_check_modules(LIBNL3 REQUIRED libnl-3.0 libnl-genl-3.0)
|
||||||
|
|
||||||
|
# Enable automatic moc and uic processing
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
|
||||||
|
# Add src to include path for relative includes
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
|
||||||
|
|
||||||
|
# Create executable
|
||||||
|
add_executable(SHinterface
|
||||||
|
src/sensors/mqttsensorsource.h src/sensors/mqttsensorsource.cpp)
|
||||||
|
|
||||||
|
# Add sources to executable
|
||||||
|
target_sources(SHinterface
|
||||||
|
PRIVATE
|
||||||
|
src/main.cpp
|
||||||
|
src/mainobject.h
|
||||||
|
src/mainobject.cpp
|
||||||
|
src/apgetconnected.h
|
||||||
|
src/apgetconnected.cpp
|
||||||
|
src/microcontroller.h
|
||||||
|
src/microcontroller.cpp
|
||||||
|
src/sun.h
|
||||||
|
src/sun.cpp
|
||||||
|
src/programmode.h
|
||||||
|
src/programmode.cpp
|
||||||
|
src/tcpserver.h
|
||||||
|
src/tcpserver.cpp
|
||||||
|
src/pipewire.h
|
||||||
|
src/pipewire.cpp
|
||||||
|
|
||||||
|
src/actors/actor.h
|
||||||
|
src/actors/actor.cpp
|
||||||
|
src/actors/factoractor.h
|
||||||
|
src/actors/factoractor.cpp
|
||||||
|
src/actors/polynomalactor.h
|
||||||
|
src/actors/polynomalactor.cpp
|
||||||
|
src/actors/sensoractor.h
|
||||||
|
src/actors/sensoractor.cpp
|
||||||
|
src/actors/alarmtime.h
|
||||||
|
src/actors/alarmtime.cpp
|
||||||
|
src/actors/regulator.h
|
||||||
|
src/actors/regulator.cpp
|
||||||
|
src/actors/timeractor.h
|
||||||
|
src/actors/timeractor.cpp
|
||||||
|
|
||||||
|
src/sensors/sensor.h
|
||||||
|
src/sensors/sensor.cpp
|
||||||
|
src/sensors/sunsensor.h
|
||||||
|
src/sensors/sunsensor.cpp
|
||||||
|
|
||||||
|
src/items/item.h
|
||||||
|
src/items/item.cpp
|
||||||
|
src/items/relay.h
|
||||||
|
src/items/relay.cpp
|
||||||
|
src/items/poweritem.h
|
||||||
|
src/items/poweritem.cpp
|
||||||
|
src/items/messageitem.h
|
||||||
|
src/items/messageitem.cpp
|
||||||
|
src/items/systemitem.h
|
||||||
|
src/items/systemitem.cpp
|
||||||
|
src/items/auxitem.h
|
||||||
|
src/items/auxitem.cpp
|
||||||
|
src/items/rgbitem.h
|
||||||
|
src/items/rgbitem.cpp
|
||||||
|
src/items/itemsource.h
|
||||||
|
src/items/itemsource.cpp
|
||||||
|
src/items/itemloadersource.h
|
||||||
|
src/items/itemloadersource.cpp
|
||||||
|
src/items/fixeditemsource.h
|
||||||
|
src/items/fixeditemsource.cpp
|
||||||
|
src/items/itemstore.h
|
||||||
|
src/items/itemstore.cpp
|
||||||
|
|
||||||
|
src/ui/mainwindow.h
|
||||||
|
src/ui/mainwindow.cpp
|
||||||
|
src/ui/itemwidget.h
|
||||||
|
src/ui/itemwidget.cpp
|
||||||
|
src/ui/itemscrollbox.h
|
||||||
|
src/ui/itemscrollbox.cpp
|
||||||
|
src/ui/sensorlistwidget.h
|
||||||
|
src/ui/sensorlistwidget.cpp
|
||||||
|
src/ui/itemcreationdialog.h
|
||||||
|
src/ui/itemcreationdialog.cpp
|
||||||
|
src/ui/itemsettingsdialog.h
|
||||||
|
src/ui/itemsettingsdialog.cpp
|
||||||
|
src/ui/actorsettingsdialog.h
|
||||||
|
src/ui/actorsettingsdialog.cpp
|
||||||
|
|
||||||
|
src/ui/actorwidgets/factoractorwidget.h
|
||||||
|
src/ui/actorwidgets/factoractorwidget.cpp
|
||||||
|
src/ui/actorwidgets/polynomalactorwidget.h
|
||||||
|
src/ui/actorwidgets/polynomalactorwidget.cpp
|
||||||
|
src/ui/actorwidgets/sensoractorwidget.h
|
||||||
|
src/ui/actorwidgets/sensoractorwidget.cpp
|
||||||
|
src/ui/actorwidgets/timeractorwidget.h
|
||||||
|
src/ui/actorwidgets/timeractorwidget.cpp
|
||||||
|
src/ui/actorwidgets/alarmwidget.h
|
||||||
|
src/ui/actorwidgets/alarmwidget.cpp
|
||||||
|
src/ui/actorwidgets/regulatorwdiget.h
|
||||||
|
src/ui/actorwidgets/regulatorwdiget.cpp
|
||||||
|
|
||||||
|
src/ui/itemsettingswidgets/messageitemsettingswidget.h
|
||||||
|
src/ui/itemsettingswidgets/messageitemsettingswidget.cpp
|
||||||
|
src/ui/itemsettingswidgets/relayitemsettingswidget.h
|
||||||
|
src/ui/itemsettingswidgets/relayitemsettingswidget.cpp
|
||||||
|
src/ui/itemsettingswidgets/systemitemsettingswidget.h
|
||||||
|
src/ui/itemsettingswidgets/systemitemsettingswidget.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add UI files
|
||||||
|
target_sources(SHinterface
|
||||||
|
PRIVATE
|
||||||
|
src/ui/mainwindow.ui
|
||||||
|
src/ui/itemwidget.ui
|
||||||
|
src/ui/relayscrollbox.ui
|
||||||
|
src/ui/itemcreationdialog.ui
|
||||||
|
src/ui/itemsettingsdialog.ui
|
||||||
|
src/ui/actorsettingsdialog.ui
|
||||||
|
src/ui/actorwidgets/factoractorwidget.ui
|
||||||
|
src/ui/actorwidgets/polynomalactorwidget.ui
|
||||||
|
src/ui/actorwidgets/sensoractorwidget.ui
|
||||||
|
src/ui/actorwidgets/timeractorwidget.ui
|
||||||
|
src/ui/actorwidgets/alarmwidget.ui
|
||||||
|
src/ui/actorwidgets/regulatorwdiget.ui
|
||||||
|
src/ui/itemsettingswidgets/messageitemsettingswidget.ui
|
||||||
|
src/ui/itemsettingswidgets/relayitemsettingswidget.ui
|
||||||
|
src/ui/itemsettingswidgets/systemitemsettingswidget.ui
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add resource file
|
||||||
|
target_sources(SHinterface
|
||||||
|
PRIVATE
|
||||||
|
resources.qrc
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link libraries
|
||||||
|
target_link_libraries(SHinterface
|
||||||
|
Qt6::Core
|
||||||
|
Qt6::Gui
|
||||||
|
Qt6::Widgets
|
||||||
|
Qt6::Network
|
||||||
|
Qt6::Multimedia
|
||||||
|
Qt6::SerialPort
|
||||||
|
Qt6::Mqtt
|
||||||
|
${PIPEWIRE_LIBRARIES}
|
||||||
|
${LIBNL3_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Add include paths
|
||||||
|
include_directories(${PIPEWIRE_INCLUDE_DIRS} ${LIBNL3_INCLUDE_DIRS})
|
||||||
156
SHinterface.pro
156
SHinterface.pro
|
|
@ -1,156 +0,0 @@
|
||||||
#-------------------------------------------------
|
|
||||||
#
|
|
||||||
# Project created by QtCreator 2017-06-01T22:31:38
|
|
||||||
#
|
|
||||||
#-------------------------------------------------
|
|
||||||
|
|
||||||
QT += core gui widgets network multimedia
|
|
||||||
|
|
||||||
QT += serialport
|
|
||||||
|
|
||||||
TARGET = SHinterface
|
|
||||||
TEMPLATE = app
|
|
||||||
|
|
||||||
INCLUDEPATH += /usr/include/libnl3/
|
|
||||||
|
|
||||||
LIBS += -lnl-3 -lnl-genl-3
|
|
||||||
|
|
||||||
# The following define makes your compiler emit warnings if you use
|
|
||||||
# any feature of Qt which as been marked as deprecated (the exact warnings
|
|
||||||
# depend on your compiler). Please consult the documentation of the
|
|
||||||
# deprecated API in order to know how to port your code away from it.
|
|
||||||
DEFINES += QT_DEPRECATED_WARNINGS
|
|
||||||
|
|
||||||
QMAKE_CXXFLAGS += -std=c++17 -O2
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
src/actors/factoractor.cpp \
|
|
||||||
src/actors/polynomalactor.cpp \
|
|
||||||
src/broadcast.cpp \
|
|
||||||
src/iomuliplexer.cpp \
|
|
||||||
src/items/messageitem.cpp \
|
|
||||||
src/items/systemitem.cpp \
|
|
||||||
src/ui/actorwidgets/factoractorwidget.cpp \
|
|
||||||
src/ui/itemcreationdialog.cpp \
|
|
||||||
src/ui/itemsettingswidgets/messageitemsettingswidget.cpp \
|
|
||||||
src/mainobject.cpp \
|
|
||||||
src/apgetconnected.cpp \
|
|
||||||
src/ui/actorwidgets/polynomalactorwidget.cpp \
|
|
||||||
src/ui/actorwidgets/sensoractorwidget.cpp \
|
|
||||||
src/ui/actorwidgets/alarmwidget.cpp \
|
|
||||||
src/ui/actorwidgets/timeractorwidget.cpp \
|
|
||||||
src/ui/itemsettingswidgets/relayitemsettingswidget.cpp \
|
|
||||||
src/ui/itemsettingswidgets/systemitemsettingswidget.cpp \
|
|
||||||
src/ui/itemwidget.cpp \
|
|
||||||
src/ui/itemsettingsdialog.cpp \
|
|
||||||
src/ui/itemscrollbox.cpp \
|
|
||||||
src/items/poweritem.cpp \
|
|
||||||
src/ui/actorwidgets/regulatorwdiget.cpp
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
src/ui/actorsettingsdialog.cpp \
|
|
||||||
src/ui/mainwindow.cpp \
|
|
||||||
src/ui/sensorlistwidget.cpp
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
src/actors/actor.cpp \
|
|
||||||
src/actors/sensoractor.cpp \
|
|
||||||
src/actors/alarmtime.cpp \
|
|
||||||
src/actors/regulator.cpp \
|
|
||||||
src/actors/timeractor.cpp
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
src/sensors/sensor.cpp \
|
|
||||||
src/sensors/speakersensor.cpp \
|
|
||||||
src/sensors/sunsensor.cpp \
|
|
||||||
src/sensors/ocupancysensor.cpp
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
src/items/relay.cpp \
|
|
||||||
src/items/item.cpp \
|
|
||||||
src/items/itemstore.cpp \
|
|
||||||
src/items/auxitem.cpp \
|
|
||||||
src/items/rgbitem.cpp
|
|
||||||
|
|
||||||
SOURCES += \
|
|
||||||
src/alarmactions.cpp \
|
|
||||||
src/main.cpp \
|
|
||||||
src/microcontroller.cpp \
|
|
||||||
src/sun.cpp
|
|
||||||
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
src/actors/factoractor.h \
|
|
||||||
src/actors/polynomalactor.h \
|
|
||||||
src/broadcast.h \
|
|
||||||
src/iomuliplexer.h \
|
|
||||||
src/items/messageitem.h \
|
|
||||||
src/items/systemitem.h \
|
|
||||||
src/ui/actorwidgets/factoractorwidget.h \
|
|
||||||
src/ui/itemcreationdialog.h \
|
|
||||||
src/ui/itemsettingswidgets/messageitemsettingswidget.h \
|
|
||||||
src/mainobject.h \
|
|
||||||
src/apgetconnected.h \
|
|
||||||
src/ui/actorwidgets/alarmwidget.h \
|
|
||||||
src/ui/actorwidgets/polynomalactorwidget.h \
|
|
||||||
src/ui/actorwidgets/sensoractorwidget.h \
|
|
||||||
src/ui/actorwidgets/timeractorwidget.h \
|
|
||||||
src/ui/itemsettingswidgets/relayitemsettingswidget.h \
|
|
||||||
src/ui/itemsettingswidgets/systemitemsettingswidget.h \
|
|
||||||
src/ui/itemwidget.h \
|
|
||||||
src/ui/itemsettingsdialog.h \
|
|
||||||
src/ui/itemscrollbox.h \
|
|
||||||
src/items/poweritem.h \
|
|
||||||
src/ui/actorwidgets/regulatorwdiget.h
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
src/ui/actorsettingsdialog.h \
|
|
||||||
src/ui/mainwindow.h \
|
|
||||||
src/ui/sensorlistwidget.h
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
src/actors/actor.h \
|
|
||||||
src/actors/alarmtime.h \
|
|
||||||
src/actors/sensoractor.h \
|
|
||||||
src/actors/regulator.h \
|
|
||||||
src/actors/timeractor.h
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
src/sensors/sensor.h \
|
|
||||||
src/sensors/speakersensor.h \
|
|
||||||
src/sensors/sunsensor.h \
|
|
||||||
src/sensors/ocupancysensor.h
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
src/items/relay.h \
|
|
||||||
src/items/item.h \
|
|
||||||
src/items/itemstore.h \
|
|
||||||
src/items/auxitem.h \
|
|
||||||
src/items/rgbitem.h
|
|
||||||
|
|
||||||
HEADERS += \
|
|
||||||
src/alarmactions.h \
|
|
||||||
src/microcontroller.h \
|
|
||||||
src/sun.h
|
|
||||||
|
|
||||||
FORMS += \
|
|
||||||
src/ui/actorwidgets/factoractorwidget.ui \
|
|
||||||
src/ui/itemcreationdialog.ui \
|
|
||||||
src/ui/itemsettingswidgets/messageitemsettingswidget.ui \
|
|
||||||
src/ui/actorsettingsdialog.ui \
|
|
||||||
src/ui/actorwidgets/polynomalactorwidget.ui \
|
|
||||||
src/ui/itemsettingswidgets/relayitemsettingswidget.ui \
|
|
||||||
src/ui/itemsettingswidgets/systemitemsettingswidget.ui \
|
|
||||||
src/ui/mainwindow.ui \
|
|
||||||
src/ui/relayscrollbox.ui \
|
|
||||||
src/ui/actorwidgets/sensoractorwidget.ui \
|
|
||||||
src/ui/actorwidgets/alarmwidget.ui \
|
|
||||||
src/ui/actorwidgets/timeractorwidget.ui \
|
|
||||||
src/ui/itemsettingsdialog.ui \
|
|
||||||
src/ui/itemwidget.ui \
|
|
||||||
src/ui/actorwidgets/regulatorwdiget.ui
|
|
||||||
|
|
||||||
android:FORMS += src/ui/mainwindow-android.ui
|
|
||||||
|
|
||||||
RESOURCES += \
|
|
||||||
resources.qrc
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
#include "actor.h"
|
|
||||||
#include<QDebug>
|
|
||||||
|
|
||||||
Actor::Actor(QObject *parent): QObject(parent)
|
|
||||||
{
|
|
||||||
buildName();
|
|
||||||
}
|
|
||||||
|
|
||||||
Actor::~Actor()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::performAction()
|
|
||||||
{
|
|
||||||
if(active)
|
|
||||||
{
|
|
||||||
trigger();
|
|
||||||
if(action_ == ACTION_OFF) off();
|
|
||||||
else if(action_ == ACTION_ON) on();
|
|
||||||
else if(action_ != ACTION_TOGGLE) toggle();
|
|
||||||
else if(action_ != ACTION_VALUE) sigValue(value_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::makeActive()
|
|
||||||
{
|
|
||||||
active = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Actor::makeInactive()
|
|
||||||
{
|
|
||||||
active = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::buildName()
|
|
||||||
{
|
|
||||||
name = "Actor";
|
|
||||||
appendActionToName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::appendActionToName()
|
|
||||||
{
|
|
||||||
if(action_ == ACTION_OFF || action_ == ACTION_DEFAULT ) name.append("off");
|
|
||||||
else if(action_ == ACTION_ON ) name.append("on");
|
|
||||||
else if(action_ == ACTION_TOGGLE ) name.append("toggle");
|
|
||||||
else if(action_ == ACTION_VALUE ) name.append("value to " + QString::number(value_));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::setActive(int state)
|
|
||||||
{
|
|
||||||
state ? makeActive() : makeInactive();
|
|
||||||
buildName();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Actor::isActive()
|
|
||||||
{
|
|
||||||
return active;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Actor::isExausted()
|
|
||||||
{
|
|
||||||
return exausted;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::saveSettings(QString subsecton, QSettings* settings)
|
|
||||||
{
|
|
||||||
settings->setValue(subsecton + "Active", active);
|
|
||||||
settings->setValue(subsecton + "Exausted", exausted);
|
|
||||||
settings->setValue(subsecton + "Name", name);
|
|
||||||
settings->setValue(subsecton + "Action", action_);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::loadSettings(QString subsecton, QSettings* settings)
|
|
||||||
{
|
|
||||||
active = settings->value(subsecton + "Active").toBool();
|
|
||||||
exausted = settings->value(subsecton + "Exausted").toBool();
|
|
||||||
name = settings->value(subsecton + "Name").toString();
|
|
||||||
action_ = settings->value(subsecton + "Action").toUInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::setAction(uint8_t action)
|
|
||||||
{
|
|
||||||
action_ = action;
|
|
||||||
qDebug()<<"setting action to "<<action;
|
|
||||||
buildName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::setValue(uint8_t value)
|
|
||||||
{
|
|
||||||
value_=value;
|
|
||||||
buildName();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Actor::onStateChanged(bool state)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
#include "../items/item.h"
|
#include "items/item.h"
|
||||||
|
|
||||||
class Actor : public Item
|
class Actor : public Item
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,17 +4,17 @@ AlarmTime::AlarmTime(const QDateTime time, QObject *parent) : Actor(parent), tim
|
||||||
{
|
{
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||||
timer.setInterval(1000);
|
timer.setInterval(1000);
|
||||||
run();
|
AlarmTime::run();
|
||||||
}
|
}
|
||||||
|
|
||||||
AlarmTime::~AlarmTime()
|
AlarmTime::~AlarmTime()
|
||||||
{
|
{
|
||||||
makeInactive();
|
AlarmTime::makeInactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AlarmTime::run()
|
void AlarmTime::run()
|
||||||
{
|
{
|
||||||
makeInactive();
|
AlarmTime::makeInactive();
|
||||||
|
|
||||||
active = true;
|
active = true;
|
||||||
timer.start();
|
timer.start();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef POLYNOMALACTOR_H
|
#ifndef POLYNOMALACTOR_H
|
||||||
#define POLYNOMALACTOR_H
|
#define POLYNOMALACTOR_H
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "../sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
|
|
||||||
class PolynomalActor: public Actor
|
class PolynomalActor: public Actor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "../sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
|
|
||||||
class Regulator : public Actor
|
class Regulator : public Actor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "actor.h"
|
#include "actor.h"
|
||||||
#include "../sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
|
|
||||||
class SensorActor : public Actor
|
class SensorActor : public Actor
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
#include "alarmactions.h"
|
|
||||||
#include <QProcess>
|
|
||||||
|
|
||||||
AlarmActions::AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent) : QObject(parent), _micro(micro),
|
|
||||||
a_(a)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void AlarmActions::syncoff()
|
|
||||||
{
|
|
||||||
qDebug()<<"syncoff";
|
|
||||||
QProcess::execute ("syncoff", QStringList());
|
|
||||||
a_->exit(0);
|
|
||||||
}
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
#ifndef POWER_H
|
|
||||||
#define POWER_H
|
|
||||||
|
|
||||||
#include <QApplication>
|
|
||||||
#include "microcontroller.h"
|
|
||||||
|
|
||||||
class AlarmActions : public QObject
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
Q_OBJECT
|
|
||||||
Microcontroller* _micro;
|
|
||||||
QApplication* a_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent = nullptr);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
void syncoff();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // POWER_H
|
|
||||||
|
|
@ -1,139 +0,0 @@
|
||||||
#include "broadcast.h"
|
|
||||||
#include <QJsonDocument>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include <QJsonArray>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
BroadCast::BroadCast(QIODevice* const iodevice, bool master ): master_(master), iodevice_(iodevice)
|
|
||||||
{
|
|
||||||
if(iodevice_ != nullptr) connect(iodevice_, &QIODevice::readyRead, this, &BroadCast::readyRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::write(const char * const buffer, const size_t length)
|
|
||||||
{
|
|
||||||
QByteArray mBuffer("bcst: ");
|
|
||||||
for (size_t i = 0; i < length; ++i)
|
|
||||||
{
|
|
||||||
if(buffer[i] != '\n' && buffer[i] != '\0') mBuffer.push_back(buffer[i]);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mBuffer.push_back('\\');
|
|
||||||
if(buffer[i] == '\n')mBuffer.push_back('n');
|
|
||||||
else mBuffer.push_back('0');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mBuffer.push_back('\n');
|
|
||||||
if(iodevice_)iodevice_->write(mBuffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::write(const QByteArray& buffer)
|
|
||||||
{
|
|
||||||
write(buffer.data(), buffer.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::sendJson(const QJsonObject& json)
|
|
||||||
{
|
|
||||||
QJsonDocument jsonDocument(json);
|
|
||||||
QByteArray buffer("JSON: ");
|
|
||||||
buffer.append(jsonDocument.toJson());
|
|
||||||
write(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::sendSensors()
|
|
||||||
{
|
|
||||||
if(iodevice_)
|
|
||||||
{
|
|
||||||
for(auto& sensor: *globalSensors.getSensors())
|
|
||||||
iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::requestSensors()
|
|
||||||
{
|
|
||||||
if(iodevice_)
|
|
||||||
iodevice_->write("bcst: GETSENSORS\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::requestJson()
|
|
||||||
{
|
|
||||||
if(iodevice_)
|
|
||||||
iodevice_->write("bcst: GETJSN\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::decodeMaster(const QByteArray& buffer)
|
|
||||||
{
|
|
||||||
if(buffer.startsWith("GETJSN"))
|
|
||||||
{
|
|
||||||
qDebug()<<"json requested";
|
|
||||||
jsonRequested();
|
|
||||||
}
|
|
||||||
else if(buffer.startsWith("GETSENSORS") )
|
|
||||||
{
|
|
||||||
qDebug()<<"sensors requested";
|
|
||||||
sendSensors();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::decode(QByteArray buffer)
|
|
||||||
{
|
|
||||||
qDebug()<<"decodeing: "<<buffer;
|
|
||||||
if(buffer.size() >= 6 && buffer[0] == 'J' && buffer[1] == 'S' && buffer[2] == 'O' && buffer[3] == 'N'
|
|
||||||
&& buffer[4] == ':')
|
|
||||||
{
|
|
||||||
qDebug()<<"got json";
|
|
||||||
buffer.remove(0,6);
|
|
||||||
for(int i = 0; i < buffer.size()-1; ++i)
|
|
||||||
{
|
|
||||||
if( buffer[i] == '\\' && buffer[i+1] == 'n' )
|
|
||||||
{
|
|
||||||
buffer[i] = '\n';
|
|
||||||
buffer.remove(i+1,1);
|
|
||||||
}
|
|
||||||
else if( buffer[i] == '\\' && buffer[i+1] == '0' )
|
|
||||||
{
|
|
||||||
buffer[i] = '\0';
|
|
||||||
buffer.remove(i+1,1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonParseError error;
|
|
||||||
QJsonDocument document = QJsonDocument::fromJson(buffer, &error);
|
|
||||||
|
|
||||||
qDebug()<<"JSON:";
|
|
||||||
qDebug()<<document.toJson().data();
|
|
||||||
QJsonObject jsonObject = document.object();
|
|
||||||
if(error.error == QJsonParseError::NoError && !document.isEmpty() && !jsonObject.isEmpty()) gotJson(jsonObject);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
qDebug()<<error.errorString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if(buffer.size() >= 6 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'N' && buffer[3] == 'S'
|
|
||||||
&& buffer[4] == 'O' && buffer[5] == 'R')
|
|
||||||
{
|
|
||||||
Sensor sensor = Sensor::sensorFromString(buffer);
|
|
||||||
if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::sendMessage(const QString &title, const QString &body)
|
|
||||||
{
|
|
||||||
write(QByteArray("MESG ") + title.toLatin1() + " BODY " + body.toLatin1());
|
|
||||||
}
|
|
||||||
|
|
||||||
void BroadCast::readyRead()
|
|
||||||
{
|
|
||||||
buffer_.append(iodevice_->readAll());
|
|
||||||
int newlineIndex = buffer_.indexOf('\n');
|
|
||||||
while( newlineIndex != -1 )
|
|
||||||
{
|
|
||||||
if(buffer_.startsWith("bcst: "))
|
|
||||||
{
|
|
||||||
QByteArray tmp = buffer_.mid(6,newlineIndex-6);
|
|
||||||
decode(tmp);
|
|
||||||
if(master_)decodeMaster(tmp);
|
|
||||||
}
|
|
||||||
buffer_.remove(0, newlineIndex+1);
|
|
||||||
newlineIndex = buffer_.indexOf('\n');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,55 +0,0 @@
|
||||||
#ifndef BROADCAST_H
|
|
||||||
#define BROADCAST_H
|
|
||||||
#include <QIODevice>
|
|
||||||
#include <QObject>
|
|
||||||
#include <QString>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include "sensors/sensor.h"
|
|
||||||
|
|
||||||
class BroadCast: public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
bool master_;
|
|
||||||
|
|
||||||
static constexpr uint8_t MODE_PREPACKET = 0;
|
|
||||||
static constexpr uint8_t MODE_PACKET = 1;
|
|
||||||
|
|
||||||
QByteArray buffer_;
|
|
||||||
|
|
||||||
QIODevice* const iodevice_;
|
|
||||||
|
|
||||||
void write(const char * const buffer, const size_t length);
|
|
||||||
void write(const QByteArray& buffer);
|
|
||||||
|
|
||||||
void decode(QByteArray buffer);
|
|
||||||
void decodeMaster(const QByteArray& buffer);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
|
|
||||||
void readyRead();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
|
|
||||||
void requestJson();
|
|
||||||
void requestSensors();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
void jsonRequested();
|
|
||||||
void gotJson(QJsonObject json);
|
|
||||||
void gotSensorState(Sensor sensor);
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
BroadCast(QIODevice* const iodevice = nullptr, bool master = true);
|
|
||||||
void sendJson(const QJsonObject& json);
|
|
||||||
void sendSensors();
|
|
||||||
void sendMessage(const QString& title, const QString& body);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // BROADCAST_H
|
|
||||||
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
#include "iomuliplexer.h"
|
|
||||||
#include<QDebug>
|
|
||||||
|
|
||||||
VirutalIODevice::VirutalIODevice(QObject* parent): QBuffer(parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 VirutalIODevice::writeData(const char *data, qint64 len)
|
|
||||||
{
|
|
||||||
blockSignals(true);
|
|
||||||
qint64 ret = QBuffer::writeData(data, len);
|
|
||||||
blockSignals(false);
|
|
||||||
masterReadyRead();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 VirutalIODevice::masterWrite(const QByteArray &byteArray)
|
|
||||||
{
|
|
||||||
return masterWrite(byteArray.data(), byteArray.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
qint64 VirutalIODevice::masterWrite(const char *data, qint64 maxSize)
|
|
||||||
{
|
|
||||||
blockSignals(true);
|
|
||||||
qint64 ret = QBuffer::writeData(data, maxSize);
|
|
||||||
blockSignals(false);
|
|
||||||
readyRead();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
IoMuliplexer::IoMuliplexer(QIODevice* mainDevice, QObject* Parent): IoMuliplexer(Parent)
|
|
||||||
{
|
|
||||||
setIoDevice(mainDevice);
|
|
||||||
}
|
|
||||||
|
|
||||||
IoMuliplexer::IoMuliplexer(QObject* Parent): QObject(Parent)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
IoMuliplexer::~IoMuliplexer()
|
|
||||||
{
|
|
||||||
for(size_t i = 0; i < ioDevices_.size(); ++i) delete ioDevices_[i];
|
|
||||||
ioDevices_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IoMuliplexer::setIoDevice(QIODevice* mainDevice)
|
|
||||||
{
|
|
||||||
mainDevice_ = mainDevice;
|
|
||||||
connect(mainDevice_, &QIODevice::readyRead, this, &IoMuliplexer::mainIsReadyRead);
|
|
||||||
}
|
|
||||||
|
|
||||||
QIODevice* IoMuliplexer::getIoDevice()
|
|
||||||
{
|
|
||||||
ioDevices_.push_back(new VirutalIODevice);
|
|
||||||
ioDevices_.back()->open(QIODevice::ReadWrite);
|
|
||||||
connect(ioDevices_.back(), &VirutalIODevice::masterReadyRead, this, &IoMuliplexer::clientIsReadyRead);
|
|
||||||
return ioDevices_.back();
|
|
||||||
}
|
|
||||||
|
|
||||||
void IoMuliplexer::clientIsReadyRead()
|
|
||||||
{
|
|
||||||
VirutalIODevice* device = dynamic_cast<VirutalIODevice*>(sender());
|
|
||||||
if(device)
|
|
||||||
{
|
|
||||||
QByteArray array = device->readAll();
|
|
||||||
mainDevice_->write(array);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IoMuliplexer::mainIsReadyRead()
|
|
||||||
{
|
|
||||||
QByteArray array = mainDevice_->readAll();
|
|
||||||
for(size_t i = 0; i < ioDevices_.size(); ++i) ioDevices_[i]->masterWrite(array);
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
#ifndef IOMULIPLEXER_H
|
|
||||||
#define IOMULIPLEXER_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <vector>
|
|
||||||
#include <QIODevice>
|
|
||||||
#include <QBuffer>
|
|
||||||
|
|
||||||
class VirutalIODevice: public QBuffer
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
|
|
||||||
VirutalIODevice(QObject* parent = nullptr);
|
|
||||||
virtual ~VirutalIODevice() override {}
|
|
||||||
|
|
||||||
virtual qint64 writeData(const char *data, qint64 len) override;
|
|
||||||
|
|
||||||
qint64 masterWrite(const QByteArray &byteArray);
|
|
||||||
qint64 masterWrite(const char *data, qint64 maxSize);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
|
|
||||||
void masterReadyRead();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class IoMuliplexer: public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
|
|
||||||
QIODevice* mainDevice_;
|
|
||||||
std::vector< VirutalIODevice* > ioDevices_;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit IoMuliplexer(QIODevice* mainDevice, QObject* Parent = nullptr);
|
|
||||||
explicit IoMuliplexer(QObject* Parent = nullptr);
|
|
||||||
|
|
||||||
~IoMuliplexer();
|
|
||||||
|
|
||||||
void setIoDevice(QIODevice* mainDevice);
|
|
||||||
|
|
||||||
QIODevice* getIoDevice();
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
|
|
||||||
void mainIsReadyRead();
|
|
||||||
void clientIsReadyRead();
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // IOMULIPLEXER_H
|
|
||||||
|
|
@ -3,12 +3,12 @@
|
||||||
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value,
|
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value,
|
||||||
QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||||
{
|
{
|
||||||
|
type_ = ITEM_VALUE_UINT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuxItem::setValue(uint8_t value)
|
void AuxItem::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
assert(micro_);
|
||||||
micro_->setAuxPwm(value);
|
micro_->setAuxPwm(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "../microcontroller.h"
|
#include "microcontroller.h"
|
||||||
|
|
||||||
class AuxItem: public Item
|
class AuxItem: public Item
|
||||||
{
|
{
|
||||||
|
|
@ -9,13 +9,12 @@ class AuxItem: public Item
|
||||||
private:
|
private:
|
||||||
Microcontroller* micro_;
|
Microcontroller* micro_;
|
||||||
|
|
||||||
public slots:
|
protected:
|
||||||
|
virtual void enactValue(uint8_t value) override;
|
||||||
virtual void setValue(uint8_t value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
AuxItem(Microcontroller* micro = nullptr, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||||
uint8_t value = 0, QObject* parent = nullptr);
|
uint8_t value = 0, QObject* parent = nullptr);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
14
src/items/fixeditemsource.cpp
Normal file
14
src/items/fixeditemsource.cpp
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
#include "fixeditemsource.h"
|
||||||
|
|
||||||
|
FixedItemSource::FixedItemSource(Microcontroller* micro, QObject *parent):
|
||||||
|
ItemSource{parent},
|
||||||
|
powerItem(new PowerItem(5487423)),
|
||||||
|
rgbItem(new RgbItem(micro, 5487422, "Rgb Lights")),
|
||||||
|
auxItem(new AuxItem(micro, 5487421, "Desk Light"))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FixedItemSource::refresh()
|
||||||
|
{
|
||||||
|
gotItems({powerItem, rgbItem, auxItem});
|
||||||
|
}
|
||||||
22
src/items/fixeditemsource.h
Normal file
22
src/items/fixeditemsource.h
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#ifndef FIXEDITEMSOURCE_H
|
||||||
|
#define FIXEDITEMSOURCE_H
|
||||||
|
|
||||||
|
#include "itemsource.h"
|
||||||
|
#include "poweritem.h"
|
||||||
|
#include "rgbitem.h"
|
||||||
|
#include "auxitem.h"
|
||||||
|
#include "microcontroller.h"
|
||||||
|
|
||||||
|
class FixedItemSource : public ItemSource
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
std::shared_ptr<PowerItem> powerItem;
|
||||||
|
std::shared_ptr<RgbItem> rgbItem;
|
||||||
|
std::shared_ptr<AuxItem> auxItem;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit FixedItemSource(Microcontroller* micro, QObject *parent = nullptr);
|
||||||
|
virtual void refresh() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FIXEDITEMSOURCE_H
|
||||||
|
|
@ -1,14 +1,20 @@
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
|
#include "actors/sensoractor.h"
|
||||||
|
#include "actors/regulator.h"
|
||||||
|
#include "actors/polynomalactor.h"
|
||||||
|
#include "programmode.h"
|
||||||
#include "relay.h"
|
#include "relay.h"
|
||||||
#include "../microcontroller.h"
|
#include "messageitem.h"
|
||||||
#include "../actors/sensoractor.h"
|
#include "systemitem.h"
|
||||||
#include "../actors/regulator.h"
|
#include "auxitem.h"
|
||||||
#include "../actors/polynomalactor.h"
|
#include "poweritem.h"
|
||||||
|
#include "rgbitem.h"
|
||||||
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
|
||||||
ItemData::ItemData(uint32_t itemIdIn, QString name, uint8_t value): name_(name), value_(value), itemId_(itemIdIn)
|
ItemData::ItemData(uint32_t itemIdIn, QString name, uint8_t value, bool loaded, bool hidden, item_value_type_t type):
|
||||||
|
name_(name), value_(value), itemId_(itemIdIn), loaded_(loaded), hidden_(hidden), type_(type)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -33,11 +39,63 @@ uint32_t ItemData::id() const
|
||||||
return itemId_;
|
return itemId_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemData::store(QJsonObject &json)
|
||||||
|
{
|
||||||
|
json["Name"] = name_;
|
||||||
|
json["ItemId"] = static_cast<double>(itemId_);
|
||||||
|
json["Value"] = static_cast<double>(value_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemData::load(const QJsonObject &json, const bool preserve)
|
||||||
|
{
|
||||||
|
if(!preserve)
|
||||||
|
{
|
||||||
|
name_ = json["Name"].toString(name_);
|
||||||
|
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
||||||
|
value_ = json["Value"].toInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ItemData::getLoaded() const
|
||||||
|
{
|
||||||
|
return loaded_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemData::setLoaded(bool loaded)
|
||||||
|
{
|
||||||
|
loaded_ = loaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ItemData::hasChanged(const ItemData& other)
|
||||||
|
{
|
||||||
|
if(other != *this)
|
||||||
|
return false;
|
||||||
|
if(other.getName() != getName())
|
||||||
|
return true;
|
||||||
|
if(other.getValue() != getValue())
|
||||||
|
return true;
|
||||||
|
if(other.getLoaded() != getLoaded())
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ItemData::isHidden()
|
||||||
|
{
|
||||||
|
return hidden_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemData::setHidden(bool hidden)
|
||||||
|
{
|
||||||
|
hidden_ = hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
item_value_type_t ItemData::getValueType()
|
||||||
|
{
|
||||||
|
return type_;
|
||||||
|
}
|
||||||
|
|
||||||
//item
|
//item
|
||||||
|
|
||||||
bool Item::secondaryFlag = false;
|
|
||||||
|
|
||||||
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
||||||
value)
|
value)
|
||||||
{
|
{
|
||||||
|
|
@ -55,8 +113,7 @@ Item::~Item()
|
||||||
|
|
||||||
void Item::store(QJsonObject &json)
|
void Item::store(QJsonObject &json)
|
||||||
{
|
{
|
||||||
json["Name"] = name_;
|
ItemData::store(json);
|
||||||
json["ItemId"] = static_cast<double>(itemId_);
|
|
||||||
json["override"] = override_;
|
json["override"] = override_;
|
||||||
QJsonArray actorsArray;
|
QJsonArray actorsArray;
|
||||||
for(size_t i = 0; i < actors_.size(); ++i)
|
for(size_t i = 0; i < actors_.size(); ++i)
|
||||||
|
|
@ -73,11 +130,7 @@ void Item::store(QJsonObject &json)
|
||||||
|
|
||||||
void Item::load(const QJsonObject &json, const bool preserve)
|
void Item::load(const QJsonObject &json, const bool preserve)
|
||||||
{
|
{
|
||||||
if(!preserve)
|
ItemData::load(json, preserve);
|
||||||
{
|
|
||||||
name_ = json["Name"].toString(name_);
|
|
||||||
itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
|
|
||||||
}
|
|
||||||
override_ = json["override"].toBool(false);
|
override_ = json["override"].toBool(false);
|
||||||
const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
|
const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
|
||||||
for(int i = 0; i < actorsArray.size(); ++i)
|
for(int i = 0; i < actorsArray.size(); ++i)
|
||||||
|
|
@ -85,46 +138,60 @@ void Item::load(const QJsonObject &json, const bool preserve)
|
||||||
if(actorsArray[i].isObject())
|
if(actorsArray[i].isObject())
|
||||||
{
|
{
|
||||||
std::shared_ptr<Actor> actor = Actor::loadActor(actorsArray[i].toObject());
|
std::shared_ptr<Actor> actor = Actor::loadActor(actorsArray[i].toObject());
|
||||||
if(actor != nullptr) addActor(actor);
|
if(actor != nullptr)
|
||||||
|
addActor(actor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::actorSetValue(uint8_t value)
|
void Item::actorSetValue(uint8_t value)
|
||||||
{
|
{
|
||||||
if(!override_) setValue(value);
|
if(!override_ && (programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY))
|
||||||
|
setValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::setValue(uint8_t value)
|
void Item::setValue(uint8_t value)
|
||||||
{
|
{
|
||||||
value_ = value;
|
qDebug()<<__func__;
|
||||||
valueChanged(value_);
|
informValue(value);
|
||||||
|
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||||
|
enactValue(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::informValue(uint8_t value)
|
void Item::informValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
if(value_ != value)
|
||||||
|
{
|
||||||
|
value_ = value;
|
||||||
|
valueChanged(value_);
|
||||||
|
updated(*this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Item::enactValue(uint8_t value)
|
||||||
|
{
|
||||||
|
(void)value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::addActor(std::shared_ptr<Actor> actor)
|
void Item::addActor(std::shared_ptr<Actor> actor)
|
||||||
{
|
{
|
||||||
actor->setParent(this);
|
actor->setParent(this);
|
||||||
actors_.push_back(actor);
|
actors_.push_back(actor);
|
||||||
if(!secondaryFlag)
|
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||||
{
|
|
||||||
connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
|
connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
|
||||||
}
|
|
||||||
connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
|
connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
|
||||||
|
|
||||||
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
|
||||||
if(sensorActor)connect(&globalSensors, &SensorStore::sensorChangedState, sensorActor.get(), &SensorActor::sensorEvent);
|
if(sensorActor)
|
||||||
|
connect(&globalSensors, &SensorStore::sensorChangedState, sensorActor.get(), &SensorActor::sensorEvent);
|
||||||
|
|
||||||
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
|
std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
|
||||||
if(regulator)connect(&globalSensors, &SensorStore::sensorChangedState, regulator.get(), &Regulator::sensorEvent);
|
if(regulator)
|
||||||
|
connect(&globalSensors, &SensorStore::sensorChangedState, regulator.get(), &Regulator::sensorEvent);
|
||||||
|
|
||||||
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
||||||
if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor.get(),
|
if(polynomalActor != nullptr )
|
||||||
&PolynomalActor::sensorEvent);
|
connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor.get(), &PolynomalActor::sensorEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Item::removeActor(std::shared_ptr<Actor> actor)
|
bool Item::removeActor(std::shared_ptr<Actor> actor)
|
||||||
|
|
@ -167,5 +234,50 @@ bool Item::hasActors()
|
||||||
|
|
||||||
void Item::setActorsActive(bool in)
|
void Item::setActorsActive(bool in)
|
||||||
{
|
{
|
||||||
for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
for(unsigned i = 0; i < actors_.size(); i++)
|
||||||
|
in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Item::mergeLoaded(Item& item)
|
||||||
|
{
|
||||||
|
name_ = item.name_;
|
||||||
|
actors_.clear();
|
||||||
|
for(std::shared_ptr<Actor> actor : item.actors_)
|
||||||
|
addActor(actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Item> Item::loadItem(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
std::shared_ptr<Item> newItem = nullptr;
|
||||||
|
if(json["Type"].toString("") == "Relay")
|
||||||
|
{
|
||||||
|
newItem = std::shared_ptr<Relay>(new Relay);
|
||||||
|
}
|
||||||
|
else if(json["Type"].toString("") == "Message")
|
||||||
|
{
|
||||||
|
newItem = std::shared_ptr<MessageItem>(new MessageItem);
|
||||||
|
}
|
||||||
|
else if(json["Type"].toString("") == "System")
|
||||||
|
{
|
||||||
|
newItem = std::shared_ptr<SystemItem>(new SystemItem);
|
||||||
|
}
|
||||||
|
else if(json["Type"].toString("") == "Aux")
|
||||||
|
{
|
||||||
|
newItem = std::shared_ptr<AuxItem>(new AuxItem);
|
||||||
|
}
|
||||||
|
else if(json["Type"].toString("") == "Power")
|
||||||
|
{
|
||||||
|
newItem = std::shared_ptr<PowerItem>(new PowerItem);
|
||||||
|
}
|
||||||
|
else if(json["Type"].toString("") == "Rgb")
|
||||||
|
{
|
||||||
|
newItem = std::shared_ptr<RgbItem>(new RgbItem);
|
||||||
|
}
|
||||||
|
if(newItem)
|
||||||
|
{
|
||||||
|
newItem->load(json);
|
||||||
|
newItem->setLoaded(true);
|
||||||
|
}
|
||||||
|
return newItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,16 +8,29 @@
|
||||||
|
|
||||||
class Actor;
|
class Actor;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
ITEM_VALUE_BOOL = 0,
|
||||||
|
ITEM_VALUE_UINT,
|
||||||
|
ITEM_VALUE_NO_VALUE
|
||||||
|
} item_value_type_t;
|
||||||
|
|
||||||
class ItemData
|
class ItemData
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
QString name_;
|
QString name_;
|
||||||
uint8_t value_;
|
uint8_t value_;
|
||||||
uint32_t itemId_;
|
uint32_t itemId_;
|
||||||
|
bool loaded_;
|
||||||
|
bool hidden_;
|
||||||
|
item_value_type_t type_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(),
|
||||||
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0);
|
QString name = "Item",
|
||||||
|
uint8_t value = 0,
|
||||||
|
bool loaded = false,
|
||||||
|
bool hidden = false,
|
||||||
|
item_value_type_t type = ITEM_VALUE_BOOL);
|
||||||
|
|
||||||
inline bool operator==(const ItemData& in) const
|
inline bool operator==(const ItemData& in) const
|
||||||
{
|
{
|
||||||
|
|
@ -30,9 +43,17 @@ public:
|
||||||
|
|
||||||
uint32_t id() const;
|
uint32_t id() const;
|
||||||
|
|
||||||
|
bool hasChanged(const ItemData& other);
|
||||||
void setName(QString name);
|
void setName(QString name);
|
||||||
uint8_t getValue() const;
|
uint8_t getValue() const;
|
||||||
|
bool getLoaded() const;
|
||||||
|
void setLoaded(bool loaded);
|
||||||
|
bool isHidden();
|
||||||
|
void setHidden(bool hidden);
|
||||||
|
item_value_type_t getValueType();
|
||||||
virtual QString getName() const;
|
virtual QString getName() const;
|
||||||
|
virtual void store(QJsonObject& json);
|
||||||
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -44,20 +65,15 @@ private:
|
||||||
|
|
||||||
bool override_ = false;
|
bool override_ = false;
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
static bool secondaryFlag;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void valueChanged(uint8_t value);
|
void valueChanged(uint8_t value);
|
||||||
|
void updated(ItemData data);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
virtual void actorSetValue(uint8_t value);
|
virtual void actorSetValue(uint8_t value);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void setValue(uint8_t value);
|
||||||
virtual void setValue(uint8_t value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -76,9 +92,15 @@ public:
|
||||||
void setOverride(const bool in);
|
void setOverride(const bool in);
|
||||||
bool getOverride();
|
bool getOverride();
|
||||||
void informValue(uint8_t value);
|
void informValue(uint8_t value);
|
||||||
|
void mergeLoaded(Item& item);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json);
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||||
|
|
||||||
|
static std::shared_ptr<Item> loadItem(const QJsonObject& json);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void enactValue(uint8_t value);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
38
src/items/itemloadersource.cpp
Normal file
38
src/items/itemloadersource.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
#include "itemloadersource.h"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
ItemLoaderSource::ItemLoaderSource(const QJsonObject& json, QObject *parent):
|
||||||
|
ItemSource{parent},
|
||||||
|
json(json)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemLoaderSource::refresh()
|
||||||
|
{
|
||||||
|
std::vector<std::shared_ptr<Item>> items;
|
||||||
|
const QJsonArray itemsArray(json["Items"].toArray());
|
||||||
|
for(int i = 0; i < itemsArray.size(); ++i)
|
||||||
|
{
|
||||||
|
if(!itemsArray[i].isObject())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const QJsonObject itemObject = itemsArray[i].toObject();
|
||||||
|
std::shared_ptr<Item> newItem = Item::loadItem(itemObject);
|
||||||
|
if(newItem)
|
||||||
|
{
|
||||||
|
items.push_back(newItem);
|
||||||
|
qDebug()<<"Loaded item"<<newItem->getName();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
gotItems(items);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemLoaderSource::updateJson(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
this->json = json;
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemLoaderSource::~ItemLoaderSource()
|
||||||
|
{}
|
||||||
|
|
||||||
21
src/items/itemloadersource.h
Normal file
21
src/items/itemloadersource.h
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef ITEMLOADERSOURCE_H
|
||||||
|
#define ITEMLOADERSOURCE_H
|
||||||
|
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "itemsource.h"
|
||||||
|
|
||||||
|
class ItemLoaderSource : public ItemSource
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QJsonObject json;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ItemLoaderSource(const QJsonObject& json = QJsonObject(), QObject *parent = nullptr);
|
||||||
|
~ItemLoaderSource();
|
||||||
|
void updateJson(const QJsonObject& json);
|
||||||
|
virtual void refresh() override;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ITEMLOADERSOURCE_H
|
||||||
5
src/items/itemsource.cpp
Normal file
5
src/items/itemsource.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
#include "itemsource.h"
|
||||||
|
|
||||||
|
ItemSource::ItemSource(QObject *parent)
|
||||||
|
: QObject{parent}
|
||||||
|
{}
|
||||||
25
src/items/itemsource.h
Normal file
25
src/items/itemsource.h
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
#ifndef ITEMSOURCE_H
|
||||||
|
#define ITEMSOURCE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "item.h"
|
||||||
|
|
||||||
|
class ItemSource : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ItemSource(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
virtual void refresh() = 0;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void gotItems(std::vector<std::shared_ptr<Item>> items, bool inform = true);
|
||||||
|
void requestReplaceItems(std::vector<std::shared_ptr<Item>> items);
|
||||||
|
void updateItems(std::vector<ItemData> items, bool inform = true);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ITEMSOURCE_H
|
||||||
|
|
@ -1,52 +1,42 @@
|
||||||
#include "itemstore.h"
|
#include "itemstore.h"
|
||||||
#include "relay.h"
|
|
||||||
#include "messageitem.h"
|
|
||||||
#include "systemitem.h"
|
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
|
#include <typeinfo>
|
||||||
|
|
||||||
ItemStore::ItemStore(QObject *parent): QObject(parent)
|
ItemStore::ItemStore(QObject *parent): QObject(parent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::addItem(std::shared_ptr<Item> item)
|
void ItemStore::addItem(std::shared_ptr<Item> item, bool inform)
|
||||||
{
|
|
||||||
bool mached = false;
|
|
||||||
for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true;
|
|
||||||
if(!mached)
|
|
||||||
{
|
|
||||||
items_.push_back(std::shared_ptr<Item>(item));
|
|
||||||
itemAdded(std::weak_ptr<Item>(items_.back()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
|
|
||||||
{
|
{
|
||||||
|
std::shared_ptr<Item> matched = nullptr;
|
||||||
for(unsigned i = 0; i < items_.size(); i++ )
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
{
|
{
|
||||||
if(Relay* relay = dynamic_cast<Relay*>(items_[i].get()))
|
if(*items_[i] == *item)
|
||||||
{
|
{
|
||||||
bool mached = false;
|
matched = items_[i];
|
||||||
for(unsigned j = 0; j < itemIn.size(); j++) if(*(items_[i]) == *(itemIn[j]))
|
break;
|
||||||
{
|
|
||||||
mached = true;
|
|
||||||
if(itemIn[j]->getValue() != items_[i]->getValue()) items_[i]->informValue(itemIn[j]->getValue());
|
|
||||||
Relay* relayIn = dynamic_cast<Relay*>(itemIn[j].get());
|
|
||||||
if(relayIn)
|
|
||||||
{
|
|
||||||
if(relay->getId() != relayIn->getId()) relay->setId(relayIn->getId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if(!mached)
|
if(!matched)
|
||||||
{
|
{
|
||||||
itemDeleted(*items_[i].get());
|
items_.push_back(std::shared_ptr<Item>(item));
|
||||||
items_.erase(items_.begin()+i);
|
connect(item.get(), &Item::updated, this, &ItemStore::itemUpdateSlot);
|
||||||
|
qDebug()<<"Item"<<item->getName()<<"added"<<(item->getLoaded() ? "from loaded" : "");
|
||||||
|
itemAdded(std::weak_ptr<Item>(items_.back()));
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(item->getLoaded())
|
||||||
|
matched->mergeLoaded(*item);
|
||||||
|
else if(item->getValue() != matched->getValue())
|
||||||
|
updateItem(*item, inform);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(unsigned j = 0; j < itemIn.size(); j++)addItem(itemIn[j]);
|
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn, bool inform)
|
||||||
|
{
|
||||||
|
for(unsigned j = 0; j < itemIn.size(); j++)
|
||||||
|
addItem(itemIn[j], inform);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::removeItem(const ItemData& item)
|
void ItemStore::removeItem(const ItemData& item)
|
||||||
|
|
@ -55,12 +45,26 @@ void ItemStore::removeItem(const ItemData& item)
|
||||||
{
|
{
|
||||||
if(item == *items_[j])
|
if(item == *items_[j])
|
||||||
{
|
{
|
||||||
|
qDebug()<<"Item"<<item.getName()<<"deleted";
|
||||||
|
itemDeleted(*items_[j]);
|
||||||
items_.erase(items_.begin()+j);
|
items_.erase(items_.begin()+j);
|
||||||
--j;
|
--j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemStore::replaceItems(const std::vector<std::shared_ptr<Item>>& items)
|
||||||
|
{
|
||||||
|
addItems(items, true);
|
||||||
|
std::vector<ItemData> deletedItems;
|
||||||
|
for(std::shared_ptr<Item> item : items_)
|
||||||
|
{
|
||||||
|
if(std::find_if(items.begin(), items.end(), [item](const std::shared_ptr<Item> other){return *item == *other;}) == items.end())
|
||||||
|
deletedItems.push_back(*item);
|
||||||
|
}
|
||||||
|
for(const ItemData& item : deletedItems)
|
||||||
|
removeItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
void ItemStore::clear()
|
void ItemStore::clear()
|
||||||
{
|
{
|
||||||
|
|
@ -69,19 +73,33 @@ void ItemStore::clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ItemStore::itemStateChanged(const ItemData& item)
|
void ItemStore::updateItems(std::vector<ItemData> items, bool inform)
|
||||||
{
|
{
|
||||||
|
for(const ItemData& item : items)
|
||||||
|
updateItem(item, inform);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemStore::updateItem(const ItemData& item, bool inform)
|
||||||
|
{
|
||||||
for(unsigned i = 0; i < items_.size(); i++ )
|
for(unsigned i = 0; i < items_.size(); i++ )
|
||||||
{
|
{
|
||||||
if(items_[i]->operator==(item))
|
if(items_[i]->operator==(item))
|
||||||
{
|
{
|
||||||
|
if(items_[i]->hasChanged(item))
|
||||||
if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
|
{
|
||||||
|
if(items_[i]->getValue() != item.getValue())
|
||||||
|
{
|
||||||
|
items_[i]->setLoaded(false);
|
||||||
|
if(inform)
|
||||||
|
items_[i]->informValue(item.getValue());
|
||||||
|
else
|
||||||
|
items_[i]->setValue(item.getValue());
|
||||||
|
}
|
||||||
|
qDebug()<<"Item"<<items_[i]->getName()<<"updated";
|
||||||
|
itemUpdated(items_[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::store(QJsonObject& json)
|
void ItemStore::store(QJsonObject& json)
|
||||||
|
|
@ -96,35 +114,41 @@ void ItemStore::store(QJsonObject& json)
|
||||||
json["Items"] = itemsArray;
|
json["Items"] = itemsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemStore::load(const QJsonObject& json)
|
void ItemStore::itemUpdateSlot(ItemData data)
|
||||||
{
|
{
|
||||||
const QJsonArray itemsArray(json["Items"].toArray(QJsonArray()));
|
for(std::shared_ptr<Item>& item: items_)
|
||||||
for(int i = 0; i < itemsArray.size(); ++i)
|
|
||||||
{
|
{
|
||||||
if(itemsArray[i].isObject())
|
if(*item == data)
|
||||||
{
|
itemUpdated(std::weak_ptr<Item>(item));
|
||||||
const QJsonObject itemObject = itemsArray[i].toObject();
|
|
||||||
std::shared_ptr<Item> newItem;
|
|
||||||
if(itemObject["Type"].toString("") == "Relay")
|
|
||||||
{
|
|
||||||
newItem = std::shared_ptr<Relay>(new Relay());
|
|
||||||
}
|
|
||||||
else if(itemObject["Type"].toString("") == "Message")
|
|
||||||
{
|
|
||||||
newItem = std::shared_ptr<MessageItem>(new MessageItem);
|
|
||||||
}
|
|
||||||
else if(itemObject["Type"].toString("") == "System")
|
|
||||||
{
|
|
||||||
newItem = std::shared_ptr<SystemItem>(new SystemItem());
|
|
||||||
}
|
|
||||||
else if(itemObject["Type"].toString("") == "Aux")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
if(newItem)
|
|
||||||
{
|
|
||||||
newItem->load(itemObject);
|
|
||||||
addItem(newItem);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Item> ItemStore::getItem(uint32_t id)
|
||||||
|
{
|
||||||
|
for(std::shared_ptr<Item>& item : items_)
|
||||||
|
{
|
||||||
|
if(item->id() == id)
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemStore::registerItemSource(ItemSource* source)
|
||||||
|
{
|
||||||
|
qDebug()<<__func__<<typeid(*source).name();
|
||||||
|
connect(source, &ItemSource::gotItems, this, &ItemStore::addItems);
|
||||||
|
connect(source, &ItemSource::updateItems, this, &ItemStore::updateItems);
|
||||||
|
connect(source, &ItemSource::requestReplaceItems, this, &ItemStore::replaceItems);
|
||||||
|
connect(this, &ItemStore::sigRefresh, source, &ItemSource::refresh);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ItemStore::refresh()
|
||||||
|
{
|
||||||
|
for(std::shared_ptr<Item>& item : items_)
|
||||||
|
itemDeleted(*item);
|
||||||
|
items_.clear();
|
||||||
|
sigRefresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStore globalItems;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "../sensors/sensor.h"
|
#include "itemsource.h"
|
||||||
|
|
||||||
#include <QJsonObject>
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
|
@ -22,8 +22,10 @@ public:
|
||||||
return &items_;
|
return &items_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<Item> getItem(uint32_t id);
|
||||||
|
|
||||||
|
void registerItemSource(ItemSource* source);
|
||||||
void store(QJsonObject &json);
|
void store(QJsonObject &json);
|
||||||
void load(const QJsonObject &json);
|
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
|
@ -31,11 +33,21 @@ signals:
|
||||||
|
|
||||||
void itemDeleted(ItemData item);
|
void itemDeleted(ItemData item);
|
||||||
void itemAdded(std::weak_ptr<Item> Item);
|
void itemAdded(std::weak_ptr<Item> Item);
|
||||||
|
void itemUpdated(std::weak_ptr<Item> Item);
|
||||||
|
void sigRefresh();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void removeItem(const ItemData& item);
|
void removeItem(const ItemData& item);
|
||||||
void addItem(std::shared_ptr<Item> item);
|
void addItem(std::shared_ptr<Item> item, bool inform = true);
|
||||||
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
|
void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn, bool inform = true);
|
||||||
void itemStateChanged(const ItemData& item);
|
void replaceItems(const std::vector<std::shared_ptr<Item>>& items);
|
||||||
|
void updateItems(std::vector<ItemData> items, bool inform = true);
|
||||||
|
void updateItem(const ItemData& item, bool inform = true);
|
||||||
|
void refresh();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void itemUpdateSlot(ItemData data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern ItemStore globalItems;
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,19 @@
|
||||||
#include "messageitem.h"
|
#include "messageitem.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QSound>
|
#include <QSoundEffect>
|
||||||
|
|
||||||
BroadCast* MessageItem::broadCast = nullptr;
|
|
||||||
|
|
||||||
MessageItem::MessageItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent):
|
MessageItem::MessageItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent):
|
||||||
Item(itemIdIn, name, value, parent)
|
Item(itemIdIn, name, value, parent)
|
||||||
{
|
{
|
||||||
|
alertSound.setVolume(1.0);
|
||||||
|
type_ = ITEM_VALUE_NO_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageItem::MessageItem(const ItemData& itemData, QObject *parent):
|
MessageItem::MessageItem(const ItemData& itemData, QObject *parent):
|
||||||
Item(itemData, parent)
|
Item(itemData, parent)
|
||||||
{
|
{
|
||||||
|
alertSound.setVolume(1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MessageItem::~MessageItem()
|
MessageItem::~MessageItem()
|
||||||
|
|
@ -22,13 +21,12 @@ MessageItem::~MessageItem()
|
||||||
closeMessageBox();
|
closeMessageBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageItem::setValue(uint8_t value)
|
void MessageItem::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
|
||||||
if(value && !messageBox_)
|
if(value && !messageBox_)
|
||||||
{
|
{
|
||||||
if(broadCast) broadCast->sendMessage(name_, message_);
|
if(!alertSoundFileName.isEmpty())
|
||||||
if(!alertSoundFileName.isEmpty()) QSound::play(alertSoundFileName);
|
alertSound.play();
|
||||||
messageBox_ = new QMessageBox(QMessageBox::NoIcon, name_, message_);
|
messageBox_ = new QMessageBox(QMessageBox::NoIcon, name_, message_);
|
||||||
messageBox_->setModal(false);
|
messageBox_->setModal(false);
|
||||||
connect(messageBox_, &QMessageBox::finished, this, &MessageItem::closeMessageBox);
|
connect(messageBox_, &QMessageBox::finished, this, &MessageItem::closeMessageBox);
|
||||||
|
|
@ -60,6 +58,7 @@ QString MessageItem::getAlert()
|
||||||
void MessageItem::setAlert(const QString &in)
|
void MessageItem::setAlert(const QString &in)
|
||||||
{
|
{
|
||||||
alertSoundFileName = in;
|
alertSoundFileName = in;
|
||||||
|
alertSound.setSource(QUrl::fromLocalFile(alertSoundFileName));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageItem::setMessage(const QString& in)
|
void MessageItem::setMessage(const QString& in)
|
||||||
|
|
@ -77,7 +76,8 @@ void MessageItem::store(QJsonObject &json)
|
||||||
json["Type"] = "Message";
|
json["Type"] = "Message";
|
||||||
Item::store(json);
|
Item::store(json);
|
||||||
json["Message"] = message_;
|
json["Message"] = message_;
|
||||||
if(!alertSoundFileName.isEmpty()) json["Alert"] = alertSoundFileName;
|
if(!alertSoundFileName.isEmpty())
|
||||||
|
json["Alert"] = alertSoundFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessageItem::load(const QJsonObject &json, const bool preserve)
|
void MessageItem::load(const QJsonObject &json, const bool preserve)
|
||||||
|
|
@ -85,4 +85,6 @@ void MessageItem::load(const QJsonObject &json, const bool preserve)
|
||||||
Item::load(json,preserve);
|
Item::load(json,preserve);
|
||||||
message_ = json["Message"].toString("Invalid Message");
|
message_ = json["Message"].toString("Invalid Message");
|
||||||
alertSoundFileName = json["Alert"].toString("");
|
alertSoundFileName = json["Alert"].toString("");
|
||||||
|
if(!alertSoundFileName.isEmpty())
|
||||||
|
alertSound.setSource(QUrl::fromLocalFile(alertSoundFileName));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@
|
||||||
#define MESSAGEITEM_H
|
#define MESSAGEITEM_H
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QSoundEffect>
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "../broadcast.h"
|
|
||||||
|
|
||||||
class MessageItem : public Item
|
class MessageItem : public Item
|
||||||
{
|
{
|
||||||
|
|
@ -14,17 +14,13 @@ private:
|
||||||
QString message_;
|
QString message_;
|
||||||
QMessageBox* messageBox_ = nullptr;
|
QMessageBox* messageBox_ = nullptr;
|
||||||
QString alertSoundFileName = "";
|
QString alertSoundFileName = "";
|
||||||
|
QSoundEffect alertSound;
|
||||||
public:
|
|
||||||
static BroadCast* broadCast;
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void closeMessageBox();
|
void closeMessageBox();
|
||||||
|
|
||||||
public:
|
protected:
|
||||||
|
virtual void enactValue(uint8_t value) override;
|
||||||
virtual void setValue(uint8_t value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
@ -38,8 +34,8 @@ public:
|
||||||
void setAlert(const QString& in);
|
void setAlert(const QString& in);
|
||||||
QString getAlert();
|
QString getAlert();
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
virtual void load(const QJsonObject& json, const bool preserve = false) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MESSAGEITEM_H
|
#endif // MESSAGEITEM_H
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,20 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value,
|
PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* parent):
|
||||||
parent)
|
Item(itemIdIn, name, value, parent)
|
||||||
{
|
{
|
||||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||||
setValue(true);
|
PowerItem::setValue(true);
|
||||||
|
hidden_ = true;
|
||||||
|
type_ = ITEM_VALUE_NO_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerItem::setValue(uint8_t value)
|
void PowerItem::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
qDebug()<<"shutdown";
|
|
||||||
Item::setValue(value);
|
|
||||||
if(!value)
|
if(!value)
|
||||||
{
|
{
|
||||||
|
qDebug()<<"shutdown";
|
||||||
QTimer::singleShot(5000, this, &PowerItem::timeout);
|
QTimer::singleShot(5000, this, &PowerItem::timeout);
|
||||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 1, "Shutdown Imminent", true));
|
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 1, "Shutdown Imminent", true));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include "../sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
#include "../microcontroller.h"
|
#include "microcontroller.h"
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
|
@ -16,19 +16,17 @@ signals:
|
||||||
void stateChanged(Sensor sensor);
|
void stateChanged(Sensor sensor);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void timeout();
|
void timeout();
|
||||||
|
|
||||||
public slots:
|
protected:
|
||||||
|
virtual void enactValue(uint8_t value) override;
|
||||||
virtual void setValue(uint8_t value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PowerItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0,
|
PowerItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Power", uint8_t value = 0,
|
||||||
QObject* parent = nullptr);
|
QObject* parent = nullptr);
|
||||||
void emmitSensor()
|
void emmitSensor()
|
||||||
{
|
{
|
||||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||||
}
|
}
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -9,16 +9,17 @@ Relay::Relay(uint8_t id, QString name, uint16_t address, bool state, QObject* pa
|
||||||
id_(id), address_(address)
|
id_(id), address_(address)
|
||||||
{
|
{
|
||||||
itemId_ = address | ((uint32_t)id << 16);
|
itemId_ = address | ((uint32_t)id << 16);
|
||||||
qDebug()<<"Relay "<<id_<<"Name "<<name<<" id "<<itemId_<<" state "<<state<<" addr: "<<address;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Relay::setValue(uint8_t value)
|
void Relay::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
qDebug()<<"Relay"<<__func__<<micro_;
|
||||||
if(micro_)
|
if(micro_)
|
||||||
{
|
{
|
||||||
if(value)micro_->relayOn(id_);
|
if(value)
|
||||||
else micro_->relayOff(id_);
|
micro_->relayOn(id_);
|
||||||
|
else
|
||||||
|
micro_->relayOff(id_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include<stdint.h>
|
#include<stdint.h>
|
||||||
#include<QObject>
|
#include<QObject>
|
||||||
|
|
||||||
#include "../sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
class Microcontroller;
|
class Microcontroller;
|
||||||
|
|
@ -18,9 +18,10 @@ private:
|
||||||
uint8_t id_;
|
uint8_t id_;
|
||||||
uint16_t address_;
|
uint16_t address_;
|
||||||
|
|
||||||
public slots:
|
protected:
|
||||||
|
virtual void enactValue(uint8_t value) override;
|
||||||
|
|
||||||
virtual void setValue(uint8_t value);
|
public slots:
|
||||||
void on();
|
void on();
|
||||||
void off();
|
void off();
|
||||||
void toggle();
|
void toggle();
|
||||||
|
|
@ -37,7 +38,7 @@ public:
|
||||||
micro_ = micro;
|
micro_ = micro;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
virtual void load(const QJsonObject& json, const bool preserve = false) override;
|
||||||
};
|
};
|
||||||
#endif // RELAY_H
|
#endif // RELAY_H
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@ RgbItem::RgbItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RgbItem::setValue(uint8_t value)
|
void RgbItem::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
Item::setValue(value);
|
assert(micro_);
|
||||||
value ? micro_->rgbOn() : micro_->rgbOff();
|
value ? micro_->rgbOn() : micro_->rgbOff();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../microcontroller.h"
|
#include "microcontroller.h"
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
class RgbItem: public Item
|
class RgbItem: public Item
|
||||||
|
|
@ -9,13 +9,12 @@ class RgbItem: public Item
|
||||||
private:
|
private:
|
||||||
Microcontroller* micro_;
|
Microcontroller* micro_;
|
||||||
|
|
||||||
public slots:
|
protected:
|
||||||
|
virtual void enactValue(uint8_t value) override;
|
||||||
virtual void setValue(uint8_t value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RgbItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
RgbItem(Microcontroller* micro = nullptr, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||||
uint8_t value = 0, QObject* parent = nullptr);
|
uint8_t value = 0, QObject* parent = nullptr);
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#include "systemitem.h"
|
#include "systemitem.h"
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
void SystemItem::setValue(uint8_t value)
|
void SystemItem::enactValue(uint8_t value)
|
||||||
{
|
{
|
||||||
QProcess::execute(value ? onCommand_ : offCommand_);
|
QProcess::execute(value ? onCommand_ : offCommand_);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,19 @@
|
||||||
#ifndef SYSTEMITEM_H
|
#ifndef SYSTEMITEM_H
|
||||||
#define SYSTEMITEM_H
|
#define SYSTEMITEM_H
|
||||||
|
|
||||||
|
|
||||||
#include "item.h"
|
#include "item.h"
|
||||||
|
|
||||||
class SystemItem : public Item
|
class SystemItem : public Item
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private:
|
private:
|
||||||
|
|
||||||
QString onCommand_;
|
QString onCommand_;
|
||||||
QString offCommand_;
|
QString offCommand_;
|
||||||
|
|
||||||
public:
|
protected:
|
||||||
|
virtual void enactValue(uint8_t value) override;
|
||||||
virtual void setValue(uint8_t value);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SystemItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,
|
SystemItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,
|
||||||
QObject *parent = nullptr);
|
QObject *parent = nullptr);
|
||||||
SystemItem(const ItemData& itemData, QObject *parent = nullptr);
|
SystemItem(const ItemData& itemData, QObject *parent = nullptr);
|
||||||
|
|
@ -34,8 +30,8 @@ public:
|
||||||
return offCommand_;
|
return offCommand_;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void store(QJsonObject& json);
|
virtual void store(QJsonObject& json) override;
|
||||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
virtual void load(const QJsonObject& json, const bool preserve = false) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYSTEMITEM_H
|
#endif // SYSTEMITEM_H
|
||||||
|
|
|
||||||
155
src/main.cpp
155
src/main.cpp
|
|
@ -1,26 +1,16 @@
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
#include <stdio.h>
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTcpSocket>
|
#include <QTcpSocket>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QSettings>
|
||||||
//Currently pipewire support is disabled
|
|
||||||
//#include <pipewire/pipewire.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
|
||||||
#include <QtSerialPort/QtSerialPort>
|
#include <QtSerialPort/QtSerialPort>
|
||||||
#include <QtSerialPort/QSerialPortInfo>
|
#include <QtSerialPort/QSerialPortInfo>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "microcontroller.h"
|
|
||||||
#include "ui/mainwindow.h"
|
#include "ui/mainwindow.h"
|
||||||
#include "items/itemstore.h"
|
#include "items/itemstore.h"
|
||||||
#include "mainobject.h"
|
#include "mainobject.h"
|
||||||
|
#include "programmode.h"
|
||||||
|
|
||||||
#define BAUD QSerialPort::Baud38400
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
|
@ -37,102 +27,113 @@ int main(int argc, char *argv[])
|
||||||
QDir::setCurrent(a.applicationDirPath());
|
QDir::setCurrent(a.applicationDirPath());
|
||||||
|
|
||||||
//parse comand line
|
//parse comand line
|
||||||
#ifndef Q_OS_ANDROID
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.setApplicationDescription("Smart Home Interface");
|
parser.setApplicationDescription("Smart Home Interface");
|
||||||
parser.addHelpOption();
|
parser.addHelpOption();
|
||||||
parser.addVersionOption();
|
parser.addVersionOption();
|
||||||
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
|
QCommandLineOption masterOption(QStringList() << "m" << "master", QCoreApplication::translate("main", "Use in master mode"));
|
||||||
parser.addOption(tcpOption);
|
parser.addOption(masterOption);
|
||||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main",
|
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "address", "0.0.0.0");
|
||||||
"Set server host ip addres"), "adress");
|
|
||||||
parser.addOption(hostOption);
|
parser.addOption(hostOption);
|
||||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main",
|
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port"), "port", "104476");
|
||||||
"Set server Port in TCP mode or Serial port in serial mode"), "port");
|
|
||||||
parser.addOption(portOption);
|
parser.addOption(portOption);
|
||||||
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main",
|
QCommandLineOption settingsPathOption(QStringList()<<"c"<<"config", QCoreApplication::translate("main", "Set config file"), "configFilePath",
|
||||||
"Use serial connection"));
|
QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
|
||||||
parser.addOption(serialOption);
|
|
||||||
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
|
|
||||||
parser.addOption(baudOption);
|
|
||||||
QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main",
|
|
||||||
"Set config file"), "configFilePath");
|
|
||||||
parser.addOption(settingsPathOption);
|
parser.addOption(settingsPathOption);
|
||||||
QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main",
|
QCommandLineOption headlessOption(QStringList()<<"e"<<"headless", QCoreApplication::translate("main", "Dont start the gui"));
|
||||||
"Set if instance is not main instance"));
|
parser.addOption(headlessOption);
|
||||||
parser.addOption(secondaryOption);
|
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
#endif
|
|
||||||
|
|
||||||
QIODevice* masterIODevice = nullptr;
|
int retVal;
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
programMode = PROGRAM_MODE_UI_ONLY;
|
||||||
if(parser.isSet(tcpOption))
|
if(parser.isSet(masterOption))
|
||||||
{
|
{
|
||||||
|
programMode = PROGRAM_MODE_PRIMARY;
|
||||||
|
if(parser.isSet(headlessOption))
|
||||||
|
programMode = PROGRAM_MODE_HEADLESS_PRIMARY;
|
||||||
|
}
|
||||||
|
if(programMode == PROGRAM_MODE_PRIMARY || programMode == PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||||
|
{
|
||||||
|
QString settingsPath = parser.value(settingsPathOption);
|
||||||
|
QJsonObject json = MainObject::getJsonObjectFromDisk(settingsPath);
|
||||||
|
bool tcpMicro = json["MicroTcp"].toBool(true);
|
||||||
|
json["MicroTcp"] = tcpMicro;
|
||||||
|
|
||||||
|
QIODevice* microDevice = nullptr;
|
||||||
|
if(tcpMicro)
|
||||||
|
{
|
||||||
|
int port = json["MicroTcpPort"].toInt(6856);
|
||||||
|
json["MicroTcpPort"] = port;
|
||||||
|
QString host = json["MicroTcpHost"].toString("127.0.0.1");
|
||||||
|
json["MicroTcpHost"] = host;
|
||||||
|
|
||||||
QTcpSocket* microSocket = new QTcpSocket;
|
QTcpSocket* microSocket = new QTcpSocket;
|
||||||
|
|
||||||
int port = 6856;
|
qInfo()<<"connecting to "<<host<<':'<<port<<" for tcp micro";
|
||||||
if(parser.isSet(portOption)) port = parser.value(portOption).toInt();
|
|
||||||
|
|
||||||
QString host("127.0.0.1");
|
|
||||||
if(parser.isSet(hostOption)) host = parser.value(hostOption);
|
|
||||||
std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
|
|
||||||
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
microSocket->connectToHost(host, port, QIODevice::ReadWrite);
|
||||||
|
|
||||||
if(!microSocket->waitForConnected(1000))
|
if(!microSocket->waitForConnected(1000))
|
||||||
{
|
{
|
||||||
std::cout<<"Can not connect to to Server.\n";
|
qCritical()<<"Can not connect to tcp micro";
|
||||||
QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
|
MainObject::storeJsonObjectToDisk(settingsPath, json);
|
||||||
|
if(programMode == PROGRAM_MODE_PRIMARY)
|
||||||
|
QMessageBox::critical(nullptr, "Error", "Can not connect to tcp micro");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
masterIODevice = microSocket;
|
microDevice = microSocket;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
QString port = json["MicroSerialPort"].toString("ttyUSB0");
|
||||||
|
json["MicroSerialPort"] = port;
|
||||||
|
int baud = json["MicroSerialBaud"].toInt(38400);
|
||||||
|
json["MicroSerialBaud"] = baud;
|
||||||
|
|
||||||
QSerialPort *microPort = new QSerialPort;
|
QSerialPort *microPort = new QSerialPort;
|
||||||
if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
|
microPort->setPortName(port);
|
||||||
else microPort->setPortName("ttyUSB0");
|
microPort->setBaudRate(baud);
|
||||||
|
microPort->open(QIODevice::ReadWrite);
|
||||||
|
|
||||||
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
|
if(!microPort->isOpen())
|
||||||
else microPort->setBaudRate(BAUD);
|
|
||||||
|
|
||||||
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()
|
|
||||||
<<". Continueing in demo mode"<<'\n';
|
|
||||||
masterIODevice = microPort;
|
|
||||||
}
|
|
||||||
|
|
||||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "",
|
|
||||||
!parser.isSet(secondaryOption));
|
|
||||||
|
|
||||||
#else
|
|
||||||
QTcpSocket* microSocket = new QTcpSocket;
|
|
||||||
microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
|
|
||||||
if(!microSocket->waitForConnected(1000))
|
|
||||||
{
|
{
|
||||||
std::cout<<"Can not connect to to Server.\n";
|
qCritical()<<"Can not open serial port"<<port;
|
||||||
|
MainObject::storeJsonObjectToDisk(settingsPath, json);
|
||||||
|
if(programMode == PROGRAM_MODE_PRIMARY)
|
||||||
|
QMessageBox::critical(nullptr, "Error", "Can not open serial port " + port);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
masterIODevice = microSocket;
|
microDevice = microPort;
|
||||||
|
}
|
||||||
|
PrimaryMainObject mainObject(microDevice, settingsPath, parser.value(hostOption), parser.value(portOption).toInt());
|
||||||
|
QObject::connect(mainObject.tcpServer, &TcpServer::sigRequestSave, &mainObject, [&mainObject, settingsPath](){mainObject.storeToDisk(settingsPath);});
|
||||||
|
MainWindow* w = nullptr;
|
||||||
|
if(programMode != PROGRAM_MODE_HEADLESS_PRIMARY)
|
||||||
|
{
|
||||||
|
w = new MainWindow(&mainObject);
|
||||||
|
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString)));
|
||||||
|
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), w, SLOT(changeHeaderLableText(QString)));
|
||||||
|
QObject::connect(w, &MainWindow::sigSetRgb, &mainObject.micro, &Microcontroller::changeRgbColor);
|
||||||
|
QObject::connect(w, &MainWindow::sigSave, &mainObject, [&mainObject, settingsPath](){mainObject.storeToDisk(settingsPath);});
|
||||||
|
QObject::connect(w, &MainWindow::createdItem, &globalItems, [](std::shared_ptr<Item> item){globalItems.addItem(item, false);});
|
||||||
|
w->show();
|
||||||
|
}
|
||||||
|
retVal = a.exec();
|
||||||
|
|
||||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "",
|
delete w;
|
||||||
!parser.isSet(secondaryOption));
|
delete microDevice;
|
||||||
#endif
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//mainwindow
|
SecondaryMainObject mainObject(parser.value(hostOption), parser.value(portOption).toInt());
|
||||||
MainWindow w(&mainObject);
|
MainWindow w(&mainObject);
|
||||||
QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
|
QObject::connect(&w, &MainWindow::createdItem, &globalItems, [](std::shared_ptr<Item> item){globalItems.addItem(item, false);});
|
||||||
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
QObject::connect(&w, &MainWindow::sigSave, mainObject.tcpClient, &TcpClient::sendItems);
|
||||||
QObject::connect(&w, &MainWindow::sigSave, &mainObject, &MainObject::storeToDisk);
|
|
||||||
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
|
|
||||||
if(!mainObject.micro.connected())
|
|
||||||
w.changeHeaderLableText("No io debug only!");
|
|
||||||
|
|
||||||
w.show();
|
w.show();
|
||||||
|
|
||||||
int retVal = a.exec();
|
retVal = a.exec();
|
||||||
|
}
|
||||||
|
|
||||||
if(masterIODevice)
|
|
||||||
delete masterIODevice;
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,139 +1,35 @@
|
||||||
#include "mainobject.h"
|
#include "mainobject.h"
|
||||||
#include "items/messageitem.h"
|
|
||||||
|
|
||||||
MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent) :
|
#include<QJsonObject>
|
||||||
QObject(parent),
|
#include<QJsonArray>
|
||||||
master(masterIn),
|
#include<QMessageBox>
|
||||||
masterIODevice(ioDevice),
|
|
||||||
ioMultiplexer(masterIODevice),
|
|
||||||
micro(ioMultiplexer.getIoDevice()),
|
|
||||||
broadCast(ioMultiplexer.getIoDevice(), masterIn),
|
|
||||||
settingsPath(settingsPathIn),
|
|
||||||
sunSensorSource(49.884450, 8.650536),
|
|
||||||
powerItem(new PowerItem),
|
|
||||||
rgbItem(new RgbItem(µ, 5487422, "Rgb Lights")),
|
|
||||||
auxItem(new AuxItem(µ, 5487421, "Desk Light"))
|
|
||||||
|
|
||||||
|
#include "items/itemstore.h"
|
||||||
|
|
||||||
|
MainObject::MainObject(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
{
|
{
|
||||||
qDebug()<<"Is master:"<<master;
|
|
||||||
//connect sensors subsystem
|
|
||||||
QObject::connect(µ, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
|
||||||
QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
|
||||||
QObject::connect(&globalSensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
|
|
||||||
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
|
||||||
|
|
||||||
sunSensorSource.run();
|
|
||||||
//pwHandler.startLoop();
|
|
||||||
|
|
||||||
//connect item store
|
|
||||||
QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
|
|
||||||
QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
|
|
||||||
|
|
||||||
//special items
|
|
||||||
QObject::connect(powerItem.get(), &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
|
||||||
powerItem->emmitSensor();
|
|
||||||
items.addItem(rgbItem);
|
|
||||||
items.addItem(auxItem);
|
|
||||||
MessageItem::broadCast = &broadCast;
|
|
||||||
|
|
||||||
Relay::setMicrocontroller(µ);
|
|
||||||
|
|
||||||
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
|
|
||||||
QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
|
||||||
if(master)
|
|
||||||
connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
|
||||||
|
|
||||||
if(master)
|
|
||||||
{
|
|
||||||
load(getJsonObjectFromDisk(settingsPath, &noSave));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
broadCast.requestJson();
|
|
||||||
broadCast.requestSensors();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
|
||||||
Item::secondaryFlag = !master;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainObject::~MainObject()
|
MainObject::~MainObject()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainObject::store(QJsonObject &json)
|
void MainObject::refresh()
|
||||||
{
|
{
|
||||||
items.store(json);
|
globalItems.refresh();
|
||||||
|
|
||||||
QJsonObject powerObject;
|
|
||||||
powerItem->store(powerObject);
|
|
||||||
json.insert("Power", powerObject);
|
|
||||||
QJsonDocument pwrDoc(powerObject);
|
|
||||||
|
|
||||||
QJsonObject ocupancyObject;
|
|
||||||
ocupancySensor.store(ocupancyObject);
|
|
||||||
json.insert("Ocupancy", ocupancyObject);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainObject::load(const QJsonObject& json)
|
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filename, bool* error)
|
||||||
{
|
|
||||||
items.clear();
|
|
||||||
rgbItem->removeAllActors();
|
|
||||||
auxItem->removeAllActors();
|
|
||||||
powerItem->removeAllActors();
|
|
||||||
items.addItem(rgbItem);
|
|
||||||
items.addItem(auxItem);
|
|
||||||
items.load(json);
|
|
||||||
powerItem->load(json["Power"].toObject());
|
|
||||||
ocupancySensor.load(json["Ocupancy"].toObject());
|
|
||||||
qDebug()<<"aray size: "<<json.isEmpty();
|
|
||||||
if(json["Items"].toArray().size() >= 2)
|
|
||||||
{
|
|
||||||
rgbItem->load(json["Items"].toArray()[0].toObject());
|
|
||||||
auxItem->load(json["Items"].toArray()[1].toObject());
|
|
||||||
}
|
|
||||||
micro.requestState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainObject::storeToDisk()
|
|
||||||
{
|
|
||||||
if(master && !noSave)
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
store(json);
|
|
||||||
storeJsonObjectToDisk(json, settingsPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainObject::recivedJson(const QJsonObject json)
|
|
||||||
{
|
|
||||||
if(master && !noSave)
|
|
||||||
storeJsonObjectToDisk(json, settingsPath);
|
|
||||||
load(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainObject::sendJson()
|
|
||||||
{
|
|
||||||
QJsonObject json;
|
|
||||||
store(json);
|
|
||||||
broadCast.sendJson(json);
|
|
||||||
}
|
|
||||||
|
|
||||||
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* error)
|
|
||||||
{
|
{
|
||||||
QFile file;
|
QFile file;
|
||||||
|
file.setFileName(filename);
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
bool ret = file.open(QIODevice::ReadOnly);
|
||||||
if(filePath.size() > 0) file.setFileName(filePath);
|
if(!file.isOpen() || !ret)
|
||||||
else
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
file.setFileName(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
|
std::cerr<<"Can not open config file: "<<filename.toLatin1().data()<<std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
file.open(QIODevice::ReadOnly);
|
|
||||||
if(!file.isOpen()) std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QJsonParseError qerror;
|
QJsonParseError qerror;
|
||||||
|
|
@ -141,29 +37,24 @@ QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* err
|
||||||
file.close();
|
file.close();
|
||||||
if(qerror.error != QJsonParseError::NoError)
|
if(qerror.error != QJsonParseError::NoError)
|
||||||
{
|
{
|
||||||
qDebug()<<filePath<<" "<<qerror.errorString();
|
qDebug()<<filename<<" "<<qerror.errorString();
|
||||||
if(error) (*error) = true;
|
if(error)
|
||||||
|
(*error) = true;
|
||||||
}
|
}
|
||||||
return document.object();
|
return document.object();
|
||||||
}
|
}
|
||||||
return QJsonObject();
|
return QJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, QString filePath)
|
bool MainObject::storeJsonObjectToDisk(const QString& filename, const QJsonObject& json)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_ANDROID
|
QFile file(filename + ".out");
|
||||||
if(filePath.size() == 0)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json";
|
|
||||||
}
|
|
||||||
QFile file(filePath + ".out");
|
|
||||||
|
|
||||||
qDebug()<<"config file: "<<filePath;
|
qDebug()<<"config file: "<<filename;
|
||||||
file.open(QIODevice::WriteOnly);
|
bool ret = file.open(QIODevice::WriteOnly);
|
||||||
if(!file.isOpen())
|
if(!file.isOpen() || !ret)
|
||||||
{
|
{
|
||||||
std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
|
std::cerr<<"Can not open config file: "<<filename.toLatin1().data()<<std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -171,9 +62,101 @@ bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, QString filePath
|
||||||
QJsonDocument document(json);
|
QJsonDocument document(json);
|
||||||
file.write(document.toJson());
|
file.write(document.toJson());
|
||||||
file.close();
|
file.close();
|
||||||
QFile::remove(filePath);
|
QFile::remove(filename);
|
||||||
file.rename(filePath);
|
file.rename(filename);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PrimaryMainObject::PrimaryMainObject(QIODevice* microDevice, const QString& settingsPath, const QString& host, int port, QObject *parent) :
|
||||||
|
MainObject(parent),
|
||||||
|
settingsPath(settingsPath),
|
||||||
|
micro(microDevice),
|
||||||
|
tcpServer(new TcpServer),
|
||||||
|
sunSensorSource(49.824972, 8.702194),
|
||||||
|
fixedItems(µ)
|
||||||
|
{
|
||||||
|
//connect sensors subsystem
|
||||||
|
connect(&globalSensors, &SensorStore::sensorChangedState, tcpServer, &TcpServer::sensorEvent);
|
||||||
|
connect(tcpServer, &TcpServer::gotSensor, &globalSensors, &SensorStore::sensorGotState);
|
||||||
|
connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||||
|
connect(µ, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
|
||||||
|
connect(&mqttSensorSource, &MqttSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||||
|
|
||||||
|
sunSensorSource.run();
|
||||||
|
|
||||||
|
globalItems.registerItemSource(&fixedItems);
|
||||||
|
globalItems.registerItemSource(tcpServer);
|
||||||
|
globalItems.registerItemSource(µ);
|
||||||
|
globalItems.registerItemSource(&itemLoader);
|
||||||
|
|
||||||
|
Relay::setMicrocontroller(µ);
|
||||||
|
|
||||||
|
loadFromDisk(settingsPath);
|
||||||
|
|
||||||
|
QJsonObject mqttJson = settings["Mqtt"].toObject();
|
||||||
|
mqttSensorSource.start(mqttJson);
|
||||||
|
|
||||||
|
tcpServer->launch(QHostAddress(host), port);
|
||||||
|
connect(&globalItems, &ItemStore::itemUpdated, tcpServer, &TcpServer::itemUpdated);
|
||||||
|
}
|
||||||
|
|
||||||
|
PrimaryMainObject::~PrimaryMainObject()
|
||||||
|
{
|
||||||
|
storeToDisk(settingsPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrimaryMainObject::store(QJsonObject &json)
|
||||||
|
{
|
||||||
|
globalItems.store(json);
|
||||||
|
QJsonObject mqttJson = json["Mqtt"].toObject();
|
||||||
|
mqttSensorSource.store(mqttJson);
|
||||||
|
json["Mqtt"] = mqttJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PrimaryMainObject::load(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
settings = json;
|
||||||
|
itemLoader.updateJson(json);
|
||||||
|
globalItems.clear();
|
||||||
|
globalItems.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PrimaryMainObject::storeToDisk(const QString& filename)
|
||||||
|
{
|
||||||
|
store(settings);
|
||||||
|
itemLoader.updateJson(settings);
|
||||||
|
return storeJsonObjectToDisk(filename, settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PrimaryMainObject::loadFromDisk(const QString& filename)
|
||||||
|
{
|
||||||
|
bool error = false;
|
||||||
|
QJsonObject json = getJsonObjectFromDisk(filename, &error);
|
||||||
|
if(!error)
|
||||||
|
load(json);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
SecondaryMainObject::SecondaryMainObject(QString host, int port, QObject *parent) :
|
||||||
|
MainObject(parent),
|
||||||
|
tcpClient(new TcpClient)
|
||||||
|
{
|
||||||
|
connect(tcpClient, &TcpClient::gotSensor, &globalSensors, &SensorStore::sensorGotState);
|
||||||
|
globalItems.registerItemSource(tcpClient);
|
||||||
|
|
||||||
|
if(!tcpClient->launch(QHostAddress(host), port))
|
||||||
|
{
|
||||||
|
QMessageBox::critical(nullptr, "Error", "Could not connect to "+host+":"+QString::number(port));
|
||||||
|
QMetaObject::invokeMethod(this, [](){exit(1);}, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(&globalItems, &ItemStore::itemUpdated, tcpClient, &TcpClient::itemUpdated);
|
||||||
|
|
||||||
|
globalItems.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
SecondaryMainObject::~SecondaryMainObject()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
#define MAINOBJECT_H
|
#define MAINOBJECT_H
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <stdio.h>
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
@ -12,80 +11,65 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
#ifndef Q_OS_ANDROID
|
|
||||||
#include <QtSerialPort/QtSerialPort>
|
|
||||||
#include <QtSerialPort/QSerialPortInfo>
|
|
||||||
#include <QCommandLineParser>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "actors/alarmtime.h"
|
|
||||||
#include "microcontroller.h"
|
#include "microcontroller.h"
|
||||||
#include "ui/mainwindow.h"
|
#include "ui/mainwindow.h"
|
||||||
#include "sensors/speakersensor.h"
|
|
||||||
#include "sensors/sunsensor.h"
|
#include "sensors/sunsensor.h"
|
||||||
#include "sensors/ocupancysensor.h"
|
#include "sensors/mqttsensorsource.h"
|
||||||
#include "sensors/sensor.h"
|
#include "items/fixeditemsource.h"
|
||||||
#include "items/itemstore.h"
|
#include "items/itemloadersource.h"
|
||||||
#include "items/auxitem.h"
|
#include "tcpserver.h"
|
||||||
#include "items/rgbitem.h"
|
|
||||||
#include "items/poweritem.h"
|
|
||||||
#include "iomuliplexer.h"
|
|
||||||
#include "broadcast.h"
|
|
||||||
//#include "pipewire.h"
|
|
||||||
|
|
||||||
class MainObject : public QObject
|
class MainObject : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MainObject(QObject *parent = nullptr);
|
||||||
|
~MainObject();
|
||||||
|
static QJsonObject getJsonObjectFromDisk(const QString& filename, bool* error = nullptr);
|
||||||
|
static bool storeJsonObjectToDisk(const QString& filename, const QJsonObject& json);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
class PrimaryMainObject : public MainObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//io
|
QString settingsPath;
|
||||||
const bool master;
|
QJsonObject settings;
|
||||||
|
|
||||||
bool noSave = false;
|
|
||||||
|
|
||||||
QIODevice * const masterIODevice = nullptr;
|
|
||||||
IoMuliplexer ioMultiplexer;
|
|
||||||
|
|
||||||
Microcontroller micro;
|
Microcontroller micro;
|
||||||
BroadCast broadCast;
|
TcpServer* tcpServer;
|
||||||
|
|
||||||
|
|
||||||
const QString settingsPath;
|
|
||||||
|
|
||||||
//sensors
|
//sensors
|
||||||
SunSensorSource sunSensorSource;
|
SunSensorSource sunSensorSource;
|
||||||
OcupancySensorSource ocupancySensor;
|
MqttSensorSource mqttSensorSource;
|
||||||
|
|
||||||
//items
|
//item sources
|
||||||
ItemStore items;
|
FixedItemSource fixedItems;
|
||||||
|
ItemLoaderSource itemLoader;
|
||||||
std::shared_ptr<PowerItem> powerItem;
|
|
||||||
std::shared_ptr<RgbItem> rgbItem;
|
|
||||||
std::shared_ptr<AuxItem> auxItem;
|
|
||||||
|
|
||||||
//PipeWireHandler pwHandler;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
|
|
||||||
static bool storeJsonObjectToDisk(const QJsonObject& json, QString filePath = "");
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent = nullptr);
|
explicit PrimaryMainObject(QIODevice* microDevice, const QString& settingsPath, const QString& host, int port, QObject *parent = nullptr);
|
||||||
~MainObject();
|
~PrimaryMainObject();
|
||||||
|
|
||||||
void store(QJsonObject& json);
|
void store(QJsonObject& json);
|
||||||
|
|
||||||
void load(const QJsonObject& json);
|
void load(const QJsonObject& json);
|
||||||
|
bool storeToDisk(const QString& filename);
|
||||||
|
bool loadFromDisk(const QString& filename);
|
||||||
|
};
|
||||||
|
|
||||||
signals:
|
class SecondaryMainObject : public MainObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
TcpClient* tcpClient;
|
||||||
|
|
||||||
public slots:
|
public:
|
||||||
|
explicit SecondaryMainObject(QString host, int port, QObject *parent = nullptr);
|
||||||
void storeToDisk();
|
~SecondaryMainObject();
|
||||||
void sendJson();
|
|
||||||
void recivedJson(const QJsonObject json);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,6 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
static constexpr bool debug = true;
|
|
||||||
|
|
||||||
void Microcontroller::relayToggle(int state, int relay)
|
void Microcontroller::relayToggle(int state, int relay)
|
||||||
{
|
{
|
||||||
char buffer[8];
|
char buffer[8];
|
||||||
|
|
@ -40,7 +38,6 @@ void Microcontroller::changeRgbColor(const QColor color)
|
||||||
char buffer[64];
|
char buffer[64];
|
||||||
int length = sprintf(buffer, "rgb set %03d %03d %03d\n", color.red(), color.green(), color.blue());
|
int length = sprintf(buffer, "rgb set %03d %03d %03d\n", color.red(), color.green(), color.blue());
|
||||||
write(buffer, length);
|
write(buffer, length);
|
||||||
std::cout<<buffer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::setAuxPwm(int duty)
|
void Microcontroller::setAuxPwm(int duty)
|
||||||
|
|
@ -52,9 +49,6 @@ void Microcontroller::setAuxPwm(int duty)
|
||||||
|
|
||||||
void Microcontroller::write(const QByteArray& buffer)
|
void Microcontroller::write(const QByteArray& buffer)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_ANDROID
|
|
||||||
if constexpr(debug) std::cerr<<buffer.data();
|
|
||||||
#endif
|
|
||||||
if(_port != nullptr)
|
if(_port != nullptr)
|
||||||
{
|
{
|
||||||
_port->write(buffer);
|
_port->write(buffer);
|
||||||
|
|
@ -65,9 +59,6 @@ void Microcontroller::write(const QByteArray& buffer)
|
||||||
|
|
||||||
void Microcontroller::write(char* buffer, const size_t length)
|
void Microcontroller::write(char* buffer, const size_t length)
|
||||||
{
|
{
|
||||||
#ifndef Q_OS_ANDROID
|
|
||||||
if constexpr(debug) std::cerr<<buffer;
|
|
||||||
#endif
|
|
||||||
if(_port != nullptr)
|
if(_port != nullptr)
|
||||||
{
|
{
|
||||||
_port->write(buffer, length);
|
_port->write(buffer, length);
|
||||||
|
|
@ -95,7 +86,7 @@ bool Microcontroller::connected()
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::requestState()
|
void Microcontroller::refresh()
|
||||||
{
|
{
|
||||||
write("state\n");
|
write("state\n");
|
||||||
}
|
}
|
||||||
|
|
@ -151,8 +142,7 @@ void Microcontroller::processList(const QString& buffer)
|
||||||
else if(buffer.contains("EOL"))
|
else if(buffer.contains("EOL"))
|
||||||
{
|
{
|
||||||
listMode = false;
|
listMode = false;
|
||||||
qDebug()<<"got relay list " << relayList.size();
|
gotItems(relayList);
|
||||||
gotRelayList(relayList);
|
|
||||||
relayList.clear();
|
relayList.clear();
|
||||||
}
|
}
|
||||||
else listMode = false;
|
else listMode = false;
|
||||||
|
|
@ -160,19 +150,23 @@ void Microcontroller::processList(const QString& buffer)
|
||||||
|
|
||||||
void Microcontroller::processRelayState(const QString& buffer)
|
void Microcontroller::processRelayState(const QString& buffer)
|
||||||
{
|
{
|
||||||
itemChanged(static_cast<ItemData>(*processRelayLine(buffer)));
|
updateItems({static_cast<ItemData>(*processRelayLine(buffer))});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microcontroller::processSensorState(const QString& buffer)
|
void Microcontroller::processSensorState(const QString& buffer)
|
||||||
{
|
{
|
||||||
Sensor sensor = Sensor::sensorFromString(buffer);
|
Sensor sensor = Sensor::sensorFromString(buffer);
|
||||||
if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
|
if(sensor.type != Sensor::TYPE_DUMMY)
|
||||||
|
gotSensorState(sensor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Microcontroller::processMicroReturn()
|
void Microcontroller::processMicroReturn()
|
||||||
{
|
{
|
||||||
if(listMode) processList(_buffer);
|
if(listMode)
|
||||||
|
{
|
||||||
|
processList(_buffer);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(_buffer.startsWith("Items:"))
|
if(_buffer.startsWith("Items:"))
|
||||||
|
|
@ -180,8 +174,14 @@ void Microcontroller::processMicroReturn()
|
||||||
listMode = true;
|
listMode = true;
|
||||||
relayList.clear();
|
relayList.clear();
|
||||||
}
|
}
|
||||||
else if(_buffer.startsWith("ITEM NUMBER:"))processRelayState(_buffer);
|
else if(_buffer.startsWith("ITEM NUMBER:"))
|
||||||
else if(_buffer.startsWith("SENSOR")) processSensorState(_buffer);
|
{
|
||||||
|
processRelayState(_buffer);
|
||||||
|
}
|
||||||
|
else if(_buffer.startsWith("SENSOR"))
|
||||||
|
{
|
||||||
|
processSensorState(_buffer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#ifndef MICROCONTROLLER_H
|
#ifndef MICROCONTROLLER_H
|
||||||
#define MICROCONTROLLER_H
|
#define MICROCONTROLLER_H
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QIODevice>
|
#include <QIODevice>
|
||||||
|
|
@ -17,8 +15,9 @@
|
||||||
#include "items/item.h"
|
#include "items/item.h"
|
||||||
#include "items/relay.h"
|
#include "items/relay.h"
|
||||||
#include "sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
|
#include "items/itemsource.h"
|
||||||
|
|
||||||
class Microcontroller : public QObject
|
class Microcontroller : public ItemSource
|
||||||
{
|
{
|
||||||
|
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -65,7 +64,7 @@ public slots:
|
||||||
void setPattern(int pattern);
|
void setPattern(int pattern);
|
||||||
void startSunrise();
|
void startSunrise();
|
||||||
|
|
||||||
void requestState();
|
void refresh() override;
|
||||||
|
|
||||||
void setAuxPwm(int duty);
|
void setAuxPwm(int duty);
|
||||||
|
|
||||||
|
|
@ -79,10 +78,6 @@ private slots:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void textRecived(const QString string);
|
void textRecived(const QString string);
|
||||||
void itemChanged(ItemData relay);
|
|
||||||
void auxStateChanged(int value);
|
|
||||||
void gotRelayList(std::vector< std::shared_ptr<Item> >&);
|
|
||||||
|
|
||||||
void gotSensorState(Sensor sensor);
|
void gotSensorState(Sensor sensor);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
3
src/programmode.cpp
Normal file
3
src/programmode.cpp
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
#include "programmode.h"
|
||||||
|
|
||||||
|
program_mode_t programMode = PROGRAM_MODE_PRIMARY;
|
||||||
13
src/programmode.h
Normal file
13
src/programmode.h
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
#ifndef PROGRAMMODE_H
|
||||||
|
#define PROGRAMMODE_H
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
PROGRAM_MODE_PRIMARY = 0,
|
||||||
|
PROGRAM_MODE_HEADLESS_PRIMARY,
|
||||||
|
PROGRAM_MODE_UI_ONLY
|
||||||
|
} program_mode_t;
|
||||||
|
|
||||||
|
extern program_mode_t programMode;
|
||||||
|
|
||||||
|
#endif // PROGRAMMODE_H
|
||||||
187
src/sensors/mqttsensorsource.cpp
Normal file
187
src/sensors/mqttsensorsource.cpp
Normal file
|
|
@ -0,0 +1,187 @@
|
||||||
|
#include "mqttsensorsource.h"
|
||||||
|
|
||||||
|
#include<QJsonArray>
|
||||||
|
|
||||||
|
MqttSensorSource::MqttSensorSource(QObject *parent)
|
||||||
|
: QObject{parent}
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void MqttSensorSource::start(const QJsonObject& settings)
|
||||||
|
{
|
||||||
|
baseTopicName = settings["BaseTopic"].toString("zigbee2mqtt");
|
||||||
|
|
||||||
|
connect(&client, &QMqttClient::stateChanged, this, &MqttSensorSource::onClientStateChanged);
|
||||||
|
connect(&client, &QMqttClient::errorChanged, this, &MqttSensorSource::onClientError);
|
||||||
|
|
||||||
|
client.setHostname(settings["Host"].toString("127.0.0.1"));
|
||||||
|
client.setPort(settings["Port"].toInt(1883));
|
||||||
|
if(settings.contains("User"))
|
||||||
|
client.setUsername(settings["User"].toString());
|
||||||
|
if(settings.contains("Password"))
|
||||||
|
client.setPassword(settings["Password"].toString());
|
||||||
|
client.setProtocolVersion(QMqttClient::MQTT_5_0);
|
||||||
|
|
||||||
|
client.connectToHost();
|
||||||
|
|
||||||
|
QJsonArray sensorsArray = settings["Sensors"].toArray();
|
||||||
|
|
||||||
|
for(QJsonValueRef sensorRef : sensorsArray)
|
||||||
|
{
|
||||||
|
QJsonObject sensorObject = sensorRef.toObject();
|
||||||
|
if(!sensorObject.contains("Topic"))
|
||||||
|
continue;
|
||||||
|
SensorSubscription sensor;
|
||||||
|
sensor.topic = sensorObject["Topic"].toString();
|
||||||
|
if(!sensorObject.contains("Name"))
|
||||||
|
sensor.name = sensor.topic;
|
||||||
|
else
|
||||||
|
sensor.name = sensorObject["Name"].toString();
|
||||||
|
sensor.id = qHash(baseTopicName + "/" + sensor.topic);
|
||||||
|
sensors.push_back(sensor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MqttSensorSource::onClientError(QMqttClient::ClientError error)
|
||||||
|
{
|
||||||
|
qWarning()<<"MQTT Client error:"<<error;
|
||||||
|
}
|
||||||
|
|
||||||
|
MqttSensorSource::SensorSubscription& MqttSensorSource::findSubscription(const QString& topic)
|
||||||
|
{
|
||||||
|
for(SensorSubscription& sensor : sensors)
|
||||||
|
{
|
||||||
|
if(baseTopicName + "/" + sensor.topic == topic)
|
||||||
|
return sensor;
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MqttSensorSource::onClientStateChanged(QMqttClient::ClientState state)
|
||||||
|
{
|
||||||
|
if(state == QMqttClient::ClientState::Connected)
|
||||||
|
{
|
||||||
|
qInfo()<<"Connected to MQTT broker at "<<client.hostname()<<client.port();
|
||||||
|
for(SensorSubscription& sensor : sensors)
|
||||||
|
{
|
||||||
|
qDebug()<<"MQTT subscribeing to"<<baseTopicName + "/" + sensor.topic;
|
||||||
|
sensor.subscription = client.subscribe(baseTopicName + "/" + sensor.topic);
|
||||||
|
connect(sensor.subscription, &QMqttSubscription::messageReceived, this, &MqttSensorSource::onMessageReceived);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (state == QMqttClient::ClientState::Disconnected)
|
||||||
|
{
|
||||||
|
qWarning()<<"Lost connection to MQTT broker";
|
||||||
|
for(SensorSubscription& sensor : sensors)
|
||||||
|
{
|
||||||
|
if(sensor.subscription)
|
||||||
|
{
|
||||||
|
client.unsubscribe(sensor.topic);
|
||||||
|
sensor.subscription = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(state == QMqttClient::ClientState::Connecting)
|
||||||
|
{
|
||||||
|
qInfo()<<"Connecting to MQTT broker at "<<client.hostname()<<client.port();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MqttSensorSource::onMessageReceived(const QMqttMessage& message)
|
||||||
|
{
|
||||||
|
Sensor sensor;
|
||||||
|
SensorSubscription& sensorSub = findSubscription(message.topic().name());
|
||||||
|
QString baseName = sensorSub.name;
|
||||||
|
sensor.id = sensorSub.id;
|
||||||
|
sensor.updateSeen();
|
||||||
|
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(message.payload());
|
||||||
|
if(doc.isObject())
|
||||||
|
{
|
||||||
|
QJsonObject obj = doc.object();
|
||||||
|
if(obj.contains("temperature"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " Temperature";
|
||||||
|
sensor.type = Sensor::TYPE_TEMPERATURE;
|
||||||
|
sensor.field = obj["temperature"].toDouble(0);
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj.contains("humidity"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " Humidity";
|
||||||
|
sensor.type = Sensor::TYPE_HUMIDITY;
|
||||||
|
sensor.field = obj["humidity"].toDouble(0);
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj.contains("illuminance"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " Illuminance";
|
||||||
|
sensor.type = Sensor::TYPE_BRIGHTNESS;
|
||||||
|
sensor.field = obj["illuminance"].toDouble(0);
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj.contains("presence"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " Presence";
|
||||||
|
sensor.type = Sensor::TYPE_OCUPANCY;
|
||||||
|
sensor.field = obj["presence"].toBool() ? 1 : 0;
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj.contains("co2"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " co2";
|
||||||
|
sensor.type = Sensor::TYPE_CO2;
|
||||||
|
sensor.field = obj["co2"].toDouble(0);
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj.contains("formaldehyd"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " Formaldehyd";
|
||||||
|
sensor.type = Sensor::TYPE_FORMALDEHYD;
|
||||||
|
sensor.field = obj["formaldehyd"].toDouble(0);
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj.contains("pm25"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " pm25";
|
||||||
|
sensor.type = Sensor::TYPE_PM25;
|
||||||
|
sensor.field = obj["pm25"].toDouble(0);
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(obj.contains("voc"))
|
||||||
|
{
|
||||||
|
sensor.name = baseName + " VOC";
|
||||||
|
sensor.type = Sensor::TYPE_TOTAL_VOC;
|
||||||
|
sensor.field = obj["voc"].toDouble(0);
|
||||||
|
stateChanged(sensor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MqttSensorSource::store(QJsonObject& json)
|
||||||
|
{
|
||||||
|
json["Host"] = client.hostname();
|
||||||
|
json["Port"] = client.port();
|
||||||
|
json["BaseTopic"] = baseTopicName;
|
||||||
|
if(client.username() != "")
|
||||||
|
json["User"] = client.username();
|
||||||
|
if(client.password() != "")
|
||||||
|
json["Password"] = client.password();
|
||||||
|
QJsonArray sensorsArray;
|
||||||
|
for(const SensorSubscription& sensor : sensors)
|
||||||
|
{
|
||||||
|
QJsonObject sensorObject;
|
||||||
|
sensorObject["Name"] = sensor.name;
|
||||||
|
sensorObject["Topic"] = sensor.topic;
|
||||||
|
sensorsArray.append(sensorObject);
|
||||||
|
}
|
||||||
|
json["Sensors"] = sensorsArray;
|
||||||
|
}
|
||||||
|
|
||||||
44
src/sensors/mqttsensorsource.h
Normal file
44
src/sensors/mqttsensorsource.h
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
#ifndef MQTTSENSORSOURCE_H
|
||||||
|
#define MQTTSENSORSOURCE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QtMqtt/QMqttClient>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "sensor.h"
|
||||||
|
|
||||||
|
class MqttSensorSource : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
struct SensorSubscription
|
||||||
|
{
|
||||||
|
uint64_t id;
|
||||||
|
QString topic;
|
||||||
|
QString name;
|
||||||
|
QMqttSubscription* subscription = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
QString baseTopicName;
|
||||||
|
std::vector<SensorSubscription> sensors;
|
||||||
|
QMqttClient client;
|
||||||
|
|
||||||
|
private:
|
||||||
|
SensorSubscription& findSubscription(const QString& topic);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onClientStateChanged(QMqttClient::ClientState state);
|
||||||
|
void onMessageReceived(const QMqttMessage& message);
|
||||||
|
void onClientError(QMqttClient::ClientError error);
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit MqttSensorSource(QObject *parent = nullptr);
|
||||||
|
void start(const QJsonObject& settings);
|
||||||
|
void store(QJsonObject& json);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void stateChanged(Sensor sensor);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // MQTTSENSORSOURCE_H
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
#include "ocupancysensor.h"
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
#include "../apgetconnected.h"
|
|
||||||
|
|
||||||
|
|
||||||
OcupancySensorSource::OcupancySensorSource(QObject *parent, const QString& device,
|
|
||||||
const QString& deviceMac): QObject (parent), deviceMac_(deviceMac), device_(device)
|
|
||||||
{
|
|
||||||
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OcupancySensorSource::sensorEvent(Sensor sensor)
|
|
||||||
{
|
|
||||||
if(sensor.type == Sensor::TYPE_DOOR && sensor.id == 1 && sensor.field != 0.0f)
|
|
||||||
{
|
|
||||||
if(occupied == false) stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, 1, "Occupancy"));
|
|
||||||
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OcupancySensorSource::Timeout()
|
|
||||||
{
|
|
||||||
int error = 0;
|
|
||||||
qDebug()<<"testing for occupancy";
|
|
||||||
std::vector<uint64_t> devices = ap::connectedDevices(device_.toLatin1().toStdString(), error);
|
|
||||||
if(error == 0)
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
for(size_t i = 0; i < devices.size(); ++i)
|
|
||||||
{
|
|
||||||
std::string mac = ap::macAddrToString(devices[i]);
|
|
||||||
if(mac.find(deviceMac_.toLatin1().toStdString()) != std::string::npos)
|
|
||||||
{
|
|
||||||
found = true;
|
|
||||||
qDebug()<<"occupied";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, found, "Occupancy"));
|
|
||||||
occupied = found;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, true, "Occupancy"));
|
|
||||||
qDebug()<<"occupancy sensor error "<<error;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void OcupancySensorSource::store(QJsonObject &json)
|
|
||||||
{
|
|
||||||
json["Device"] = device_;
|
|
||||||
json["MacAddres"] = deviceMac_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void OcupancySensorSource::load(const QJsonObject &json)
|
|
||||||
{
|
|
||||||
device_ = json["Device"].toString("wlan0");
|
|
||||||
deviceMac_ = json["MacAddres"].toString("60:BE:B5:25:8C:E0");
|
|
||||||
}
|
|
||||||
|
|
@ -1,33 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QJsonObject>
|
|
||||||
#include "sensor.h"
|
|
||||||
|
|
||||||
class OcupancySensorSource : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
|
|
||||||
QString deviceMac_;
|
|
||||||
QString device_;
|
|
||||||
bool occupied = true;
|
|
||||||
static constexpr unsigned timeoutMs = (15 * 60) * 1000;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit OcupancySensorSource(QObject *parent = nullptr, const QString& device = "wlan0",
|
|
||||||
const QString& deviceMac = "60:BE:B5:25:8C:E0");
|
|
||||||
|
|
||||||
void store(QJsonObject& json);
|
|
||||||
void load(const QJsonObject& json);
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void sensorEvent(Sensor sensor);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
|
|
||||||
void Timeout();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void stateChanged(Sensor sensor);
|
|
||||||
};
|
|
||||||
|
|
@ -1,74 +0,0 @@
|
||||||
#include "pipewiresensor.h"
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
static const struct pw_node_events node_events = {
|
|
||||||
.version = PW_VERSION_NODE_EVENTS,
|
|
||||||
.info = &PipeWireSensorSource::nodeEventHandler,
|
|
||||||
.param = nullptr
|
|
||||||
};
|
|
||||||
|
|
||||||
PipeWireSensorSource::PipeWireSensorSource(PipeWireHandler* handler, const std::string& nodeName, uint8_t id, QObject *parent)
|
|
||||||
: QObject{parent}, handler_(handler), nodeName_(nodeName), id_(id)
|
|
||||||
{
|
|
||||||
connect(handler_, &PipeWireHandler::nodeAdded, this, &PipeWireSensorSource::nodeAdded);
|
|
||||||
connect(&timer, &QTimer::timeout, this, &PipeWireSensorSource::offTimeout);
|
|
||||||
timer.setSingleShot(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipeWireSensorSource::offTimeout()
|
|
||||||
{
|
|
||||||
if(state == false)
|
|
||||||
return;
|
|
||||||
state = false;
|
|
||||||
stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, id_, state));
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipeWireSensorSource::nodeEventHandler(void* data, const struct pw_node_info *info)
|
|
||||||
{
|
|
||||||
PipeWireSensorSource* source = static_cast<PipeWireSensorSource*>(data);
|
|
||||||
|
|
||||||
if(info->state == source->prevState)
|
|
||||||
return;
|
|
||||||
|
|
||||||
source->prevState = info->state;
|
|
||||||
|
|
||||||
switch (info->state)
|
|
||||||
{
|
|
||||||
case PW_NODE_STATE_ERROR:
|
|
||||||
case PW_NODE_STATE_CREATING:
|
|
||||||
source->state = false;
|
|
||||||
source->stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, source->id_, 0));
|
|
||||||
break;
|
|
||||||
case PW_NODE_STATE_SUSPENDED:
|
|
||||||
case PW_NODE_STATE_IDLE:
|
|
||||||
if(source->state == true)
|
|
||||||
source->timer.start(10000);
|
|
||||||
break;
|
|
||||||
case PW_NODE_STATE_RUNNING:
|
|
||||||
if(source->state == false)
|
|
||||||
{
|
|
||||||
source->state = true;
|
|
||||||
source->stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, source->id_, source->state));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PipeWireSensorSource::nodeAdded(PipeWireHandler::PwNode node)
|
|
||||||
{
|
|
||||||
if(node.name == nodeName_)
|
|
||||||
{
|
|
||||||
|
|
||||||
sinkNode = static_cast<struct pw_node*>(pw_registry_bind(handler_->getRegistry(), node.id, PW_TYPE_INTERFACE_Node, PW_VERSION_CLIENT, 0));
|
|
||||||
if(sinkNode)
|
|
||||||
{
|
|
||||||
qDebug()<<"Failed to register to required pipewire node"<<node.name.c_str()<<"as id"<<node.id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
pw_node_add_listener(sinkNode, &sinkListener, &node_events, this);
|
|
||||||
qDebug()<<"Found required pipewire node"<<node.name.c_str()<<"as id"<<node.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
#ifndef PIPEWIRESENSOR_H
|
|
||||||
#define PIPEWIRESENSOR_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <string>
|
|
||||||
#include <pipewire/core.h>
|
|
||||||
#include <pipewire/pipewire.h>
|
|
||||||
#include <QTimer>
|
|
||||||
|
|
||||||
#include "sensor.h"
|
|
||||||
#include "../pipewire.h"
|
|
||||||
|
|
||||||
class PipeWireSensorSource : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
PipeWireHandler* handler_;
|
|
||||||
std::string nodeName_;
|
|
||||||
struct pw_node* sinkNode = nullptr;
|
|
||||||
struct spa_hook sinkListener;
|
|
||||||
pw_node_state prevState = PW_NODE_STATE_SUSPENDED;
|
|
||||||
QTimer timer;
|
|
||||||
uint8_t id_;
|
|
||||||
bool state = false;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void offTimeout();
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit PipeWireSensorSource(PipeWireHandler* handler, const std::string& nodeName, uint8_t id, QObject *parent = nullptr);
|
|
||||||
static void nodeEventHandler(void* data, const struct pw_node_info *info);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void stateChanged(Sensor sensor);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void nodeAdded(PipeWireHandler::PwNode node);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // PIPEWIRESENSOR_H
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include<QDateTime>
|
#include<QDateTime>
|
||||||
#include<QObject>
|
#include<QObject>
|
||||||
#include<vector>
|
#include<vector>
|
||||||
|
#include<QJsonObject>
|
||||||
|
|
||||||
class Sensor
|
class Sensor
|
||||||
{
|
{
|
||||||
|
|
@ -16,6 +17,10 @@ public:
|
||||||
static constexpr uint8_t TYPE_BRIGHTNESS = 4;
|
static constexpr uint8_t TYPE_BRIGHTNESS = 4;
|
||||||
static constexpr uint8_t TYPE_BUTTON = 5;
|
static constexpr uint8_t TYPE_BUTTON = 5;
|
||||||
static constexpr uint8_t TYPE_ADC = 6;
|
static constexpr uint8_t TYPE_ADC = 6;
|
||||||
|
static constexpr uint8_t TYPE_CO2 = 7;
|
||||||
|
static constexpr uint8_t TYPE_FORMALDEHYD= 8;
|
||||||
|
static constexpr uint8_t TYPE_PM25 = 9;
|
||||||
|
static constexpr uint8_t TYPE_TOTAL_VOC = 10;
|
||||||
static constexpr uint8_t TYPE_LOWBATTERY = 128;
|
static constexpr uint8_t TYPE_LOWBATTERY = 128;
|
||||||
static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
|
static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
|
||||||
static constexpr uint8_t TYPE_OCUPANCY = 252;
|
static constexpr uint8_t TYPE_OCUPANCY = 252;
|
||||||
|
|
@ -24,13 +29,13 @@ public:
|
||||||
static constexpr uint8_t TYPE_DUMMY = 255;
|
static constexpr uint8_t TYPE_DUMMY = 255;
|
||||||
|
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t id;
|
uint64_t id;
|
||||||
float field;
|
float field;
|
||||||
QString name;
|
QString name;
|
||||||
QDateTime lastSeen;
|
QDateTime lastSeen;
|
||||||
bool hidden;
|
bool hidden;
|
||||||
|
|
||||||
Sensor(uint8_t typeIn, uint8_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false): type(typeIn),
|
Sensor(uint64_t typeIn, uint8_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false): type(typeIn),
|
||||||
id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
||||||
{
|
{
|
||||||
lastSeen = QDateTime::currentDateTime();
|
lastSeen = QDateTime::currentDateTime();
|
||||||
|
|
@ -41,6 +46,15 @@ public:
|
||||||
{
|
{
|
||||||
lastSeen = QDateTime::currentDateTime();
|
lastSeen = QDateTime::currentDateTime();
|
||||||
}
|
}
|
||||||
|
Sensor(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
type = json["SensorType"].toInt(0);
|
||||||
|
id = json["Id"].toInt(0);
|
||||||
|
field = json["Field"].toDouble(0);
|
||||||
|
name = json["Name"].toString("Sensor");
|
||||||
|
lastSeen = QDateTime::fromString(json["LastSeen"].toString(""));
|
||||||
|
hidden = json["Hidden"].toBool(false);
|
||||||
|
}
|
||||||
inline bool operator==(const Sensor& in) const
|
inline bool operator==(const Sensor& in) const
|
||||||
{
|
{
|
||||||
return type==in.type && id == in.id;
|
return type==in.type && id == in.id;
|
||||||
|
|
@ -77,15 +91,32 @@ public:
|
||||||
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field) +
|
QString::number((type == Sensor::TYPE_HUMIDITY || type == Sensor::TYPE_TEMPERATURE) ? field*10 : field) +
|
||||||
" TIME: " + QString::number(lastSeen.toSecsSinceEpoch());
|
" TIME: " + QString::number(lastSeen.toSecsSinceEpoch());
|
||||||
}
|
}
|
||||||
|
inline void store(QJsonObject& json)
|
||||||
|
{
|
||||||
|
json["Type"] = "Sensor";
|
||||||
|
json["SensorType"] = static_cast<int>(type);
|
||||||
|
json["Id"] = static_cast<int>(id);
|
||||||
|
json["Field"] = field;
|
||||||
|
json["Name"] = name;
|
||||||
|
json["LastSeen"] = lastSeen.toString();
|
||||||
|
json["Hidden"] = hidden;
|
||||||
|
}
|
||||||
inline void generateName()
|
inline void generateName()
|
||||||
{
|
{
|
||||||
if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
|
if(type == TYPE_TEMPERATURE)
|
||||||
else if(type == TYPE_DOOR) name = "Door " + QString::number(id);
|
name = "Temperature " + QString::number(id);
|
||||||
else if(type == TYPE_BUTTON) name = "Button " + QString::number(id);
|
else if(type == TYPE_DOOR)
|
||||||
else if(type == TYPE_AUDIO_OUTPUT) name = "Speakers " + QString::number(id);
|
name = "Door " + QString::number(id);
|
||||||
else if(type == TYPE_HUMIDITY) name = "Humidity " + QString::number(id);
|
else if(type == TYPE_BUTTON)
|
||||||
else if(type == TYPE_SUN_ALTITUDE) name = "Solar Altitude";
|
name = "Button " + QString::number(id);
|
||||||
else if(type == TYPE_SHUTDOWN_IMMINENT) name = "Shutdown Imminent";
|
else if(type == TYPE_AUDIO_OUTPUT)
|
||||||
|
name = "Speakers " + QString::number(id);
|
||||||
|
else if(type == TYPE_HUMIDITY)
|
||||||
|
name = "Humidity " + QString::number(id);
|
||||||
|
else if(type == TYPE_SUN_ALTITUDE)
|
||||||
|
name = "Solar Altitude";
|
||||||
|
else if(type == TYPE_SHUTDOWN_IMMINENT)
|
||||||
|
name = "Shutdown Imminent";
|
||||||
else name = "Sensor Type " + QString::number(type) + " Id " + QString::number(id);
|
else name = "Sensor Type " + QString::number(type) + " Id " + QString::number(id);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
#include "speakersensor.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
SpeakerSensorSource::SpeakerSensorSource(QString name, QObject *parent) : QObject(parent), name_(name)
|
|
||||||
{
|
|
||||||
silenceCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpeakerSensorSource::~SpeakerSensorSource()
|
|
||||||
{
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpeakerSensorSource::run()
|
|
||||||
{
|
|
||||||
abort();
|
|
||||||
arecord.start( "arecord", {"--disable-softvol", "-r", "8000", "-D", "front", "-"});
|
|
||||||
|
|
||||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
|
||||||
timer.setInterval(500);
|
|
||||||
timer.start();
|
|
||||||
|
|
||||||
stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 1, name_));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void SpeakerSensorSource::abort()
|
|
||||||
{
|
|
||||||
if(arecord.state() == QProcess::Running)arecord.close();
|
|
||||||
if(timer.isActive())timer.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SpeakerSensorSource::doTick()
|
|
||||||
{
|
|
||||||
if(arecord.state() == QProcess::Running)
|
|
||||||
{
|
|
||||||
QByteArray buffer = arecord.readAllStandardOutput();
|
|
||||||
//qDebug()<<(int16_t)buffer[0];
|
|
||||||
for(long i = 0; i < buffer.size(); i++)
|
|
||||||
{
|
|
||||||
if((int16_t)buffer.at(i) != -128)
|
|
||||||
{
|
|
||||||
silenceCount = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(silenceCount > 40 && state)
|
|
||||||
{
|
|
||||||
stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 0, name_));
|
|
||||||
state = false;
|
|
||||||
}
|
|
||||||
else if(silenceCount == 0 && !state)
|
|
||||||
{
|
|
||||||
stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 1, name_));
|
|
||||||
state = true;
|
|
||||||
}
|
|
||||||
silenceCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
#ifndef AMPMANAGER_H
|
|
||||||
#define AMPMANAGER_H
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QRunnable>
|
|
||||||
#include <QScopedPointer>
|
|
||||||
#include <QEventLoop>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <QProcess>
|
|
||||||
#include <QByteArray>
|
|
||||||
|
|
||||||
#include "sensor.h"
|
|
||||||
|
|
||||||
|
|
||||||
class SpeakerSensorSource : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
private:
|
|
||||||
QString name_;
|
|
||||||
bool state = true;
|
|
||||||
QTimer timer;
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit SpeakerSensorSource(QString name = "", QObject *parent = nullptr);
|
|
||||||
~SpeakerSensorSource();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void run();
|
|
||||||
void abort();
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void stateChanged(Sensor sensor);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void doTick();
|
|
||||||
|
|
||||||
private:
|
|
||||||
long silenceCount = 0;
|
|
||||||
|
|
||||||
QProcess arecord;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // AMPMANAGER_H
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#include "../sun.h"
|
#include "sun.h"
|
||||||
#include "sensor.h"
|
#include "sensor.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
342
src/tcpserver.cpp
Normal file
342
src/tcpserver.cpp
Normal file
|
|
@ -0,0 +1,342 @@
|
||||||
|
#include <QTcpSocket>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "items/item.h"
|
||||||
|
#include "items/itemstore.h"
|
||||||
|
#include "tcpserver.h"
|
||||||
|
|
||||||
|
|
||||||
|
TcpService::TcpService(QObject* parent):
|
||||||
|
ItemSource(parent)
|
||||||
|
{}
|
||||||
|
|
||||||
|
QJsonObject TcpService::createMessage(const QString& type, const QJsonArray& data)
|
||||||
|
{
|
||||||
|
QJsonObject json;
|
||||||
|
json["MessageType"] = type;
|
||||||
|
json["Data"] = data;
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpService::sensorEvent(Sensor sensor)
|
||||||
|
{
|
||||||
|
QJsonArray sensors;
|
||||||
|
QJsonObject sensorjson;
|
||||||
|
sensor.store(sensorjson);
|
||||||
|
sensors.append(sensorjson);
|
||||||
|
QJsonObject json = createMessage("SensorUpdate", sensors);
|
||||||
|
sendJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpService::itemUpdated(std::weak_ptr<Item> item)
|
||||||
|
{
|
||||||
|
qDebug()<<__func__;
|
||||||
|
QJsonArray items;
|
||||||
|
QJsonObject itemjson;
|
||||||
|
item.lock()->store(itemjson);
|
||||||
|
items.append(itemjson);
|
||||||
|
QJsonObject json = createMessage("ItemUpdate", items);
|
||||||
|
json["FullList"] = false;
|
||||||
|
sendJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpService::refresh()
|
||||||
|
{
|
||||||
|
sendJson(createMessage("GetSensors", QJsonArray()));
|
||||||
|
sendJson(createMessage("GetItems", QJsonArray()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpService::sendSensors()
|
||||||
|
{
|
||||||
|
QJsonArray sensors;
|
||||||
|
for(auto& sensor: *globalSensors.getSensors())
|
||||||
|
{
|
||||||
|
QJsonObject sensorjson;
|
||||||
|
sensor.store(sensorjson);
|
||||||
|
sensors.append(sensorjson);
|
||||||
|
}
|
||||||
|
sendJson(createMessage("SensorUpdate", sensors));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpService::sendItems()
|
||||||
|
{
|
||||||
|
QJsonArray items;
|
||||||
|
for(auto& item: *globalItems.getItems())
|
||||||
|
{
|
||||||
|
QJsonObject itemjson;
|
||||||
|
item->store(itemjson);
|
||||||
|
items.append(itemjson);
|
||||||
|
}
|
||||||
|
QJsonObject json = createMessage("ItemUpdate", items);
|
||||||
|
json["FullList"] = true;
|
||||||
|
sendJson(json);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TcpService::processIncomeingJson(const QByteArray& jsonbytes)
|
||||||
|
{
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(jsonbytes);
|
||||||
|
qDebug()<<"Got Json:"<<QString::fromLatin1(doc.toJson(QJsonDocument::JsonFormat::Indented));
|
||||||
|
QJsonObject json = doc.object();
|
||||||
|
QString type = json["MessageType"].toString();
|
||||||
|
if(type == "GetSensors")
|
||||||
|
{
|
||||||
|
qDebug()<<"Sending sensors";
|
||||||
|
sendSensors();
|
||||||
|
}
|
||||||
|
else if(type == "GetItems")
|
||||||
|
{
|
||||||
|
qDebug()<<"Sending Items";
|
||||||
|
sendItems();
|
||||||
|
}
|
||||||
|
else if(type == "SensorUpdate")
|
||||||
|
{
|
||||||
|
QJsonArray data = json["Data"].toArray();
|
||||||
|
for(QJsonValueRef sensorjson : data)
|
||||||
|
{
|
||||||
|
QJsonObject jsonobject = sensorjson.toObject();
|
||||||
|
Sensor sensor(jsonobject);
|
||||||
|
gotSensor(sensor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpClient::TcpClient(QObject* parent):
|
||||||
|
TcpService(parent),
|
||||||
|
socket(new QTcpSocket(this))
|
||||||
|
{
|
||||||
|
connect(socket, &QTcpSocket::readyRead, this, &TcpClient::socketReadyRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::sendJson(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
QByteArray jsonData = QJsonDocument(json).toJson();
|
||||||
|
socket->write(QString("MSG JSON LEN " + QString::number(jsonData.size()) + "\n").toLatin1() + jsonData);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TcpClient::launch(const QHostAddress &address, quint16 port)
|
||||||
|
{
|
||||||
|
socket->connectToHost(address, port);
|
||||||
|
return socket->waitForConnected(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::processIncomeingJson(const QByteArray& jsonbytes)
|
||||||
|
{
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(jsonbytes);
|
||||||
|
QJsonObject json = doc.object();
|
||||||
|
QString type = json["MessageType"].toString();
|
||||||
|
if(type == "ItemUpdate")
|
||||||
|
{
|
||||||
|
std::cout<<"Got item json:\n"<<QString::fromLatin1(jsonbytes).toStdString();
|
||||||
|
QJsonArray data = json["Data"].toArray();
|
||||||
|
std::vector<std::shared_ptr<Item>> items;
|
||||||
|
for(QJsonValueRef itemjson : data)
|
||||||
|
{
|
||||||
|
QJsonObject jsonobject = itemjson.toObject();
|
||||||
|
std::shared_ptr<Item> item = Item::loadItem(jsonobject);
|
||||||
|
if(item)
|
||||||
|
{
|
||||||
|
item->setLoaded(false);
|
||||||
|
items.push_back(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!items.empty())
|
||||||
|
gotItems(items, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TcpService::processIncomeingJson(jsonbytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::processComand(const QByteArray& command)
|
||||||
|
{
|
||||||
|
if(command.startsWith("MSG JSON LEN "))
|
||||||
|
{
|
||||||
|
state = STATE_RECV_JSON;
|
||||||
|
recievebytes = command.mid(13).toLongLong();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpClient::socketReadyRead()
|
||||||
|
{
|
||||||
|
buffer += socket->readAll();
|
||||||
|
bool remianing = true;
|
||||||
|
while(remianing)
|
||||||
|
{
|
||||||
|
remianing = false;
|
||||||
|
while(state == STATE_IDLE && buffer.contains('\n'))
|
||||||
|
{
|
||||||
|
size_t newlineIndex = buffer.indexOf('\n');
|
||||||
|
QByteArray command = buffer.left(newlineIndex);
|
||||||
|
buffer.remove(0, newlineIndex+1);
|
||||||
|
processComand(command);
|
||||||
|
remianing = true;
|
||||||
|
}
|
||||||
|
if(state == STATE_RECV_JSON)
|
||||||
|
{
|
||||||
|
if(recievebytes <= buffer.size())
|
||||||
|
{
|
||||||
|
QByteArray json = buffer.left(recievebytes);
|
||||||
|
buffer.remove(0, recievebytes);
|
||||||
|
recievebytes = 0;
|
||||||
|
state = STATE_IDLE;
|
||||||
|
processIncomeingJson(json);
|
||||||
|
remianing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpClient::~TcpClient()
|
||||||
|
{
|
||||||
|
delete socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
TcpServer::TcpServer(QObject* parent):
|
||||||
|
TcpService(parent),
|
||||||
|
server(this)
|
||||||
|
{
|
||||||
|
connect(&server, &QTcpServer::newConnection, this, &TcpServer::incomingConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::sendJson(const QJsonObject& json)
|
||||||
|
{
|
||||||
|
for(auto client: clients)
|
||||||
|
{
|
||||||
|
QByteArray jsonData = QJsonDocument(json).toJson();
|
||||||
|
client.socket->write(QString("MSG JSON LEN " + QString::number(jsonData.size()) + "\n").toLatin1() + jsonData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::processIncomeingJson(const QByteArray& jsonbytes)
|
||||||
|
{
|
||||||
|
QJsonDocument doc = QJsonDocument::fromJson(jsonbytes);
|
||||||
|
QJsonObject json = doc.object();
|
||||||
|
QString type = json["MessageType"].toString();
|
||||||
|
if(type == "ItemUpdate")
|
||||||
|
{
|
||||||
|
qDebug()<<"Got Items";
|
||||||
|
QJsonArray data = json["Data"].toArray();
|
||||||
|
bool FullList = json["FullList"].toBool(false);
|
||||||
|
std::vector<std::shared_ptr<Item>> items;
|
||||||
|
for(QJsonValueRef itemjson : data)
|
||||||
|
{
|
||||||
|
QJsonObject jsonobject = itemjson.toObject();
|
||||||
|
std::shared_ptr<Item> item = Item::loadItem(jsonobject);
|
||||||
|
item->setLoaded(FullList);
|
||||||
|
if(item)
|
||||||
|
items.push_back(item);
|
||||||
|
}
|
||||||
|
if(FullList && !items.empty())
|
||||||
|
{
|
||||||
|
requestReplaceItems(items);
|
||||||
|
sigRequestSave();
|
||||||
|
}
|
||||||
|
else if(!items.empty())
|
||||||
|
{
|
||||||
|
gotItems(items, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TcpService::processIncomeingJson(jsonbytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TcpServer::launch(const QHostAddress &address, quint16 port)
|
||||||
|
{
|
||||||
|
return server.listen(address, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::incomingConnection()
|
||||||
|
{
|
||||||
|
while(server.hasPendingConnections())
|
||||||
|
{
|
||||||
|
QTcpSocket* client = server.nextPendingConnection();
|
||||||
|
qDebug()<<"Got new client from"<<client->peerAddress().toString();
|
||||||
|
if(client)
|
||||||
|
{
|
||||||
|
clients.push_back({client});
|
||||||
|
connect(client, &QTcpSocket::errorOccurred, this, &TcpServer::socketError);
|
||||||
|
connect(client, &QTcpSocket::disconnected, this, &TcpServer::socketDisconnect);
|
||||||
|
connect(client, &QTcpSocket::readyRead, this, &TcpServer::socketReadyRead);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::socketError(QAbstractSocket::SocketError socketError)
|
||||||
|
{
|
||||||
|
(void)socketError;
|
||||||
|
for(size_t i = 0; i < clients.size(); i++)
|
||||||
|
{
|
||||||
|
if(clients[i].socket == TcpServer::sender())
|
||||||
|
{
|
||||||
|
clients.erase(clients.begin()+i);
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void TcpServer::socketDisconnect()
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < clients.size(); i++)
|
||||||
|
{
|
||||||
|
if(clients[i].socket == TcpServer::sender())
|
||||||
|
{
|
||||||
|
clients.erase(clients.begin()+i);
|
||||||
|
--i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::processComand(const QByteArray& command, Client& client)
|
||||||
|
{
|
||||||
|
if(command.startsWith("MSG JSON LEN "))
|
||||||
|
{
|
||||||
|
client.state = STATE_RECV_JSON;
|
||||||
|
client.recievebytes = command.mid(13).toLongLong();
|
||||||
|
qDebug()<<"Got command:"<<QString::fromLatin1(command);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TcpServer::socketReadyRead()
|
||||||
|
{
|
||||||
|
for(size_t i = 0; i < clients.size(); i++)
|
||||||
|
{
|
||||||
|
if(clients[i].socket == sender())
|
||||||
|
{
|
||||||
|
QByteArray newChars = clients[i].socket->readAll();
|
||||||
|
clients[i].buffer += newChars;
|
||||||
|
|
||||||
|
bool remianing = true;
|
||||||
|
while(remianing)
|
||||||
|
{
|
||||||
|
qDebug()<<clients[i].buffer;
|
||||||
|
remianing = false;
|
||||||
|
while(clients[i].state == STATE_IDLE && clients[i].buffer.contains('\n'))
|
||||||
|
{
|
||||||
|
size_t newlineIndex = clients[i].buffer.indexOf('\n');
|
||||||
|
QByteArray command = clients[i].buffer.left(newlineIndex);
|
||||||
|
clients[i].buffer.remove(0, newlineIndex+1);
|
||||||
|
processComand(command, clients[i]);
|
||||||
|
remianing = true;
|
||||||
|
}
|
||||||
|
if(clients[i].state == STATE_RECV_JSON)
|
||||||
|
{
|
||||||
|
if(clients[i].recievebytes <= clients[i].buffer.size())
|
||||||
|
{
|
||||||
|
QByteArray json = clients[i].buffer.left(clients[i].recievebytes);
|
||||||
|
clients[i].buffer.remove(0, clients[i].recievebytes);
|
||||||
|
clients[i].recievebytes = 0;
|
||||||
|
clients[i].state = STATE_IDLE;
|
||||||
|
processIncomeingJson(json);
|
||||||
|
remianing = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
101
src/tcpserver.h
Normal file
101
src/tcpserver.h
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
#ifndef TCPSERVER_H
|
||||||
|
#define TCPSERVER_H
|
||||||
|
|
||||||
|
#include <QTcpServer>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "sensors/sensor.h"
|
||||||
|
#include "items/item.h"
|
||||||
|
#include "items/itemsource.h"
|
||||||
|
|
||||||
|
class TcpService : public ItemSource
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
protected:
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
STATE_IDLE,
|
||||||
|
STATE_RECV_JSON,
|
||||||
|
} client_state_t;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void gotSensor(Sensor sensor);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void sensorEvent(Sensor sensor);
|
||||||
|
void itemUpdated(std::weak_ptr<Item> item);
|
||||||
|
virtual void refresh() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TcpService(QObject* parent = nullptr);
|
||||||
|
void sendSensors();
|
||||||
|
void sendItems();
|
||||||
|
virtual void sendJson(const QJsonObject& json) = 0;
|
||||||
|
virtual bool launch(const QHostAddress &address = QHostAddress::Any, quint16 port = 0) = 0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static QJsonObject createMessage(const QString& type, const QJsonArray& data);
|
||||||
|
virtual void processIncomeingJson(const QByteArray& jsonbytes);
|
||||||
|
};
|
||||||
|
|
||||||
|
class TcpClient : public TcpService
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
QTcpSocket* socket;
|
||||||
|
client_state_t state = STATE_IDLE;
|
||||||
|
long long recievebytes = 0;
|
||||||
|
QByteArray buffer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TcpClient(QObject* parent = nullptr);
|
||||||
|
~TcpClient();
|
||||||
|
virtual bool launch(const QHostAddress &address = QHostAddress::Any, quint16 port = 0) override;
|
||||||
|
virtual void sendJson(const QJsonObject& json) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void processIncomeingJson(const QByteArray& jsonbytes) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void socketReadyRead();
|
||||||
|
void processComand(const QByteArray& command);
|
||||||
|
};
|
||||||
|
|
||||||
|
class TcpServer : public TcpService
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
struct Client
|
||||||
|
{
|
||||||
|
QTcpSocket* socket;
|
||||||
|
QByteArray buffer;
|
||||||
|
client_state_t state = STATE_IDLE;
|
||||||
|
long long recievebytes = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<Client> clients;
|
||||||
|
QTcpServer server;
|
||||||
|
|
||||||
|
public:
|
||||||
|
TcpServer(QObject* parent = nullptr);
|
||||||
|
virtual bool launch(const QHostAddress &address = QHostAddress::Any, quint16 port = 0) override;
|
||||||
|
virtual void sendJson(const QJsonObject& json) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sigRequestSave();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void incomingConnection();
|
||||||
|
void socketError(QAbstractSocket::SocketError socketError);
|
||||||
|
void socketDisconnect();
|
||||||
|
void socketReadyRead();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void processIncomeingJson(const QByteArray& jsonbytes) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void processComand(const QByteArray& command, Client& client);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TCPSERVER_H
|
||||||
|
|
@ -24,16 +24,16 @@
|
||||||
</property>
|
</property>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<property name="fieldGrowthPolicy">
|
<property name="fieldGrowthPolicy">
|
||||||
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
|
<enum>QFormLayout::FieldGrowthPolicy::AllNonFixedFieldsGrow</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="rowWrapPolicy">
|
<property name="rowWrapPolicy">
|
||||||
<enum>QFormLayout::DontWrapRows</enum>
|
<enum>QFormLayout::RowWrapPolicy::DontWrapRows</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="labelAlignment">
|
<property name="labelAlignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="formAlignment">
|
<property name="formAlignment">
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignTop</set>
|
||||||
</property>
|
</property>
|
||||||
<property name="horizontalSpacing">
|
<property name="horizontalSpacing">
|
||||||
<number>50</number>
|
<number>50</number>
|
||||||
|
|
@ -57,7 +57,7 @@
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="currentSection">
|
<property name="currentSection">
|
||||||
<enum>QDateTimeEdit::DaySection</enum>
|
<enum>QDateTimeEdit::Section::DaySection</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="displayFormat">
|
<property name="displayFormat">
|
||||||
<string>dd.MM.yyyy hh:mm</string>
|
<string>dd.MM.yyyy hh:mm</string>
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>SensorListWidget</class>
|
<class>SensorListWidget</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header location="global">../src/ui/sensorlistwidget.h</header>
|
<header location="local">ui/sensorlistwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>SensorListWidget</class>
|
<class>SensorListWidget</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header location="global">../src/ui/sensorlistwidget.h</header>
|
<header location="local">ui/sensorlistwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>SensorListWidget</class>
|
<class>SensorListWidget</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header location="global">../src/ui/sensorlistwidget.h</header>
|
<header location="local">ui/sensorlistwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,9 @@ void ItemScrollBox::addItem(std::weak_ptr<Item> item)
|
||||||
{
|
{
|
||||||
if(auto workItem = item.lock())
|
if(auto workItem = item.lock())
|
||||||
{
|
{
|
||||||
if(dynamic_cast<AuxItem*>(workItem.get()))
|
if(workItem->isHidden())
|
||||||
{
|
return;
|
||||||
widgets_.push_back(new ItemWidget(item, true));
|
|
||||||
}
|
|
||||||
else if(dynamic_cast<MessageItem*>(workItem.get()))
|
|
||||||
{
|
|
||||||
widgets_.push_back(new ItemWidget(item, false, true));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
widgets_.push_back(new ItemWidget(item));
|
widgets_.push_back(new ItemWidget(item));
|
||||||
}
|
|
||||||
ui->relayWidgetVbox->addWidget(widgets_.back());
|
ui->relayWidgetVbox->addWidget(widgets_.back());
|
||||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
|
||||||
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@
|
||||||
#include "../actors/factoractor.h"
|
#include "../actors/factoractor.h"
|
||||||
#include "../items/messageitem.h"
|
#include "../items/messageitem.h"
|
||||||
#include "../items/systemitem.h"
|
#include "../items/systemitem.h"
|
||||||
#include "./itemsettingswidgets/messageitemsettingswidget.h"
|
#include "itemsettingswidgets/messageitemsettingswidget.h"
|
||||||
#include "./itemsettingswidgets/systemitemsettingswidget.h"
|
#include "itemsettingswidgets/systemitemsettingswidget.h"
|
||||||
#include "./itemsettingswidgets/relayitemsettingswidget.h"
|
#include "itemsettingswidgets/relayitemsettingswidget.h"
|
||||||
#include<memory>
|
#include<memory>
|
||||||
|
|
||||||
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
|
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
|
||||||
|
|
@ -177,7 +177,7 @@ void ItemSettingsDialog::editActor()
|
||||||
dialog->show();
|
dialog->show();
|
||||||
dialog->exec();
|
dialog->exec();
|
||||||
|
|
||||||
for(int i = 0; i < ui->tableWidget->rowCount() && i < static_cast<size_t>(item_->getActors().size()); ++i)
|
for(int i = 0; i < ui->tableWidget->rowCount() && i < static_cast<int>(item_->getActors().size()); ++i)
|
||||||
{
|
{
|
||||||
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
||||||
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
||||||
|
|
|
||||||
|
|
@ -5,39 +5,47 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSlider>
|
#include <QSlider>
|
||||||
|
|
||||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, bool nameOnly, QWidget *parent) :
|
ItemWidget::ItemWidget(std::weak_ptr<Item> item, QWidget *parent) :
|
||||||
QWidget(parent),
|
QWidget(parent),
|
||||||
item_(item),
|
item_(item),
|
||||||
ui(new Ui::ItemWidget)
|
ui(new Ui::ItemWidget)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
if(analog)
|
if(auto workingItem = item_.lock())
|
||||||
|
{
|
||||||
|
if(workingItem->getValueType() == ITEM_VALUE_UINT)
|
||||||
{
|
{
|
||||||
ui->horizontalSpacer->changeSize(0,0);
|
ui->horizontalSpacer->changeSize(0,0);
|
||||||
ui->checkBox->hide();
|
ui->checkBox->hide();
|
||||||
}
|
}
|
||||||
else if(nameOnly)
|
else if(workingItem->getValueType() == ITEM_VALUE_NO_VALUE)
|
||||||
{
|
{
|
||||||
ui->checkBox->hide();
|
ui->checkBox->hide();
|
||||||
ui->slider->hide();
|
ui->slider->hide();
|
||||||
}
|
}
|
||||||
else ui->slider->hide();
|
else
|
||||||
|
|
||||||
if(auto workingRelay = item_.lock())
|
|
||||||
{
|
{
|
||||||
ui->checkBox->setChecked(workingRelay->getValue());
|
ui->slider->hide();
|
||||||
|
}
|
||||||
|
|
||||||
ui->label->setText(workingRelay->getName());
|
ui->checkBox->setChecked(workingItem->getValue());
|
||||||
|
|
||||||
if(analog)connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
|
ui->label->setText(workingItem->getName());
|
||||||
else connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
|
||||||
|
if(workingItem->getValueType() == ITEM_VALUE_UINT)
|
||||||
|
connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
|
||||||
|
else
|
||||||
|
connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
|
||||||
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
|
||||||
connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
|
connect(workingItem.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
|
||||||
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
|
connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
|
||||||
|
|
||||||
}
|
}
|
||||||
else disable();
|
else
|
||||||
|
{
|
||||||
|
disable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::deleteItem()
|
void ItemWidget::deleteItem()
|
||||||
|
|
@ -50,14 +58,18 @@ void ItemWidget::deleteItem()
|
||||||
|
|
||||||
void ItemWidget::moveToValue(int value)
|
void ItemWidget::moveToValue(int value)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock()) workingItem->setValue(value);
|
if(auto workingItem = item_.lock())
|
||||||
else disable();
|
workingItem->setValue(value);
|
||||||
|
else
|
||||||
|
disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::moveToState(bool state)
|
void ItemWidget::moveToState(bool state)
|
||||||
{
|
{
|
||||||
if(auto workingItem = item_.lock()) workingItem->setValue(state);
|
if(auto workingItem = item_.lock())
|
||||||
else disable();
|
workingItem->setValue(state);
|
||||||
|
else
|
||||||
|
disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemWidget::disable()
|
void ItemWidget::disable()
|
||||||
|
|
@ -70,9 +82,9 @@ void ItemWidget::disable()
|
||||||
|
|
||||||
bool ItemWidget::controles(const ItemData& relay)
|
bool ItemWidget::controles(const ItemData& relay)
|
||||||
{
|
{
|
||||||
if(auto workingRelay = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
{
|
{
|
||||||
if(relay == *workingRelay) return true;
|
if(relay == *workingItem) return true;
|
||||||
else return false;
|
else return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -80,9 +92,9 @@ bool ItemWidget::controles(const ItemData& relay)
|
||||||
|
|
||||||
void ItemWidget::showSettingsDialog()
|
void ItemWidget::showSettingsDialog()
|
||||||
{
|
{
|
||||||
if(auto workingRelay = item_.lock())
|
if(auto workingItem = item_.lock())
|
||||||
{
|
{
|
||||||
ItemSettingsDialog dialog(workingRelay, this);
|
ItemSettingsDialog dialog(workingItem, this);
|
||||||
dialog.exec();
|
dialog.exec();
|
||||||
}
|
}
|
||||||
else disable();
|
else disable();
|
||||||
|
|
@ -95,7 +107,6 @@ std::weak_ptr<Item> ItemWidget::getItem()
|
||||||
|
|
||||||
void ItemWidget::stateChanged(int state)
|
void ItemWidget::stateChanged(int state)
|
||||||
{
|
{
|
||||||
qDebug()<<"widget got state "<<state;
|
|
||||||
ui->slider->blockSignals(true);
|
ui->slider->blockSignals(true);
|
||||||
ui->slider->setValue(state);
|
ui->slider->setValue(state);
|
||||||
ui->slider->blockSignals(false);
|
ui->slider->blockSignals(false);
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ private slots:
|
||||||
void deleteItem();
|
void deleteItem();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ItemWidget(std::weak_ptr<Item> item, bool analog = false, bool nameOnly = false, QWidget *parent = nullptr);
|
explicit ItemWidget(std::weak_ptr<Item> item, QWidget *parent = nullptr);
|
||||||
std::weak_ptr<Item> getItem();
|
std::weak_ptr<Item> getItem();
|
||||||
bool controles(const ItemData& relay);
|
bool controles(const ItemData& relay);
|
||||||
~ItemWidget();
|
~ItemWidget();
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizeHint" stdset="0">
|
<property name="sizeHint" stdset="0">
|
||||||
<size>
|
<size>
|
||||||
|
|
@ -46,10 +46,10 @@
|
||||||
<number>255</number>
|
<number>255</number>
|
||||||
</property>
|
</property>
|
||||||
<property name="tracking">
|
<property name="tracking">
|
||||||
<bool>true</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
|
|
@ -245,13 +245,13 @@
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>ItemScrollBox</class>
|
<class>ItemScrollBox</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header location="global">../src/ui/itemscrollbox.h</header>
|
<header location="global">../ui/itemscrollbox.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>SensorListWidget</class>
|
<class>SensorListWidget</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header location="global">../src/ui/sensorlistwidget.h</header>
|
<header location="global">../ui/sensorlistwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
|
||||||
|
|
@ -1,46 +1,35 @@
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "itemscrollbox.h"
|
#include "itemscrollbox.h"
|
||||||
#include "itemsettingsdialog.h"
|
#include "itemsettingsdialog.h"
|
||||||
#include "itemcreationdialog.h"
|
#include "itemcreationdialog.h"
|
||||||
#include "../mainobject.h"
|
#include "mainobject.h"
|
||||||
#include <QMessageBox>
|
#include "programmode.h"
|
||||||
|
#include "items/poweritem.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||||
QMainWindow(parent),
|
QMainWindow(parent),
|
||||||
ui(new Ui::MainWindow),
|
ui(new Ui::MainWindow),
|
||||||
colorChooser(this),
|
colorChooser(this)
|
||||||
_micro(&mainObject->micro),
|
|
||||||
_powerItem(mainObject->powerItem)
|
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
if(!mainObject->master)
|
|
||||||
{
|
|
||||||
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigSave);
|
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigSave);
|
||||||
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::saved);
|
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, [this](){QMessageBox::information(this, "Saved", "Settings where saved");});
|
||||||
}
|
|
||||||
|
|
||||||
connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
|
connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
|
||||||
|
|
||||||
//Relays
|
connect(ui->pushButton_refesh, &QPushButton::clicked, mainObject, &MainObject::refresh);
|
||||||
if(mainObject->master)connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
|
connect(&globalItems, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
||||||
else
|
connect(&globalItems, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
||||||
{
|
|
||||||
connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
|
|
||||||
connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestSensors);
|
|
||||||
}
|
|
||||||
connect(&mainObject->items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
|
|
||||||
connect(&mainObject->items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < mainObject->items.getItems()->size(); ++i)
|
for(size_t i = 0; i < globalItems.getItems()->size(); ++i)
|
||||||
{
|
ui->relayList->addItem(globalItems.getItems()->at(i));
|
||||||
ui->relayList->addItem(mainObject->items.getItems()->at(i));
|
|
||||||
}
|
if(programMode != PROGRAM_MODE_PRIMARY)
|
||||||
|
ui->label_serialRecive->setHidden(true);
|
||||||
|
|
||||||
//Sensors
|
//Sensors
|
||||||
ui->sensorListView->setShowHidden(false);
|
ui->sensorListView->setShowHidden(false);
|
||||||
|
|
@ -48,12 +37,14 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||||
connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
|
connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
|
||||||
|
|
||||||
//RGB Leds
|
//RGB Leds
|
||||||
connect(&colorChooser, SIGNAL(colorSelected(QColor)), this, SLOT(slotChangedRgb(QColor)));
|
connect(&colorChooser, &QColorDialog::colorSelected, this, &MainWindow::sigSetRgb);
|
||||||
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
|
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
|
||||||
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
|
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
|
||||||
|
if(programMode != PROGRAM_MODE_PRIMARY)
|
||||||
|
ui->button_color->hide();
|
||||||
|
|
||||||
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
||||||
connect(ui->relayList, &ItemScrollBox::deleteRequest, &mainObject->items, &ItemStore::removeItem);
|
connect(ui->relayList, &ItemScrollBox::deleteRequest, &globalItems, &ItemStore::removeItem);
|
||||||
|
|
||||||
ui->splitter->setStretchFactor(1, 1);
|
ui->splitter->setStretchFactor(1, 1);
|
||||||
}
|
}
|
||||||
|
|
@ -65,30 +56,31 @@ MainWindow::~MainWindow()
|
||||||
|
|
||||||
void MainWindow::showPowerItemDialog()
|
void MainWindow::showPowerItemDialog()
|
||||||
{
|
{
|
||||||
ItemSettingsDialog diag(std::shared_ptr<Item>(_powerItem), this);
|
std::shared_ptr<PowerItem> powerItem;
|
||||||
|
for(std::shared_ptr<Item> item : *globalItems.getItems())
|
||||||
|
{
|
||||||
|
powerItem = std::dynamic_pointer_cast<PowerItem>(item);
|
||||||
|
if(powerItem)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(powerItem)
|
||||||
|
{
|
||||||
|
ItemSettingsDialog diag(std::shared_ptr<Item>(powerItem), this);
|
||||||
diag.show();
|
diag.show();
|
||||||
diag.exec();
|
diag.exec();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
void MainWindow::saved()
|
|
||||||
{
|
{
|
||||||
QMessageBox::information(this, "Saved", "Settings where saved");
|
QMessageBox::warning(this, "Error", "No power item found, refresh first");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::slotChangedRgb(const QColor color)
|
|
||||||
{
|
|
||||||
_micro->changeRgbColor(color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::showItemCreationDialog()
|
void MainWindow::showItemCreationDialog()
|
||||||
{
|
{
|
||||||
ItemCreationDialog diag(this);
|
ItemCreationDialog diag(this);
|
||||||
diag.show();
|
diag.show();
|
||||||
if(diag.exec())
|
if(diag.exec())
|
||||||
{
|
|
||||||
createdItem(diag.item);
|
createdItem(diag.item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::changeHeaderLableText(QString string)
|
void MainWindow::changeHeaderLableText(QString string)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,9 @@
|
||||||
#include <QColorDialog>
|
#include <QColorDialog>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <vector>
|
#include <memory>
|
||||||
#include "../actors/alarmtime.h"
|
|
||||||
#include "../microcontroller.h"
|
|
||||||
#include "../sensors/sensor.h"
|
|
||||||
#include "../items/itemstore.h"
|
|
||||||
#include "../items/poweritem.h"
|
|
||||||
#include "../broadcast.h"
|
|
||||||
|
|
||||||
|
#include<items/item.h>
|
||||||
|
|
||||||
class MainObject;
|
class MainObject;
|
||||||
|
|
||||||
|
|
@ -34,23 +29,17 @@ private:
|
||||||
|
|
||||||
QColorDialog colorChooser;
|
QColorDialog colorChooser;
|
||||||
|
|
||||||
Microcontroller *_micro;
|
|
||||||
|
|
||||||
std::shared_ptr<PowerItem> _powerItem;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
void sigBrodcast();
|
|
||||||
void sigSave();
|
void sigSave();
|
||||||
void createdItem(std::shared_ptr<Item> item);
|
void createdItem(std::shared_ptr<Item> item);
|
||||||
|
void sigSetRgb(const QColor color);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
//RGB
|
//RGB
|
||||||
void slotChangedRgb(const QColor color);
|
|
||||||
void showPowerItemDialog();
|
void showPowerItemDialog();
|
||||||
void showItemCreationDialog();
|
void showItemCreationDialog();
|
||||||
void saved();
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,21 +37,21 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="layoutDirection">
|
<property name="layoutDirection">
|
||||||
<enum>Qt::LeftToRight</enum>
|
<enum>Qt::LayoutDirection::LeftToRight</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoFillBackground">
|
<property name="autoFillBackground">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
<layout class="QVBoxLayout" name="verticalLayout_5" stretch="0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter">
|
<widget class="QSplitter" name="splitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="childrenCollapsible">
|
<property name="childrenCollapsible">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_serialRecive">
|
<widget class="QLabel" name="label_serialRecive">
|
||||||
|
|
@ -62,13 +62,13 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="frameShape">
|
<property name="frameShape">
|
||||||
<enum>QFrame::Box</enum>
|
<enum>QFrame::Shape::Box</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>SHinterface</string>
|
<string>SHinterface</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="textFormat">
|
<property name="textFormat">
|
||||||
<enum>Qt::AutoText</enum>
|
<enum>Qt::TextFormat::AutoText</enum>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -99,7 +99,7 @@
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="selectionMode">
|
<property name="selectionMode">
|
||||||
<enum>QAbstractItemView::NoSelection</enum>
|
<enum>QAbstractItemView::SelectionMode::NoSelection</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="showGrid" stdset="0">
|
<property name="showGrid" stdset="0">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
|
@ -114,49 +114,11 @@
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="button_color">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>0</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="maximumSize">
|
|
||||||
<size>
|
|
||||||
<width>16777215</width>
|
|
||||||
<height>48</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="baseSize">
|
|
||||||
<size>
|
|
||||||
<width>0</width>
|
|
||||||
<height>128</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>Color</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
|
||||||
<widget class="QPushButton" name="pushButton_power">
|
|
||||||
<property name="text">
|
|
||||||
<string>Config Shutdown</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="">
|
<widget class="QWidget" name="layoutWidget">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
|
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QGroupBox" name="groupBox">
|
||||||
|
|
@ -194,6 +156,52 @@
|
||||||
<property name="topMargin">
|
<property name="topMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="pushButton_power">
|
||||||
|
<property name="text">
|
||||||
|
<string>Config Shutdown</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="button_color">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="baseSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>128</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Color</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton_refesh">
|
<widget class="QPushButton" name="pushButton_refesh">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
@ -224,7 +232,7 @@
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="layoutDirection">
|
<property name="layoutDirection">
|
||||||
<enum>Qt::RightToLeft</enum>
|
<enum>Qt::LayoutDirection::RightToLeft</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Quit</string>
|
<string>Quit</string>
|
||||||
|
|
@ -236,21 +244,17 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
|
||||||
</layout>
|
|
||||||
</widget>
|
|
||||||
</widget>
|
|
||||||
<layoutdefault spacing="6" margin="11"/>
|
<layoutdefault spacing="6" margin="11"/>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>SensorListWidget</class>
|
<class>SensorListWidget</class>
|
||||||
<extends>QListView</extends>
|
<extends>QListView</extends>
|
||||||
<header location="global">../src/ui/sensorlistwidget.h</header>
|
<header location="global">ui/sensorlistwidget.h</header>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
<class>ItemScrollBox</class>
|
<class>ItemScrollBox</class>
|
||||||
<extends>QWidget</extends>
|
<extends>QWidget</extends>
|
||||||
<header location="global">../src/ui/itemscrollbox.h</header>
|
<header location="global">ui/itemscrollbox.h</header>
|
||||||
<container>1</container>
|
<container>1</container>
|
||||||
</customwidget>
|
</customwidget>
|
||||||
</customwidgets>
|
</customwidgets>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <QTableWidget>
|
#include <QTableWidget>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "../sensors/sensor.h"
|
#include "sensors/sensor.h"
|
||||||
|
|
||||||
class SensorListItem : public QTableWidgetItem
|
class SensorListItem : public QTableWidgetItem
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue