Compare commits

..

No commits in common. "master" and "954eec754c68e20213480a745ace23f99980e0fa" have entirely different histories.

96 changed files with 2718 additions and 3481 deletions

View file

@ -88,7 +88,7 @@ uint8_t Actor::getTriggerValue()
void Actor::onValueChanged(uint8_t value) void Actor::onValueChanged(uint8_t value)
{ {
(void)value;
} }
std::shared_ptr<Actor> Actor::createActor(const QString& type) std::shared_ptr<Actor> Actor::createActor(const QString& type)

View file

@ -61,7 +61,7 @@ QString AlarmTime::getName() const
void AlarmTime::setRepeat(const uint8_t repeat) void AlarmTime::setRepeat(const uint8_t repeat)
{ {
repeat_ = repeat; repeat_=repeat;
exausted = false; exausted = false;
} }

View file

@ -26,9 +26,8 @@ void MultiFactorActor::setValue(uint8_t value)
{ {
performAction(); performAction();
} }
exausted = true; bool exausted = true;
for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
exausted = false;
} }
} }

View file

@ -29,28 +29,13 @@ public:
virtual QString getName() const; virtual QString getName() const;
void setFactorActor(std::shared_ptr<Actor> factorActor); void setFactorActor(std::shared_ptr<Actor> factorActor);
std::shared_ptr<Actor> getFactorActor() std::shared_ptr<Actor> getFactorActor(){return factorActor_;}
{ void setFactorDirection(const bool direction){factorDirection = direction;}
return factorActor_; bool getFactorDirection(){return factorDirection;}
} uint getPreCancleTime(){return preCancleMin_;}
void setFactorDirection(const bool direction) void setPreCancleTime(uint minutes){preCancleMin_ = minutes;}
{
factorDirection = direction;
}
bool getFactorDirection()
{
return factorDirection;
}
uint getPreCancleTime()
{
return preCancleMin_;
}
void setPreCancleTime(uint minutes)
{
preCancleMin_ = minutes;
}
virtual ~MultiFactorActor() {} virtual ~MultiFactorActor(){}
virtual void store(QJsonObject& json); virtual void store(QJsonObject& json);
virtual void load(const QJsonObject& json, bool preserve); virtual void load(const QJsonObject& json, bool preserve);

View file

