Compare commits
10 Commits
954eec754c
...
d8471789b7
Author | SHA1 | Date | |
---|---|---|---|
d8471789b7 | |||
a301bdbaa7 | |||
260334ef35 | |||
146c33673a | |||
a00c8a52f8 | |||
0acf6c7fc4 | |||
03c2be7977 | |||
fa45072998 | |||
a6aad07f05 | |||
09b23fc296 |
@ -88,7 +88,7 @@ uint8_t Actor::getTriggerValue()
|
||||
|
||||
void Actor::onValueChanged(uint8_t value)
|
||||
{
|
||||
|
||||
(void)value;
|
||||
}
|
||||
|
||||
std::shared_ptr<Actor> Actor::createActor(const QString& type)
|
||||
|
@ -26,8 +26,9 @@ void MultiFactorActor::setValue(uint8_t value)
|
||||
{
|
||||
performAction();
|
||||
}
|
||||
bool exausted = true;
|
||||
for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
|
||||
exausted = true;
|
||||
for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted())
|
||||
exausted = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,11 +29,26 @@ public:
|
||||
virtual QString getName() const;
|
||||
|
||||
void setFactorActor(std::shared_ptr<Actor> factorActor);
|
||||
std::shared_ptr<Actor> getFactorActor(){return factorActor_;}
|
||||
void setFactorDirection(const bool direction){factorDirection = direction;}
|
||||
bool getFactorDirection(){return factorDirection;}
|
||||
uint getPreCancleTime(){return preCancleMin_;}
|
||||
void setPreCancleTime(uint minutes){preCancleMin_ = minutes;}
|
||||
std::shared_ptr<Actor> getFactorActor()
|
||||
{
|
||||
return factorActor_;
|
||||
}
|
||||
void setFactorDirection(const bool direction)
|
||||
{
|
||||
factorDirection = direction;
|
||||
}
|
||||
bool getFactorDirection()
|
||||
{
|
||||
return factorDirection;
|
||||
}
|
||||
uint getPreCancleTime()
|
||||
{
|
||||
return preCancleMin_;
|
||||
}
|
||||
void setPreCancleTime(uint minutes)
|
||||
{
|
||||
preCancleMin_ = minutes;
|
||||
}
|
||||
|
||||
virtual ~MultiFactorActor() {}
|
||||
|
||||
|
@ -35,7 +35,8 @@ void PolynomalActor::sensorEvent(Sensor sensor)
|
||||
{
|
||||
if(active && sensor == sensor_)
|
||||
{
|
||||
double result = pow3_*(sensor.field*sensor.field*sensor.field)+pow2_*(sensor.field*sensor.field)+pow1_*sensor.field+pow0_;
|
||||
double result = pow3_*(sensor.field*sensor.field*sensor.field)+pow2_*(sensor.field*sensor.field)+pow1_*sensor.field
|
||||
+pow0_;
|
||||
if(result < 0) result = 0;
|
||||
else if(result > 254) result = 255;
|
||||
if(result != prevValue)sigValue(static_cast<uint8_t>(result));
|
||||
@ -76,7 +77,8 @@ QString PolynomalActor::getName() const
|
||||
else
|
||||
{
|
||||
QString string;
|
||||
string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
|
||||
string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(
|
||||
pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ public:
|
||||
PolynomalActor(const Sensor sensor, QObject* parent = nullptr);
|
||||
PolynomalActor(QObject* parent = nullptr);
|
||||
void setSensor(const Sensor sensor);
|
||||
Sensor getSensor(){return sensor_;}
|
||||
Sensor getSensor()
|
||||
{
|
||||
return sensor_;
|
||||
}
|
||||
virtual QString getName() const;
|
||||
virtual ~PolynomalActor() {}
|
||||
|
||||
|
@ -34,6 +34,14 @@ void Regulator::sensorEvent(Sensor sensor)
|
||||
}
|
||||
}
|
||||
|
||||
void Regulator::makeInactive()
|
||||
{
|
||||
first = true;
|
||||
if(active)
|
||||
sigValue(!triggerValue);
|
||||
Actor::makeInactive();
|
||||
}
|
||||
|
||||
void Regulator::setPoint(float setPoint)
|
||||
{
|
||||
setPoint_ = setPoint;
|
||||
|
@ -22,14 +22,24 @@ public slots:
|
||||
void setPoint( float setPoint );
|
||||
void setBand ( float band );
|
||||
void setInvert( bool invert );
|
||||
virtual void makeInactive() override;
|
||||
|
||||
public:
|
||||
|
||||
float getBand() {return band_;}
|
||||
float getSetPoint() {return setPoint_;}
|
||||
float getBand()
|
||||
{
|
||||
return band_;
|
||||
}
|
||||
float getSetPoint()
|
||||
{
|
||||
return setPoint_;
|
||||
}
|
||||
Regulator(const Sensor sensor, QObject* parent = nullptr);
|
||||
Regulator(QObject* parent = nullptr);
|
||||
Sensor getSensor(){return sensor_;}
|
||||
Sensor getSensor()
|
||||
{
|
||||
return sensor_;
|
||||
}
|
||||
virtual QString getName() const;
|
||||
virtual ~Regulator() {}
|
||||
|
||||
|
@ -21,8 +21,10 @@ void SensorActor::sensorEvent(Sensor sensor)
|
||||
{
|
||||
if(sensor == sensor_)
|
||||
{
|
||||
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_ && sensor.field >= threshold_ ) performAction();
|
||||
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_ && sensor.field <= threshold_) performAction();
|
||||
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_
|
||||
&& sensor.field >= threshold_ ) performAction();
|
||||
else if((sloap_ == SLOPE_DOWN || sloap_ == SLOPE_BOTH) && sensor_.field > threshold_
|
||||
&& sensor.field <= threshold_) performAction();
|
||||
sensor_ = sensor;
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,10 @@ public:
|
||||
|
||||
SensorActor(const Sensor sensor, QObject* parent = nullptr);
|
||||
SensorActor(QObject* parent = nullptr);
|
||||
Sensor getSensor(){return sensor_;}
|
||||
Sensor getSensor()
|
||||
{
|
||||
return sensor_;
|
||||
}
|
||||
virtual QString getName() const;
|
||||
virtual ~SensorActor() {}
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include "alarmactions.h"
|
||||
#include <QProcess>
|
||||
|
||||
AlarmActions::AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent) : QObject(parent), _micro(micro), a_(a)
|
||||
AlarmActions::AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent) : QObject(parent), _micro(micro),
|
||||
a_(a)
|
||||
{
|
||||
|
||||
}
|
||||
@ -9,6 +10,6 @@ AlarmActions::AlarmActions(QApplication* a, Microcontroller* micro, QObject *par
|
||||
void AlarmActions::syncoff()
|
||||
{
|
||||
qDebug()<<"syncoff";
|
||||
QProcess::execute ( "syncoff" );
|
||||
QProcess::execute ("syncoff", QStringList());
|
||||
a_->exit(0);
|
||||
}
|
||||
|
@ -53,6 +53,8 @@ static int nl80211Init(struct nl_sock* nl_sock, int* nl80211_id)
|
||||
|
||||
static int errorHandler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
|
||||
{
|
||||
(void)nla;
|
||||
(void)err;
|
||||
printf("netlink error\n");
|
||||
*reinterpret_cast<int*>(arg) = 0;
|
||||
return NL_STOP;
|
||||
@ -60,12 +62,14 @@ static int errorHandler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg
|
||||
|
||||
static int finishHandler(struct nl_msg *msg, void *arg)
|
||||
{
|
||||
(void)msg;
|
||||
*reinterpret_cast<int*>(arg) = 0;
|
||||
return NL_SKIP;
|
||||
}
|
||||
|
||||
static int ackHandler(struct nl_msg *msg, void *arg)
|
||||
{
|
||||
(void)msg;
|
||||
*reinterpret_cast<int*>(arg) = 0;
|
||||
return NL_STOP;
|
||||
}
|
||||
|
@ -41,20 +41,23 @@ void BroadCast::sendJson(const QJsonObject& json)
|
||||
|
||||
void BroadCast::sendSensors()
|
||||
{
|
||||
if(iodevice_)for(auto& sensor: *globalSensors.getSensors())
|
||||
if(iodevice_)
|
||||
{
|
||||
for(auto& sensor: *globalSensors.getSensors())
|
||||
iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n');
|
||||
}
|
||||
}
|
||||
|
||||
void BroadCast::requestSensors()
|
||||
{
|
||||
if(iodevice_)iodevice_->write("bcst: GETSENSORS\n");
|
||||
if(iodevice_)
|
||||
iodevice_->write("bcst: GETSENSORS\n");
|
||||
}
|
||||
|
||||
void BroadCast::requestJson()
|
||||
{
|
||||
if(iodevice_)iodevice_->write("bcst: GETJSN\n");
|
||||
if(iodevice_)
|
||||
iodevice_->write("bcst: GETJSN\n");
|
||||
}
|
||||
|
||||
void BroadCast::decodeMaster(const QByteArray& buffer)
|
||||
@ -74,7 +77,8 @@ void BroadCast::decodeMaster(const QByteArray& buffer)
|
||||
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] == ':')
|
||||
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);
|
||||
@ -104,7 +108,8 @@ void BroadCast::decode(QByteArray buffer)
|
||||
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')
|
||||
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);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "auxitem.h"
|
||||
|
||||
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||
AuxItem::AuxItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value,
|
||||
QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ public slots:
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||
uint8_t value = 0, QObject* parent = nullptr);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
};
|
||||
|
@ -38,7 +38,8 @@ uint32_t ItemData::id() const
|
||||
|
||||
bool Item::secondaryFlag = false;
|
||||
|
||||
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name, value)
|
||||
Item::Item(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): QObject(parent), ItemData (itemIdIn, name,
|
||||
value)
|
||||
{
|
||||
|
||||
}
|
||||
@ -122,7 +123,8 @@ void Item::addActor(std::shared_ptr<Actor> actor)
|
||||
if(regulator)connect(&globalSensors, &SensorStore::sensorChangedState, regulator.get(), &Regulator::sensorEvent);
|
||||
|
||||
std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
|
||||
if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor.get(), &PolynomalActor::sensorEvent);
|
||||
if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor.get(),
|
||||
&PolynomalActor::sensorEvent);
|
||||
}
|
||||
|
||||
bool Item::removeActor(std::shared_ptr<Actor> actor)
|
||||
|
@ -19,8 +19,14 @@ public:
|
||||
|
||||
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0);
|
||||
|
||||
inline bool operator==(const ItemData& in) const{ return itemId_==in.itemId_; }
|
||||
inline bool operator!=(const ItemData& in) const{ return itemId_!=in.itemId_; }
|
||||
inline bool operator==(const ItemData& in) const
|
||||
{
|
||||
return itemId_==in.itemId_;
|
||||
}
|
||||
inline bool operator!=(const ItemData& in) const
|
||||
{
|
||||
return itemId_!=in.itemId_;
|
||||
}
|
||||
|
||||
uint32_t id() const;
|
||||
|
||||
@ -55,7 +61,8 @@ public slots:
|
||||
|
||||
public:
|
||||
|
||||
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
||||
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,
|
||||
QObject *parent = nullptr);
|
||||
Item(const ItemData& itemData, QObject *parent = nullptr);
|
||||
|
||||
virtual ~Item();
|
||||
|
@ -17,7 +17,10 @@ public:
|
||||
ItemStore(QObject *parent = nullptr);
|
||||
virtual ~ItemStore() {}
|
||||
|
||||
inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
|
||||
inline std::vector< std::shared_ptr<Item> >* getItems()
|
||||
{
|
||||
return &items_;
|
||||
}
|
||||
|
||||
void store(QJsonObject &json);
|
||||
void load(const QJsonObject &json);
|
||||
|
@ -28,7 +28,8 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
MessageItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
||||
MessageItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,
|
||||
QObject *parent = nullptr);
|
||||
MessageItem(const ItemData& itemData, QObject *parent = nullptr);
|
||||
~MessageItem();
|
||||
|
||||
|
@ -3,7 +3,8 @@
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent)
|
||||
PowerItem::PowerItem(uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value,
|
||||
parent)
|
||||
{
|
||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||
setValue(true);
|
||||
@ -23,7 +24,7 @@ void PowerItem::setValue(uint8_t value)
|
||||
void PowerItem::timeout()
|
||||
{
|
||||
qDebug()<<"shutdown timeout";
|
||||
QProcess::startDetached("syncoff");
|
||||
QProcess::startDetached("syncoff", QStringList());
|
||||
}
|
||||
|
||||
void PowerItem::store(QJsonObject& json)
|
||||
|
@ -24,7 +24,11 @@ public slots:
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
PowerItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||
void emmitSensor(){stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));}
|
||||
PowerItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0,
|
||||
QObject* parent = nullptr);
|
||||
void emmitSensor()
|
||||
{
|
||||
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
|
||||
}
|
||||
virtual void store(QJsonObject& json);
|
||||
};
|
||||
|
@ -5,7 +5,8 @@
|
||||
|
||||
Microcontroller* Relay::micro_ = nullptr;
|
||||
|
||||
Relay::Relay(uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(0, name, state, parent), id_(id), address_(address)
|
||||
Relay::Relay(uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(0, name, state, parent),
|
||||
id_(id), address_(address)
|
||||
{
|
||||
itemId_ = address | ((uint32_t)id << 16);
|
||||
qDebug()<<"Relay "<<id_<<"Name "<<name<<" id "<<itemId_<<" state "<<state<<" addr: "<<address;
|
||||
|
@ -32,7 +32,10 @@ public:
|
||||
uint8_t getId() const;
|
||||
void setId(uint8_t id);
|
||||
|
||||
inline static void setMicrocontroller(Microcontroller* micro){ micro_ = micro; }
|
||||
inline static void setMicrocontroller(Microcontroller* micro)
|
||||
{
|
||||
micro_ = micro;
|
||||
}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "rgbitem.h"
|
||||
|
||||
RgbItem::RgbItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||
RgbItem::RgbItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value,
|
||||
QObject* parent): Item(itemIdIn, name, value, parent), micro_(micro)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ public slots:
|
||||
virtual void setValue(uint8_t value);
|
||||
|
||||
public:
|
||||
RgbItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", uint8_t value = 0, QObject* parent = nullptr);
|
||||
RgbItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "",
|
||||
uint8_t value = 0, QObject* parent = nullptr);
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
};
|
||||
|
@ -18,14 +18,21 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
SystemItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
|
||||
SystemItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,
|
||||
QObject *parent = nullptr);
|
||||
SystemItem(const ItemData& itemData, QObject *parent = nullptr);
|
||||
~SystemItem() = default;
|
||||
|
||||
void setOnCommand(const QString& in);
|
||||
void setOffCommand(const QString& in);
|
||||
QString getOnCommand(){return onCommand_;}
|
||||
QString getOffCommand(){return offCommand_;}
|
||||
QString getOnCommand()
|
||||
{
|
||||
return onCommand_;
|
||||
}
|
||||
QString getOffCommand()
|
||||
{
|
||||
return offCommand_;
|
||||
}
|
||||
|
||||
virtual void store(QJsonObject& json);
|
||||
virtual void load(const QJsonObject& json, const bool preserve = false);
|
||||
|
41
src/main.cpp
41
src/main.cpp
@ -4,6 +4,9 @@
|
||||
#include <QTcpSocket>
|
||||
#include <QMessageBox>
|
||||
|
||||
//Currently pipewire support is disabled
|
||||
//#include <pipewire/pipewire.h>
|
||||
|
||||
|
||||
#ifndef Q_OS_ANDROID
|
||||
#include <QtSerialPort/QtSerialPort>
|
||||
@ -11,18 +14,9 @@
|
||||
#include <QCommandLineParser>
|
||||
#endif
|
||||
|
||||
#include "actors/alarmtime.h"
|
||||
#include "microcontroller.h"
|
||||
#include "ui/mainwindow.h"
|
||||
#include "sensors/speakersensor.h"
|
||||
#include "sensors/sunsensor.h"
|
||||
#include "sensors/ocupancysensor.h"
|
||||
#include "alarmactions.h"
|
||||
#include "sensors/sensor.h"
|
||||
#include "items/itemstore.h"
|
||||
#include "items/auxitem.h"
|
||||
#include "items/rgbitem.h"
|
||||
#include "items/poweritem.h"
|
||||
#include "mainobject.h"
|
||||
|
||||
|
||||
@ -32,6 +26,8 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
|
||||
//pw_init(&argc, &argv);
|
||||
|
||||
//set info
|
||||
QCoreApplication::setOrganizationName("UVOS");
|
||||
QCoreApplication::setOrganizationDomain("uvos.xyz");
|
||||
@ -48,17 +44,22 @@ int main(int argc, char *argv[])
|
||||
parser.addVersionOption();
|
||||
QCommandLineOption tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
|
||||
parser.addOption(tcpOption);
|
||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "adress");
|
||||
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main",
|
||||
"Set server host ip addres"), "adress");
|
||||
parser.addOption(hostOption);
|
||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main", "Set server Port in TCP mode or Serial port in serial mode"), "port");
|
||||
QCommandLineOption portOption(QStringList() << "p" << "port", QCoreApplication::translate("main",
|
||||
"Set server Port in TCP mode or Serial port in serial mode"), "port");
|
||||
parser.addOption(portOption);
|
||||
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main", "Use serial connection"));
|
||||
QCommandLineOption serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main",
|
||||
"Use serial connection"));
|
||||
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");
|
||||
QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main",
|
||||
"Set config file"), "configFilePath");
|
||||
parser.addOption(settingsPathOption);
|
||||
QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main", "Set if instance is not main instance"));
|
||||
QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main",
|
||||
"Set if instance is not main instance"));
|
||||
parser.addOption(secondaryOption);
|
||||
parser.process(a);
|
||||
#endif
|
||||
@ -94,11 +95,13 @@ int main(int argc, char *argv[])
|
||||
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
|
||||
else microPort->setBaudRate(BAUD);
|
||||
|
||||
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
|
||||
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));
|
||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "",
|
||||
!parser.isSet(secondaryOption));
|
||||
|
||||
#else
|
||||
QTcpSocket* microSocket = new QTcpSocket;
|
||||
@ -110,7 +113,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
masterIODevice = microSocket;
|
||||
|
||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
|
||||
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "",
|
||||
!parser.isSet(secondaryOption));
|
||||
#endif
|
||||
|
||||
|
||||
@ -120,7 +124,8 @@ int main(int argc, char *argv[])
|
||||
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
|
||||
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!");
|
||||
if(!mainObject.micro.connected())
|
||||
w.changeHeaderLableText("No io debug only!");
|
||||
|
||||
w.show();
|
||||
|
||||
|
@ -23,6 +23,7 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
||||
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
|
||||
|
||||
sunSensorSource.run();
|
||||
//pwHandler.startLoop();
|
||||
|
||||
//connect item store
|
||||
QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
|
||||
@ -35,14 +36,17 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
|
||||
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)
|
||||
connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
|
||||
|
||||
if(master) load(getJsonObjectFromDisk(settingsPath, &noSave));
|
||||
if(master)
|
||||
{
|
||||
load(getJsonObjectFromDisk(settingsPath, &noSave));
|
||||
}
|
||||
else
|
||||
{
|
||||
broadCast.requestJson();
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "items/poweritem.h"
|
||||
#include "iomuliplexer.h"
|
||||
#include "broadcast.h"
|
||||
//#include "pipewire.h"
|
||||
|
||||
class MainObject : public QObject
|
||||
{
|
||||
@ -49,6 +50,7 @@ public:
|
||||
Microcontroller micro;
|
||||
BroadCast broadCast;
|
||||
|
||||
|
||||
const QString settingsPath;
|
||||
|
||||
//sensors
|
||||
@ -62,6 +64,8 @@ public:
|
||||
std::shared_ptr<RgbItem> rgbItem;
|
||||
std::shared_ptr<AuxItem> auxItem;
|
||||
|
||||
//PipeWireHandler pwHandler;
|
||||
|
||||
private:
|
||||
|
||||
static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
|
||||
|
@ -130,7 +130,8 @@ std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
|
||||
for(int i = 10; i < bufferList.size(); i++) name.append(bufferList[i] + ' ');
|
||||
if(name.size() > 1)name.remove(name.size()-1, 1);
|
||||
else name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2));
|
||||
return std::shared_ptr<Relay>( new Relay(bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), bufferList[8].toInt()));
|
||||
return std::shared_ptr<Relay>( new Relay(bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2),
|
||||
bufferList[8].toInt()));
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
72
src/pipewire.cpp
Normal file
72
src/pipewire.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
#include "pipewire.h"
|
||||
#include <stdexcept>
|
||||
#include <QDebug>
|
||||
|
||||
static const struct pw_registry_events registry_events = {
|
||||
.version = PW_VERSION_REGISTRY_EVENTS,
|
||||
.global = &PipeWireHandler::registryEventHandler,
|
||||
.global_remove = nullptr
|
||||
};
|
||||
|
||||
PipeWireHandler::PipeWireHandler()
|
||||
{
|
||||
loop = pw_thread_loop_new("SHinterface", nullptr);
|
||||
if(!loop)
|
||||
throw std::runtime_error("Could not create pipewire main loop");
|
||||
|
||||
context = pw_context_new(pw_thread_loop_get_loop(loop), nullptr, 0);
|
||||
if(!context)
|
||||
throw std::runtime_error("Could not create pipewire context");
|
||||
|
||||
core = pw_context_connect(context, NULL, 0);
|
||||
if(!core)
|
||||
throw std::runtime_error("Could not connect to pipewire");
|
||||
|
||||
registry = pw_core_get_registry(core, PW_VERSION_REGISTRY, 0);
|
||||
if(!registry)
|
||||
throw std::runtime_error("Could not get pipewire registry");
|
||||
|
||||
spa_zero(registryListener);
|
||||
pw_registry_add_listener(registry, ®istryListener, ®istry_events, this);
|
||||
}
|
||||
|
||||
bool PipeWireHandler::startLoop()
|
||||
{
|
||||
if(!loop || !context || !core || !registry)
|
||||
return false;
|
||||
int ret = pw_thread_loop_start(loop);
|
||||
return ret == 0;
|
||||
}
|
||||
|
||||
struct pw_registry* PipeWireHandler::getRegistry()
|
||||
{
|
||||
return registry;
|
||||
}
|
||||
|
||||
void PipeWireHandler::registryEventHandler(void *data, uint32_t id,
|
||||
uint32_t permissions, const char *type, uint32_t version,
|
||||
const struct spa_dict *props)
|
||||
{
|
||||
(void)permissions;
|
||||
(void)version;
|
||||
|
||||
PipeWireHandler* handler = static_cast<PipeWireHandler*>(data);
|
||||
|
||||
if(std::string(type) == PW_TYPE_INTERFACE_Node)
|
||||
{
|
||||
const struct spa_dict_item *item = spa_dict_lookup_item(props, "node.name");
|
||||
if(item)
|
||||
{
|
||||
qDebug()<<"got new pipewire node:"<<id<<"name:"<<item->value;
|
||||
handler->nodeAdded({id, item->value});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PipeWireHandler::~PipeWireHandler()
|
||||
{
|
||||
pw_core_disconnect(core);
|
||||
pw_context_destroy(context);
|
||||
pw_thread_loop_stop(loop);
|
||||
}
|
||||
|
56
src/pipewire.h
Normal file
56
src/pipewire.h
Normal file
@ -0,0 +1,56 @@
|
||||
#pragma once
|
||||
|
||||
#include <pipewire/context.h>
|
||||
#include <pipewire/core.h>
|
||||
#include <pipewire/pipewire.h>
|
||||
#include <QObject>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
class PipeWireHandler: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
struct PwNode
|
||||
{
|
||||
uint32_t id;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
struct pw_thread_loop* loop;
|
||||
struct pw_context* context;
|
||||
struct pw_core* core;
|
||||
struct pw_registry* registry;
|
||||
struct spa_hook registryListener;
|
||||
|
||||
void write(const char * const buffer, const size_t length);
|
||||
void write(const QByteArray& buffer);
|
||||
|
||||
void decode(QByteArray buffer);
|
||||
void decodeMaster(const QByteArray& buffer);
|
||||
|
||||
public:
|
||||
|
||||
static void registryEventHandler(void *data, uint32_t id,
|
||||
uint32_t permissions, const char *type, uint32_t version,
|
||||
const struct spa_dict *props);
|
||||
|
||||
signals:
|
||||
|
||||
void nodeAdded(PwNode node);
|
||||
void nodeRemoved(PwNode node);
|
||||
|
||||
public:
|
||||
|
||||
PipeWireHandler();
|
||||
PipeWireHandler(const PipeWireHandler&) = delete;
|
||||
PipeWireHandler operator=(const PipeWireHandler&) = delete;
|
||||
bool startLoop();
|
||||
struct pw_registry* getRegistry();
|
||||
|
||||
~PipeWireHandler();
|
||||
};
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include "../apgetconnected.h"
|
||||
|
||||
|
||||
OcupancySensorSource::OcupancySensorSource(QObject *parent, const QString& device, const QString& deviceMac): QObject (parent), deviceMac_(deviceMac), device_(device)
|
||||
OcupancySensorSource::OcupancySensorSource(QObject *parent, const QString& device,
|
||||
const QString& deviceMac): QObject (parent), deviceMac_(deviceMac), device_(device)
|
||||
{
|
||||
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
|
||||
}
|
||||
|
@ -15,7 +15,8 @@ private:
|
||||
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");
|
||||
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);
|
||||
|
74
src/sensors/pipewiresensor.cpp
Normal file
74
src/sensors/pipewiresensor.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
40
src/sensors/pipewiresensor.h
Normal file
40
src/sensors/pipewiresensor.h
Normal file
@ -0,0 +1,40 @@
|
||||
#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
|
@ -30,33 +30,52 @@ public:
|
||||
QDateTime lastSeen;
|
||||
bool hidden;
|
||||
|
||||
Sensor(uint8_t typeIn, uint8_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false): type(typeIn), id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
||||
Sensor(uint8_t typeIn, uint8_t idIn, float fieldIn = 0, QString nameIn = "", bool hiddenIn = false): type(typeIn),
|
||||
id(idIn), field(fieldIn), name(nameIn), hidden(hiddenIn)
|
||||
{
|
||||
lastSeen = QDateTime::currentDateTime();
|
||||
if(nameIn == "") generateName();
|
||||
if(nameIn == "")
|
||||
generateName();
|
||||
}
|
||||
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false)
|
||||
{
|
||||
lastSeen = QDateTime::currentDateTime();
|
||||
}
|
||||
inline bool operator==(const Sensor& in) const{ return type==in.type && id == in.id; }
|
||||
inline bool operator!=(const Sensor& in) const{ return !(*this==in); }
|
||||
inline void updateSeen(){lastSeen = QDateTime::currentDateTime();}
|
||||
inline bool operator==(const Sensor& in) const
|
||||
{
|
||||
return type==in.type && id == in.id;
|
||||
}
|
||||
inline bool operator!=(const Sensor& in) const
|
||||
{
|
||||
return !(*this==in);
|
||||
}
|
||||
inline void updateSeen()
|
||||
{
|
||||
lastSeen = QDateTime::currentDateTime();
|
||||
}
|
||||
static Sensor sensorFromString(const QString& str)
|
||||
{
|
||||
QStringList bufferList = str.split(' ');
|
||||
if(bufferList.size() >= 7)
|
||||
{
|
||||
Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt());
|
||||
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE) sensor.field = sensor.field/10;
|
||||
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE)
|
||||
sensor.field = sensor.field/10;
|
||||
|
||||
if(bufferList.size() >= 9)
|
||||
sensor.lastSeen = QDateTime::fromSecsSinceEpoch(bufferList[8].toLongLong());
|
||||
return sensor;
|
||||
}
|
||||
else return Sensor(TYPE_DUMMY, 0, 0, "", true);
|
||||
else
|
||||
{
|
||||
return Sensor(TYPE_DUMMY, 0, 0, "", true);
|
||||
}
|
||||
}
|
||||
QString toString()
|
||||
{
|
||||
return QString("SENSOR TYPE: ")+QString::number(type)+" ID: "+QString::number(id)+" FIELD: "+
|
||||
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());
|
||||
}
|
||||
inline void generateName()
|
||||
{
|
||||
@ -82,7 +101,10 @@ public:
|
||||
SensorStore(QObject *parent = nullptr);
|
||||
virtual ~SensorStore() {}
|
||||
|
||||
inline std::vector<Sensor>* getSensors(){ return &sensors_; }
|
||||
inline std::vector<Sensor>* getSensors()
|
||||
{
|
||||
return &sensors_;
|
||||
}
|
||||
|
||||
|
||||
public slots:
|
||||
|
@ -15,7 +15,7 @@ SpeakerSensorSource::~SpeakerSensorSource()
|
||||
void SpeakerSensorSource::run()
|
||||
{
|
||||
abort();
|
||||
arecord.start( "arecord --disable-softvol -r 8000 -D front -" );
|
||||
arecord.start( "arecord", {"--disable-softvol", "-r", "8000", "-D", "front", "-"});
|
||||
|
||||
connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
|
||||
timer.setInterval(500);
|
||||
|
24
src/sun.cpp
24
src/sun.cpp
@ -63,7 +63,8 @@ std::time_t Sun::JdTime::toStdTime()
|
||||
return millenniumTime;
|
||||
}
|
||||
|
||||
Sun::Sun(double latitude, double longitude, double altitude): latitude_(latitude), longetude_(longitude), altitude_(altitude)
|
||||
Sun::Sun(double latitude, double longitude, double altitude): latitude_(latitude), longetude_(longitude),
|
||||
altitude_(altitude)
|
||||
{}
|
||||
|
||||
double Sun::nextMeanSolarNoonJD(const JdTime& time)
|
||||
@ -78,7 +79,8 @@ double Sun::meanSolarAnomaly(double meanSolarNoon)
|
||||
|
||||
double Sun::eqOfCenter(double meanSolarAnomaly)
|
||||
{
|
||||
return 1.9148*sin(meanSolarAnomaly*TO_RADS) + 0.0200*sin(2*meanSolarAnomaly*TO_RADS) + 0.0003*sin(3*meanSolarAnomaly*TO_RADS);
|
||||
return 1.9148*sin(meanSolarAnomaly*TO_RADS) + 0.0200*sin(2*meanSolarAnomaly*TO_RADS) + 0.0003*sin(
|
||||
3*meanSolarAnomaly*TO_RADS);
|
||||
}
|
||||
|
||||
double Sun::eclipticLongitude(double eqOfCenter, double meanSolarAnomaly)
|
||||
@ -108,7 +110,8 @@ double Sun::hourAngle(double localSolarTime)
|
||||
|
||||
double Sun::hourAngleAtSunset(double solarDeclination)
|
||||
{
|
||||
return TO_DEGS*acos((sin((-0.83-(2.076*sqrt(altitude_)/60.0))*TO_RADS) - sin(solarDeclination*TO_RADS)*sin(latitude_*TO_RADS))/(cos(latitude_*TO_RADS)*cos(solarDeclination*TO_RADS)));
|
||||
return TO_DEGS*acos((sin((-0.83-(2.076*sqrt(altitude_)/60.0))*TO_RADS) - sin(solarDeclination*TO_RADS)*sin(
|
||||
latitude_*TO_RADS))/(cos(latitude_*TO_RADS)*cos(solarDeclination*TO_RADS)));
|
||||
}
|
||||
|
||||
double Sun::altitude()
|
||||
@ -120,7 +123,8 @@ double Sun::altitude()
|
||||
double localSolarTimeValue = localSolarTime(time, equationOfTime(meanSolarAnomalyValue, eclipticLongitudeValue));
|
||||
double declinationValue = solarDeclination(eclipticLongitudeValue);
|
||||
|
||||
double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos(declinationValue*TO_RADS)*cos(hourAngle(localSolarTimeValue)*TO_RADS);
|
||||
double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos(
|
||||
declinationValue*TO_RADS)*cos(hourAngle(localSolarTimeValue)*TO_RADS);
|
||||
|
||||
return TO_DEGS*asin(cosZenithAngle);
|
||||
}
|
||||
@ -133,7 +137,8 @@ double Sun::maximumAltitude()
|
||||
double eclipticLongitudeValue = eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue);
|
||||
double declinationValue = solarDeclination(eclipticLongitudeValue);
|
||||
|
||||
double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos(declinationValue*TO_RADS);
|
||||
double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos(
|
||||
declinationValue*TO_RADS);
|
||||
|
||||
return TO_DEGS*asin(cosZenithAngle);
|
||||
}
|
||||
@ -143,7 +148,6 @@ double Sun::azimuth()
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::time_t Sun::riseTime()
|
||||
{
|
||||
JdTime time;
|
||||
@ -153,10 +157,12 @@ std::time_t Sun::riseTime()
|
||||
double declinationValue = solarDeclination(eclipticLongitudeValue);
|
||||
double hourAngleValue = hourAngleAtSunset(declinationValue);
|
||||
|
||||
time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue, eclipticLongitudeValue) - hourAngleValue/360.0;
|
||||
time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue,
|
||||
eclipticLongitudeValue) - hourAngleValue/360.0;
|
||||
|
||||
return time.toStdTime();
|
||||
}
|
||||
|
||||
std::time_t Sun::setTime()
|
||||
{
|
||||
JdTime time;
|
||||
@ -166,12 +172,12 @@ std::time_t Sun::setTime()
|
||||
double declinationValue = solarDeclination(eclipticLongitudeValue);
|
||||
double hourAngleValue = hourAngleAtSunset(declinationValue);
|
||||
|
||||
time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue, eclipticLongitudeValue) + hourAngleValue/360.0;
|
||||
time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue,
|
||||
eclipticLongitudeValue) + hourAngleValue/360.0;
|
||||
|
||||
return time.toStdTime();
|
||||
}
|
||||
|
||||
|
||||
double Sun::declination()
|
||||
{
|
||||
JdTime time;
|
||||
|
@ -10,7 +10,8 @@
|
||||
#include "actorwidgets/polynomalactorwidget.h"
|
||||
#include "actorwidgets/factoractorwidget.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class ActorSettingsDialog;
|
||||
}
|
||||
|
||||
|
@ -7,11 +7,6 @@ AlarmWidget::AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent) :
|
||||
ui(new Ui::AlarmWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->checkBox, &QCheckBox::stateChanged, this, &AlarmWidget::toggleRepeating);
|
||||
connect(ui->radioButton, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
connect(ui->radioButton_2, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
connect(ui->radioButton_3, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
connect(ui->radioButton_4, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
|
||||
ui->dateTimeEdit->setDateTime(alarm->getDateTime());
|
||||
|
||||
@ -31,11 +26,20 @@ AlarmWidget::AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent) :
|
||||
ui->radioButton_4->setEnabled(true);
|
||||
}
|
||||
|
||||
if(alarm_->getRepeat() == AlarmTime::REPEAT_DAILY) ui->radioButton->setChecked(true);
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_WEEKLY) ui->radioButton_2->setChecked(true);
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_MONTHLY)ui->radioButton_3->setChecked(true);
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_YEARLY) ui->radioButton_4->setChecked(true);
|
||||
if(alarm_->getRepeat() == AlarmTime::REPEAT_DAILY)
|
||||
ui->radioButton->setChecked(true);
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_WEEKLY)
|
||||
ui->radioButton_2->setChecked(true);
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_MONTHLY)
|
||||
ui->radioButton_3->setChecked(true);
|
||||
else if(alarm_->getRepeat() == AlarmTime::REPEAT_YEARLY)
|
||||
ui->radioButton_4->setChecked(true);
|
||||
|
||||
connect(ui->checkBox, &QCheckBox::stateChanged, this, &AlarmWidget::toggleRepeating);
|
||||
connect(ui->radioButton, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
connect(ui->radioButton_2, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
connect(ui->radioButton_3, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
connect(ui->radioButton_4, &QRadioButton::clicked, this, &AlarmWidget::setRepeatingType);
|
||||
connect(ui->dateTimeEdit, &QDateTimeEdit::dateTimeChanged, alarm.get(), &AlarmTime::changeTime);
|
||||
}
|
||||
|
||||
@ -46,10 +50,14 @@ AlarmWidget::~AlarmWidget()
|
||||
|
||||
void AlarmWidget::setRepeatingType()
|
||||
{
|
||||
if(ui->radioButton->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_DAILY);
|
||||
if(ui->radioButton_2->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_WEEKLY);
|
||||
if(ui->radioButton_3->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_MONTHLY);
|
||||
if(ui->radioButton_4->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_YEARLY);
|
||||
if(ui->radioButton->isChecked())
|
||||
alarm_->setRepeat(AlarmTime::REPEAT_DAILY);
|
||||
if(ui->radioButton_2->isChecked())
|
||||
alarm_->setRepeat(AlarmTime::REPEAT_WEEKLY);
|
||||
if(ui->radioButton_3->isChecked())
|
||||
alarm_->setRepeat(AlarmTime::REPEAT_MONTHLY);
|
||||
if(ui->radioButton_4->isChecked())
|
||||
alarm_->setRepeat(AlarmTime::REPEAT_YEARLY);
|
||||
}
|
||||
|
||||
void AlarmWidget::toggleRepeating(int state)
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include <memory>
|
||||
#include "../../actors/alarmtime.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class AlarmWidget;
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <QWidget>
|
||||
#include "../../actors/factoractor.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class FactorActorWidget;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include "polynomalactorwidget.h"
|
||||
#include "ui_polynomalactorwidget.h"
|
||||
|
||||
PolynomalActorWidget::PolynomalActorWidget(std::shared_ptr<PolynomalActor> actor, SensorStore* sensors, QWidget *parent):
|
||||
PolynomalActorWidget::PolynomalActorWidget(std::shared_ptr<PolynomalActor> actor, SensorStore* sensors,
|
||||
QWidget *parent):
|
||||
QWidget(parent),
|
||||
sensors_(sensors),
|
||||
actor_(actor),
|
||||
@ -39,7 +40,8 @@ PolynomalActorWidget::~PolynomalActorWidget()
|
||||
|
||||
void PolynomalActorWidget::setPow()
|
||||
{
|
||||
actor_->setCoeffiancts(ui->doubleSpinBox_pow3->value(), ui->doubleSpinBox_pow2->value(), ui->doubleSpinBox_pow1->value(), ui->doubleSpinBox_pow0->value());
|
||||
actor_->setCoeffiancts(ui->doubleSpinBox_pow3->value(), ui->doubleSpinBox_pow2->value(),
|
||||
ui->doubleSpinBox_pow1->value(), ui->doubleSpinBox_pow0->value());
|
||||
}
|
||||
|
||||
void PolynomalActorWidget::setSensor(const QModelIndex &index)
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <QWidget>
|
||||
#include "../../actors/polynomalactor.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class PolynomalActorWidget;
|
||||
}
|
||||
|
||||
@ -15,7 +16,8 @@ class PolynomalActorWidget : public QWidget
|
||||
std::shared_ptr<PolynomalActor> actor_;
|
||||
|
||||
public:
|
||||
explicit PolynomalActorWidget(std::shared_ptr<PolynomalActor> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
explicit PolynomalActorWidget(std::shared_ptr<PolynomalActor> regulator, SensorStore* sensors = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
~PolynomalActorWidget();
|
||||
|
||||
private slots:
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <QWidget>
|
||||
#include "../../actors/regulator.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class RegulatorWdiget;
|
||||
}
|
||||
|
||||
@ -16,7 +17,8 @@ class RegulatorWdiget : public QWidget
|
||||
SensorStore* sensors_;
|
||||
|
||||
public:
|
||||
explicit RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
explicit RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
~RegulatorWdiget();
|
||||
|
||||
private slots:
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include <QItemSelection>
|
||||
#include "../../actors/sensoractor.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class SensorActorWidget;
|
||||
}
|
||||
|
||||
@ -17,7 +18,8 @@ class SensorActorWidget : public QWidget
|
||||
SensorStore* sensors_;
|
||||
|
||||
public:
|
||||
explicit SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
|
||||
explicit SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors = nullptr,
|
||||
QWidget *parent = nullptr);
|
||||
~SensorActorWidget();
|
||||
|
||||
private slots:
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <QWidget>
|
||||
#include "../../actors/timeractor.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class TimerActorWidget;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include <memory>
|
||||
#include "../items/item.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class ItemCreationDialog;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
#include "../items/itemstore.h"
|
||||
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class RelayScrollBox;
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ void ItemSettingsDialog::addActor()
|
||||
|
||||
void ItemSettingsDialog::removeActor()
|
||||
{
|
||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow()))
|
||||
{
|
||||
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
|
||||
loadActorList();
|
||||
@ -153,7 +153,7 @@ void ItemSettingsDialog::removeActor()
|
||||
|
||||
void ItemSettingsDialog::editActor()
|
||||
{
|
||||
if(item_->getActors().size() > ui->tableWidget->currentRow())
|
||||
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow()))
|
||||
{
|
||||
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
|
||||
|
||||
@ -177,7 +177,7 @@ void ItemSettingsDialog::editActor()
|
||||
dialog->show();
|
||||
dialog->exec();
|
||||
|
||||
for(int i = 0; i < ui->tableWidget->rowCount() && i < item_->getActors().size(); ++i)
|
||||
for(int i = 0; i < ui->tableWidget->rowCount() && i < static_cast<size_t>(item_->getActors().size()); ++i)
|
||||
{
|
||||
ui->tableWidget->item(i, 0)->setText(item_->getActors()[i]->getName());
|
||||
ui->tableWidget->item(i, 1)->setText(item_->getActors()[i]->actionName());
|
||||
|
@ -6,7 +6,8 @@
|
||||
#include <memory>
|
||||
#include "../items/relay.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class ItemSettingsDialog;
|
||||
}
|
||||
|
||||
|
@ -115,7 +115,7 @@
|
||||
<number>3</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="horizontalHeaderMinimumSectionSize">
|
||||
<number>32</number>
|
||||
|
48
src/ui/itemsettingswidgets/messageitemsettingswidget.cpp
Normal file
48
src/ui/itemsettingswidgets/messageitemsettingswidget.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "messageitemsettingswidget.h"
|
||||
#include "ui_messageitemsettingswidget.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QDebug>
|
||||
|
||||
MessageItemSettingsWidget::MessageItemSettingsWidget(std::weak_ptr<MessageItem> item, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
item_(item),
|
||||
ui(new Ui::MessageItemSettingsWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
qDebug()<<"test";
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
ui->lineEdit->setText(workingItem->getMessage());
|
||||
ui->lineEdit_alert->setText(workingItem->getAlert());
|
||||
}
|
||||
|
||||
connect(ui->lineEdit, &QLineEdit::textChanged, this, &MessageItemSettingsWidget::setText);
|
||||
connect(ui->lineEdit_alert, &QLineEdit::textChanged, this, &MessageItemSettingsWidget::setAlert);
|
||||
connect(ui->pushButton, &QPushButton::pressed, [this]()
|
||||
{
|
||||
ui->lineEdit_alert->setText(QFileDialog::getOpenFileName(this, "Choose File"));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void MessageItemSettingsWidget::setText(const QString& text)
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
workingItem->setMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
void MessageItemSettingsWidget::setAlert(const QString &in)
|
||||
{
|
||||
if(auto workingItem = item_.lock())
|
||||
{
|
||||
workingItem->setAlert(in);
|
||||
}
|
||||
}
|
||||
|
||||
MessageItemSettingsWidget::~MessageItemSettingsWidget()
|
||||
{
|
||||
delete ui;
|
||||
}
|
31
src/ui/itemsettingswidgets/messageitemsettingswidget.h
Normal file
31
src/ui/itemsettingswidgets/messageitemsettingswidget.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MESSAGEITEMSETTINGSWIDGET_H
|
||||
#define MESSAGEITEMSETTINGSWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <memory>
|
||||
#include "../../items/messageitem.h"
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class MessageItemSettingsWidget;
|
||||
}
|
||||
|
||||
class MessageItemSettingsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
std::weak_ptr<MessageItem> item_;
|
||||
|
||||
private slots:
|
||||
|
||||
void setText(const QString& text);
|
||||
void setAlert(const QString &in);
|
||||
|
||||
public:
|
||||
explicit MessageItemSettingsWidget(std::weak_ptr<MessageItem> item, QWidget *parent = nullptr);
|
||||
~MessageItemSettingsWidget();
|
||||
|
||||
private:
|
||||
Ui::MessageItemSettingsWidget *ui;
|
||||
};
|
||||
|
||||
#endif // MESSAGEITEMSETTINGSWIDGET_H
|
59
src/ui/itemsettingswidgets/messageitemsettingswidget.ui
Normal file
59
src/ui/itemsettingswidgets/messageitemsettingswidget.ui
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MessageItemSettingsWidget</class>
|
||||
<widget class="QWidget" name="MessageItemSettingsWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>124</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Text:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Alert:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_alert"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Browse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -5,7 +5,8 @@
|
||||
#include <memory>
|
||||
#include "../../items/relay.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class RelayItemSettingsWidget;
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,8 @@
|
||||
#include <memory>
|
||||
#include "../../items/systemitem.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class SystemItemSettingsWidget;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,8 @@
|
||||
#include "itemsettingsdialog.h"
|
||||
#include "../items/item.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Ui
|
||||
{
|
||||
class ItemWidget;
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "itemsettingsdialog.h"
|
||||
#include "itemcreationdialog.h"
|
||||
#include "../mainobject.h"
|
||||
#include <QMessageBox>
|
||||
|
||||
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
@ -15,9 +16,14 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||
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::saved);
|
||||
}
|
||||
|
||||
connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
|
||||
|
||||
@ -42,12 +48,14 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
|
||||
connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
|
||||
|
||||
//RGB Leds
|
||||
connect(&colorChooser, SIGNAL(colorSelected(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
|
||||
connect(&colorChooser, SIGNAL(colorSelected(QColor)), this, SLOT(slotChangedRgb(QColor)));
|
||||
connect(ui->button_quit, SIGNAL(clicked()), this, SLOT(close()));
|
||||
connect(ui->button_color, SIGNAL(clicked()), &colorChooser, SLOT(show()));
|
||||
|
||||
connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
|
||||
connect(ui->relayList, &ItemScrollBox::deleteRequest, &mainObject->items, &ItemStore::removeItem);
|
||||
|
||||
ui->splitter->setStretchFactor(1, 1);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
@ -62,6 +70,11 @@ void MainWindow::showPowerItemDialog()
|
||||
diag.exec();
|
||||
}
|
||||
|
||||
void MainWindow::saved()
|
||||
{
|
||||
QMessageBox::information(this, "Saved", "Settings where saved");
|
||||
}
|
||||
|
||||
void MainWindow::slotChangedRgb(const QColor color)
|
||||
{
|
||||
_micro->changeRgbColor(color);
|
||||
|
@ -50,6 +50,7 @@ private slots:
|
||||
void slotChangedRgb(const QColor color);
|
||||
void showPowerItemDialog();
|
||||
void showItemCreationDialog();
|
||||
void saved();
|
||||
|
||||
public slots:
|
||||
|
||||
|
@ -42,8 +42,16 @@
|
||||
<property name="autoFillBackground">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0,1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<item>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="childrenCollapsible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_serialRecive">
|
||||
@ -78,6 +86,18 @@
|
||||
</property>
|
||||
<item>
|
||||
<widget class="SensorListWidget" name="sensorListView">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
@ -135,8 +155,8 @@
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
</widget>
|
||||
<widget class="QWidget" name="">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,0">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
@ -214,6 +234,8 @@
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -4,19 +4,21 @@
|
||||
#include <QHeaderView>
|
||||
#include <QScroller>
|
||||
|
||||
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent), showHidden_(showHidden)
|
||||
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent),
|
||||
showHidden_(showHidden)
|
||||
{
|
||||
setColumnCount(2);
|
||||
setColumnCount(3);
|
||||
setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
|
||||
QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture);
|
||||
setAutoScroll(true);
|
||||
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
|
||||
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
||||
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||
sensorsChanged(std::vector<Sensor>());
|
||||
verticalHeader()->hide();
|
||||
}
|
||||
|
||||
SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden, QWidget* parent): QTableWidget (parent), showHidden_(showHidden)
|
||||
SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden,
|
||||
QWidget* parent): QTableWidget (parent), showHidden_(showHidden)
|
||||
{
|
||||
sensorsChanged(*(sensorStore.getSensors()));
|
||||
}
|
||||
@ -26,17 +28,11 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
|
||||
clear();
|
||||
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
|
||||
setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
|
||||
size_t nonHiddenCount = sensors.size();
|
||||
if(!showHidden_)
|
||||
{
|
||||
nonHiddenCount = 0;
|
||||
for(size_t i = 0; i < sensors.size(); ++i)
|
||||
{
|
||||
if(!sensors[i].hidden) nonHiddenCount++;
|
||||
}
|
||||
}
|
||||
setHorizontalHeaderItem(2, new QTableWidgetItem("Time"));
|
||||
size_t listLen = 0;
|
||||
for(size_t i = 0; i < sensors.size(); ++i) if(showHidden_ || !sensors[i].hidden) ++listLen;
|
||||
for(size_t i = 0; i < sensors.size(); ++i)
|
||||
if(showHidden_ || !sensors[i].hidden)
|
||||
++listLen;
|
||||
setRowCount(static_cast<int>(listLen));
|
||||
size_t row = 0;
|
||||
for(size_t i = 0; i < sensors.size(); ++i)
|
||||
@ -49,20 +45,26 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
|
||||
|
||||
if(sensors[i].type == Sensor::TYPE_DOOR)
|
||||
{
|
||||
if(static_cast<bool>(sensors[i].field)) itemString.append("\"Open\"");
|
||||
if(static_cast<bool>(sensors[i].field))
|
||||
itemString.append("\"Open\"");
|
||||
else itemString.append("\"Closed\"");
|
||||
}
|
||||
else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT)
|
||||
{
|
||||
if(static_cast<bool>(sensors[i].field)) itemString.append("\"Playing\"");
|
||||
if(static_cast<bool>(sensors[i].field))
|
||||
itemString.append("\"Playing\"");
|
||||
else itemString.append("\"Silent\"");
|
||||
}
|
||||
|
||||
setItem(static_cast<int>(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? " (H)" : "")));
|
||||
setItem(static_cast<int>(row), 1, new QTableWidgetItem(itemString));
|
||||
if(sensors[i].type <= 128)
|
||||
setItem(static_cast<int>(row), 2, new QTableWidgetItem(sensors[i].lastSeen.time().toString("hh:mm")));
|
||||
++row;
|
||||
}
|
||||
}
|
||||
sortItems(0, Qt::AscendingOrder);
|
||||
resizeColumnsToContents();
|
||||
}
|
||||
|
||||
void SensorListWidget::setShowHidden(const bool showHidden)
|
||||
|
Reference in New Issue
Block a user