@ -35,8 +35,7 @@ void PolynomalActor::sensorEvent(Sensor sensor)
{ {
if(active && sensor == sensor_) if(active && sensor == sensor_)
{ {
double result = pow3_*(sensor.field*sensor.field*sensor.field)+pow2_*(sensor.field*sensor.field)+pow1_*sensor.field double result = pow3_*(sensor.field*sensor.field*sensor.field)+pow2_*(sensor.field*sensor.field)+pow1_*sensor.field+pow0_;
+pow0_;
if(result < 0) result = 0; if(result < 0) result = 0;
else if(result > 254) result = 255; else if(result > 254) result = 255;
if(result != prevValue)sigValue(static_cast<uint8_t>(result)); if(result != prevValue)sigValue(static_cast<uint8_t>(result));
@ -77,8 +76,7 @@ QString PolynomalActor::getName() const
else else
{ {
QString string; QString string;
string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number( string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
return string; return string;
} }
} }

View file

@ -28,12 +28,9 @@ public:
PolynomalActor(const Sensor sensor, QObject* parent = nullptr); PolynomalActor(const Sensor sensor, QObject* parent = nullptr);
PolynomalActor(QObject* parent = nullptr); PolynomalActor(QObject* parent = nullptr);
void setSensor(const Sensor sensor); void setSensor(const Sensor sensor);
Sensor getSensor() Sensor getSensor(){return sensor_;}
{
return sensor_;
}
virtual QString getName() const; virtual QString getName() const;
virtual ~PolynomalActor() {} virtual ~PolynomalActor(){}
virtual void store(QJsonObject& json); virtual void store(QJsonObject& json);
virtual void load(const QJsonObject& json, bool preserve); virtual void load(const QJsonObject& json, bool preserve);

View file

@ -4,16 +4,12 @@
Regulator::Regulator(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor) Regulator::Regulator(const Sensor sensor, QObject* parent): Actor(parent), sensor_(sensor)
{ {
timer.setSingleShot(true);
timer.start(timeout_*1000);
connect(&timer, &QTimer::timeout, this, &Regulator::timeout);
} }
Regulator::Regulator(QObject* parent): Actor(parent) Regulator::Regulator(QObject* parent): Actor(parent)
{ {
timer.setSingleShot(true);
timer.start(timeout_*1000);
connect(&timer, &QTimer::timeout, this, &Regulator::timeout);
} }
void Regulator::setSensor(const Sensor sensor) void Regulator::setSensor(const Sensor sensor)
@ -25,7 +21,6 @@ void Regulator::sensorEvent(Sensor sensor)
{ {
if(active && sensor == sensor_) if(active && sensor == sensor_)
{ {
timer.start(timeout_*1000);
if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) ) if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
{ {
sigValue(triggerValue); sigValue(triggerValue);
@ -39,20 +34,6 @@ void Regulator::sensorEvent(Sensor sensor)
} }
} }
void Regulator::makeInactive()
{
first = true;
if(active)
sigValue(!triggerValue);
timer.stop();
Actor::makeInactive();
}
void Regulator::timeout()
{
sigValue(safeValue_);
}
void Regulator::setPoint(float setPoint) void Regulator::setPoint(float setPoint)
{ {
setPoint_ = setPoint; setPoint_ = setPoint;
@ -68,25 +49,12 @@ void Regulator::setInvert( bool invert )
invert_ = invert; invert_ = invert;
} }
void Regulator::setSafeValue(int value)
{
safeValue_ = value;
}
void Regulator::setTimeout(int value)
{
timeout_ = value;
timer.start(timeout_*1000);
}
void Regulator::store(QJsonObject& json) void Regulator::store(QJsonObject& json)
{ {
json["Type"] = "Regulator"; json["Type"] = "Regulator";
Actor::store(json); Actor::store(json);
json["Band"] = band_; json["Band"] = band_;
json["SetPoint"] = setPoint_; json["SetPoint"] = setPoint_;
json["SafeValue"] = safeValue_;
json["Timeout"] = timeout_;
json["SensorType"] = static_cast<int>(sensor_.type); json["SensorType"] = static_cast<int>(sensor_.type);
json["SensorId"] = static_cast<int>(sensor_.id); json["SensorId"] = static_cast<int>(sensor_.id);
json["SensorField"] = sensor_.field; json["SensorField"] = sensor_.field;
@ -98,21 +66,15 @@ void Regulator::load(const QJsonObject& json, bool preserve)
Actor::load(json, preserve); Actor::load(json, preserve);
band_ = json["Band"].toDouble(1); band_ = json["Band"].toDouble(1);
setPoint_ = json["SetPoint"].toDouble(22); setPoint_ = json["SetPoint"].toDouble(22);
safeValue_ = json["SafeValue"].toDouble(0);
timeout_ = json["Timeout"].toDouble(1800);
sensor_.type = json["SensorType"].toInt(0); sensor_.type = json["SensorType"].toInt(0);
sensor_.id = json["SensorId"].toInt(0); sensor_.id = json["SensorId"].toInt(0);
sensor_.field = json["SensorField"].toInt(0); sensor_.field = json["SensorField"].toInt(0);
sensor_.name = json["SensorName"].toString("Sensor"); sensor_.name = json["SensorName"].toString("Sensor");
timer.start(timeout_*1000);
} }
QString Regulator::getName() const QString Regulator::getName() const
{ {
if(name_.size() > 0) if(name_.size() > 0) return name_;
{
return name_;
}
else else
{ {
QString string; QString string;

View file

@ -1,7 +1,4 @@
#pragma once #pragma once
#include <QTimer>
#include "actor.h" #include "actor.h"
#include "../sensors/sensor.h" #include "../sensors/sensor.h"
@ -14,54 +11,27 @@ private:
float setPoint_ = 0; float setPoint_ = 0;
float band_ = 1; float band_ = 1;
bool invert_ = false; bool invert_ = false;
int timeout_ = 1800;
int safeValue_ = 0;
QTimer timer;
bool first = true; bool first = true;
private slots:
void timeout();
public slots: public slots:
void sensorEvent(Sensor sensor); void sensorEvent(Sensor sensor);
void setSensor(const Sensor sensor); void setSensor(const Sensor sensor);
void setPoint(float setPoint ); void setPoint( float setPoint );
void setBand (float band ); void setBand ( float band );
void setInvert(bool invert ); void setInvert( bool invert );
void setSafeValue(int value);
void setTimeout(int value);
virtual void makeInactive() override;
public: public:
float getBand() float getBand() {return band_;}
{ float getSetPoint() {return setPoint_;}
return band_;
}
float getSetPoint()
{
return setPoint_;
}
int getSafeValue()
{
return safeValue_;
}
int getTimeout()
{
return timeout_;
}
Regulator(const Sensor sensor, QObject* parent = nullptr); Regulator(const Sensor sensor, QObject* parent = nullptr);
Regulator(QObject* parent = nullptr); Regulator(QObject* parent = nullptr);
Sensor getSensor() Sensor getSensor(){return sensor_;}
{
return sensor_;
}
virtual QString getName() const; virtual QString getName() const;
virtual ~Regulator() {} virtual ~Regulator(){}
virtual void store(QJsonObject& json); virtual void store(QJsonObject& json);
virtual void load(const QJsonObject& json, bool preserve); virtual void load(const QJsonObject& json, bool preserve);

View file

@ -21,10 +21,8 @@ void SensorActor::sensorEvent(Sensor sensor)
{ {
if(sensor == sensor_) if(sensor == sensor_)
{ {
if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_ if((sloap_ == SLOPE_UP || sloap_ == SLOPE_BOTH) && sensor_.field < threshold_ && sensor.field >= threshold_ ) performAction();
&& sensor.field >= threshold_ ) performAction(); else if((sloap_ == SLOPE_DOWN || 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; sensor_ = sensor;
} }
} }

View file

@ -28,12 +28,9 @@ public:
SensorActor(const Sensor sensor, QObject* parent = nullptr); SensorActor(const Sensor sensor, QObject* parent = nullptr);
SensorActor(QObject* parent = nullptr); SensorActor(QObject* parent = nullptr);
Sensor getSensor() Sensor getSensor(){return sensor_;}
{
return sensor_;
}
virtual QString getName() const; virtual QString getName() const;
virtual ~SensorActor() {} virtual ~SensorActor(){}
float getThreshold(); float getThreshold();
uint8_t getSloap(); uint8_t getSloap();

View file

@ -1,8 +1,7 @@
#include "alarmactions.h" #include "alarmactions.h"
#include <QProcess> #include <QProcess>
AlarmActions::AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent) : QObject(parent), _micro(micro), AlarmActions::AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent) : QObject(parent), _micro(micro), a_(a)
a_(a)
{ {
} }
@ -10,6 +9,6 @@ AlarmActions::AlarmActions(QApplication* a, Microcontroller* micro, QObject *par
void AlarmActions::syncoff() void AlarmActions::syncoff()
{ {
qDebug()<<"syncoff"; qDebug()<<"syncoff";
QProcess::execute ("syncoff", QStringList()); QProcess::execute ( "syncoff" );
a_->exit(0); a_->exit(0);
} }

View file

@ -53,8 +53,6 @@ static int nl80211Init(struct nl_sock* nl_sock, int* nl80211_id)
static int errorHandler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg) static int errorHandler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
{ {
(void)nla;
(void)err;
printf("netlink error\n"); printf("netlink error\n");
*reinterpret_cast<int*>(arg) = 0; *reinterpret_cast<int*>(arg) = 0;
return NL_STOP; return NL_STOP;
@ -62,14 +60,12 @@ static int errorHandler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg
static int finishHandler(struct nl_msg *msg, void *arg) static int finishHandler(struct nl_msg *msg, void *arg)
{ {
(void)msg;
*reinterpret_cast<int*>(arg) = 0; *reinterpret_cast<int*>(arg) = 0;
return NL_SKIP; return NL_SKIP;
} }
static int ackHandler(struct nl_msg *msg, void *arg) static int ackHandler(struct nl_msg *msg, void *arg)
{ {
(void)msg;
*reinterpret_cast<int*>(arg) = 0; *reinterpret_cast<int*>(arg) = 0;
return NL_STOP; return NL_STOP;
} }
@ -154,7 +150,7 @@ std::vector<uint64_t> connectedDevices(const std::string& ifDevice, int& error)
} }
} }
nla_put_failure: nla_put_failure:
nl_cb_put(cb); nl_cb_put(cb);
nl_cb_put(s_cb); nl_cb_put(s_cb);
nlmsg_free(msg); nlmsg_free(msg);

View file

@ -6,14 +6,14 @@
namespace ap namespace ap
{ {
enum ERRORS enum ERRORS
{ {
SUCESS, SUCESS,
ERR_INIT, ERR_INIT,
ERR_NO_DEV, ERR_NO_DEV,
ERR_ALLOC, ERR_ALLOC,
ERR_GENERAL ERR_GENERAL
}; };
std::vector<uint64_t> connectedDevices(const std::string& ifDevice, int& error); std::vector<uint64_t> connectedDevices(const std::string& ifDevice, int& error);
std::string macAddrToString(uint64_t macAddr); std::string macAddrToString(uint64_t macAddr);
} }

View file

@ -41,23 +41,20 @@ void BroadCast::sendJson(const QJsonObject& json)
void BroadCast::sendSensors() void BroadCast::sendSensors()
{ {
if(iodevice_) if(iodevice_)for(auto& sensor: *globalSensors.getSensors())
{ {
for(auto& sensor: *globalSensors.getSensors())
iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n'); iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n');
} }
} }
void BroadCast::requestSensors() void BroadCast::requestSensors()
{ {
if(iodevice_) if(iodevice_)iodevice_->write("bcst: GETSENSORS\n");
iodevice_->write("bcst: GETSENSORS\n");
} }
void BroadCast::requestJson() void BroadCast::requestJson()
{ {
if(iodevice_) if(iodevice_)iodevice_->write("bcst: GETJSN\n");
iodevice_->write("bcst: GETJSN\n");
} }
void BroadCast::decodeMaster(const QByteArray& buffer) void BroadCast::decodeMaster(const QByteArray& buffer)
@ -77,8 +74,7 @@ void BroadCast::decodeMaster(const QByteArray& buffer)
void BroadCast::decode(QByteArray buffer) void BroadCast::decode(QByteArray buffer)
{ {
qDebug()<<"decodeing: "<<buffer; qDebug()<<"decodeing: "<<buffer;
if(buffer.size() >= 6 && buffer[0] == 'J' && buffer[1] == 'S' && buffer[2] == 'O' && buffer[3] == 'N' if(buffer.size() >= 6 && buffer[0] == 'J' && buffer[1] == 'S' && buffer[2] == 'O' && buffer[3] == 'N' && buffer[4] == ':')
&& buffer[4] == ':')
{ {
qDebug()<<"got json"; qDebug()<<"got json";
buffer.remove(0,6); buffer.remove(0,6);
@ -108,8 +104,7 @@ void BroadCast::decode(QByteArray buffer)
qDebug()<<error.errorString(); qDebug()<<error.errorString();
} }
} }
else if(buffer.size() >= 6 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'N' && buffer[3] == 'S' else if(buffer.size() >= 6 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'N' && buffer[3] == 'S' && buffer[4] == 'O' && buffer[5] == 'R')
&& buffer[4] == 'O' && buffer[5] == 'R')
{ {
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);

View file

@ -1,7 +1,6 @@
#include "auxitem.h" #include "auxitem.h"
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)
{ {
} }

View file

@ -14,8 +14,7 @@ public slots:
virtual void setValue(uint8_t value); virtual void setValue(uint8_t value);
public: public:
AuxItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", AuxItem(Microcontroller* micro, 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);
}; };

View file

@ -38,8 +38,7 @@ uint32_t ItemData::id() const
bool Item::secondaryFlag = false; 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)
{ {
} }
@ -123,8 +122,7 @@ void Item::addActor(std::shared_ptr<Actor> 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 )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor.get(), &PolynomalActor::sensorEvent);
&PolynomalActor::sensorEvent);
} }
bool Item::removeActor(std::shared_ptr<Actor> actor) bool Item::removeActor(std::shared_ptr<Actor> actor)

View file

@ -19,14 +19,8 @@ public:
ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0); ItemData(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0);
inline bool operator==(const ItemData& in) const inline bool operator==(const ItemData& in) const{ return itemId_==in.itemId_; }
{ inline bool operator!=(const ItemData& in) const{ return itemId_!=in.itemId_; }
return itemId_==in.itemId_;
}
inline bool operator!=(const ItemData& in) const
{
return itemId_!=in.itemId_;
}
uint32_t id() const; uint32_t id() const;
@ -61,8 +55,7 @@ public slots:
public: public:
Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
QObject *parent = nullptr);
Item(const ItemData& itemData, QObject *parent = nullptr); Item(const ItemData& itemData, QObject *parent = nullptr);
virtual ~Item(); virtual ~Item();

View file

@ -15,12 +15,9 @@ private:
public: public:
ItemStore(QObject *parent = nullptr); ItemStore(QObject *parent = nullptr);
virtual ~ItemStore() {} virtual ~ItemStore(){}
inline std::vector< std::shared_ptr<Item> >* getItems() inline std::vector< std::shared_ptr<Item> >* getItems(){ return &items_; }
{
return &items_;
}
void store(QJsonObject &json); void store(QJsonObject &json);
void load(const QJsonObject &json); void load(const QJsonObject &json);

View file

@ -8,7 +8,7 @@
class MessageItem : public Item class MessageItem : public Item
{ {
Q_OBJECT Q_OBJECT
private: private:
QString message_; QString message_;
@ -28,8 +28,7 @@ public:
public: public:
MessageItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, MessageItem(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0, QObject *parent = nullptr);
QObject *parent = nullptr);
MessageItem(const ItemData& itemData, QObject *parent = nullptr); MessageItem(const ItemData& itemData, QObject *parent = nullptr);
~MessageItem(); ~MessageItem();

View file

@ -3,8 +3,7 @@
#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): Item(itemIdIn, name, value, parent)
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); setValue(true);
@ -24,7 +23,7 @@ void PowerItem::setValue(uint8_t value)
void PowerItem::timeout() void PowerItem::timeout()
{ {
qDebug()<<"shutdown timeout"; qDebug()<<"shutdown timeout";
QProcess::startDetached("syncoff", QStringList()); QProcess::startDetached("syncoff");
} }
void PowerItem::store(QJsonObject& json) void PowerItem::store(QJsonObject& json)

View file

@ -24,11 +24,7 @@ public slots:
virtual void setValue(uint8_t value); 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 = "", uint8_t value = 0, QObject* parent = nullptr);
QObject* parent = nullptr); void emmitSensor(){stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));}
void emmitSensor()
{
stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
}
virtual void store(QJsonObject& json); virtual void store(QJsonObject& json);
}; };

View file

@ -5,8 +5,7 @@
Microcontroller* Relay::micro_ = nullptr; Microcontroller* Relay::micro_ = nullptr;
Relay::Relay(uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(0, name, state, parent), Relay::Relay(uint8_t id, QString name, uint16_t address, bool state, QObject* parent): Item(0, name, state, parent), 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; qDebug()<<"Relay "<<id_<<"Name "<<name<<" id "<<itemId_<<" state "<<state<<" addr: "<<address;

View file

@ -32,10 +32,7 @@ public:
uint8_t getId() const; uint8_t getId() const;
void setId(uint8_t id); void setId(uint8_t id);
inline static void setMicrocontroller(Microcontroller* micro) inline static void setMicrocontroller(Microcontroller* micro){ micro_ = micro; }
{
micro_ = micro;
}
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);

View file

@ -1,7 +1,6 @@
#include "rgbitem.h" #include "rgbitem.h"
RgbItem::RgbItem(Microcontroller* micro, uint32_t itemIdIn, QString name, uint8_t value, RgbItem::RgbItem(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)
{ {
} }

View file

@ -14,8 +14,7 @@ public slots:
virtual void setValue(uint8_t value); virtual void setValue(uint8_t value);
public: public:
RgbItem(Microcontroller* micro, uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "", RgbItem(Microcontroller* micro, 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);
}; };

View file

@ -7,13 +7,13 @@ void SystemItem::setValue(uint8_t value)
} }
SystemItem::SystemItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent): SystemItem::SystemItem(uint32_t itemIdIn, QString name, uint8_t value, QObject *parent):
Item(itemIdIn, name, value, parent) Item(itemIdIn, name, value, parent)
{ {
} }
SystemItem::SystemItem(const ItemData& itemData, QObject *parent): SystemItem::SystemItem(const ItemData& itemData, QObject *parent):
Item(itemData, parent) Item(itemData, parent)
{ {
} }

View file

@ -6,7 +6,7 @@
class SystemItem : public Item class SystemItem : public Item
{ {
Q_OBJECT Q_OBJECT
private: private:
QString onCommand_; QString onCommand_;
@ -18,21 +18,14 @@ public:
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);
~SystemItem() = default; ~SystemItem() = default;
void setOnCommand(const QString& in); void setOnCommand(const QString& in);
void setOffCommand(const QString& in); void setOffCommand(const QString& in);
QString getOnCommand() QString getOnCommand(){return onCommand_;}
{ QString getOffCommand(){return offCommand_;}
return onCommand_;
}
QString getOffCommand()
{
return offCommand_;
}
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);

View file

@ -4,9 +4,6 @@
#include <QTcpSocket> #include <QTcpSocket>
#include <QMessageBox> #include <QMessageBox>
//Currently pipewire support is disabled
//#include <pipewire/pipewire.h>
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
#include <QtSerialPort/QtSerialPort> #include <QtSerialPort/QtSerialPort>
@ -14,9 +11,18 @@
#include <QCommandLineParser> #include <QCommandLineParser>
#endif #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/ocupancysensor.h"
#include "alarmactions.h"
#include "sensors/sensor.h"
#include "items/itemstore.h" #include "items/itemstore.h"
#include "items/auxitem.h"
#include "items/rgbitem.h"
#include "items/poweritem.h"
#include "mainobject.h" #include "mainobject.h"
@ -26,8 +32,6 @@ int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
//pw_init(&argc, &argv);
//set info //set info
QCoreApplication::setOrganizationName("UVOS"); QCoreApplication::setOrganizationName("UVOS");
QCoreApplication::setOrganizationDomain("uvos.xyz"); QCoreApplication::setOrganizationDomain("uvos.xyz");
@ -37,36 +41,31 @@ int main(int argc, char *argv[])
QDir::setCurrent(a.applicationDirPath()); QDir::setCurrent(a.applicationDirPath());
//parse comand line //parse comand line
#ifndef Q_OS_ANDROID #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 tcpOption(QStringList() << "t" << "tcp", QCoreApplication::translate("main", "Use Tcp connection"));
parser.addOption(tcpOption); parser.addOption(tcpOption);
QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", QCommandLineOption hostOption(QStringList() << "H" << "host", QCoreApplication::translate("main", "Set server host ip addres"), "adress");
"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 in TCP mode or Serial port in serial mode"), "port");
"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 serialOption(QStringList() << "s" << "serial", QCoreApplication::translate("main", "Use serial connection"));
"Use serial connection"));
parser.addOption(serialOption); parser.addOption(serialOption);
QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate")); QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
parser.addOption(baudOption); parser.addOption(baudOption);
QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main", QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main", "Set config file"), "configFilePath");
"Set config file"), "configFilePath");
parser.addOption(settingsPathOption); parser.addOption(settingsPathOption);
QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main", QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main", "Set if instance is not main instance"));
"Set if instance is not main instance"));
parser.addOption(secondaryOption); parser.addOption(secondaryOption);
parser.process(a); parser.process(a);
#endif #endif
QIODevice* masterIODevice = nullptr; QIODevice* masterIODevice = nullptr;
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
if(parser.isSet(tcpOption)) if(parser.isSet(tcpOption))
{ {
QTcpSocket* microSocket = new QTcpSocket; QTcpSocket* microSocket = new QTcpSocket;
@ -95,15 +94,13 @@ int main(int argc, char *argv[])
if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt()); if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
else microPort->setBaudRate(BAUD); else microPort->setBaudRate(BAUD);
if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString() if(!microPort->open(QIODevice::ReadWrite)) std::cout<<"Can not open serial port "<<microPort->portName().toStdString()<<". Continueing in demo mode"<<'\n';
<<". Continueing in demo mode"<<'\n';
masterIODevice = microPort; masterIODevice = microPort;
} }
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
!parser.isSet(secondaryOption));
#else #else
QTcpSocket* microSocket = new QTcpSocket; QTcpSocket* microSocket = new QTcpSocket;
microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite); microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
if(!microSocket->waitForConnected(1000)) if(!microSocket->waitForConnected(1000))
@ -113,9 +110,8 @@ int main(int argc, char *argv[])
} }
masterIODevice = microSocket; masterIODevice = microSocket;
MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
!parser.isSet(secondaryOption)); #endif
#endif
//mainwindow //mainwindow
@ -124,8 +120,7 @@ int main(int argc, char *argv[])
QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson); QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
QObject::connect(&w, &MainWindow::sigSave, &mainObject, &MainObject::storeToDisk); QObject::connect(&w, &MainWindow::sigSave, &mainObject, &MainObject::storeToDisk);
QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem); QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
if(!mainObject.micro.connected()) if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
w.changeHeaderLableText("No io debug only!");
w.show(); w.show();

View file

@ -23,7 +23,6 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState); QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
sunSensorSource.run(); sunSensorSource.run();
//pwHandler.startLoop();
//connect item store //connect item store
QObject::connect(&micro, &Microcontroller::gotRelayList, &items, &ItemStore::addItems); QObject::connect(&micro, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
@ -36,26 +35,23 @@ MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const
items.addItem(auxItem); items.addItem(auxItem);
MessageItem::broadCast = &broadCast; MessageItem::broadCast = &broadCast;
Relay::setMicrocontroller(&micro); Relay::setMicrocontroller(&micro);
connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson); connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState); QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
if(master) if(master)connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
if(master) if(master) load(getJsonObjectFromDisk(settingsPath, &noSave));
{
load(getJsonObjectFromDisk(settingsPath, &noSave));
}
else else
{ {
broadCast.requestJson(); broadCast.requestJson();
broadCast.requestSensors(); broadCast.requestSensors();
} }
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
Item::secondaryFlag = !master; Item::secondaryFlag = !master;
#endif #endif
} }
MainObject::~MainObject() MainObject::~MainObject()
@ -124,10 +120,10 @@ QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* err
{ {
QFile file; QFile file;
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
if(filePath.size() > 0) file.setFileName(filePath); if(filePath.size() > 0) file.setFileName(filePath);
else else
#endif #endif
{ {
file.setFileName(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json"); file.setFileName(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
} }
@ -151,9 +147,9 @@ QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* err
bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, QString filePath) bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, QString filePath)
{ {
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
if(filePath.size() == 0) if(filePath.size() == 0)
#endif #endif
{ {
filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json"; filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json";
} }

View file

@ -32,7 +32,6 @@
#include "items/poweritem.h" #include "items/poweritem.h"
#include "iomuliplexer.h" #include "iomuliplexer.h"
#include "broadcast.h" #include "broadcast.h"
//#include "pipewire.h"
class MainObject : public QObject class MainObject : public QObject
{ {
@ -50,7 +49,6 @@ public:
Microcontroller micro; Microcontroller micro;
BroadCast broadCast; BroadCast broadCast;
const QString settingsPath; const QString settingsPath;
//sensors //sensors
@ -64,8 +62,6 @@ public:
std::shared_ptr<RgbItem> rgbItem; std::shared_ptr<RgbItem> rgbItem;
std::shared_ptr<AuxItem> auxItem; std::shared_ptr<AuxItem> auxItem;
//PipeWireHandler pwHandler;
private: private:
static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr); static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);

View file

@ -41,10 +41,10 @@ void Microcontroller::changeRgbColor(const QColor color)
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; std::cout<<buffer;
} }
void Microcontroller::setAuxPwm(int duty) void Microcontroller::setAuxPwm(int duty)
{ {
char buffer[64]; char buffer[64];
int length = sprintf(buffer, "aux set %03d\n", duty ); int length = sprintf(buffer, "aux set %03d\n", duty );
write(buffer, length); write(buffer, length);
@ -52,9 +52,9 @@ void Microcontroller::setAuxPwm(int duty)
void Microcontroller::write(const QByteArray& buffer) void Microcontroller::write(const QByteArray& buffer)
{ {
#ifndef Q_OS_ANDROID #ifndef Q_OS_ANDROID
if constexpr(debug) std::cerr<<buffer.data(); if constexpr(debug) std::cerr<<buffer.data();
#endif #endif
if(_port != nullptr) if(_port != nullptr)
{ {
_port->write(buffer); _port->write(buffer);
@ -65,9 +65,9 @@ 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 #ifndef Q_OS_ANDROID
if constexpr(debug) std::cerr<<buffer; if constexpr(debug) std::cerr<<buffer;
#endif #endif
if(_port != nullptr) if(_port != nullptr)
{ {
_port->write(buffer, length); _port->write(buffer, length);
@ -127,16 +127,10 @@ std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
if(bufferList.size() >= 9 && buffer.startsWith("ITEM NUMBER:")) if(bufferList.size() >= 9 && buffer.startsWith("ITEM NUMBER:"))
{ {
QString name; QString name;
for(int i = 10; i < bufferList.size(); i++) for(int i = 10; i < bufferList.size(); i++) name.append(bufferList[i] + ' ');
name.append(bufferList[i] + ' '); if(name.size() > 1)name.remove(name.size()-1, 1);
if(name.size() > 1) else name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2));
name.remove(name.size()-1, 1); return std::shared_ptr<Relay>( new Relay(bufferList[2].toInt(), name, bufferList[4].toInt(nullptr, 2), bufferList[8].toInt()));
else
name = "Relay " + QString::number(bufferList[1].toInt(nullptr, 2));
return std::shared_ptr<Relay>(new Relay(bufferList[2].toInt(),
name,
bufferList[6].toInt(nullptr, 2),
bufferList[8].toInt()));
} }
return nullptr; return nullptr;
} }

View file

@ -1,72 +0,0 @@
#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, &registryListener, &registry_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);
}

View file

@ -1,56 +0,0 @@
#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();
};

View file

@ -5,8 +5,7 @@
#include "../apgetconnected.h" #include "../apgetconnected.h"
OcupancySensorSource::OcupancySensorSource(QObject *parent, const QString& device, OcupancySensorSource::OcupancySensorSource(QObject *parent, const QString& device, const QString& deviceMac): QObject (parent), deviceMac_(deviceMac), device_(device)
const QString& deviceMac): QObject (parent), deviceMac_(deviceMac), device_(device)
{ {
QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout); QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
} }

View file

@ -15,8 +15,7 @@ private:
static constexpr unsigned timeoutMs = (15 * 60) * 1000; static constexpr unsigned timeoutMs = (15 * 60) * 1000;
public: public:
explicit OcupancySensorSource(QObject *parent = nullptr, const QString& device = "wlan0", explicit OcupancySensorSource(QObject *parent = nullptr, const QString& device = "wlan0", const QString& deviceMac = "60:BE:B5:25:8C:E0");
const QString& deviceMac = "60:BE:B5:25:8C:E0");
void store(QJsonObject& json); void store(QJsonObject& json);
void load(const QJsonObject& json); void load(const QJsonObject& json);

View file

@ -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;
}
}

View file

@ -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

View file

@ -30,52 +30,33 @@ public:
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(uint8_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();
if(nameIn == "") if(nameIn == "") generateName();
generateName();
} }
Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false) Sensor(QString nameIn = "dummy"): type(TYPE_DUMMY), id(0), field(0), name(nameIn), hidden(false)
{ {
lastSeen = QDateTime::currentDateTime(); lastSeen = QDateTime::currentDateTime();
} }
inline bool operator==(const Sensor& in) const inline bool operator==(const Sensor& in) const{ return type==in.type && id == in.id; }
{ inline bool operator!=(const Sensor& in) const{ return !(*this==in); }
return type==in.type && id == in.id; inline void updateSeen(){lastSeen = QDateTime::currentDateTime();}
}
inline bool operator!=(const Sensor& in) const
{
return !(*this==in);
}
inline void updateSeen()
{
lastSeen = QDateTime::currentDateTime();
}
static Sensor sensorFromString(const QString& str) static Sensor sensorFromString(const QString& str)
{ {
QStringList bufferList = str.split(' '); QStringList bufferList = str.split(' ');
if(bufferList.size() >= 7) if(bufferList.size() >= 7)
{ {
Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt()); Sensor sensor(bufferList[2].toUInt(), bufferList[4].toUInt(), bufferList[6].toUInt());
if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE) if(sensor.type == Sensor::TYPE_HUMIDITY || sensor.type == Sensor::TYPE_TEMPERATURE) sensor.field = sensor.field/10;
sensor.field = sensor.field/10;
if(bufferList.size() >= 9)
sensor.lastSeen = QDateTime::fromSecsSinceEpoch(bufferList[8].toLongLong());
return sensor; return sensor;
} }
else else return Sensor(TYPE_DUMMY, 0, 0, "", true);
{
return Sensor(TYPE_DUMMY, 0, 0, "", true);
}
} }
QString toString() QString toString()
{ {
return QString("SENSOR TYPE: ")+QString::number(type)+" ID: "+QString::number(id)+" FIELD: "+ 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() inline void generateName()
{ {
@ -99,12 +80,9 @@ private:
public: public:
SensorStore(QObject *parent = nullptr); SensorStore(QObject *parent = nullptr);
virtual ~SensorStore() {} virtual ~SensorStore(){}
inline std::vector<Sensor>* getSensors() inline std::vector<Sensor>* getSensors(){ return &sensors_; }
{
return &sensors_;
}
public slots: public slots:

View file

@ -15,7 +15,7 @@ SpeakerSensorSource::~SpeakerSensorSource()
void SpeakerSensorSource::run() void SpeakerSensorSource::run()
{ {
abort(); 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())); connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
timer.setInterval(500); timer.setInterval(500);

View file

@ -63,8 +63,7 @@ std::time_t Sun::JdTime::toStdTime()
return millenniumTime; return millenniumTime;
} }
Sun::Sun(double latitude, double longitude, double altitude): latitude_(latitude), longetude_(longitude), Sun::Sun(double latitude, double longitude, double altitude): latitude_(latitude), longetude_(longitude), altitude_(altitude)
altitude_(altitude)
{} {}
double Sun::nextMeanSolarNoonJD(const JdTime& time) double Sun::nextMeanSolarNoonJD(const JdTime& time)
@ -79,8 +78,7 @@ double Sun::meanSolarAnomaly(double meanSolarNoon)
double Sun::eqOfCenter(double meanSolarAnomaly) double Sun::eqOfCenter(double meanSolarAnomaly)
{ {
return 1.9148*sin(meanSolarAnomaly*TO_RADS) + 0.0200*sin(2*meanSolarAnomaly*TO_RADS) + 0.0003*sin( return 1.9148*sin(meanSolarAnomaly*TO_RADS) + 0.0200*sin(2*meanSolarAnomaly*TO_RADS) + 0.0003*sin(3*meanSolarAnomaly*TO_RADS);
3*meanSolarAnomaly*TO_RADS);
} }
double Sun::eclipticLongitude(double eqOfCenter, double meanSolarAnomaly) double Sun::eclipticLongitude(double eqOfCenter, double meanSolarAnomaly)
@ -110,8 +108,7 @@ double Sun::hourAngle(double localSolarTime)
double Sun::hourAngleAtSunset(double solarDeclination) 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( 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)));
latitude_*TO_RADS))/(cos(latitude_*TO_RADS)*cos(solarDeclination*TO_RADS)));
} }
double Sun::altitude() double Sun::altitude()
@ -123,8 +120,7 @@ double Sun::altitude()
double localSolarTimeValue = localSolarTime(time, equationOfTime(meanSolarAnomalyValue, eclipticLongitudeValue)); double localSolarTimeValue = localSolarTime(time, equationOfTime(meanSolarAnomalyValue, eclipticLongitudeValue));
double declinationValue = solarDeclination(eclipticLongitudeValue); double declinationValue = solarDeclination(eclipticLongitudeValue);
double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos( double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos(declinationValue*TO_RADS)*cos(hourAngle(localSolarTimeValue)*TO_RADS);
declinationValue*TO_RADS)*cos(hourAngle(localSolarTimeValue)*TO_RADS);
return TO_DEGS*asin(cosZenithAngle); return TO_DEGS*asin(cosZenithAngle);
} }
@ -137,8 +133,7 @@ double Sun::maximumAltitude()
double eclipticLongitudeValue = eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue); double eclipticLongitudeValue = eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue);
double declinationValue = solarDeclination(eclipticLongitudeValue); double declinationValue = solarDeclination(eclipticLongitudeValue);
double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos( double cosZenithAngle = sin(latitude_*TO_RADS)*sin(declinationValue*TO_RADS)+cos(latitude_*TO_RADS)*cos(declinationValue*TO_RADS);
declinationValue*TO_RADS);
return TO_DEGS*asin(cosZenithAngle); return TO_DEGS*asin(cosZenithAngle);
} }
@ -148,6 +143,7 @@ double Sun::azimuth()
return 0; return 0;
} }
std::time_t Sun::riseTime() std::time_t Sun::riseTime()
{ {
JdTime time; JdTime time;
@ -157,12 +153,10 @@ std::time_t Sun::riseTime()
double declinationValue = solarDeclination(eclipticLongitudeValue); double declinationValue = solarDeclination(eclipticLongitudeValue);
double hourAngleValue = hourAngleAtSunset(declinationValue); double hourAngleValue = hourAngleAtSunset(declinationValue);
time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue, time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue, eclipticLongitudeValue) - hourAngleValue/360.0;
eclipticLongitudeValue) - hourAngleValue/360.0;
return time.toStdTime(); return time.toStdTime();
} }
std::time_t Sun::setTime() std::time_t Sun::setTime()
{ {
JdTime time; JdTime time;
@ -172,12 +166,12 @@ std::time_t Sun::setTime()
double declinationValue = solarDeclination(eclipticLongitudeValue); double declinationValue = solarDeclination(eclipticLongitudeValue);
double hourAngleValue = hourAngleAtSunset(declinationValue); double hourAngleValue = hourAngleAtSunset(declinationValue);
time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue, time.julianDate = meanSolarNoonValue + equationOfTime(meanSolarAnomalyValue, eclipticLongitudeValue) + hourAngleValue/360.0;
eclipticLongitudeValue) + hourAngleValue/360.0;
return time.toStdTime(); return time.toStdTime();
} }
double Sun::declination() double Sun::declination()
{ {
JdTime time; JdTime time;

View file

@ -16,9 +16,9 @@ ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<AlarmTime> alarm, QWidg
} }
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<SensorActor> actor, QWidget *parent) : ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<SensorActor> actor, QWidget *parent) :
QDialog(parent), QDialog(parent),
actor_(actor), actor_(actor),
ui(new Ui::ActorSettingsDialog) ui(new Ui::ActorSettingsDialog)
{ {
init(); init();
@ -38,9 +38,9 @@ ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<Regulator> actor, QWidg
} }
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWidget *parent) : ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWidget *parent) :
QDialog(parent), QDialog(parent),
actor_(actor), actor_(actor),
ui(new Ui::ActorSettingsDialog) ui(new Ui::ActorSettingsDialog)
{ {
init(); init();
@ -49,9 +49,9 @@ ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWid
} }
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor, QWidget *parent) : ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor, QWidget *parent) :
QDialog(parent), QDialog(parent),
actor_(actor), actor_(actor),
ui(new Ui::ActorSettingsDialog) ui(new Ui::ActorSettingsDialog)
{ {
init(); init();
@ -60,9 +60,9 @@ ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor,
} }
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor, QWidget *parent) : ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor, QWidget *parent) :
QDialog(parent), QDialog(parent),
actor_(actor), actor_(actor),
ui(new Ui::ActorSettingsDialog) ui(new Ui::ActorSettingsDialog)
{ {
init(); init();
widget = new FactorActorWidget(actor, this); widget = new FactorActorWidget(actor, this);
@ -70,9 +70,9 @@ ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor
} }
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<Actor> actor, QWidget *parent) : ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<Actor> actor, QWidget *parent) :
QDialog(parent), QDialog(parent),
actor_(actor), actor_(actor),
ui(new Ui::ActorSettingsDialog) ui(new Ui::ActorSettingsDialog)
{ {
init(); init();
} }
@ -83,20 +83,14 @@ void ActorSettingsDialog::init()
connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(int))); connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(int)));
connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int))); connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
connect(ui->pushButton_editItem, &QPushButton::clicked, this, &ActorSettingsDialog::editAsItem); connect(ui->pushButton_editItem, &QPushButton::clicked, this, &ActorSettingsDialog::editAsItem);
connect(ui->pushButton_enable, &QPushButton::clicked, this, &ActorSettingsDialog::setEnabled);
ui->spinBox->hide(); ui->spinBox->hide();
ui->spinBox->setValue(actor_->getTriggerValue()); ui->spinBox->setValue(actor_->getTriggerValue());
if(actor_->getTriggerValue() == 0) if(actor_->getTriggerValue() == 0) ui->comboBox_action->setCurrentIndex(0);
ui->comboBox_action->setCurrentIndex(0); else if(actor_->getTriggerValue() == 1) ui->comboBox_action->setCurrentIndex(1);
else if(actor_->getTriggerValue() == 1) else ui->comboBox_action->setCurrentIndex(2);
ui->comboBox_action->setCurrentIndex(1);
else
ui->comboBox_action->setCurrentIndex(2);
ui->label_Exausted->setText(actor_->isExausted() ? "True" : "False"); ui->label_Exausted->setText(actor_->isExausted() ? "True" : "False");
ui->label_Enabled->setText(actor_->isActive() ? "True" : "False");
ui->pushButton_enable->setText(actor_->isActive() ? "Disable" : "Enable");
} }
ActorSettingsDialog::~ActorSettingsDialog() ActorSettingsDialog::~ActorSettingsDialog()
@ -110,13 +104,6 @@ void ActorSettingsDialog::editAsItem()
itemSettingsDiag.exec(); itemSettingsDiag.exec();
} }
void ActorSettingsDialog::setEnabled()
{
actor_->setActive(!actor_->isActive());
ui->label_Enabled->setText(actor_->isActive() ? "True" : "False");
ui->pushButton_enable->setText(actor_->isActive() ? "Disable" : "Enable");
}
void ActorSettingsDialog::valueChanged(int value) void ActorSettingsDialog::valueChanged(int value)
{ {
actor_->setTriggerValue(value); actor_->setTriggerValue(value);

View file

@ -10,8 +10,7 @@
#include "actorwidgets/polynomalactorwidget.h" #include "actorwidgets/polynomalactorwidget.h"
#include "actorwidgets/factoractorwidget.h" #include "actorwidgets/factoractorwidget.h"
namespace Ui namespace Ui {
{
class ActorSettingsDialog; class ActorSettingsDialog;
} }
@ -41,7 +40,6 @@ private slots:
void changeAction(int index); void changeAction(int index);
void valueChanged(int value); void valueChanged(int value);
void editAsItem(); void editAsItem();
void setEnabled();
private: private:

View file

@ -85,63 +85,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Enabled:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_Enabled">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>True</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_enable">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item>

View file

@ -7,6 +7,11 @@ AlarmWidget::AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent) :
ui(new Ui::AlarmWidget) ui(new Ui::AlarmWidget)
{ {
ui->setupUi(this); 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()); ui->dateTimeEdit->setDateTime(alarm->getDateTime());
@ -26,20 +31,11 @@ AlarmWidget::AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent) :
ui->radioButton_4->setEnabled(true); ui->radioButton_4->setEnabled(true);
} }
if(alarm_->getRepeat() == AlarmTime::REPEAT_DAILY) if(alarm_->getRepeat() == AlarmTime::REPEAT_DAILY) ui->radioButton->setChecked(true);
ui->radioButton->setChecked(true); else if(alarm_->getRepeat() == AlarmTime::REPEAT_WEEKLY) ui->radioButton_2->setChecked(true);
else if(alarm_->getRepeat() == AlarmTime::REPEAT_WEEKLY) else if(alarm_->getRepeat() == AlarmTime::REPEAT_MONTHLY)ui->radioButton_3->setChecked(true);
ui->radioButton_2->setChecked(true); else if(alarm_->getRepeat() == AlarmTime::REPEAT_YEARLY) ui->radioButton_4->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); connect(ui->dateTimeEdit, &QDateTimeEdit::dateTimeChanged, alarm.get(), &AlarmTime::changeTime);
} }
@ -50,14 +46,10 @@ AlarmWidget::~AlarmWidget()
void AlarmWidget::setRepeatingType() void AlarmWidget::setRepeatingType()
{ {
if(ui->radioButton->isChecked()) if(ui->radioButton->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_DAILY);
alarm_->setRepeat(AlarmTime::REPEAT_DAILY); if(ui->radioButton_2->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_WEEKLY);
if(ui->radioButton_2->isChecked()) if(ui->radioButton_3->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_MONTHLY);
alarm_->setRepeat(AlarmTime::REPEAT_WEEKLY); if(ui->radioButton_4->isChecked())alarm_->setRepeat(AlarmTime::REPEAT_YEARLY);
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) void AlarmWidget::toggleRepeating(int state)

View file

@ -5,8 +5,7 @@
#include <memory> #include <memory>
#include "../../actors/alarmtime.h" #include "../../actors/alarmtime.h"
namespace Ui namespace Ui {
{
class AlarmWidget; class AlarmWidget;
} }

View file

@ -4,8 +4,7 @@
#include <QWidget> #include <QWidget>
#include "../../actors/factoractor.h" #include "../../actors/factoractor.h"
namespace Ui namespace Ui {
{
class FactorActorWidget; class FactorActorWidget;
} }

View file

@ -1,8 +1,7 @@
#include "polynomalactorwidget.h" #include "polynomalactorwidget.h"
#include "ui_polynomalactorwidget.h" #include "ui_polynomalactorwidget.h"
PolynomalActorWidget::PolynomalActorWidget(std::shared_ptr<PolynomalActor> actor, SensorStore* sensors, PolynomalActorWidget::PolynomalActorWidget(std::shared_ptr<PolynomalActor> actor, SensorStore* sensors, QWidget *parent):
QWidget *parent):
QWidget(parent), QWidget(parent),
sensors_(sensors), sensors_(sensors),
actor_(actor), actor_(actor),
@ -40,11 +39,10 @@ PolynomalActorWidget::~PolynomalActorWidget()
void PolynomalActorWidget::setPow() void PolynomalActorWidget::setPow()
{ {
actor_->setCoeffiancts(ui->doubleSpinBox_pow3->value(), ui->doubleSpinBox_pow2->value(), actor_->setCoeffiancts(ui->doubleSpinBox_pow3->value(), ui->doubleSpinBox_pow2->value(), ui->doubleSpinBox_pow1->value(), ui->doubleSpinBox_pow0->value());
ui->doubleSpinBox_pow1->value(), ui->doubleSpinBox_pow0->value());
} }
void PolynomalActorWidget::setSensor(const QModelIndex &index) void PolynomalActorWidget::setSensor(const QModelIndex &index)
{ {
actor_->setSensor(ui->listView->getSensorForIndex(index)); actor_->setSensor(sensors_->getSensors()->at(index.row()));
} }

View file

@ -4,8 +4,7 @@
#include <QWidget> #include <QWidget>
#include "../../actors/polynomalactor.h" #include "../../actors/polynomalactor.h"
namespace Ui namespace Ui {
{
class PolynomalActorWidget; class PolynomalActorWidget;
} }
@ -16,8 +15,7 @@ class PolynomalActorWidget : public QWidget
std::shared_ptr<PolynomalActor> actor_; std::shared_ptr<PolynomalActor> actor_;
public: public:
explicit PolynomalActorWidget(std::shared_ptr<PolynomalActor> regulator, SensorStore* sensors = nullptr, explicit PolynomalActorWidget(std::shared_ptr<PolynomalActor> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
QWidget *parent = nullptr);
~PolynomalActorWidget(); ~PolynomalActorWidget();
private slots: private slots:

View file

@ -24,17 +24,12 @@ RegulatorWdiget::RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorSto
} }
ui->doubleSpinBox_setPoint->setValue(regulator->getSetPoint()); ui->doubleSpinBox_setPoint->setValue(regulator->getSetPoint());
ui->doubleSpinBox_band->setValue(regulator->getBand()); ui->doubleSpinBox_band->setValue(regulator->getBand());
ui->spinBox_safe->setValue(regulator_->getSafeValue());
ui->spinBox_timeout->setValue(regulator_->getTimeout());
connect(ui->listView, &SensorListWidget::clicked, this, &RegulatorWdiget::setSensor); connect(ui->listView, &SensorListWidget::clicked, this, &RegulatorWdiget::setSensor);
connect(ui->doubleSpinBox_setPoint, SIGNAL(valueChanged(double)), this, SLOT(setPoint(double))); connect(ui->doubleSpinBox_setPoint, SIGNAL(valueChanged(double)), this, SLOT(setPoint(double)));
connect(ui->doubleSpinBox_band, SIGNAL(valueChanged(double)), this, SLOT(setBand(double))); connect(ui->doubleSpinBox_band, SIGNAL(valueChanged(double)), this, SLOT(setBand(double)));
connect(ui->spinBox_safe, SIGNAL(valueChanged(int)), regulator_.get(), SLOT(setSafeValue(int)));
connect(ui->spinBox_timeout, SIGNAL(valueChanged(int)), regulator_.get(), SLOT(setTimeout(int)));
} }
void RegulatorWdiget::setPoint(double in) void RegulatorWdiget::setPoint(double in)
{ {
regulator_->setPoint(in); regulator_->setPoint(in);
@ -47,7 +42,7 @@ void RegulatorWdiget::setBand(double band)
void RegulatorWdiget::setSensor(const QModelIndex &index) void RegulatorWdiget::setSensor(const QModelIndex &index)
{ {
regulator_->setSensor(ui->listView->getSensorForIndex(index)); regulator_->setSensor(sensors_->getSensors()->at(index.row()));
setPoint(ui->listView->getSensorForIndex(index).field); setPoint(sensors_->getSensors()->at(index.row()).field);
ui->doubleSpinBox_setPoint->setValue(ui->listView->getSensorForIndex(index).field); ui->doubleSpinBox_setPoint->setValue(sensors_->getSensors()->at(index.row()).field);
} }

View file

@ -4,8 +4,7 @@
#include <QWidget> #include <QWidget>
#include "../../actors/regulator.h" #include "../../actors/regulator.h"
namespace Ui namespace Ui {
{
class RegulatorWdiget; class RegulatorWdiget;
} }
@ -17,8 +16,7 @@ class RegulatorWdiget : public QWidget
SensorStore* sensors_; SensorStore* sensors_;
public: public:
explicit RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors = nullptr, explicit RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
QWidget *parent = nullptr);
~RegulatorWdiget(); ~RegulatorWdiget();
private slots: private slots:

View file

@ -38,8 +38,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QGridLayout" name="gridLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item row="0" column="1"> <item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Set Point</string>
</property>
</widget>
</item>
<item>
<widget class="QDoubleSpinBox" name="doubleSpinBox_setPoint"> <widget class="QDoubleSpinBox" name="doubleSpinBox_setPoint">
<property name="minimum"> <property name="minimum">
<double>-9999.989999999999782</double> <double>-9999.989999999999782</double>
@ -49,7 +56,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="2"> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred"> <sizepolicy hsizetype="Fixed" vsizetype="Preferred">
@ -62,46 +69,9 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="2"> <item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Timeout</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Set Point</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QDoubleSpinBox" name="doubleSpinBox_band"/> <widget class="QDoubleSpinBox" name="doubleSpinBox_band"/>
</item> </item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Safety Value</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox_safe"/>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="spinBox_timeout">
<property name="suffix">
<string> s</string>
</property>
<property name="maximum">
<number>999999999</number>
</property>
<property name="value">
<number>1800</number>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View file

@ -17,12 +17,9 @@ SensorActorWidget::SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, S
ui->label->hide(); ui->label->hide();
} }
if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) ui->comboBox_slope->setCurrentIndex(0);
ui->comboBox_slope->setCurrentIndex(0); else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) ui->comboBox_slope->setCurrentIndex(1);
else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) else if(sensorActor_->getSloap() == SensorActor::SLOPE_BOTH) ui->comboBox_slope->setCurrentIndex(2);
ui->comboBox_slope->setCurrentIndex(1);
else if(sensorActor_->getSloap() == SensorActor::SLOPE_BOTH)
ui->comboBox_slope->setCurrentIndex(2);
ui->doubleSpinBox_threshold->setValue(sensorActor_->getThreshold()); ui->doubleSpinBox_threshold->setValue(sensorActor_->getThreshold());
@ -50,5 +47,6 @@ void SensorActorWidget::setSlope(int index)
void SensorActorWidget::setSensor(const QModelIndex &index) void SensorActorWidget::setSensor(const QModelIndex &index)
{ {
sensorActor_->setSensor(ui->listView->getSensorForIndex(index)); sensorActor_->setSensor(sensors_->getSensors()->at(index.row()));
qDebug()<<"Selected "<<sensors_->getSensors()->at(index.row()).name;
} }

View file

@ -5,8 +5,7 @@
#include <QItemSelection> #include <QItemSelection>
#include "../../actors/sensoractor.h" #include "../../actors/sensoractor.h"
namespace Ui namespace Ui {
{
class SensorActorWidget; class SensorActorWidget;
} }
@ -18,8 +17,7 @@ class SensorActorWidget : public QWidget
SensorStore* sensors_; SensorStore* sensors_;
public: public:
explicit SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors = nullptr, explicit SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
QWidget *parent = nullptr);
~SensorActorWidget(); ~SensorActorWidget();
private slots: private slots:

View file

@ -4,8 +4,7 @@
#include <QWidget> #include <QWidget>
#include "../../actors/timeractor.h" #include "../../actors/timeractor.h"
namespace Ui namespace Ui {
{
class TimerActorWidget; class TimerActorWidget;
} }

View file

@ -5,8 +5,7 @@
#include <memory> #include <memory>
#include "../items/item.h" #include "../items/item.h"
namespace Ui namespace Ui {
{
class ItemCreationDialog; class ItemCreationDialog;
} }

View file

@ -11,8 +11,7 @@
#include "../items/itemstore.h" #include "../items/itemstore.h"
namespace Ui namespace Ui {
{
class RelayScrollBox; class RelayScrollBox;
} }

View file

@ -1,4 +1,4 @@
#include "itemsettingsdialog.h" #include "itemsettingsdialog.h"
#include "ui_itemsettingsdialog.h" #include "ui_itemsettingsdialog.h"
#include "actorsettingsdialog.h" #include "actorsettingsdialog.h"
#include "../actors/alarmtime.h" #include "../actors/alarmtime.h"
@ -144,7 +144,7 @@ void ItemSettingsDialog::addActor()
void ItemSettingsDialog::removeActor() void ItemSettingsDialog::removeActor()
{ {
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow())) if(item_->getActors().size() > ui->tableWidget->currentRow())
{ {
item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow())); item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
loadActorList(); loadActorList();
@ -153,7 +153,7 @@ void ItemSettingsDialog::removeActor()
void ItemSettingsDialog::editActor() void ItemSettingsDialog::editActor()
{ {
if(item_->getActors().size() > static_cast<size_t>(ui->tableWidget->currentRow())) if(item_->getActors().size() > ui->tableWidget->currentRow())
{ {
std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()]; std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
@ -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 < 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());

View file

@ -6,8 +6,7 @@
#include <memory> #include <memory>
#include "../items/relay.h" #include "../items/relay.h"
namespace Ui namespace Ui {
{
class ItemSettingsDialog; class ItemSettingsDialog;
} }

View file

@ -115,7 +115,7 @@
<number>3</number> <number>3</number>
</property> </property>
<attribute name="horizontalHeaderVisible"> <attribute name="horizontalHeaderVisible">
<bool>true</bool> <bool>false</bool>
</attribute> </attribute>
<attribute name="horizontalHeaderMinimumSectionSize"> <attribute name="horizontalHeaderMinimumSectionSize">
<number>32</number> <number>32</number>

View file

@ -1,48 +0,0 @@
#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;
}

View file

@ -1,31 +0,0 @@
#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

View file

@ -1,59 +0,0 @@
<?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>

View file

@ -5,8 +5,7 @@
#include <memory> #include <memory>
#include "../../items/relay.h" #include "../../items/relay.h"
namespace Ui namespace Ui {
{
class RelayItemSettingsWidget; class RelayItemSettingsWidget;
} }

View file

@ -5,8 +5,7 @@
#include <memory> #include <memory>
#include "../../items/systemitem.h" #include "../../items/systemitem.h"
namespace Ui namespace Ui {
{
class SystemItemSettingsWidget; class SystemItemSettingsWidget;
} }

View file

@ -6,8 +6,7 @@
#include "itemsettingsdialog.h" #include "itemsettingsdialog.h"
#include "../items/item.h" #include "../items/item.h"
namespace Ui namespace Ui {
{
class ItemWidget; class ItemWidget;
} }

View file

@ -4,7 +4,6 @@
#include "itemsettingsdialog.h" #include "itemsettingsdialog.h"
#include "itemcreationdialog.h" #include "itemcreationdialog.h"
#include "../mainobject.h" #include "../mainobject.h"
#include <QMessageBox>
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) : MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
@ -16,14 +15,9 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
ui->setupUi(this); ui->setupUi(this);
if(!mainObject->master) if(!mainObject->master)
{
connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast); connect(ui->pushButton_broadcast, &QPushButton::clicked, this, &MainWindow::sigBrodcast);
}
else 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_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog())); connect(ui->pushButton_power, SIGNAL(clicked()), this, SLOT(showPowerItemDialog()));
@ -48,14 +42,12 @@ 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, SIGNAL(colorSelected(const QColor)), this, SLOT(slotChangedRgb(const QColor)));
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()));
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, &mainObject->items, &ItemStore::removeItem);
ui->splitter->setStretchFactor(1, 1);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -70,11 +62,6 @@ void MainWindow::showPowerItemDialog()
diag.exec(); diag.exec();
} }
void MainWindow::saved()
{
QMessageBox::information(this, "Saved", "Settings where saved");
}
void MainWindow::slotChangedRgb(const QColor color) void MainWindow::slotChangedRgb(const QColor color)
{ {
_micro->changeRgbColor(color); _micro->changeRgbColor(color);

View file

@ -50,7 +50,6 @@ private slots:
void slotChangedRgb(const QColor color); void slotChangedRgb(const QColor color);
void showPowerItemDialog(); void showPowerItemDialog();
void showItemCreationDialog(); void showItemCreationDialog();
void saved();
public slots: public slots:

View file

@ -42,16 +42,8 @@
<property name="autoFillBackground"> <property name="autoFillBackground">
<bool>false</bool> <bool>false</bool>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QHBoxLayout" name="horizontalLayout_10" stretch="0,1">
<item> <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"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
<item> <item>
<widget class="QLabel" name="label_serialRecive"> <widget class="QLabel" name="label_serialRecive">
@ -86,18 +78,6 @@
</property> </property>
<item> <item>
<widget class="SensorListWidget" name="sensorListView"> <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"> <property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum> <enum>QAbstractItemView::NoSelection</enum>
</property> </property>
@ -155,8 +135,8 @@
</layout> </layout>
</item> </item>
</layout> </layout>
</widget> </item>
<widget class="QWidget" name=""> <item>
<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">
@ -234,8 +214,6 @@
</layout> </layout>
</item> </item>
</layout> </layout>
</widget>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>

View file

@ -4,21 +4,19 @@
#include <QHeaderView> #include <QHeaderView>
#include <QScroller> #include <QScroller>
SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent), SensorListWidget::SensorListWidget(const bool showHidden, QWidget *parent): QTableWidget(parent), showHidden_(showHidden)
showHidden_(showHidden)
{ {
setColumnCount(3); setColumnCount(2);
setSelectionBehavior(QAbstractItemView::SelectRows); setSelectionBehavior(QAbstractItemView::SelectRows);
horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch); horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture); QScroller::grabGesture(this, QScroller::LeftMouseButtonGesture);
setAutoScroll(true); setAutoScroll(true);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
sensorsChanged(std::vector<Sensor>()); setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
verticalHeader()->hide(); setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
} }
SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden, SensorListWidget::SensorListWidget(SensorStore& sensorStore, const bool showHidden, QWidget* parent): QTableWidget (parent), showHidden_(showHidden)
QWidget* parent): QTableWidget (parent), showHidden_(showHidden)
{ {
sensorsChanged(*(sensorStore.getSensors())); sensorsChanged(*(sensorStore.getSensors()));
} }
@ -28,11 +26,17 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
clear(); clear();
setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor")); setHorizontalHeaderItem(0, new QTableWidgetItem("Sensor"));
setHorizontalHeaderItem(1, new QTableWidgetItem("Value")); setHorizontalHeaderItem(1, new QTableWidgetItem("Value"));
setHorizontalHeaderItem(2, new QTableWidgetItem("Time")); size_t nonHiddenCount = sensors.size();
size_t listLen = 0; if(!showHidden_)
{
nonHiddenCount = 0;
for(size_t i = 0; i < sensors.size(); ++i) for(size_t i = 0; i < sensors.size(); ++i)
if(showHidden_ || !sensors[i].hidden) {
++listLen; if(!sensors[i].hidden) nonHiddenCount++;
}
}
size_t listLen = 0;
for(size_t i = 0; i < sensors.size(); ++i) if(showHidden_ || !sensors[i].hidden) ++listLen;
setRowCount(static_cast<int>(listLen)); setRowCount(static_cast<int>(listLen));
size_t row = 0; size_t row = 0;
for(size_t i = 0; i < sensors.size(); ++i) for(size_t i = 0; i < sensors.size(); ++i)
@ -45,31 +49,20 @@ void SensorListWidget::sensorsChanged(std::vector<Sensor> sensors)
if(sensors[i].type == Sensor::TYPE_DOOR) if(sensors[i].type == Sensor::TYPE_DOOR)
{ {
if(static_cast<bool>(sensors[i].field)) if(static_cast<bool>(sensors[i].field)) itemString.append("\"Open\"");
itemString.append("\"Open\"");
else itemString.append("\"Closed\""); else itemString.append("\"Closed\"");
} }
else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT) else if(sensors[i].type == Sensor::TYPE_AUDIO_OUTPUT)
{ {
if(static_cast<bool>(sensors[i].field)) if(static_cast<bool>(sensors[i].field)) itemString.append("\"Playing\"");
itemString.append("\"Playing\"");
else itemString.append("\"Silent\""); else itemString.append("\"Silent\"");
} }
setItem(static_cast<int>(row), 0, new SensorListItem(sensors[i].name + (sensors[i].hidden ? " (H)" : ""), sensors[i])); setItem(static_cast<int>(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? "(H)" : "")));
setItem(static_cast<int>(row), 1, new QTableWidgetItem(itemString)); 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; ++row;
} }
} }
sortItems(0, Qt::AscendingOrder);
resizeColumnsToContents();
}
const Sensor& SensorListWidget::getSensorForIndex(const QModelIndex &index)
{
return static_cast<SensorListItem*>(item(index.row(), 0))->getSensor();
} }
void SensorListWidget::setShowHidden(const bool showHidden) void SensorListWidget::setShowHidden(const bool showHidden)
@ -77,13 +70,3 @@ void SensorListWidget::setShowHidden(const bool showHidden)
showHidden_=showHidden; showHidden_=showHidden;
} }
const Sensor& SensorListItem::getSensor()
{
return sensor;
}
SensorListItem::SensorListItem(const QString& text, const Sensor& sensor):
QTableWidgetItem(text, 1001), sensor(sensor)
{
}

View file

@ -3,15 +3,6 @@
#include <vector> #include <vector>
#include "../sensors/sensor.h" #include "../sensors/sensor.h"
class SensorListItem : public QTableWidgetItem
{
Sensor sensor;
public:
const Sensor& getSensor();
SensorListItem(const QString& text, const Sensor& sensor);
};
class SensorListWidget : public QTableWidget class SensorListWidget : public QTableWidget
{ {
Q_OBJECT Q_OBJECT
@ -20,11 +11,10 @@ class SensorListWidget : public QTableWidget
public: public:
SensorListWidget(const bool showHidden = true, QWidget* parent = nullptr); SensorListWidget(const bool showHidden = true, QWidget *parent = nullptr);
SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr); SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr);
virtual ~SensorListWidget() {} virtual ~SensorListWidget(){}
void setShowHidden(const bool showHidden); void setShowHidden(const bool showHidden);
const Sensor& getSensorForIndex(const QModelIndex &index);
public slots: public slots: