move from tabs to spaces
This commit is contained in:
		
							parent
							
								
									a6aad07f05
								
							
						
					
					
						commit
						fa45072998
					
				
					 86 changed files with 2611 additions and 2486 deletions
				
			
		| 
						 | 
				
			
			@ -19,71 +19,71 @@ Actor::~Actor()
 | 
			
		|||
 | 
			
		||||
void Actor::performAction()
 | 
			
		||||
{
 | 
			
		||||
    if(active)
 | 
			
		||||
    {
 | 
			
		||||
        sigValue(triggerValue);
 | 
			
		||||
    }
 | 
			
		||||
	if(active)
 | 
			
		||||
	{
 | 
			
		||||
		sigValue(triggerValue);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::makeActive()
 | 
			
		||||
{
 | 
			
		||||
    active = true;
 | 
			
		||||
	active = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void Actor::makeInactive()
 | 
			
		||||
{
 | 
			
		||||
    active = false;
 | 
			
		||||
	active = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Actor::actionName()
 | 
			
		||||
{
 | 
			
		||||
    QString string;
 | 
			
		||||
    if(triggerValue == 0 ) string = "off";
 | 
			
		||||
    else if(triggerValue == 1 )  string = "on";
 | 
			
		||||
    else string = "value to " + QString::number(triggerValue);
 | 
			
		||||
    return  string;
 | 
			
		||||
	QString string;
 | 
			
		||||
	if(triggerValue == 0 ) string = "off";
 | 
			
		||||
	else if(triggerValue == 1 )  string = "on";
 | 
			
		||||
	else string = "value to " + QString::number(triggerValue);
 | 
			
		||||
	return  string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::setActive(uint8_t state)
 | 
			
		||||
{
 | 
			
		||||
    state ? makeActive() : makeInactive();
 | 
			
		||||
	state ? makeActive() : makeInactive();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Actor::isActive()
 | 
			
		||||
{
 | 
			
		||||
    return active;
 | 
			
		||||
	return active;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Actor::isExausted()
 | 
			
		||||
{
 | 
			
		||||
    return exausted;
 | 
			
		||||
	return exausted;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
    json["Active"] =  active;
 | 
			
		||||
    json["Exausted"] = exausted;
 | 
			
		||||
    json["TriggerValue"] = triggerValue;
 | 
			
		||||
	Item::store(json);
 | 
			
		||||
	json["Active"] =  active;
 | 
			
		||||
	json["Exausted"] = exausted;
 | 
			
		||||
	json["TriggerValue"] = triggerValue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::load(const QJsonObject& json, const bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Item::load(json, preserve);
 | 
			
		||||
    active = json["Active"].toBool();
 | 
			
		||||
    exausted = json["Exausted"].toBool();
 | 
			
		||||
    triggerValue = json["TriggerValue"].toInt();
 | 
			
		||||
	Item::load(json, preserve);
 | 
			
		||||
	active = json["Active"].toBool();
 | 
			
		||||
	exausted = json["Exausted"].toBool();
 | 
			
		||||
	triggerValue = json["TriggerValue"].toInt();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::setTriggerValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    triggerValue=value;
 | 
			
		||||
	triggerValue=value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t Actor::getTriggerValue()
 | 
			
		||||
{
 | 
			
		||||
    return  triggerValue;
 | 
			
		||||
	return  triggerValue;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::onValueChanged(uint8_t value)
 | 
			
		||||
| 
						 | 
				
			
			@ -93,28 +93,28 @@ void Actor::onValueChanged(uint8_t value)
 | 
			
		|||
 | 
			
		||||
std::shared_ptr<Actor> Actor::createActor(const QString& type)
 | 
			
		||||
{
 | 
			
		||||
    std::shared_ptr<Actor> actor;
 | 
			
		||||
    if(type == "Alarm") actor = std::shared_ptr<Actor>(new AlarmTime());
 | 
			
		||||
    else if(type == "Sensor") actor = std::shared_ptr<Actor>(new SensorActor());
 | 
			
		||||
    else if(type == "Timer") actor = std::shared_ptr<Actor>(new TimerActor());
 | 
			
		||||
    else if(type == "Regulator") actor = std::shared_ptr<Actor>(new Regulator());
 | 
			
		||||
    else if(type == "Polynomal") actor = std::shared_ptr<Actor>(new PolynomalActor());
 | 
			
		||||
    else if(type == "MultiFactor") actor = std::shared_ptr<Actor>(new MultiFactorActor());
 | 
			
		||||
    else if(type == "Actor") actor = std::shared_ptr<Actor>(new Actor());
 | 
			
		||||
    return actor;
 | 
			
		||||
	std::shared_ptr<Actor> actor;
 | 
			
		||||
	if(type == "Alarm") actor = std::shared_ptr<Actor>(new AlarmTime());
 | 
			
		||||
	else if(type == "Sensor") actor = std::shared_ptr<Actor>(new SensorActor());
 | 
			
		||||
	else if(type == "Timer") actor = std::shared_ptr<Actor>(new TimerActor());
 | 
			
		||||
	else if(type == "Regulator") actor = std::shared_ptr<Actor>(new Regulator());
 | 
			
		||||
	else if(type == "Polynomal") actor = std::shared_ptr<Actor>(new PolynomalActor());
 | 
			
		||||
	else if(type == "MultiFactor") actor = std::shared_ptr<Actor>(new MultiFactorActor());
 | 
			
		||||
	else if(type == "Actor") actor = std::shared_ptr<Actor>(new Actor());
 | 
			
		||||
	return actor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<Actor> Actor::loadActor(const QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    QString type = json["Type"].toString("Actor");
 | 
			
		||||
    std::shared_ptr<Actor> actor = createActor(type);
 | 
			
		||||
    if(actor) actor->load(json);
 | 
			
		||||
    return actor;
 | 
			
		||||
	QString type = json["Type"].toString("Actor");
 | 
			
		||||
	std::shared_ptr<Actor> actor = createActor(type);
 | 
			
		||||
	if(actor) actor->load(json);
 | 
			
		||||
	return actor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Actor::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    Item::setValue(value);
 | 
			
		||||
    setActive(value);
 | 
			
		||||
	Item::setValue(value);
 | 
			
		||||
	setActive(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,46 +9,46 @@
 | 
			
		|||
 | 
			
		||||
class Actor : public Item
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    uint8_t triggerValue = 0;
 | 
			
		||||
	uint8_t triggerValue = 0;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    bool active = true;
 | 
			
		||||
    bool exausted = false;
 | 
			
		||||
	bool active = true;
 | 
			
		||||
	bool exausted = false;
 | 
			
		||||
 | 
			
		||||
    void performAction();
 | 
			
		||||
	void performAction();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void sigValue(uint8_t value);
 | 
			
		||||
	void sigValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    virtual void makeActive();
 | 
			
		||||
    virtual void makeInactive();
 | 
			
		||||
    virtual void setActive(uint8_t state);
 | 
			
		||||
    virtual void onValueChanged(uint8_t state);
 | 
			
		||||
	virtual void makeActive();
 | 
			
		||||
	virtual void makeInactive();
 | 
			
		||||
	virtual void setActive(uint8_t state);
 | 
			
		||||
	virtual void onValueChanged(uint8_t state);
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	virtual void setValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    Actor(QObject* parent = nullptr);
 | 
			
		||||
    virtual ~Actor();
 | 
			
		||||
    bool isExausted();
 | 
			
		||||
	Actor(QObject* parent = nullptr);
 | 
			
		||||
	virtual ~Actor();
 | 
			
		||||
	bool isExausted();
 | 
			
		||||
 | 
			
		||||
    virtual QString actionName();
 | 
			
		||||
	virtual QString actionName();
 | 
			
		||||
 | 
			
		||||
    bool isActive();
 | 
			
		||||
    void setTriggerValue(uint8_t value);
 | 
			
		||||
	bool isActive();
 | 
			
		||||
	void setTriggerValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
    uint8_t getTriggerValue();
 | 
			
		||||
	uint8_t getTriggerValue();
 | 
			
		||||
 | 
			
		||||
    static std::shared_ptr<Actor> createActor(const QString& type);
 | 
			
		||||
	static std::shared_ptr<Actor> createActor(const QString& type);
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
    static std::shared_ptr<Actor> loadActor(const QJsonObject& json);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
	static std::shared_ptr<Actor> loadActor(const QJsonObject& json);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ACTOR_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,132 +2,132 @@
 | 
			
		|||
 | 
			
		||||
AlarmTime::AlarmTime(const QDateTime time, QObject *parent) : Actor(parent), time_(time)
 | 
			
		||||
{
 | 
			
		||||
    connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
    timer.setInterval(1000);
 | 
			
		||||
    run();
 | 
			
		||||
	connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
	timer.setInterval(1000);
 | 
			
		||||
	run();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AlarmTime::~AlarmTime()
 | 
			
		||||
{
 | 
			
		||||
    makeInactive();
 | 
			
		||||
	makeInactive();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmTime::run()
 | 
			
		||||
{
 | 
			
		||||
    makeInactive();
 | 
			
		||||
	makeInactive();
 | 
			
		||||
 | 
			
		||||
    active = true;
 | 
			
		||||
    timer.start();
 | 
			
		||||
	active = true;
 | 
			
		||||
	timer.start();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmTime::makeActive()
 | 
			
		||||
{
 | 
			
		||||
    run();
 | 
			
		||||
	run();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString AlarmTime::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name_.size() > 0)return  name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
        string = "Alarm: ";
 | 
			
		||||
        if(repeat_ == REPEAT_DAILY)
 | 
			
		||||
        {
 | 
			
		||||
            string.append("daily ");
 | 
			
		||||
            string.append(time_.toString("HH:mm"));
 | 
			
		||||
        }
 | 
			
		||||
        else if(repeat_ == REPEAT_WEEKLY)
 | 
			
		||||
        {
 | 
			
		||||
            string.append("weekly ");
 | 
			
		||||
            string.append(time_.toString("ddd HH:mm"));
 | 
			
		||||
	if(name_.size() > 0)return  name_;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QString string;
 | 
			
		||||
		string = "Alarm: ";
 | 
			
		||||
		if(repeat_ == REPEAT_DAILY)
 | 
			
		||||
		{
 | 
			
		||||
			string.append("daily ");
 | 
			
		||||
			string.append(time_.toString("HH:mm"));
 | 
			
		||||
		}
 | 
			
		||||
		else if(repeat_ == REPEAT_WEEKLY)
 | 
			
		||||
		{
 | 
			
		||||
			string.append("weekly ");
 | 
			
		||||
			string.append(time_.toString("ddd HH:mm"));
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        else if(repeat_ == REPEAT_MONTHLY)
 | 
			
		||||
        {
 | 
			
		||||
             string.append("monthly ");
 | 
			
		||||
             string.append(time_.toString("dd HH:mm"));
 | 
			
		||||
        }
 | 
			
		||||
        else if(repeat_ == REPEAT_YEARLY)
 | 
			
		||||
        {
 | 
			
		||||
            string.append("yearly ");
 | 
			
		||||
             string.append(time_.toString("dd.mm HH:mm"));
 | 
			
		||||
		}
 | 
			
		||||
		else if(repeat_ == REPEAT_MONTHLY)
 | 
			
		||||
		{
 | 
			
		||||
			string.append("monthly ");
 | 
			
		||||
			string.append(time_.toString("dd HH:mm"));
 | 
			
		||||
		}
 | 
			
		||||
		else if(repeat_ == REPEAT_YEARLY)
 | 
			
		||||
		{
 | 
			
		||||
			string.append("yearly ");
 | 
			
		||||
			string.append(time_.toString("dd.mm HH:mm"));
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        else string.append(time_.toString("dd.mm.yyyy HH:mm"));
 | 
			
		||||
        return string;
 | 
			
		||||
    }
 | 
			
		||||
		}
 | 
			
		||||
		else string.append(time_.toString("dd.mm.yyyy HH:mm"));
 | 
			
		||||
		return string;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmTime::setRepeat(const uint8_t repeat)
 | 
			
		||||
{
 | 
			
		||||
    repeat_=repeat;
 | 
			
		||||
    exausted = false;
 | 
			
		||||
	repeat_=repeat;
 | 
			
		||||
	exausted = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t AlarmTime::getRepeat()
 | 
			
		||||
{
 | 
			
		||||
    return repeat_;
 | 
			
		||||
	return repeat_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QDateTime AlarmTime::getDateTime()
 | 
			
		||||
{
 | 
			
		||||
    return time_;
 | 
			
		||||
	return time_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmTime::makeInactive()
 | 
			
		||||
{
 | 
			
		||||
    timer.stop();
 | 
			
		||||
    active = false;
 | 
			
		||||
	timer.stop();
 | 
			
		||||
	active = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmTime::doTick()
 | 
			
		||||
{
 | 
			
		||||
    if(
 | 
			
		||||
            (
 | 
			
		||||
                (triggerd_ == false)                                                                                           &&
 | 
			
		||||
                (time_.date().year()  == QDate::currentDate().year()  || repeat_ != REPEAT_NEVER)                              &&
 | 
			
		||||
                (time_.date().month() == QDate::currentDate().month() || repeat_ == REPEAT_MONTHLY || repeat_ == REPEAT_DAILY) &&
 | 
			
		||||
                (time_.date().day()   == QDate::currentDate().day()   || repeat_ == REPEAT_DAILY)
 | 
			
		||||
            )
 | 
			
		||||
            ||
 | 
			
		||||
            (
 | 
			
		||||
                (repeat_ == REPEAT_WEEKLY) &&
 | 
			
		||||
                (time_.date().dayOfWeek() == QDate::currentDate().dayOfWeek())
 | 
			
		||||
            )
 | 
			
		||||
      )
 | 
			
		||||
    {
 | 
			
		||||
       if(time_.time().hour() == QTime::currentTime().hour() && time_.time().minute() == QTime::currentTime().minute())
 | 
			
		||||
       {
 | 
			
		||||
           triggerd_=true;
 | 
			
		||||
           performAction();
 | 
			
		||||
           if(repeat_ == REPEAT_NEVER) exausted = true;
 | 
			
		||||
       }
 | 
			
		||||
    }
 | 
			
		||||
    else if( repeat_ != REPEAT_NEVER && time_.time().hour() != QTime::currentTime().hour() ) triggerd_=false;
 | 
			
		||||
	if(
 | 
			
		||||
	    (
 | 
			
		||||
	        (triggerd_ == false)                                                                                           &&
 | 
			
		||||
	        (time_.date().year()  == QDate::currentDate().year()  || repeat_ != REPEAT_NEVER)                              &&
 | 
			
		||||
	        (time_.date().month() == QDate::currentDate().month() || repeat_ == REPEAT_MONTHLY || repeat_ == REPEAT_DAILY) &&
 | 
			
		||||
	        (time_.date().day()   == QDate::currentDate().day()   || repeat_ == REPEAT_DAILY)
 | 
			
		||||
	    )
 | 
			
		||||
	    ||
 | 
			
		||||
	    (
 | 
			
		||||
	        (repeat_ == REPEAT_WEEKLY) &&
 | 
			
		||||
	        (time_.date().dayOfWeek() == QDate::currentDate().dayOfWeek())
 | 
			
		||||
	    )
 | 
			
		||||
	)
 | 
			
		||||
	{
 | 
			
		||||
		if(time_.time().hour() == QTime::currentTime().hour() && time_.time().minute() == QTime::currentTime().minute())
 | 
			
		||||
		{
 | 
			
		||||
			triggerd_=true;
 | 
			
		||||
			performAction();
 | 
			
		||||
			if(repeat_ == REPEAT_NEVER) exausted = true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else if( repeat_ != REPEAT_NEVER && time_.time().hour() != QTime::currentTime().hour() ) triggerd_=false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmTime::changeTime(const QDateTime& time)
 | 
			
		||||
{
 | 
			
		||||
    time_=time;
 | 
			
		||||
    exausted = false;
 | 
			
		||||
    qDebug()<<"time: "<<time_;
 | 
			
		||||
	time_=time;
 | 
			
		||||
	exausted = false;
 | 
			
		||||
	qDebug()<<"time: "<<time_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void AlarmTime::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Alarm";
 | 
			
		||||
    Actor::store(json);
 | 
			
		||||
    json["Time"] = time_.toString();
 | 
			
		||||
    json["Repeat"] = repeat_;
 | 
			
		||||
	json["Type"] = "Alarm";
 | 
			
		||||
	Actor::store(json);
 | 
			
		||||
	json["Time"] = time_.toString();
 | 
			
		||||
	json["Repeat"] = repeat_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmTime::load(const QJsonObject& json, const bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    bool oldActive = isActive();
 | 
			
		||||
    Actor::load(json, preserve);
 | 
			
		||||
    time_ = QDateTime::fromString(json["Time"].toString(""));
 | 
			
		||||
    repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
 | 
			
		||||
    if(oldActive != isActive()) setActive(isActive());
 | 
			
		||||
	bool oldActive = isActive();
 | 
			
		||||
	Actor::load(json, preserve);
 | 
			
		||||
	time_ = QDateTime::fromString(json["Time"].toString(""));
 | 
			
		||||
	repeat_ = json["Repeat"].toInt(REPEAT_NEVER);
 | 
			
		||||
	if(oldActive != isActive()) setActive(isActive());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,41 +14,41 @@
 | 
			
		|||
 | 
			
		||||
class AlarmTime :  public Actor, public QRunnable
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
    static const uint8_t REPEAT_NEVER = 0;
 | 
			
		||||
    static const uint8_t REPEAT_DAILY = 1;
 | 
			
		||||
    static const uint8_t REPEAT_WEEKLY = 2;
 | 
			
		||||
    static const uint8_t REPEAT_MONTHLY = 3;
 | 
			
		||||
    static const uint8_t REPEAT_YEARLY = 4;
 | 
			
		||||
	static const uint8_t REPEAT_NEVER = 0;
 | 
			
		||||
	static const uint8_t REPEAT_DAILY = 1;
 | 
			
		||||
	static const uint8_t REPEAT_WEEKLY = 2;
 | 
			
		||||
	static const uint8_t REPEAT_MONTHLY = 3;
 | 
			
		||||
	static const uint8_t REPEAT_YEARLY = 4;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    bool triggerd_ = false;
 | 
			
		||||
    QDateTime time_;
 | 
			
		||||
    QTimer timer;
 | 
			
		||||
    uint8_t repeat_ = REPEAT_NEVER;
 | 
			
		||||
	bool triggerd_ = false;
 | 
			
		||||
	QDateTime time_;
 | 
			
		||||
	QTimer timer;
 | 
			
		||||
	uint8_t repeat_ = REPEAT_NEVER;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit AlarmTime(const QDateTime time = QDateTime::currentDateTime(), QObject *parent = nullptr);
 | 
			
		||||
    ~AlarmTime();
 | 
			
		||||
	explicit AlarmTime(const QDateTime time = QDateTime::currentDateTime(), QObject *parent = nullptr);
 | 
			
		||||
	~AlarmTime();
 | 
			
		||||
 | 
			
		||||
    QDateTime getDateTime();
 | 
			
		||||
	QDateTime getDateTime();
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
 | 
			
		||||
    uint8_t getRepeat();
 | 
			
		||||
	uint8_t getRepeat();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void run();
 | 
			
		||||
    virtual void makeActive();
 | 
			
		||||
    virtual void makeInactive();
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
    void doTick();
 | 
			
		||||
    void changeTime(const QDateTime& time);
 | 
			
		||||
    void setRepeat(const uint8_t repeat);
 | 
			
		||||
	void run();
 | 
			
		||||
	virtual void makeActive();
 | 
			
		||||
	virtual void makeInactive();
 | 
			
		||||
	virtual QString getName() const;
 | 
			
		||||
	void doTick();
 | 
			
		||||
	void changeTime(const QDateTime& time);
 | 
			
		||||
	void setRepeat(const uint8_t repeat);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ALARMTIME_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,79 +1,79 @@
 | 
			
		|||
#include "factoractor.h"
 | 
			
		||||
 | 
			
		||||
MultiFactorActor::MultiFactorActor(Actor* factorActor, const uint preCancleMin, QObject *parent):
 | 
			
		||||
    Actor(parent),
 | 
			
		||||
    factorActor_(factorActor),
 | 
			
		||||
    preCancleMin_(preCancleMin)
 | 
			
		||||
	Actor(parent),
 | 
			
		||||
	factorActor_(factorActor),
 | 
			
		||||
	preCancleMin_(preCancleMin)
 | 
			
		||||
{
 | 
			
		||||
    activationTime.setMSecsSinceEpoch(0);
 | 
			
		||||
    if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
 | 
			
		||||
	activationTime.setMSecsSinceEpoch(0);
 | 
			
		||||
	if(factorActor) connect(factorActor, &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiFactorActor::factorActorSlot(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    if(value == factorDirection)
 | 
			
		||||
    {
 | 
			
		||||
        activationTime = QDateTime::currentDateTime();
 | 
			
		||||
    }
 | 
			
		||||
	if(value == factorDirection)
 | 
			
		||||
	{
 | 
			
		||||
		activationTime = QDateTime::currentDateTime();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiFactorActor::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    if(value)
 | 
			
		||||
    {
 | 
			
		||||
        QDateTime current = QDateTime::currentDateTime();
 | 
			
		||||
        if(current.addSecs(-preCancleMin_*60) > activationTime )
 | 
			
		||||
        {
 | 
			
		||||
            performAction();
 | 
			
		||||
        }
 | 
			
		||||
        bool exausted = true;
 | 
			
		||||
        for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
 | 
			
		||||
    }
 | 
			
		||||
	if(value)
 | 
			
		||||
	{
 | 
			
		||||
		QDateTime current = QDateTime::currentDateTime();
 | 
			
		||||
		if(current.addSecs(-preCancleMin_*60) > activationTime )
 | 
			
		||||
		{
 | 
			
		||||
			performAction();
 | 
			
		||||
		}
 | 
			
		||||
		bool exausted = true;
 | 
			
		||||
		for(size_t i = 0; i < getActors().size(); ++i) if(!getActors()[i]->isExausted()) exausted = false;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString MultiFactorActor::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name_.size() > 0) return name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
        string = "Multi Factor \"" + (factorActor_ ? factorActor_->getName() : "NULL") + "\"";
 | 
			
		||||
        return string;
 | 
			
		||||
    }
 | 
			
		||||
	if(name_.size() > 0) return name_;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QString string;
 | 
			
		||||
		string = "Multi Factor \"" + (factorActor_ ? factorActor_->getName() : "NULL") + "\"";
 | 
			
		||||
		return string;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiFactorActor::setFactorActor(std::shared_ptr<Actor> factorActor)
 | 
			
		||||
{
 | 
			
		||||
    factorActor_=factorActor;
 | 
			
		||||
    connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
 | 
			
		||||
	factorActor_=factorActor;
 | 
			
		||||
	connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiFactorActor::store(QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "MultiFactor";
 | 
			
		||||
    Actor::store(json);
 | 
			
		||||
    json["PreCancleMinutes"] = static_cast<int>(preCancleMin_);
 | 
			
		||||
    json["FactorDirection"] = factorDirection;
 | 
			
		||||
    QJsonObject factorActorObject;
 | 
			
		||||
    if(factorActor_)
 | 
			
		||||
    {
 | 
			
		||||
        factorActor_->store(factorActorObject);
 | 
			
		||||
    }
 | 
			
		||||
	json["Type"] = "MultiFactor";
 | 
			
		||||
	Actor::store(json);
 | 
			
		||||
	json["PreCancleMinutes"] = static_cast<int>(preCancleMin_);
 | 
			
		||||
	json["FactorDirection"] = factorDirection;
 | 
			
		||||
	QJsonObject factorActorObject;
 | 
			
		||||
	if(factorActor_)
 | 
			
		||||
	{
 | 
			
		||||
		factorActor_->store(factorActorObject);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MultiFactorActor::load(const QJsonObject &json, bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Actor::load(json, preserve);
 | 
			
		||||
    preCancleMin_ = static_cast<uint>(json["PreCancleMinutes"].toInt(10));
 | 
			
		||||
    factorDirection = json["FacotorDirection"].toBool(true);
 | 
			
		||||
    if(json["FactorActor"].isObject())
 | 
			
		||||
    {
 | 
			
		||||
        factorActor_ = Actor::loadActor(json["FactorActor"].toObject());
 | 
			
		||||
    }
 | 
			
		||||
    if(factorActor_)
 | 
			
		||||
    {
 | 
			
		||||
        connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
 | 
			
		||||
    }
 | 
			
		||||
	Actor::load(json, preserve);
 | 
			
		||||
	preCancleMin_ = static_cast<uint>(json["PreCancleMinutes"].toInt(10));
 | 
			
		||||
	factorDirection = json["FacotorDirection"].toBool(true);
 | 
			
		||||
	if(json["FactorActor"].isObject())
 | 
			
		||||
	{
 | 
			
		||||
		factorActor_ = Actor::loadActor(json["FactorActor"].toObject());
 | 
			
		||||
	}
 | 
			
		||||
	if(factorActor_)
 | 
			
		||||
	{
 | 
			
		||||
		connect(factorActor_.get(), &Actor::sigValue, this, &MultiFactorActor::factorActorSlot);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,37 +8,52 @@ class MultiFactorActor: public Actor
 | 
			
		|||
{
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<Actor> factorActor_;
 | 
			
		||||
    QDateTime activationTime;
 | 
			
		||||
    uint preCancleMin_;
 | 
			
		||||
	std::shared_ptr<Actor> factorActor_;
 | 
			
		||||
	QDateTime activationTime;
 | 
			
		||||
	uint preCancleMin_;
 | 
			
		||||
 | 
			
		||||
    bool factorDirection = true;
 | 
			
		||||
	bool factorDirection = true;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void factorActorSlot(uint8_t value);
 | 
			
		||||
	void factorActorSlot(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	virtual void setValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
 | 
			
		||||
	MultiFactorActor(Actor* FactorActor = nullptr, const uint preCancleMin = 10, QObject *parent = nullptr);
 | 
			
		||||
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
	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;}
 | 
			
		||||
	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;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    virtual ~MultiFactorActor(){}
 | 
			
		||||
	virtual ~MultiFactorActor() {}
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // REMINDERACTOR_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,72 +12,74 @@ PolynomalActor::PolynomalActor(QObject* parent): Actor(parent)
 | 
			
		|||
 | 
			
		||||
void PolynomalActor::setSensor(const Sensor sensor)
 | 
			
		||||
{
 | 
			
		||||
    sensor_ = sensor;
 | 
			
		||||
	sensor_ = sensor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void PolynomalActor::setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 )
 | 
			
		||||
{
 | 
			
		||||
    pow3_=pow3;
 | 
			
		||||
    pow2_=pow2;
 | 
			
		||||
    pow1_=pow1;
 | 
			
		||||
    pow0_=pow0;
 | 
			
		||||
	pow3_=pow3;
 | 
			
		||||
	pow2_=pow2;
 | 
			
		||||
	pow1_=pow1;
 | 
			
		||||
	pow0_=pow0;
 | 
			
		||||
}
 | 
			
		||||
void PolynomalActor::getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 )
 | 
			
		||||
{
 | 
			
		||||
    pow3=pow3_;
 | 
			
		||||
    pow2=pow2_;
 | 
			
		||||
    pow1=pow1_;
 | 
			
		||||
    pow0=pow0_;
 | 
			
		||||
	pow3=pow3_;
 | 
			
		||||
	pow2=pow2_;
 | 
			
		||||
	pow1=pow1_;
 | 
			
		||||
	pow0=pow0_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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_;
 | 
			
		||||
        if(result < 0) result = 0;
 | 
			
		||||
        else if(result > 254) result = 255;
 | 
			
		||||
        if(result != prevValue)sigValue(static_cast<uint8_t>(result));
 | 
			
		||||
        prevValue = result;
 | 
			
		||||
    }
 | 
			
		||||
	if(active && sensor == sensor_)
 | 
			
		||||
	{
 | 
			
		||||
		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));
 | 
			
		||||
		prevValue = result;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PolynomalActor::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Polynomal";
 | 
			
		||||
    Actor::store(json);
 | 
			
		||||
    json["Pow3"] = pow3_;
 | 
			
		||||
    json["Pow2"] = pow2_;
 | 
			
		||||
    json["Pow1"] = pow1_;
 | 
			
		||||
    json["Pow0"] = pow0_;
 | 
			
		||||
    json["SensorType"] = static_cast<int>(sensor_.type);
 | 
			
		||||
    json["SensorId"] = static_cast<int>(sensor_.id);
 | 
			
		||||
    json["SensorField"] = sensor_.field;
 | 
			
		||||
    json["SensorName"] = sensor_.name;
 | 
			
		||||
	json["Type"] = "Polynomal";
 | 
			
		||||
	Actor::store(json);
 | 
			
		||||
	json["Pow3"] = pow3_;
 | 
			
		||||
	json["Pow2"] = pow2_;
 | 
			
		||||
	json["Pow1"] = pow1_;
 | 
			
		||||
	json["Pow0"] = pow0_;
 | 
			
		||||
	json["SensorType"] = static_cast<int>(sensor_.type);
 | 
			
		||||
	json["SensorId"] = static_cast<int>(sensor_.id);
 | 
			
		||||
	json["SensorField"] = sensor_.field;
 | 
			
		||||
	json["SensorName"] = sensor_.name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PolynomalActor::load(const QJsonObject& json, bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Actor::load(json, preserve);
 | 
			
		||||
    pow3_ = json["Pow3"].toDouble(0);
 | 
			
		||||
    pow2_ = json["Pow2"].toDouble(0);
 | 
			
		||||
    pow1_ = json["Pow1"].toDouble(1);
 | 
			
		||||
    pow0_ = json["Pow0"].toDouble(0);
 | 
			
		||||
    sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
    sensor_.id = json["SensorId"].toInt(0);
 | 
			
		||||
    sensor_.field = json["SensorField"].toInt(0);
 | 
			
		||||
    sensor_.name = json["SensorName"].toString("Sensor");
 | 
			
		||||
	Actor::load(json, preserve);
 | 
			
		||||
	pow3_ = json["Pow3"].toDouble(0);
 | 
			
		||||
	pow2_ = json["Pow2"].toDouble(0);
 | 
			
		||||
	pow1_ = json["Pow1"].toDouble(1);
 | 
			
		||||
	pow0_ = json["Pow0"].toDouble(0);
 | 
			
		||||
	sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
	sensor_.id = json["SensorId"].toInt(0);
 | 
			
		||||
	sensor_.field = json["SensorField"].toInt(0);
 | 
			
		||||
	sensor_.name = json["SensorName"].toString("Sensor");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString PolynomalActor::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name_.size() > 0) return name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
        string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
 | 
			
		||||
        return string;
 | 
			
		||||
    }
 | 
			
		||||
	if(name_.size() > 0) return name_;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QString string;
 | 
			
		||||
		string = QString::number(pow3_) + "x^3 + " + QString::number(pow2_) + "x^2 + " + QString::number(
 | 
			
		||||
		             pow1_) + "x + " + QString::number(pow0_) + " (x: " + sensor_.name + ")";
 | 
			
		||||
		return string;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,35 +5,38 @@
 | 
			
		|||
 | 
			
		||||
class PolynomalActor: public Actor
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Sensor sensor_;
 | 
			
		||||
    double pow3_ = 0;
 | 
			
		||||
    double pow2_ = 0;
 | 
			
		||||
    double pow1_ = 1;
 | 
			
		||||
    double pow0_ = 0;
 | 
			
		||||
	Sensor sensor_;
 | 
			
		||||
	double pow3_ = 0;
 | 
			
		||||
	double pow2_ = 0;
 | 
			
		||||
	double pow1_ = 1;
 | 
			
		||||
	double pow0_ = 0;
 | 
			
		||||
 | 
			
		||||
    double prevValue = -1;
 | 
			
		||||
	double prevValue = -1;
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void sensorEvent(Sensor sensor);
 | 
			
		||||
	void sensorEvent(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    void setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 );
 | 
			
		||||
    void getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 );
 | 
			
		||||
	void setCoeffiancts( const double pow3, const double pow2, const double pow1, const double pow0 );
 | 
			
		||||
	void getCoeffiancts( double& pow3, double& pow2, double& pow1, double& pow0 );
 | 
			
		||||
 | 
			
		||||
    PolynomalActor(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
    PolynomalActor(QObject* parent = nullptr);
 | 
			
		||||
    void setSensor(const Sensor sensor);
 | 
			
		||||
    Sensor getSensor(){return sensor_;}
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
    virtual ~PolynomalActor(){}
 | 
			
		||||
	PolynomalActor(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
	PolynomalActor(QObject* parent = nullptr);
 | 
			
		||||
	void setSensor(const Sensor sensor);
 | 
			
		||||
	Sensor getSensor()
 | 
			
		||||
	{
 | 
			
		||||
		return sensor_;
 | 
			
		||||
	}
 | 
			
		||||
	virtual QString getName() const;
 | 
			
		||||
	virtual ~PolynomalActor() {}
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // POLYNOMALACTOR_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,72 +14,72 @@ Regulator::Regulator(QObject* parent): Actor(parent)
 | 
			
		|||
 | 
			
		||||
void Regulator::setSensor(const Sensor sensor)
 | 
			
		||||
{
 | 
			
		||||
    sensor_ = sensor;
 | 
			
		||||
	sensor_ = sensor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Regulator::sensorEvent(Sensor sensor)
 | 
			
		||||
{
 | 
			
		||||
    if(active && sensor == sensor_)
 | 
			
		||||
    {
 | 
			
		||||
        if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
 | 
			
		||||
        {
 | 
			
		||||
           sigValue(triggerValue);
 | 
			
		||||
        }
 | 
			
		||||
        else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
 | 
			
		||||
        {
 | 
			
		||||
            sigValue(!triggerValue);
 | 
			
		||||
        }
 | 
			
		||||
        first = false;
 | 
			
		||||
        sensor_ = sensor;
 | 
			
		||||
    }
 | 
			
		||||
	if(active && sensor == sensor_)
 | 
			
		||||
	{
 | 
			
		||||
		if( sensor.field < setPoint_-band_ && (sensor.field < sensor_.field || sensor_.field > setPoint_-band_ || first) )
 | 
			
		||||
		{
 | 
			
		||||
			sigValue(triggerValue);
 | 
			
		||||
		}
 | 
			
		||||
		else if( sensor.field > setPoint_+band_ && (sensor.field > sensor_.field || sensor_.field < setPoint_+band_ || first) )
 | 
			
		||||
		{
 | 
			
		||||
			sigValue(!triggerValue);
 | 
			
		||||
		}
 | 
			
		||||
		first = false;
 | 
			
		||||
		sensor_ = sensor;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Regulator::setPoint(float setPoint)
 | 
			
		||||
{
 | 
			
		||||
    setPoint_ = setPoint;
 | 
			
		||||
	setPoint_ = setPoint;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Regulator::setBand ( float band )
 | 
			
		||||
{
 | 
			
		||||
    band_ = band;
 | 
			
		||||
	band_ = band;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Regulator::setInvert( bool invert )
 | 
			
		||||
{
 | 
			
		||||
    invert_ = invert;
 | 
			
		||||
	invert_ = invert;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Regulator::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Regulator";
 | 
			
		||||
    Actor::store(json);
 | 
			
		||||
    json["Band"] = band_;
 | 
			
		||||
    json["SetPoint"] = setPoint_;
 | 
			
		||||
    json["SensorType"] = static_cast<int>(sensor_.type);
 | 
			
		||||
    json["SensorId"] = static_cast<int>(sensor_.id);
 | 
			
		||||
    json["SensorField"] = sensor_.field;
 | 
			
		||||
    json["SensorName"] = sensor_.name;
 | 
			
		||||
	json["Type"] = "Regulator";
 | 
			
		||||
	Actor::store(json);
 | 
			
		||||
	json["Band"] = band_;
 | 
			
		||||
	json["SetPoint"] = setPoint_;
 | 
			
		||||
	json["SensorType"] = static_cast<int>(sensor_.type);
 | 
			
		||||
	json["SensorId"] = static_cast<int>(sensor_.id);
 | 
			
		||||
	json["SensorField"] = sensor_.field;
 | 
			
		||||
	json["SensorName"] = sensor_.name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Regulator::load(const QJsonObject& json, bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Actor::load(json, preserve);
 | 
			
		||||
    band_ = json["Band"].toDouble(1);
 | 
			
		||||
    setPoint_ = json["SetPoint"].toDouble(22);
 | 
			
		||||
    sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
    sensor_.id = json["SensorId"].toInt(0);
 | 
			
		||||
    sensor_.field = json["SensorField"].toInt(0);
 | 
			
		||||
    sensor_.name = json["SensorName"].toString("Sensor");
 | 
			
		||||
	Actor::load(json, preserve);
 | 
			
		||||
	band_ = json["Band"].toDouble(1);
 | 
			
		||||
	setPoint_ = json["SetPoint"].toDouble(22);
 | 
			
		||||
	sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
	sensor_.id = json["SensorId"].toInt(0);
 | 
			
		||||
	sensor_.field = json["SensorField"].toInt(0);
 | 
			
		||||
	sensor_.name = json["SensorName"].toString("Sensor");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString Regulator::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name_.size() > 0) return name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
        string = "Regulate \"" + sensor_.name + "\" to ";
 | 
			
		||||
        string.append(QString::number(setPoint_) + " ");
 | 
			
		||||
        return string;
 | 
			
		||||
    }
 | 
			
		||||
	if(name_.size() > 0) return name_;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QString string;
 | 
			
		||||
		string = "Regulate \"" + sensor_.name + "\" to ";
 | 
			
		||||
		string.append(QString::number(setPoint_) + " ");
 | 
			
		||||
		return string;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,35 +4,44 @@
 | 
			
		|||
 | 
			
		||||
class Regulator : public Actor
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Sensor sensor_;
 | 
			
		||||
    float setPoint_ = 0;
 | 
			
		||||
    float band_ = 1;
 | 
			
		||||
    bool invert_ = false;
 | 
			
		||||
	Sensor sensor_;
 | 
			
		||||
	float setPoint_ = 0;
 | 
			
		||||
	float band_ = 1;
 | 
			
		||||
	bool invert_ = false;
 | 
			
		||||
 | 
			
		||||
    bool first = true;
 | 
			
		||||
	bool first = true;
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void sensorEvent(Sensor sensor);
 | 
			
		||||
	void sensorEvent(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
    void setSensor(const Sensor sensor);
 | 
			
		||||
    void setPoint( float setPoint );
 | 
			
		||||
    void setBand ( float band );
 | 
			
		||||
    void setInvert( bool invert );
 | 
			
		||||
	void setSensor(const Sensor sensor);
 | 
			
		||||
	void setPoint( float setPoint );
 | 
			
		||||
	void setBand ( float band );
 | 
			
		||||
	void setInvert( bool invert );
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    float getBand() {return  band_;}
 | 
			
		||||
    float getSetPoint() {return  setPoint_;}
 | 
			
		||||
    Regulator(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
    Regulator(QObject* parent = nullptr);
 | 
			
		||||
    Sensor getSensor(){return sensor_;}
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
    virtual ~Regulator(){}    
 | 
			
		||||
    
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
	float getBand()
 | 
			
		||||
	{
 | 
			
		||||
		return  band_;
 | 
			
		||||
	}
 | 
			
		||||
	float getSetPoint()
 | 
			
		||||
	{
 | 
			
		||||
		return  setPoint_;
 | 
			
		||||
	}
 | 
			
		||||
	Regulator(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
	Regulator(QObject* parent = nullptr);
 | 
			
		||||
	Sensor getSensor()
 | 
			
		||||
	{
 | 
			
		||||
		return sensor_;
 | 
			
		||||
	}
 | 
			
		||||
	virtual QString getName() const;
 | 
			
		||||
	virtual ~Regulator() {}
 | 
			
		||||
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,74 +14,76 @@ SensorActor::SensorActor(QObject* parent): Actor(parent)
 | 
			
		|||
 | 
			
		||||
void SensorActor::setSensor(const Sensor sensor)
 | 
			
		||||
{
 | 
			
		||||
    sensor_ = sensor;
 | 
			
		||||
	sensor_ = sensor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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();
 | 
			
		||||
        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();
 | 
			
		||||
		sensor_ = sensor;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorActor::setSloap(uint8_t sloap)
 | 
			
		||||
{
 | 
			
		||||
    sloap_=sloap;
 | 
			
		||||
	sloap_=sloap;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorActor::setThreshold(float threshold)
 | 
			
		||||
{
 | 
			
		||||
    threshold_ = threshold;
 | 
			
		||||
	threshold_ = threshold;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float SensorActor::getThreshold()
 | 
			
		||||
{
 | 
			
		||||
    return threshold_;
 | 
			
		||||
	return threshold_;
 | 
			
		||||
}
 | 
			
		||||
uint8_t SensorActor::getSloap()
 | 
			
		||||
{
 | 
			
		||||
    return sloap_;
 | 
			
		||||
	return sloap_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorActor::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Sensor";
 | 
			
		||||
    Actor::store(json);
 | 
			
		||||
    json["Sloap"] = sloap_;
 | 
			
		||||
    json["Threshold"] = threshold_;
 | 
			
		||||
    json["SensorType"] = static_cast<int>(sensor_.type);
 | 
			
		||||
    json["SensorId"] = static_cast<int>(sensor_.id);
 | 
			
		||||
    json["SensorField"] = sensor_.field;
 | 
			
		||||
    json["SensorName"] = sensor_.name;
 | 
			
		||||
	json["Type"] = "Sensor";
 | 
			
		||||
	Actor::store(json);
 | 
			
		||||
	json["Sloap"] = sloap_;
 | 
			
		||||
	json["Threshold"] = threshold_;
 | 
			
		||||
	json["SensorType"] = static_cast<int>(sensor_.type);
 | 
			
		||||
	json["SensorId"] = static_cast<int>(sensor_.id);
 | 
			
		||||
	json["SensorField"] = sensor_.field;
 | 
			
		||||
	json["SensorName"] = sensor_.name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorActor::load(const QJsonObject& json, bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Actor::load(json, preserve);
 | 
			
		||||
    sloap_ = json["Sloap"].toInt(0);
 | 
			
		||||
    threshold_ = json["Threshold"].toDouble(0);
 | 
			
		||||
    sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
    sensor_.id = json["SensorId"].toInt(0);
 | 
			
		||||
    sensor_.field = json["SensorField"].toInt(0);
 | 
			
		||||
    sensor_.name = json["SensorName"].toString("Sensor");
 | 
			
		||||
	Actor::load(json, preserve);
 | 
			
		||||
	sloap_ = json["Sloap"].toInt(0);
 | 
			
		||||
	threshold_ = json["Threshold"].toDouble(0);
 | 
			
		||||
	sensor_.type = json["SensorType"].toInt(0);
 | 
			
		||||
	sensor_.id = json["SensorId"].toInt(0);
 | 
			
		||||
	sensor_.field = json["SensorField"].toInt(0);
 | 
			
		||||
	sensor_.name = json["SensorName"].toString("Sensor");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString SensorActor::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name_.size() > 0) return name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
        string = "Sensor \"" + sensor_.name + "\"";
 | 
			
		||||
	if(name_.size() > 0) return name_;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QString string;
 | 
			
		||||
		string = "Sensor \"" + sensor_.name + "\"";
 | 
			
		||||
 | 
			
		||||
        if(sloap_ == SLOPE_UP) string.append(" rises to ");
 | 
			
		||||
        else if (sloap_ == SLOPE_DOWN) string.append(" drops to ");
 | 
			
		||||
        else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
 | 
			
		||||
		if(sloap_ == SLOPE_UP) string.append(" rises to ");
 | 
			
		||||
		else if (sloap_ == SLOPE_DOWN) string.append(" drops to ");
 | 
			
		||||
		else if (sloap_ == SLOPE_BOTH) string.append(" passes ");
 | 
			
		||||
 | 
			
		||||
        string.append(QString::number(threshold_) + " ");
 | 
			
		||||
        return string;
 | 
			
		||||
    }
 | 
			
		||||
		string.append(QString::number(threshold_) + " ");
 | 
			
		||||
		return string;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,39 +4,42 @@
 | 
			
		|||
 | 
			
		||||
class SensorActor : public Actor
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    static constexpr uint8_t SLOPE_UP   = 0;
 | 
			
		||||
    static constexpr uint8_t SLOPE_DOWN = 1;
 | 
			
		||||
    static constexpr uint8_t SLOPE_BOTH = 2;
 | 
			
		||||
	static constexpr uint8_t SLOPE_UP   = 0;
 | 
			
		||||
	static constexpr uint8_t SLOPE_DOWN = 1;
 | 
			
		||||
	static constexpr uint8_t SLOPE_BOTH = 2;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Sensor sensor_;
 | 
			
		||||
    uint8_t sloap_ = SLOPE_UP;
 | 
			
		||||
    float threshold_ = 0;
 | 
			
		||||
	Sensor sensor_;
 | 
			
		||||
	uint8_t sloap_ = SLOPE_UP;
 | 
			
		||||
	float threshold_ = 0;
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    
 | 
			
		||||
    void sensorEvent(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
    void setSloap(uint8_t sloap);
 | 
			
		||||
    void setSensor(const Sensor sensor);
 | 
			
		||||
    void setThreshold( float threshold );
 | 
			
		||||
	void sensorEvent(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
	void setSloap(uint8_t sloap);
 | 
			
		||||
	void setSensor(const Sensor sensor);
 | 
			
		||||
	void setThreshold( float threshold );
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    SensorActor(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
    SensorActor(QObject* parent = nullptr);
 | 
			
		||||
    Sensor getSensor(){return sensor_;}
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
    virtual ~SensorActor(){}
 | 
			
		||||
	SensorActor(const Sensor sensor, QObject* parent = nullptr);
 | 
			
		||||
	SensorActor(QObject* parent = nullptr);
 | 
			
		||||
	Sensor getSensor()
 | 
			
		||||
	{
 | 
			
		||||
		return sensor_;
 | 
			
		||||
	}
 | 
			
		||||
	virtual QString getName() const;
 | 
			
		||||
	virtual ~SensorActor() {}
 | 
			
		||||
 | 
			
		||||
    float getThreshold();
 | 
			
		||||
    uint8_t getSloap();
 | 
			
		||||
    
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
	float getThreshold();
 | 
			
		||||
	uint8_t getSloap();
 | 
			
		||||
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,55 +3,55 @@
 | 
			
		|||
 | 
			
		||||
TimerActor::TimerActor(const int timeoutSec, QObject *parent): Actor(parent), timeoutMsec_(timeoutSec*1000)
 | 
			
		||||
{
 | 
			
		||||
    connect(&timer, &QTimer::timeout, this, &TimerActor::timeout);
 | 
			
		||||
    timer.setSingleShot(true);
 | 
			
		||||
	connect(&timer, &QTimer::timeout, this, &TimerActor::timeout);
 | 
			
		||||
	timer.setSingleShot(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerActor::onValueChanged(uint8_t state)
 | 
			
		||||
{
 | 
			
		||||
    if((state && !triggerValue) || (!state && triggerValue))
 | 
			
		||||
    {
 | 
			
		||||
        if(timer.isActive()) timer.stop();
 | 
			
		||||
        timer.setInterval(timeoutMsec_);
 | 
			
		||||
        timer.start();
 | 
			
		||||
    }
 | 
			
		||||
	if((state && !triggerValue) || (!state && triggerValue))
 | 
			
		||||
	{
 | 
			
		||||
		if(timer.isActive()) timer.stop();
 | 
			
		||||
		timer.setInterval(timeoutMsec_);
 | 
			
		||||
		timer.start();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerActor::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Timer";
 | 
			
		||||
    Actor::store(json);
 | 
			
		||||
    json["Timeout"] = timeoutMsec_;
 | 
			
		||||
	json["Type"] = "Timer";
 | 
			
		||||
	Actor::store(json);
 | 
			
		||||
	json["Timeout"] = timeoutMsec_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerActor::load(const QJsonObject& json, bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Actor::load(json, preserve);
 | 
			
		||||
    timeoutMsec_ = json["Timeout"].toInt(10000);
 | 
			
		||||
	Actor::load(json, preserve);
 | 
			
		||||
	timeoutMsec_ = json["Timeout"].toInt(10000);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerActor::setTimeout(const int timeoutSec)
 | 
			
		||||
{
 | 
			
		||||
    timeoutMsec_ = timeoutSec*1000;
 | 
			
		||||
	timeoutMsec_ = timeoutSec*1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int TimerActor::getTimeout()
 | 
			
		||||
{
 | 
			
		||||
    return timeoutMsec_/1000;
 | 
			
		||||
	return timeoutMsec_/1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void TimerActor::timeout()
 | 
			
		||||
{
 | 
			
		||||
    performAction();
 | 
			
		||||
	performAction();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString TimerActor::getName() const
 | 
			
		||||
{
 | 
			
		||||
    if(name_.size() > 0) return name_;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QString string;
 | 
			
		||||
        string = "Timeout after " + QString::number(timeoutMsec_/1000) + " seconds. ";
 | 
			
		||||
        return string;
 | 
			
		||||
    }
 | 
			
		||||
	if(name_.size() > 0) return name_;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QString string;
 | 
			
		||||
		string = "Timeout after " + QString::number(timeoutMsec_/1000) + " seconds. ";
 | 
			
		||||
		return string;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,27 +4,27 @@
 | 
			
		|||
 | 
			
		||||
class TimerActor: public Actor
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    int timeoutMsec_;
 | 
			
		||||
	int timeoutMsec_;
 | 
			
		||||
 | 
			
		||||
    QTimer timer;
 | 
			
		||||
	QTimer timer;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void timeout();
 | 
			
		||||
	void timeout();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    virtual void onValueChanged(uint8_t state);
 | 
			
		||||
    void setTimeout(const int timeoutSec);
 | 
			
		||||
	virtual void onValueChanged(uint8_t state);
 | 
			
		||||
	void setTimeout(const int timeoutSec);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
	explicit TimerActor(const int timeoutSec = 60, QObject *parent = nullptr);
 | 
			
		||||
	virtual QString getName() const;
 | 
			
		||||
 | 
			
		||||
    int getTimeout();
 | 
			
		||||
	int getTimeout();
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, bool preserve);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,15 @@
 | 
			
		|||
#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)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AlarmActions::syncoff()
 | 
			
		||||
{
 | 
			
		||||
    qDebug()<<"syncoff";
 | 
			
		||||
    QProcess::execute ( "syncoff" );
 | 
			
		||||
    a_->exit(0);
 | 
			
		||||
	qDebug()<<"syncoff";
 | 
			
		||||
	QProcess::execute ( "syncoff" );
 | 
			
		||||
	a_->exit(0);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,18 +7,18 @@
 | 
			
		|||
class AlarmActions : public QObject
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    Microcontroller* _micro;
 | 
			
		||||
    QApplication* a_;
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
	Microcontroller* _micro;
 | 
			
		||||
	QApplication* a_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent = nullptr);
 | 
			
		||||
	explicit AlarmActions(QApplication* a, Microcontroller* micro, QObject *parent = nullptr);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void syncoff();
 | 
			
		||||
	void syncoff();
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,159 +14,159 @@
 | 
			
		|||
 | 
			
		||||
namespace ap
 | 
			
		||||
{
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
static int nl80211Init(struct nl_sock* nl_sock, int* nl80211_id)
 | 
			
		||||
{
 | 
			
		||||
    int err;
 | 
			
		||||
	int err;
 | 
			
		||||
 | 
			
		||||
    if (!nl_sock) 
 | 
			
		||||
    {
 | 
			
		||||
            std::cerr<<"Failed to allocate netlink socket.\n";
 | 
			
		||||
            return -ENOMEM;
 | 
			
		||||
    }
 | 
			
		||||
	if (!nl_sock)
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr<<"Failed to allocate netlink socket.\n";
 | 
			
		||||
		return -ENOMEM;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    if (genl_connect(nl_sock)) 
 | 
			
		||||
    {
 | 
			
		||||
            std::cerr<<"Failed to connect to generic netlink.\n";
 | 
			
		||||
            err = -ENOLINK;
 | 
			
		||||
            nl_socket_free(nl_sock);
 | 
			
		||||
            return err;
 | 
			
		||||
    }
 | 
			
		||||
	if (genl_connect(nl_sock))
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr<<"Failed to connect to generic netlink.\n";
 | 
			
		||||
		err = -ENOLINK;
 | 
			
		||||
		nl_socket_free(nl_sock);
 | 
			
		||||
		return err;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    nl_socket_set_buffer_size(nl_sock, 8192, 8192);
 | 
			
		||||
	nl_socket_set_buffer_size(nl_sock, 8192, 8192);
 | 
			
		||||
 | 
			
		||||
    /* try to set NETLINK_EXT_ACK to 1, ignoring errors */
 | 
			
		||||
    err = 1;
 | 
			
		||||
    setsockopt(nl_socket_get_fd(nl_sock), SOL_NETLINK, NETLINK_EXT_ACK, &err, sizeof(err));
 | 
			
		||||
	/* try to set NETLINK_EXT_ACK to 1, ignoring errors */
 | 
			
		||||
	err = 1;
 | 
			
		||||
	setsockopt(nl_socket_get_fd(nl_sock), SOL_NETLINK, NETLINK_EXT_ACK, &err, sizeof(err));
 | 
			
		||||
 | 
			
		||||
    *nl80211_id = genl_ctrl_resolve(nl_sock, "nl80211");
 | 
			
		||||
    if (*nl80211_id < 0)
 | 
			
		||||
    {
 | 
			
		||||
            std::cerr<<"nl80211 not found.\n";
 | 
			
		||||
            err = -ENOENT;
 | 
			
		||||
            nl_socket_free(nl_sock);
 | 
			
		||||
            return err;
 | 
			
		||||
    }
 | 
			
		||||
	*nl80211_id = genl_ctrl_resolve(nl_sock, "nl80211");
 | 
			
		||||
	if (*nl80211_id < 0)
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr<<"nl80211 not found.\n";
 | 
			
		||||
		err = -ENOENT;
 | 
			
		||||
		nl_socket_free(nl_sock);
 | 
			
		||||
		return err;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int errorHandler(struct sockaddr_nl *nla, struct nlmsgerr *err, void *arg)
 | 
			
		||||
{
 | 
			
		||||
    printf("netlink error\n");
 | 
			
		||||
    *reinterpret_cast<int*>(arg) = 0;
 | 
			
		||||
    return NL_STOP;
 | 
			
		||||
	printf("netlink error\n");
 | 
			
		||||
	*reinterpret_cast<int*>(arg) = 0;
 | 
			
		||||
	return NL_STOP;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int finishHandler(struct nl_msg *msg, void *arg)
 | 
			
		||||
{
 | 
			
		||||
    *reinterpret_cast<int*>(arg) = 0;
 | 
			
		||||
    return NL_SKIP;
 | 
			
		||||
	*reinterpret_cast<int*>(arg) = 0;
 | 
			
		||||
	return NL_SKIP;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int ackHandler(struct nl_msg *msg, void *arg)
 | 
			
		||||
{
 | 
			
		||||
    *reinterpret_cast<int*>(arg) = 0;
 | 
			
		||||
    return NL_STOP;
 | 
			
		||||
	*reinterpret_cast<int*>(arg) = 0;
 | 
			
		||||
	return NL_STOP;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
static int extractDeviceMac(struct nl_msg *msg, void *arg)
 | 
			
		||||
{
 | 
			
		||||
    struct nlattr* tb[NL80211_ATTR_MAX + 1];
 | 
			
		||||
    struct genlmsghdr* gnlh = (struct genlmsghdr*)nlmsg_data(nlmsg_hdr(msg));
 | 
			
		||||
    
 | 
			
		||||
    std::vector<uint64_t>* deviceMacAddrs = reinterpret_cast<std::vector<uint64_t>*>(arg);
 | 
			
		||||
    
 | 
			
		||||
    nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
 | 
			
		||||
    if (!tb[NL80211_ATTR_STA_INFO]) 
 | 
			
		||||
    {
 | 
			
		||||
        std::cerr<<"sta stats missing!\n";
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    const unsigned char* macChar = reinterpret_cast<const unsigned char*>(nla_data(tb[NL80211_ATTR_MAC]));
 | 
			
		||||
    uint64_t macAddr = 0;
 | 
			
		||||
    memcpy(&macAddr, macChar, 6);
 | 
			
		||||
    deviceMacAddrs->push_back(macAddr);
 | 
			
		||||
    
 | 
			
		||||
    return 0;
 | 
			
		||||
	struct nlattr* tb[NL80211_ATTR_MAX + 1];
 | 
			
		||||
	struct genlmsghdr* gnlh = (struct genlmsghdr*)nlmsg_data(nlmsg_hdr(msg));
 | 
			
		||||
 | 
			
		||||
	std::vector<uint64_t>* deviceMacAddrs = reinterpret_cast<std::vector<uint64_t>*>(arg);
 | 
			
		||||
 | 
			
		||||
	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NULL);
 | 
			
		||||
	if (!tb[NL80211_ATTR_STA_INFO])
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr<<"sta stats missing!\n";
 | 
			
		||||
		return -1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	const unsigned char* macChar = reinterpret_cast<const unsigned char*>(nla_data(tb[NL80211_ATTR_MAC]));
 | 
			
		||||
	uint64_t macAddr = 0;
 | 
			
		||||
	memcpy(&macAddr, macChar, 6);
 | 
			
		||||
	deviceMacAddrs->push_back(macAddr);
 | 
			
		||||
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector<uint64_t> connectedDevices(const std::string& ifDevice, int& error)
 | 
			
		||||
{
 | 
			
		||||
    struct nl_sock* nl_sock = nl_socket_alloc();
 | 
			
		||||
    int nl80211_id = 0;
 | 
			
		||||
    error = 0;
 | 
			
		||||
    
 | 
			
		||||
    if(nl80211Init(nl_sock, &nl80211_id)) 
 | 
			
		||||
    {
 | 
			
		||||
        std::cerr<<"Can not init nl80211\n";
 | 
			
		||||
        error = ERR_INIT;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    signed long long devidx = if_nametoindex(ifDevice.c_str());
 | 
			
		||||
    if(!devidx) 
 | 
			
		||||
    {
 | 
			
		||||
        std::cerr<<ifDevice<<" is not a valid if device\n";
 | 
			
		||||
        error = ERR_NO_DEV;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    struct nl_msg *msg;
 | 
			
		||||
    msg = nlmsg_alloc();
 | 
			
		||||
    if(!msg) error = ERR_ALLOC;
 | 
			
		||||
    
 | 
			
		||||
    struct nl_cb *cb = nl_cb_alloc(NL_CB_DEFAULT);
 | 
			
		||||
    struct nl_cb *s_cb = nl_cb_alloc(NL_CB_DEFAULT);
 | 
			
		||||
    if (!cb || !s_cb)  error = ERR_ALLOC;
 | 
			
		||||
    
 | 
			
		||||
    std::vector<uint64_t> deviceMacAddrs;
 | 
			
		||||
    
 | 
			
		||||
    if(error == 0)
 | 
			
		||||
    {
 | 
			
		||||
        if(!genlmsg_put(msg, 0, 0, nl80211_id, 0, NLM_F_DUMP, NL80211_CMD_GET_STATION, 0))
 | 
			
		||||
        {
 | 
			
		||||
            std::cerr<<"genlmsg_put() failed\n";
 | 
			
		||||
            error = ERR_GENERAL;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        if(error == 0)
 | 
			
		||||
        {
 | 
			
		||||
            NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, devidx);
 | 
			
		||||
            
 | 
			
		||||
            nl_socket_set_cb(nl_sock, s_cb);
 | 
			
		||||
            nl_send_auto_complete(nl_sock, msg);
 | 
			
		||||
            
 | 
			
		||||
            {
 | 
			
		||||
                int ret = 1;
 | 
			
		||||
                
 | 
			
		||||
                nl_cb_err(cb, NL_CB_CUSTOM, errorHandler, &ret);
 | 
			
		||||
                nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finishHandler, &ret);
 | 
			
		||||
                nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ackHandler, &ret);
 | 
			
		||||
                nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, extractDeviceMac, &deviceMacAddrs);
 | 
			
		||||
                
 | 
			
		||||
                while (ret > 0) nl_recvmsgs(nl_sock, cb);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    nla_put_failure:
 | 
			
		||||
    nl_cb_put(cb);
 | 
			
		||||
    nl_cb_put(s_cb);
 | 
			
		||||
    nlmsg_free(msg);
 | 
			
		||||
    nl_socket_free(nl_sock);
 | 
			
		||||
    return deviceMacAddrs;
 | 
			
		||||
	struct nl_sock* nl_sock = nl_socket_alloc();
 | 
			
		||||
	int nl80211_id = 0;
 | 
			
		||||
	error = 0;
 | 
			
		||||
 | 
			
		||||
	if(nl80211Init(nl_sock, &nl80211_id))
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr<<"Can not init nl80211\n";
 | 
			
		||||
		error = ERR_INIT;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	signed long long devidx = if_nametoindex(ifDevice.c_str());
 | 
			
		||||
	if(!devidx)
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr<<ifDevice<<" is not a valid if device\n";
 | 
			
		||||
		error = ERR_NO_DEV;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	struct nl_msg *msg;
 | 
			
		||||
	msg = nlmsg_alloc();
 | 
			
		||||
	if(!msg) error = ERR_ALLOC;
 | 
			
		||||
 | 
			
		||||
	struct nl_cb *cb = nl_cb_alloc(NL_CB_DEFAULT);
 | 
			
		||||
	struct nl_cb *s_cb = nl_cb_alloc(NL_CB_DEFAULT);
 | 
			
		||||
	if (!cb || !s_cb)  error = ERR_ALLOC;
 | 
			
		||||
 | 
			
		||||
	std::vector<uint64_t> deviceMacAddrs;
 | 
			
		||||
 | 
			
		||||
	if(error == 0)
 | 
			
		||||
	{
 | 
			
		||||
		if(!genlmsg_put(msg, 0, 0, nl80211_id, 0, NLM_F_DUMP, NL80211_CMD_GET_STATION, 0))
 | 
			
		||||
		{
 | 
			
		||||
			std::cerr<<"genlmsg_put() failed\n";
 | 
			
		||||
			error = ERR_GENERAL;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if(error == 0)
 | 
			
		||||
		{
 | 
			
		||||
			NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, devidx);
 | 
			
		||||
 | 
			
		||||
			nl_socket_set_cb(nl_sock, s_cb);
 | 
			
		||||
			nl_send_auto_complete(nl_sock, msg);
 | 
			
		||||
 | 
			
		||||
			{
 | 
			
		||||
				int ret = 1;
 | 
			
		||||
 | 
			
		||||
				nl_cb_err(cb, NL_CB_CUSTOM, errorHandler, &ret);
 | 
			
		||||
				nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finishHandler, &ret);
 | 
			
		||||
				nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ackHandler, &ret);
 | 
			
		||||
				nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, extractDeviceMac, &deviceMacAddrs);
 | 
			
		||||
 | 
			
		||||
				while (ret > 0) nl_recvmsgs(nl_sock, cb);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
nla_put_failure:
 | 
			
		||||
	nl_cb_put(cb);
 | 
			
		||||
	nl_cb_put(s_cb);
 | 
			
		||||
	nlmsg_free(msg);
 | 
			
		||||
	nl_socket_free(nl_sock);
 | 
			
		||||
	return deviceMacAddrs;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::string macAddrToString(uint64_t macAddr)
 | 
			
		||||
{
 | 
			
		||||
    unsigned char* macAddrPtr = reinterpret_cast<unsigned char*>(&macAddr);
 | 
			
		||||
    std::stringstream ss;
 | 
			
		||||
    ss<<std::uppercase<<std::setfill('0')<<std::setw(2)<<std::hex;
 | 
			
		||||
    for(unsigned int i = 0; i < 6; ++i) ss<<+macAddrPtr[i]<<':';
 | 
			
		||||
    std::string macString = ss.str();
 | 
			
		||||
    macString.pop_back();
 | 
			
		||||
    return macString;
 | 
			
		||||
	unsigned char* macAddrPtr = reinterpret_cast<unsigned char*>(&macAddr);
 | 
			
		||||
	std::stringstream ss;
 | 
			
		||||
	ss<<std::uppercase<<std::setfill('0')<<std::setw(2)<<std::hex;
 | 
			
		||||
	for(unsigned int i = 0; i < 6; ++i) ss<<+macAddrPtr[i]<<':';
 | 
			
		||||
	std::string macString = ss.str();
 | 
			
		||||
	macString.pop_back();
 | 
			
		||||
	return macString;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,14 +6,14 @@
 | 
			
		|||
 | 
			
		||||
namespace ap
 | 
			
		||||
{
 | 
			
		||||
    enum ERRORS
 | 
			
		||||
    {
 | 
			
		||||
        SUCESS,
 | 
			
		||||
        ERR_INIT,
 | 
			
		||||
        ERR_NO_DEV,
 | 
			
		||||
        ERR_ALLOC,
 | 
			
		||||
        ERR_GENERAL
 | 
			
		||||
    };
 | 
			
		||||
    std::vector<uint64_t> connectedDevices(const std::string& ifDevice, int& error);
 | 
			
		||||
    std::string macAddrToString(uint64_t macAddr);
 | 
			
		||||
enum ERRORS
 | 
			
		||||
{
 | 
			
		||||
	SUCESS,
 | 
			
		||||
	ERR_INIT,
 | 
			
		||||
	ERR_NO_DEV,
 | 
			
		||||
	ERR_ALLOC,
 | 
			
		||||
	ERR_GENERAL
 | 
			
		||||
};
 | 
			
		||||
std::vector<uint64_t> connectedDevices(const std::string& ifDevice, int& error);
 | 
			
		||||
std::string macAddrToString(uint64_t macAddr);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,129 +6,131 @@
 | 
			
		|||
 | 
			
		||||
BroadCast::BroadCast(QIODevice* const iodevice, bool master ):  master_(master), iodevice_(iodevice)
 | 
			
		||||
{
 | 
			
		||||
    if(iodevice_ != nullptr) connect(iodevice_, &QIODevice::readyRead, this, &BroadCast::readyRead);
 | 
			
		||||
	if(iodevice_ != nullptr) connect(iodevice_, &QIODevice::readyRead, this, &BroadCast::readyRead);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BroadCast::write(const char * const buffer, const size_t length)
 | 
			
		||||
{
 | 
			
		||||
    QByteArray mBuffer("bcst: ");
 | 
			
		||||
    for (size_t i = 0; i < length; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if(buffer[i] != '\n' && buffer[i] != '\0') mBuffer.push_back(buffer[i]);
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            mBuffer.push_back('\\');
 | 
			
		||||
            if(buffer[i] == '\n')mBuffer.push_back('n');
 | 
			
		||||
            else mBuffer.push_back('0');
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    mBuffer.push_back('\n');
 | 
			
		||||
    if(iodevice_)iodevice_->write(mBuffer);
 | 
			
		||||
	QByteArray mBuffer("bcst: ");
 | 
			
		||||
	for (size_t i = 0; i < length; ++i)
 | 
			
		||||
	{
 | 
			
		||||
		if(buffer[i] != '\n' && buffer[i] != '\0') mBuffer.push_back(buffer[i]);
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			mBuffer.push_back('\\');
 | 
			
		||||
			if(buffer[i] == '\n')mBuffer.push_back('n');
 | 
			
		||||
			else mBuffer.push_back('0');
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	mBuffer.push_back('\n');
 | 
			
		||||
	if(iodevice_)iodevice_->write(mBuffer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BroadCast::write(const QByteArray& buffer)
 | 
			
		||||
{
 | 
			
		||||
    write(buffer.data(), buffer.size());
 | 
			
		||||
	write(buffer.data(), buffer.size());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BroadCast::sendJson(const QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    QJsonDocument jsonDocument(json);
 | 
			
		||||
    QByteArray buffer("JSON: ");
 | 
			
		||||
    buffer.append(jsonDocument.toJson());
 | 
			
		||||
    write(buffer);
 | 
			
		||||
	QJsonDocument jsonDocument(json);
 | 
			
		||||
	QByteArray buffer("JSON: ");
 | 
			
		||||
	buffer.append(jsonDocument.toJson());
 | 
			
		||||
	write(buffer);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BroadCast::sendSensors()
 | 
			
		||||
{
 | 
			
		||||
    if(iodevice_)for(auto& sensor: *globalSensors.getSensors())
 | 
			
		||||
    {
 | 
			
		||||
        iodevice_->write("bcst: "+sensor.toString().toLatin1()+'\n');
 | 
			
		||||
    }
 | 
			
		||||
	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)
 | 
			
		||||
{
 | 
			
		||||
    if(buffer.startsWith("GETJSN"))
 | 
			
		||||
    {
 | 
			
		||||
        qDebug()<<"json requested";
 | 
			
		||||
        jsonRequested();
 | 
			
		||||
    }
 | 
			
		||||
    else if(buffer.startsWith("GETSENSORS") )
 | 
			
		||||
    {
 | 
			
		||||
        qDebug()<<"sensors requested";
 | 
			
		||||
        sendSensors();
 | 
			
		||||
    }
 | 
			
		||||
	if(buffer.startsWith("GETJSN"))
 | 
			
		||||
	{
 | 
			
		||||
		qDebug()<<"json requested";
 | 
			
		||||
		jsonRequested();
 | 
			
		||||
	}
 | 
			
		||||
	else if(buffer.startsWith("GETSENSORS") )
 | 
			
		||||
	{
 | 
			
		||||
		qDebug()<<"sensors requested";
 | 
			
		||||
		sendSensors();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BroadCast::decode(QByteArray buffer)
 | 
			
		||||
{
 | 
			
		||||
    qDebug()<<"decodeing: "<<buffer;
 | 
			
		||||
    if(buffer.size() >= 6 && buffer[0] == 'J' && buffer[1] == 'S' && buffer[2] == 'O' && buffer[3] == 'N' && buffer[4] == ':')
 | 
			
		||||
    {
 | 
			
		||||
        qDebug()<<"got json";
 | 
			
		||||
        buffer.remove(0,6);
 | 
			
		||||
        for(int i = 0; i < buffer.size()-1; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            if( buffer[i] == '\\' && buffer[i+1] == 'n' )
 | 
			
		||||
            {
 | 
			
		||||
                buffer[i] = '\n';
 | 
			
		||||
                buffer.remove(i+1,1);
 | 
			
		||||
            }
 | 
			
		||||
            else if( buffer[i] == '\\' && buffer[i+1] == '0' )
 | 
			
		||||
            {
 | 
			
		||||
                buffer[i] = '\0';
 | 
			
		||||
                buffer.remove(i+1,1);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
	qDebug()<<"decodeing: "<<buffer;
 | 
			
		||||
	if(buffer.size() >= 6 && buffer[0] == 'J' && buffer[1] == 'S' && buffer[2] == 'O' && buffer[3] == 'N'
 | 
			
		||||
	        && buffer[4] == ':')
 | 
			
		||||
	{
 | 
			
		||||
		qDebug()<<"got json";
 | 
			
		||||
		buffer.remove(0,6);
 | 
			
		||||
		for(int i = 0; i < buffer.size()-1; ++i)
 | 
			
		||||
		{
 | 
			
		||||
			if( buffer[i] == '\\' && buffer[i+1] == 'n' )
 | 
			
		||||
			{
 | 
			
		||||
				buffer[i] = '\n';
 | 
			
		||||
				buffer.remove(i+1,1);
 | 
			
		||||
			}
 | 
			
		||||
			else if( buffer[i] == '\\' && buffer[i+1] == '0' )
 | 
			
		||||
			{
 | 
			
		||||
				buffer[i] = '\0';
 | 
			
		||||
				buffer.remove(i+1,1);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
        QJsonParseError error;
 | 
			
		||||
        QJsonDocument document = QJsonDocument::fromJson(buffer, &error);
 | 
			
		||||
		QJsonParseError error;
 | 
			
		||||
		QJsonDocument document = QJsonDocument::fromJson(buffer, &error);
 | 
			
		||||
 | 
			
		||||
        qDebug()<<"JSON:";
 | 
			
		||||
        qDebug()<<document.toJson().data();
 | 
			
		||||
        QJsonObject jsonObject = document.object();
 | 
			
		||||
        if(error.error == QJsonParseError::NoError && !document.isEmpty() && !jsonObject.isEmpty()) gotJson(jsonObject);
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            qDebug()<<error.errorString();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    else if(buffer.size() >= 6 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'N' && buffer[3] == 'S' && buffer[4] == 'O' && buffer[5] == 'R')
 | 
			
		||||
    {
 | 
			
		||||
        Sensor sensor = Sensor::sensorFromString(buffer);
 | 
			
		||||
        if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
 | 
			
		||||
    }
 | 
			
		||||
		qDebug()<<"JSON:";
 | 
			
		||||
		qDebug()<<document.toJson().data();
 | 
			
		||||
		QJsonObject jsonObject = document.object();
 | 
			
		||||
		if(error.error == QJsonParseError::NoError && !document.isEmpty() && !jsonObject.isEmpty()) gotJson(jsonObject);
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			qDebug()<<error.errorString();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	else if(buffer.size() >= 6 && buffer[0] == 'S' && buffer[1] == 'E' && buffer[2] == 'N' && buffer[3] == 'S'
 | 
			
		||||
	        && buffer[4] == 'O' && buffer[5] == 'R')
 | 
			
		||||
	{
 | 
			
		||||
		Sensor sensor = Sensor::sensorFromString(buffer);
 | 
			
		||||
		if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BroadCast::sendMessage(const QString &title, const QString &body)
 | 
			
		||||
{
 | 
			
		||||
    write(QByteArray("MESG ") + title.toLatin1() + " BODY " + body.toLatin1());
 | 
			
		||||
	write(QByteArray("MESG ") + title.toLatin1() + " BODY " + body.toLatin1());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void BroadCast::readyRead()
 | 
			
		||||
{
 | 
			
		||||
    buffer_.append(iodevice_->readAll());
 | 
			
		||||
    int newlineIndex = buffer_.indexOf('\n');
 | 
			
		||||
    while( newlineIndex != -1 )
 | 
			
		||||
    {
 | 
			
		||||
        if(buffer_.startsWith("bcst: "))
 | 
			
		||||
        {
 | 
			
		||||
            QByteArray tmp = buffer_.mid(6,newlineIndex-6);
 | 
			
		||||
            decode(tmp);
 | 
			
		||||
            if(master_)decodeMaster(tmp);
 | 
			
		||||
        }
 | 
			
		||||
        buffer_.remove(0, newlineIndex+1);
 | 
			
		||||
        newlineIndex = buffer_.indexOf('\n');
 | 
			
		||||
    }
 | 
			
		||||
	buffer_.append(iodevice_->readAll());
 | 
			
		||||
	int newlineIndex = buffer_.indexOf('\n');
 | 
			
		||||
	while( newlineIndex != -1 )
 | 
			
		||||
	{
 | 
			
		||||
		if(buffer_.startsWith("bcst: "))
 | 
			
		||||
		{
 | 
			
		||||
			QByteArray tmp = buffer_.mid(6,newlineIndex-6);
 | 
			
		||||
			decode(tmp);
 | 
			
		||||
			if(master_)decodeMaster(tmp);
 | 
			
		||||
		}
 | 
			
		||||
		buffer_.remove(0, newlineIndex+1);
 | 
			
		||||
		newlineIndex = buffer_.indexOf('\n');
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,46 +8,46 @@
 | 
			
		|||
 | 
			
		||||
class BroadCast: public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    bool master_;
 | 
			
		||||
	bool master_;
 | 
			
		||||
 | 
			
		||||
    static constexpr uint8_t MODE_PREPACKET = 0;
 | 
			
		||||
    static constexpr uint8_t MODE_PACKET = 1;
 | 
			
		||||
	static constexpr uint8_t MODE_PREPACKET = 0;
 | 
			
		||||
	static constexpr uint8_t MODE_PACKET = 1;
 | 
			
		||||
 | 
			
		||||
    QByteArray buffer_;
 | 
			
		||||
	QByteArray buffer_;
 | 
			
		||||
 | 
			
		||||
    QIODevice* const iodevice_;
 | 
			
		||||
	QIODevice* const iodevice_;
 | 
			
		||||
 | 
			
		||||
    void write(const char * const buffer, const size_t length);
 | 
			
		||||
    void write(const QByteArray& buffer);
 | 
			
		||||
	void write(const char * const buffer, const size_t length);
 | 
			
		||||
	void write(const QByteArray& buffer);
 | 
			
		||||
 | 
			
		||||
    void decode(QByteArray buffer);
 | 
			
		||||
    void decodeMaster(const QByteArray& buffer);
 | 
			
		||||
	void decode(QByteArray buffer);
 | 
			
		||||
	void decodeMaster(const QByteArray& buffer);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void readyRead();
 | 
			
		||||
	void readyRead();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void requestJson();
 | 
			
		||||
    void requestSensors();
 | 
			
		||||
	void requestJson();
 | 
			
		||||
	void requestSensors();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void jsonRequested();
 | 
			
		||||
    void gotJson(QJsonObject json);
 | 
			
		||||
    void gotSensorState(Sensor sensor);
 | 
			
		||||
	void jsonRequested();
 | 
			
		||||
	void gotJson(QJsonObject json);
 | 
			
		||||
	void gotSensorState(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    BroadCast(QIODevice* const iodevice = nullptr, bool master = true);
 | 
			
		||||
    void sendJson(const QJsonObject& json);
 | 
			
		||||
    void sendSensors();
 | 
			
		||||
    void sendMessage(const QString& title, const QString& body);
 | 
			
		||||
	BroadCast(QIODevice* const iodevice = nullptr, bool master = true);
 | 
			
		||||
	void sendJson(const QJsonObject& json);
 | 
			
		||||
	void sendSensors();
 | 
			
		||||
	void sendMessage(const QString& title, const QString& body);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,30 +8,30 @@ VirutalIODevice::VirutalIODevice(QObject* parent): QBuffer(parent)
 | 
			
		|||
 | 
			
		||||
qint64 VirutalIODevice::writeData(const char *data, qint64 len)
 | 
			
		||||
{
 | 
			
		||||
    blockSignals(true);
 | 
			
		||||
    qint64 ret = QBuffer::writeData(data, len);
 | 
			
		||||
    blockSignals(false);
 | 
			
		||||
    masterReadyRead();
 | 
			
		||||
    return ret;
 | 
			
		||||
	blockSignals(true);
 | 
			
		||||
	qint64 ret = QBuffer::writeData(data, len);
 | 
			
		||||
	blockSignals(false);
 | 
			
		||||
	masterReadyRead();
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
qint64 VirutalIODevice::masterWrite(const QByteArray &byteArray)
 | 
			
		||||
{
 | 
			
		||||
    return masterWrite(byteArray.data(), byteArray.length());
 | 
			
		||||
	return masterWrite(byteArray.data(), byteArray.length());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
qint64 VirutalIODevice::masterWrite(const char *data, qint64 maxSize)
 | 
			
		||||
{
 | 
			
		||||
    blockSignals(true);
 | 
			
		||||
    qint64 ret = QBuffer::writeData(data, maxSize);
 | 
			
		||||
    blockSignals(false);
 | 
			
		||||
    readyRead();
 | 
			
		||||
    return ret;
 | 
			
		||||
	blockSignals(true);
 | 
			
		||||
	qint64 ret = QBuffer::writeData(data, maxSize);
 | 
			
		||||
	blockSignals(false);
 | 
			
		||||
	readyRead();
 | 
			
		||||
	return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IoMuliplexer::IoMuliplexer(QIODevice* mainDevice, QObject* Parent): IoMuliplexer(Parent)
 | 
			
		||||
{
 | 
			
		||||
    setIoDevice(mainDevice);
 | 
			
		||||
	setIoDevice(mainDevice);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IoMuliplexer::IoMuliplexer(QObject* Parent): QObject(Parent)
 | 
			
		||||
| 
						 | 
				
			
			@ -41,36 +41,36 @@ IoMuliplexer::IoMuliplexer(QObject* Parent): QObject(Parent)
 | 
			
		|||
 | 
			
		||||
IoMuliplexer::~IoMuliplexer()
 | 
			
		||||
{
 | 
			
		||||
    for(size_t i = 0; i < ioDevices_.size(); ++i) delete ioDevices_[i];
 | 
			
		||||
    ioDevices_.clear();
 | 
			
		||||
	for(size_t i = 0; i < ioDevices_.size(); ++i) delete ioDevices_[i];
 | 
			
		||||
	ioDevices_.clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IoMuliplexer::setIoDevice(QIODevice* mainDevice)
 | 
			
		||||
{
 | 
			
		||||
    mainDevice_ = mainDevice;
 | 
			
		||||
    connect(mainDevice_, &QIODevice::readyRead, this, &IoMuliplexer::mainIsReadyRead);
 | 
			
		||||
	mainDevice_ = mainDevice;
 | 
			
		||||
	connect(mainDevice_, &QIODevice::readyRead, this, &IoMuliplexer::mainIsReadyRead);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QIODevice* IoMuliplexer::getIoDevice()
 | 
			
		||||
{
 | 
			
		||||
    ioDevices_.push_back(new VirutalIODevice);
 | 
			
		||||
    ioDevices_.back()->open(QIODevice::ReadWrite);
 | 
			
		||||
    connect(ioDevices_.back(), &VirutalIODevice::masterReadyRead, this, &IoMuliplexer::clientIsReadyRead);
 | 
			
		||||
    return ioDevices_.back();
 | 
			
		||||
	ioDevices_.push_back(new VirutalIODevice);
 | 
			
		||||
	ioDevices_.back()->open(QIODevice::ReadWrite);
 | 
			
		||||
	connect(ioDevices_.back(), &VirutalIODevice::masterReadyRead, this, &IoMuliplexer::clientIsReadyRead);
 | 
			
		||||
	return ioDevices_.back();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IoMuliplexer::clientIsReadyRead()
 | 
			
		||||
{
 | 
			
		||||
    VirutalIODevice* device = dynamic_cast<VirutalIODevice*>(sender());
 | 
			
		||||
    if(device)
 | 
			
		||||
    {
 | 
			
		||||
        QByteArray array = device->readAll();
 | 
			
		||||
        mainDevice_->write(array);
 | 
			
		||||
    }
 | 
			
		||||
	VirutalIODevice* device = dynamic_cast<VirutalIODevice*>(sender());
 | 
			
		||||
	if(device)
 | 
			
		||||
	{
 | 
			
		||||
		QByteArray array = device->readAll();
 | 
			
		||||
		mainDevice_->write(array);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IoMuliplexer::mainIsReadyRead()
 | 
			
		||||
{
 | 
			
		||||
    QByteArray array = mainDevice_->readAll();
 | 
			
		||||
    for(size_t i = 0; i < ioDevices_.size(); ++i) ioDevices_[i]->masterWrite(array);
 | 
			
		||||
	QByteArray array = mainDevice_->readAll();
 | 
			
		||||
	for(size_t i = 0; i < ioDevices_.size(); ++i) ioDevices_[i]->masterWrite(array);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,46 +8,46 @@
 | 
			
		|||
 | 
			
		||||
class VirutalIODevice: public QBuffer
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    VirutalIODevice(QObject* parent = nullptr);
 | 
			
		||||
    virtual ~VirutalIODevice() override {}
 | 
			
		||||
	VirutalIODevice(QObject* parent = nullptr);
 | 
			
		||||
	virtual ~VirutalIODevice() override {}
 | 
			
		||||
 | 
			
		||||
    virtual qint64 writeData(const char *data, qint64 len) override;
 | 
			
		||||
	virtual qint64 writeData(const char *data, qint64 len) override;
 | 
			
		||||
 | 
			
		||||
    qint64 masterWrite(const QByteArray &byteArray);
 | 
			
		||||
    qint64 masterWrite(const char *data, qint64 maxSize);
 | 
			
		||||
	qint64 masterWrite(const QByteArray &byteArray);
 | 
			
		||||
	qint64 masterWrite(const char *data, qint64 maxSize);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void masterReadyRead();
 | 
			
		||||
	void masterReadyRead();
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class IoMuliplexer: public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    QIODevice* mainDevice_;
 | 
			
		||||
    std::vector< VirutalIODevice* > ioDevices_;
 | 
			
		||||
	QIODevice* mainDevice_;
 | 
			
		||||
	std::vector< VirutalIODevice* > ioDevices_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit IoMuliplexer(QIODevice* mainDevice, QObject* Parent = nullptr);
 | 
			
		||||
    explicit IoMuliplexer(QObject* Parent = nullptr);
 | 
			
		||||
	explicit IoMuliplexer(QIODevice* mainDevice, QObject* Parent = nullptr);
 | 
			
		||||
	explicit IoMuliplexer(QObject* Parent = nullptr);
 | 
			
		||||
 | 
			
		||||
    ~IoMuliplexer();
 | 
			
		||||
	~IoMuliplexer();
 | 
			
		||||
 | 
			
		||||
    void setIoDevice(QIODevice* mainDevice);
 | 
			
		||||
	void setIoDevice(QIODevice* mainDevice);
 | 
			
		||||
 | 
			
		||||
    QIODevice* getIoDevice();
 | 
			
		||||
	QIODevice* getIoDevice();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void mainIsReadyRead();
 | 
			
		||||
    void clientIsReadyRead();
 | 
			
		||||
	void mainIsReadyRead();
 | 
			
		||||
	void clientIsReadyRead();
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,18 +1,19 @@
 | 
			
		|||
#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)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AuxItem::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    Item::setValue(value);
 | 
			
		||||
    micro_->setAuxPwm(value);
 | 
			
		||||
	Item::setValue(value);
 | 
			
		||||
	micro_->setAuxPwm(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AuxItem::store(QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Aux";
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
	json["Type"] = "Aux";
 | 
			
		||||
	Item::store(json);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,16 +5,17 @@
 | 
			
		|||
 | 
			
		||||
class AuxItem: public Item
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    Microcontroller* micro_;
 | 
			
		||||
	Microcontroller* micro_;
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	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);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,22 +15,22 @@ ItemData::ItemData(uint32_t itemIdIn, QString name, uint8_t value): name_(name),
 | 
			
		|||
 | 
			
		||||
QString ItemData::getName() const
 | 
			
		||||
{
 | 
			
		||||
    return name_;
 | 
			
		||||
	return name_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemData::setName(QString name)
 | 
			
		||||
{
 | 
			
		||||
    name_ = name;
 | 
			
		||||
	name_ = name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t ItemData::getValue() const
 | 
			
		||||
{
 | 
			
		||||
    return value_;
 | 
			
		||||
	return value_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t ItemData::id() const
 | 
			
		||||
{
 | 
			
		||||
    return  itemId_;
 | 
			
		||||
	return  itemId_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -54,116 +55,117 @@ Item::~Item()
 | 
			
		|||
 | 
			
		||||
void Item::store(QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    json["Name"] = name_;
 | 
			
		||||
    json["ItemId"] = static_cast<double>(itemId_);
 | 
			
		||||
    json["override"] = override_;
 | 
			
		||||
    QJsonArray actorsArray;
 | 
			
		||||
    for(size_t i = 0; i < actors_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if(!actors_[i]->isExausted())
 | 
			
		||||
        {
 | 
			
		||||
            QJsonObject actorObject;
 | 
			
		||||
            actors_[i]->store(actorObject);
 | 
			
		||||
            actorsArray.append(actorObject);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    json["Actors"] = actorsArray;
 | 
			
		||||
	json["Name"] = name_;
 | 
			
		||||
	json["ItemId"] = static_cast<double>(itemId_);
 | 
			
		||||
	json["override"] = override_;
 | 
			
		||||
	QJsonArray actorsArray;
 | 
			
		||||
	for(size_t i = 0; i < actors_.size(); ++i)
 | 
			
		||||
	{
 | 
			
		||||
		if(!actors_[i]->isExausted())
 | 
			
		||||
		{
 | 
			
		||||
			QJsonObject actorObject;
 | 
			
		||||
			actors_[i]->store(actorObject);
 | 
			
		||||
			actorsArray.append(actorObject);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	json["Actors"] = actorsArray;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::load(const QJsonObject &json, const bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    if(!preserve)
 | 
			
		||||
    {
 | 
			
		||||
        name_ = json["Name"].toString(name_);
 | 
			
		||||
        itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
 | 
			
		||||
    }
 | 
			
		||||
    override_ = json["override"].toBool(false);
 | 
			
		||||
    const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
 | 
			
		||||
    for(int i = 0; i < actorsArray.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if(actorsArray[i].isObject())
 | 
			
		||||
        {
 | 
			
		||||
            std::shared_ptr<Actor> actor = Actor::loadActor(actorsArray[i].toObject());
 | 
			
		||||
            if(actor != nullptr) addActor(actor);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
	if(!preserve)
 | 
			
		||||
	{
 | 
			
		||||
		name_ = json["Name"].toString(name_);
 | 
			
		||||
		itemId_ = static_cast<uint32_t>(json["ItemId"].toDouble(0));
 | 
			
		||||
	}
 | 
			
		||||
	override_ = json["override"].toBool(false);
 | 
			
		||||
	const QJsonArray actorsArray(json["Actors"].toArray(QJsonArray()));
 | 
			
		||||
	for(int i = 0; i < actorsArray.size(); ++i)
 | 
			
		||||
	{
 | 
			
		||||
		if(actorsArray[i].isObject())
 | 
			
		||||
		{
 | 
			
		||||
			std::shared_ptr<Actor> actor = Actor::loadActor(actorsArray[i].toObject());
 | 
			
		||||
			if(actor != nullptr) addActor(actor);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::actorSetValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    if(!override_) setValue(value);
 | 
			
		||||
	if(!override_) setValue(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    value_ = value;
 | 
			
		||||
    valueChanged(value_);
 | 
			
		||||
	value_ = value;
 | 
			
		||||
	valueChanged(value_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::informValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    Item::setValue(value);
 | 
			
		||||
	Item::setValue(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::addActor(std::shared_ptr<Actor> actor)
 | 
			
		||||
{
 | 
			
		||||
    actor->setParent(this);
 | 
			
		||||
    actors_.push_back(actor);
 | 
			
		||||
    if(!secondaryFlag)
 | 
			
		||||
    {
 | 
			
		||||
        connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
 | 
			
		||||
    }
 | 
			
		||||
    connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
 | 
			
		||||
	actor->setParent(this);
 | 
			
		||||
	actors_.push_back(actor);
 | 
			
		||||
	if(!secondaryFlag)
 | 
			
		||||
	{
 | 
			
		||||
		connect(actor.get(), &Actor::sigValue, this, &Item::actorSetValue);
 | 
			
		||||
	}
 | 
			
		||||
	connect(this, &Item::valueChanged, actor.get(), &Actor::onValueChanged);
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
 | 
			
		||||
    if(sensorActor)connect(&globalSensors, &SensorStore::sensorChangedState, sensorActor.get(), &SensorActor::sensorEvent);
 | 
			
		||||
	std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
 | 
			
		||||
	if(sensorActor)connect(&globalSensors, &SensorStore::sensorChangedState, sensorActor.get(), &SensorActor::sensorEvent);
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
 | 
			
		||||
    if(regulator)connect(&globalSensors, &SensorStore::sensorChangedState, regulator.get(), &Regulator::sensorEvent);
 | 
			
		||||
	std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(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);
 | 
			
		||||
	std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
 | 
			
		||||
	if(polynomalActor != nullptr )connect(&globalSensors, &SensorStore::sensorChangedState, polynomalActor.get(),
 | 
			
		||||
		                                      &PolynomalActor::sensorEvent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Item::removeActor(std::shared_ptr<Actor> actor)
 | 
			
		||||
{
 | 
			
		||||
    for(unsigned int i = 0; i < actors_.size(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        if(actors_[i] == actor)
 | 
			
		||||
        {
 | 
			
		||||
            actors_.erase(actors_.begin()+i);
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
	for(unsigned int i = 0; i < actors_.size(); i++)
 | 
			
		||||
	{
 | 
			
		||||
		if(actors_[i] == actor)
 | 
			
		||||
		{
 | 
			
		||||
			actors_.erase(actors_.begin()+i);
 | 
			
		||||
			return true;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::setOverride(const bool in)
 | 
			
		||||
{
 | 
			
		||||
    override_ = in;
 | 
			
		||||
	override_ = in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Item::getOverride()
 | 
			
		||||
{
 | 
			
		||||
    return override_;
 | 
			
		||||
	return override_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::removeAllActors()
 | 
			
		||||
{
 | 
			
		||||
    actors_.clear();
 | 
			
		||||
	actors_.clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::vector< std::shared_ptr<Actor> >& Item::getActors()
 | 
			
		||||
{
 | 
			
		||||
    return actors_;
 | 
			
		||||
	return actors_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Item::hasActors()
 | 
			
		||||
{
 | 
			
		||||
    return actors_.size() > 0;
 | 
			
		||||
	return actors_.size() > 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Item::setActorsActive(bool in)
 | 
			
		||||
{
 | 
			
		||||
    for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
 | 
			
		||||
	for(unsigned i = 0; i < actors_.size(); i++) in ? actors_[i]->makeActive() : actors_[i]->makeInactive();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,67 +11,74 @@ class Actor;
 | 
			
		|||
class ItemData
 | 
			
		||||
{
 | 
			
		||||
protected:
 | 
			
		||||
    QString name_;
 | 
			
		||||
    uint8_t value_;
 | 
			
		||||
    uint32_t itemId_;
 | 
			
		||||
	QString name_;
 | 
			
		||||
	uint8_t value_;
 | 
			
		||||
	uint32_t itemId_;
 | 
			
		||||
 | 
			
		||||
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{ 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;
 | 
			
		||||
	uint32_t id() const;
 | 
			
		||||
 | 
			
		||||
    void setName(QString name);
 | 
			
		||||
    uint8_t getValue() const;
 | 
			
		||||
    virtual QString getName() const;
 | 
			
		||||
	void setName(QString name);
 | 
			
		||||
	uint8_t getValue() const;
 | 
			
		||||
	virtual QString getName() const;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Item: public QObject, public ItemData
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    std::vector< std::shared_ptr<Actor> > actors_;
 | 
			
		||||
	std::vector< std::shared_ptr<Actor> > actors_;
 | 
			
		||||
 | 
			
		||||
    bool override_ = false;
 | 
			
		||||
	bool override_ = false;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    static bool secondaryFlag;
 | 
			
		||||
	static bool secondaryFlag;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void valueChanged(uint8_t value);
 | 
			
		||||
	void valueChanged(uint8_t value);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    virtual void actorSetValue(uint8_t value);
 | 
			
		||||
	virtual void actorSetValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	virtual void setValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    Item(uint32_t itemIdIn = QRandomGenerator::global()->generate(), QString name = "Item", uint8_t value = 0,  QObject *parent = nullptr);
 | 
			
		||||
    Item(const ItemData& itemData,  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();
 | 
			
		||||
	virtual ~Item();
 | 
			
		||||
 | 
			
		||||
    std::vector< std::shared_ptr<Actor> >& getActors();
 | 
			
		||||
    bool hasActors();
 | 
			
		||||
    void addActor(std::shared_ptr<Actor> actor);
 | 
			
		||||
    bool removeActor(std::shared_ptr<Actor> actor);
 | 
			
		||||
    void removeAllActors();
 | 
			
		||||
    void setActorsActive(bool in);
 | 
			
		||||
    void setOverride(const bool in);
 | 
			
		||||
    bool getOverride();
 | 
			
		||||
    void informValue(uint8_t value);
 | 
			
		||||
	std::vector< std::shared_ptr<Actor> >& getActors();
 | 
			
		||||
	bool hasActors();
 | 
			
		||||
	void addActor(std::shared_ptr<Actor> actor);
 | 
			
		||||
	bool removeActor(std::shared_ptr<Actor> actor);
 | 
			
		||||
	void removeAllActors();
 | 
			
		||||
	void setActorsActive(bool in);
 | 
			
		||||
	void setOverride(const bool in);
 | 
			
		||||
	bool getOverride();
 | 
			
		||||
	void informValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,121 +10,121 @@ ItemStore::ItemStore(QObject *parent): QObject(parent)
 | 
			
		|||
 | 
			
		||||
void ItemStore::addItem(std::shared_ptr<Item> item)
 | 
			
		||||
{
 | 
			
		||||
    bool mached = false;
 | 
			
		||||
    for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true;
 | 
			
		||||
    if(!mached)
 | 
			
		||||
    {
 | 
			
		||||
        items_.push_back(std::shared_ptr<Item>(item));
 | 
			
		||||
        itemAdded(std::weak_ptr<Item>(items_.back()));
 | 
			
		||||
    }
 | 
			
		||||
	bool mached = false;
 | 
			
		||||
	for(unsigned i = 0; i < items_.size(); i++ ) if(*items_[i] == *item) mached = true;
 | 
			
		||||
	if(!mached)
 | 
			
		||||
	{
 | 
			
		||||
		items_.push_back(std::shared_ptr<Item>(item));
 | 
			
		||||
		itemAdded(std::weak_ptr<Item>(items_.back()));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemStore::addItems(const std::vector<std::shared_ptr<Item>>& itemIn)
 | 
			
		||||
{
 | 
			
		||||
    for(unsigned i = 0; i < items_.size(); i++ )
 | 
			
		||||
    {
 | 
			
		||||
        if(Relay* relay = dynamic_cast<Relay*>(items_[i].get()))
 | 
			
		||||
        {
 | 
			
		||||
            bool mached = false;
 | 
			
		||||
            for(unsigned j = 0; j < itemIn.size(); j++) if(*(items_[i]) == *(itemIn[j]))
 | 
			
		||||
            {
 | 
			
		||||
                mached = true;
 | 
			
		||||
                if(itemIn[j]->getValue() != items_[i]->getValue()) items_[i]->informValue(itemIn[j]->getValue());
 | 
			
		||||
                Relay* relayIn = dynamic_cast<Relay*>(itemIn[j].get());
 | 
			
		||||
                if(relayIn)
 | 
			
		||||
                {
 | 
			
		||||
                    if(relay->getId() != relayIn->getId()) relay->setId(relayIn->getId());
 | 
			
		||||
                }
 | 
			
		||||
	for(unsigned i = 0; i < items_.size(); i++ )
 | 
			
		||||
	{
 | 
			
		||||
		if(Relay* relay = dynamic_cast<Relay*>(items_[i].get()))
 | 
			
		||||
		{
 | 
			
		||||
			bool mached = false;
 | 
			
		||||
			for(unsigned j = 0; j < itemIn.size(); j++) if(*(items_[i]) == *(itemIn[j]))
 | 
			
		||||
				{
 | 
			
		||||
					mached = true;
 | 
			
		||||
					if(itemIn[j]->getValue() != items_[i]->getValue()) items_[i]->informValue(itemIn[j]->getValue());
 | 
			
		||||
					Relay* relayIn = dynamic_cast<Relay*>(itemIn[j].get());
 | 
			
		||||
					if(relayIn)
 | 
			
		||||
					{
 | 
			
		||||
						if(relay->getId() != relayIn->getId()) relay->setId(relayIn->getId());
 | 
			
		||||
					}
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            if(!mached)
 | 
			
		||||
            {
 | 
			
		||||
                itemDeleted(*items_[i].get());
 | 
			
		||||
                items_.erase(items_.begin()+i);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
				}
 | 
			
		||||
			if(!mached)
 | 
			
		||||
			{
 | 
			
		||||
				itemDeleted(*items_[i].get());
 | 
			
		||||
				items_.erase(items_.begin()+i);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    for(unsigned j = 0; j < itemIn.size(); j++)addItem(itemIn[j]);
 | 
			
		||||
	for(unsigned j = 0; j < itemIn.size(); j++)addItem(itemIn[j]);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemStore::removeItem(const ItemData& item)
 | 
			
		||||
{
 | 
			
		||||
    for(unsigned j = 0; j < items_.size(); j++)
 | 
			
		||||
    {
 | 
			
		||||
        if(item == *items_[j])
 | 
			
		||||
        {
 | 
			
		||||
            items_.erase(items_.begin()+j);
 | 
			
		||||
            --j;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
	for(unsigned j = 0; j < items_.size(); j++)
 | 
			
		||||
	{
 | 
			
		||||
		if(item == *items_[j])
 | 
			
		||||
		{
 | 
			
		||||
			items_.erase(items_.begin()+j);
 | 
			
		||||
			--j;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ItemStore::clear()
 | 
			
		||||
{
 | 
			
		||||
    for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]);
 | 
			
		||||
    items_.clear();
 | 
			
		||||
	for(size_t i = 0; i < items_.size(); ++i) itemDeleted(*items_[i]);
 | 
			
		||||
	items_.clear();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void ItemStore::itemStateChanged(const ItemData& item)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
     for(unsigned i = 0; i < items_.size(); i++ )
 | 
			
		||||
     {
 | 
			
		||||
         if(items_[i]->operator==(item))
 | 
			
		||||
         {
 | 
			
		||||
	for(unsigned i = 0; i < items_.size(); i++ )
 | 
			
		||||
	{
 | 
			
		||||
		if(items_[i]->operator==(item))
 | 
			
		||||
		{
 | 
			
		||||
 | 
			
		||||
            if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
 | 
			
		||||
         }
 | 
			
		||||
			if(items_[i]->getValue() != item.getValue())items_[i]->informValue(item.getValue());
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
     }
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemStore::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    QJsonArray itemsArray;
 | 
			
		||||
    for(size_t i = 0; i < items_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        QJsonObject itemObject;
 | 
			
		||||
        items_[i]->store(itemObject);
 | 
			
		||||
        itemsArray.append(itemObject);
 | 
			
		||||
    }
 | 
			
		||||
    json["Items"] = itemsArray;
 | 
			
		||||
	QJsonArray itemsArray;
 | 
			
		||||
	for(size_t i = 0; i < items_.size(); ++i)
 | 
			
		||||
	{
 | 
			
		||||
		QJsonObject itemObject;
 | 
			
		||||
		items_[i]->store(itemObject);
 | 
			
		||||
		itemsArray.append(itemObject);
 | 
			
		||||
	}
 | 
			
		||||
	json["Items"] = itemsArray;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemStore::load(const QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    const QJsonArray itemsArray(json["Items"].toArray(QJsonArray()));
 | 
			
		||||
    for(int i = 0; i < itemsArray.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if(itemsArray[i].isObject())
 | 
			
		||||
        {
 | 
			
		||||
            const QJsonObject itemObject = itemsArray[i].toObject();
 | 
			
		||||
            std::shared_ptr<Item> newItem;
 | 
			
		||||
            if(itemObject["Type"].toString("") == "Relay")
 | 
			
		||||
            {
 | 
			
		||||
                newItem = std::shared_ptr<Relay>(new Relay());
 | 
			
		||||
            }
 | 
			
		||||
            else if(itemObject["Type"].toString("") == "Message")
 | 
			
		||||
            {
 | 
			
		||||
                newItem = std::shared_ptr<MessageItem>(new MessageItem);
 | 
			
		||||
            }
 | 
			
		||||
            else if(itemObject["Type"].toString("") == "System")
 | 
			
		||||
            {
 | 
			
		||||
                newItem = std::shared_ptr<SystemItem>(new SystemItem());
 | 
			
		||||
            }
 | 
			
		||||
            else if(itemObject["Type"].toString("") == "Aux")
 | 
			
		||||
            {
 | 
			
		||||
            }
 | 
			
		||||
            if(newItem)
 | 
			
		||||
            {
 | 
			
		||||
                newItem->load(itemObject);
 | 
			
		||||
                addItem(newItem);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
	const QJsonArray itemsArray(json["Items"].toArray(QJsonArray()));
 | 
			
		||||
	for(int i = 0; i < itemsArray.size(); ++i)
 | 
			
		||||
	{
 | 
			
		||||
		if(itemsArray[i].isObject())
 | 
			
		||||
		{
 | 
			
		||||
			const QJsonObject itemObject = itemsArray[i].toObject();
 | 
			
		||||
			std::shared_ptr<Item> newItem;
 | 
			
		||||
			if(itemObject["Type"].toString("") == "Relay")
 | 
			
		||||
			{
 | 
			
		||||
				newItem = std::shared_ptr<Relay>(new Relay());
 | 
			
		||||
			}
 | 
			
		||||
			else if(itemObject["Type"].toString("") == "Message")
 | 
			
		||||
			{
 | 
			
		||||
				newItem = std::shared_ptr<MessageItem>(new MessageItem);
 | 
			
		||||
			}
 | 
			
		||||
			else if(itemObject["Type"].toString("") == "System")
 | 
			
		||||
			{
 | 
			
		||||
				newItem = std::shared_ptr<SystemItem>(new SystemItem());
 | 
			
		||||
			}
 | 
			
		||||
			else if(itemObject["Type"].toString("") == "Aux")
 | 
			
		||||
			{
 | 
			
		||||
			}
 | 
			
		||||
			if(newItem)
 | 
			
		||||
			{
 | 
			
		||||
				newItem->load(itemObject);
 | 
			
		||||
				addItem(newItem);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,31 +8,34 @@
 | 
			
		|||
 | 
			
		||||
class ItemStore: public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    std::vector< std::shared_ptr<Item> > items_;
 | 
			
		||||
	std::vector< std::shared_ptr<Item> > items_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    ItemStore(QObject *parent = nullptr);
 | 
			
		||||
    virtual ~ItemStore(){}
 | 
			
		||||
	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);
 | 
			
		||||
	void store(QJsonObject &json);
 | 
			
		||||
	void load(const QJsonObject &json);
 | 
			
		||||
 | 
			
		||||
    void clear();
 | 
			
		||||
	void clear();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void itemDeleted(ItemData item);
 | 
			
		||||
    void itemAdded(std::weak_ptr<Item> Item);
 | 
			
		||||
	void itemDeleted(ItemData item);
 | 
			
		||||
	void itemAdded(std::weak_ptr<Item> Item);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void removeItem(const ItemData& item);
 | 
			
		||||
    void addItem(std::shared_ptr<Item> item);
 | 
			
		||||
    void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
 | 
			
		||||
    void itemStateChanged(const ItemData& item);
 | 
			
		||||
	void removeItem(const ItemData& item);
 | 
			
		||||
	void addItem(std::shared_ptr<Item> item);
 | 
			
		||||
	void addItems(const std::vector<std::shared_ptr<Item>>& itemsIn);
 | 
			
		||||
	void itemStateChanged(const ItemData& item);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,83 +6,83 @@
 | 
			
		|||
BroadCast* MessageItem::broadCast = nullptr;
 | 
			
		||||
 | 
			
		||||
MessageItem::MessageItem(uint32_t itemIdIn, QString name, uint8_t value,  QObject *parent):
 | 
			
		||||
    Item(itemIdIn, name, value, parent)
 | 
			
		||||
	Item(itemIdIn, name, value, parent)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MessageItem::MessageItem(const ItemData& itemData,  QObject *parent):
 | 
			
		||||
    Item(itemData, parent)
 | 
			
		||||
	Item(itemData, parent)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MessageItem::~MessageItem()
 | 
			
		||||
{
 | 
			
		||||
    closeMessageBox();
 | 
			
		||||
	closeMessageBox();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MessageItem::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
   Item::setValue(value);
 | 
			
		||||
   if(value && !messageBox_)
 | 
			
		||||
   {
 | 
			
		||||
       if(broadCast) broadCast->sendMessage(name_, message_);
 | 
			
		||||
       if(!alertSoundFileName.isEmpty()) QSound::play(alertSoundFileName);
 | 
			
		||||
       messageBox_ = new QMessageBox(QMessageBox::NoIcon, name_, message_);
 | 
			
		||||
       messageBox_->setModal(false);
 | 
			
		||||
       connect(messageBox_, &QMessageBox::finished, this, &MessageItem::closeMessageBox);
 | 
			
		||||
       messageBox_->show();
 | 
			
		||||
   }
 | 
			
		||||
   else if(!value && messageBox_)
 | 
			
		||||
   {
 | 
			
		||||
       closeMessageBox();
 | 
			
		||||
   }
 | 
			
		||||
	Item::setValue(value);
 | 
			
		||||
	if(value && !messageBox_)
 | 
			
		||||
	{
 | 
			
		||||
		if(broadCast) broadCast->sendMessage(name_, message_);
 | 
			
		||||
		if(!alertSoundFileName.isEmpty()) QSound::play(alertSoundFileName);
 | 
			
		||||
		messageBox_ = new QMessageBox(QMessageBox::NoIcon, name_, message_);
 | 
			
		||||
		messageBox_->setModal(false);
 | 
			
		||||
		connect(messageBox_, &QMessageBox::finished, this, &MessageItem::closeMessageBox);
 | 
			
		||||
		messageBox_->show();
 | 
			
		||||
	}
 | 
			
		||||
	else if(!value && messageBox_)
 | 
			
		||||
	{
 | 
			
		||||
		closeMessageBox();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void MessageItem::closeMessageBox()
 | 
			
		||||
{
 | 
			
		||||
    if(messageBox_)
 | 
			
		||||
    {
 | 
			
		||||
        value_ = 0;
 | 
			
		||||
        messageBox_->hide();
 | 
			
		||||
        delete messageBox_;
 | 
			
		||||
        messageBox_ = nullptr;
 | 
			
		||||
    }
 | 
			
		||||
	if(messageBox_)
 | 
			
		||||
	{
 | 
			
		||||
		value_ = 0;
 | 
			
		||||
		messageBox_->hide();
 | 
			
		||||
		delete messageBox_;
 | 
			
		||||
		messageBox_ = nullptr;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString MessageItem::getAlert()
 | 
			
		||||
{
 | 
			
		||||
    return alertSoundFileName;
 | 
			
		||||
	return alertSoundFileName;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MessageItem::setAlert(const QString &in)
 | 
			
		||||
{
 | 
			
		||||
    alertSoundFileName = in;
 | 
			
		||||
	alertSoundFileName = in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MessageItem::setMessage(const QString& in)
 | 
			
		||||
{
 | 
			
		||||
    message_ = in;
 | 
			
		||||
	message_ = in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString MessageItem::getMessage()
 | 
			
		||||
{
 | 
			
		||||
    return message_;
 | 
			
		||||
	return message_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MessageItem::store(QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Message";
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
    json["Message"] = message_;
 | 
			
		||||
    if(!alertSoundFileName.isEmpty()) json["Alert"] = alertSoundFileName;
 | 
			
		||||
	json["Type"] = "Message";
 | 
			
		||||
	Item::store(json);
 | 
			
		||||
	json["Message"] = message_;
 | 
			
		||||
	if(!alertSoundFileName.isEmpty()) json["Alert"] = alertSoundFileName;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MessageItem::load(const QJsonObject &json, const bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Item::load(json,preserve);
 | 
			
		||||
    message_ = json["Message"].toString("Invalid Message");
 | 
			
		||||
    alertSoundFileName = json["Alert"].toString("");
 | 
			
		||||
	Item::load(json,preserve);
 | 
			
		||||
	message_ = json["Message"].toString("Invalid Message");
 | 
			
		||||
	alertSoundFileName = json["Alert"].toString("");
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,37 +8,38 @@
 | 
			
		|||
 | 
			
		||||
class MessageItem : public Item
 | 
			
		||||
{
 | 
			
		||||
Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    QString message_;
 | 
			
		||||
    QMessageBox* messageBox_ = nullptr;
 | 
			
		||||
    QString alertSoundFileName = "";
 | 
			
		||||
	QString message_;
 | 
			
		||||
	QMessageBox* messageBox_ = nullptr;
 | 
			
		||||
	QString alertSoundFileName = "";
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    static BroadCast* broadCast;
 | 
			
		||||
	static BroadCast* broadCast;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void closeMessageBox();
 | 
			
		||||
	void closeMessageBox();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	virtual void setValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    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();
 | 
			
		||||
	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();
 | 
			
		||||
 | 
			
		||||
    void setMessage(const QString& in);
 | 
			
		||||
    QString getMessage();
 | 
			
		||||
    void setAlert(const QString& in);
 | 
			
		||||
    QString getAlert();
 | 
			
		||||
	void setMessage(const QString& in);
 | 
			
		||||
	QString getMessage();
 | 
			
		||||
	void setAlert(const QString& in);
 | 
			
		||||
	QString getAlert();
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // MESSAGEITEM_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,31 +3,32 @@
 | 
			
		|||
#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);
 | 
			
		||||
	stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 0, "Shutdown Imminent", true));
 | 
			
		||||
	setValue(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PowerItem::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    qDebug()<<"shutdown";
 | 
			
		||||
    Item::setValue(value);
 | 
			
		||||
    if(!value)
 | 
			
		||||
    {
 | 
			
		||||
       QTimer::singleShot(5000, this, &PowerItem::timeout);
 | 
			
		||||
       stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 1, "Shutdown Imminent", true));
 | 
			
		||||
    }
 | 
			
		||||
	qDebug()<<"shutdown";
 | 
			
		||||
	Item::setValue(value);
 | 
			
		||||
	if(!value)
 | 
			
		||||
	{
 | 
			
		||||
		QTimer::singleShot(5000, this, &PowerItem::timeout);
 | 
			
		||||
		stateChanged(Sensor(Sensor::TYPE_SHUTDOWN_IMMINENT, 0, 1, "Shutdown Imminent", true));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PowerItem::timeout()
 | 
			
		||||
{
 | 
			
		||||
    qDebug()<<"shutdown timeout";
 | 
			
		||||
    QProcess::startDetached("syncoff");
 | 
			
		||||
	qDebug()<<"shutdown timeout";
 | 
			
		||||
	QProcess::startDetached("syncoff");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PowerItem::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Power";
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
	json["Type"] = "Power";
 | 
			
		||||
	Item::store(json);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,23 +8,27 @@
 | 
			
		|||
 | 
			
		||||
class PowerItem: public Item
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void stateChanged(Sensor sensor);
 | 
			
		||||
	void stateChanged(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void timeout();
 | 
			
		||||
	void timeout();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	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));}
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
	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,66 +5,67 @@
 | 
			
		|||
 | 
			
		||||
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;
 | 
			
		||||
	itemId_ = address | ((uint32_t)id << 16);
 | 
			
		||||
	qDebug()<<"Relay "<<id_<<"Name "<<name<<" id "<<itemId_<<" state "<<state<<" addr: "<<address;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Relay::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
   Item::setValue(value);
 | 
			
		||||
   if(micro_)
 | 
			
		||||
   {
 | 
			
		||||
       if(value)micro_->relayOn(id_);
 | 
			
		||||
       else micro_->relayOff(id_);
 | 
			
		||||
   }
 | 
			
		||||
	Item::setValue(value);
 | 
			
		||||
	if(micro_)
 | 
			
		||||
	{
 | 
			
		||||
		if(value)micro_->relayOn(id_);
 | 
			
		||||
		else micro_->relayOff(id_);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Relay::on()
 | 
			
		||||
{
 | 
			
		||||
    setValue(true);
 | 
			
		||||
	setValue(true);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Relay::off()
 | 
			
		||||
{
 | 
			
		||||
   setValue(false);
 | 
			
		||||
	setValue(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Relay::toggle()
 | 
			
		||||
{
 | 
			
		||||
    value_ ? off() : on();
 | 
			
		||||
	value_ ? off() : on();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Relay::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Relay";
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
    json["Id"] = static_cast<double>(id_);
 | 
			
		||||
    json["Address"] = address_;
 | 
			
		||||
	json["Type"] = "Relay";
 | 
			
		||||
	Item::store(json);
 | 
			
		||||
	json["Id"] = static_cast<double>(id_);
 | 
			
		||||
	json["Address"] = address_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Relay::load(const QJsonObject& json, const bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Item::load(json, preserve);
 | 
			
		||||
    id_ = static_cast<uint8_t>(json["Id"].toInt(0));
 | 
			
		||||
    address_ = static_cast<uint16_t>(json["Address"].toInt(0));
 | 
			
		||||
    itemId_ = address_ | (static_cast<uint32_t>(id_) << 16);
 | 
			
		||||
	Item::load(json, preserve);
 | 
			
		||||
	id_ = static_cast<uint8_t>(json["Id"].toInt(0));
 | 
			
		||||
	address_ = static_cast<uint16_t>(json["Address"].toInt(0));
 | 
			
		||||
	itemId_ = address_ | (static_cast<uint32_t>(id_) << 16);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint16_t Relay::getAddress() const
 | 
			
		||||
{
 | 
			
		||||
    return address_;
 | 
			
		||||
	return address_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint8_t Relay::getId() const
 | 
			
		||||
{
 | 
			
		||||
    return id_;
 | 
			
		||||
	return id_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Relay::setId(uint8_t id)
 | 
			
		||||
{
 | 
			
		||||
    id_=id;
 | 
			
		||||
    itemId_ = address_ | ((uint32_t)id << 16);
 | 
			
		||||
	id_=id;
 | 
			
		||||
	itemId_ = address_ | ((uint32_t)id << 16);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,30 +11,33 @@ class Microcontroller;
 | 
			
		|||
 | 
			
		||||
class Relay : public Item
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    static Microcontroller* micro_;
 | 
			
		||||
	static Microcontroller* micro_;
 | 
			
		||||
 | 
			
		||||
    uint8_t id_;
 | 
			
		||||
    uint16_t address_;
 | 
			
		||||
	uint8_t id_;
 | 
			
		||||
	uint16_t address_;
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
    void on();
 | 
			
		||||
    void off();
 | 
			
		||||
    void toggle();
 | 
			
		||||
	virtual void setValue(uint8_t value);
 | 
			
		||||
	void on();
 | 
			
		||||
	void off();
 | 
			
		||||
	void toggle();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    Relay(uint8_t id = 0, QString name = "", uint16_t address = 0, bool state = false, QObject* parent = nullptr);
 | 
			
		||||
	Relay(uint8_t id = 0, QString name = "", uint16_t address = 0, bool state = false, QObject* parent = nullptr);
 | 
			
		||||
 | 
			
		||||
    uint16_t getAddress() const;
 | 
			
		||||
    uint8_t getId() const;
 | 
			
		||||
    void setId(uint8_t id);
 | 
			
		||||
	uint16_t getAddress() const;
 | 
			
		||||
	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);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
};
 | 
			
		||||
#endif // RELAY_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,18 +1,19 @@
 | 
			
		|||
#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)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RgbItem::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    Item::setValue(value);
 | 
			
		||||
    value ? micro_->rgbOn() : micro_->rgbOff();
 | 
			
		||||
	Item::setValue(value);
 | 
			
		||||
	value ? micro_->rgbOn() : micro_->rgbOff();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RgbItem::store(QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "Rgb";
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
	json["Type"] = "Rgb";
 | 
			
		||||
	Item::store(json);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,16 +5,17 @@
 | 
			
		|||
 | 
			
		||||
class RgbItem: public Item
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    Microcontroller* micro_;
 | 
			
		||||
	Microcontroller* micro_;
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	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);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,41 +3,41 @@
 | 
			
		|||
 | 
			
		||||
void SystemItem::setValue(uint8_t value)
 | 
			
		||||
{
 | 
			
		||||
    QProcess::execute(value ? onCommand_ : offCommand_);
 | 
			
		||||
	QProcess::execute(value ? onCommand_ : offCommand_);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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):
 | 
			
		||||
Item(itemData, parent)
 | 
			
		||||
	Item(itemData, parent)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SystemItem::setOnCommand(const QString& in)
 | 
			
		||||
{
 | 
			
		||||
    onCommand_ = in;
 | 
			
		||||
	onCommand_ = in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SystemItem::setOffCommand(const QString& in)
 | 
			
		||||
{
 | 
			
		||||
    offCommand_ = in;
 | 
			
		||||
	offCommand_ = in;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SystemItem::store(QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    json["Type"] = "System";
 | 
			
		||||
    Item::store(json);
 | 
			
		||||
    json["OnCommand"] = onCommand_;
 | 
			
		||||
    json["OffCommand"] = offCommand_;
 | 
			
		||||
	json["Type"] = "System";
 | 
			
		||||
	Item::store(json);
 | 
			
		||||
	json["OnCommand"] = onCommand_;
 | 
			
		||||
	json["OffCommand"] = offCommand_;
 | 
			
		||||
}
 | 
			
		||||
void SystemItem::load(const QJsonObject& json, const bool preserve)
 | 
			
		||||
{
 | 
			
		||||
    Item::load(json,preserve);
 | 
			
		||||
    onCommand_ = json["OnCommand"].toString("");
 | 
			
		||||
    offCommand_ = json["OffCommand"].toString("");
 | 
			
		||||
	Item::load(json,preserve);
 | 
			
		||||
	onCommand_ = json["OnCommand"].toString("");
 | 
			
		||||
	offCommand_ = json["OffCommand"].toString("");
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,29 +6,36 @@
 | 
			
		|||
 | 
			
		||||
class SystemItem : public Item
 | 
			
		||||
{
 | 
			
		||||
Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    QString onCommand_;
 | 
			
		||||
    QString offCommand_;
 | 
			
		||||
	QString onCommand_;
 | 
			
		||||
	QString offCommand_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    virtual void setValue(uint8_t value);
 | 
			
		||||
	virtual void setValue(uint8_t value);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    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;
 | 
			
		||||
	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_;}
 | 
			
		||||
	void setOnCommand(const QString& in);
 | 
			
		||||
	void setOffCommand(const QString& in);
 | 
			
		||||
	QString getOnCommand()
 | 
			
		||||
	{
 | 
			
		||||
		return onCommand_;
 | 
			
		||||
	}
 | 
			
		||||
	QString getOffCommand()
 | 
			
		||||
	{
 | 
			
		||||
		return offCommand_;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    virtual void store(QJsonObject& json);
 | 
			
		||||
    virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
	virtual void store(QJsonObject& json);
 | 
			
		||||
	virtual void load(const QJsonObject& json, const bool preserve = false);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // SYSTEMITEM_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										166
									
								
								src/main.cpp
									
										
									
									
									
								
							
							
						
						
									
										166
									
								
								src/main.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -30,104 +30,112 @@
 | 
			
		|||
 | 
			
		||||
int main(int argc, char *argv[])
 | 
			
		||||
{
 | 
			
		||||
    QApplication a(argc, argv);
 | 
			
		||||
	QApplication a(argc, argv);
 | 
			
		||||
 | 
			
		||||
    //set info
 | 
			
		||||
    QCoreApplication::setOrganizationName("UVOS");
 | 
			
		||||
    QCoreApplication::setOrganizationDomain("uvos.xyz");
 | 
			
		||||
    QCoreApplication::setApplicationName("SHinterface");
 | 
			
		||||
    QCoreApplication::setApplicationVersion("0.6");
 | 
			
		||||
	//set info
 | 
			
		||||
	QCoreApplication::setOrganizationName("UVOS");
 | 
			
		||||
	QCoreApplication::setOrganizationDomain("uvos.xyz");
 | 
			
		||||
	QCoreApplication::setApplicationName("SHinterface");
 | 
			
		||||
	QCoreApplication::setApplicationVersion("0.6");
 | 
			
		||||
 | 
			
		||||
    QDir::setCurrent(a.applicationDirPath());
 | 
			
		||||
	QDir::setCurrent(a.applicationDirPath());
 | 
			
		||||
 | 
			
		||||
    //parse comand line
 | 
			
		||||
    #ifndef Q_OS_ANDROID
 | 
			
		||||
    QCommandLineParser parser;
 | 
			
		||||
    parser.setApplicationDescription("Smart Home Interface");
 | 
			
		||||
    parser.addHelpOption();
 | 
			
		||||
    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");
 | 
			
		||||
    parser.addOption(hostOption);
 | 
			
		||||
    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"));
 | 
			
		||||
    parser.addOption(serialOption);
 | 
			
		||||
    QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
 | 
			
		||||
    parser.addOption(baudOption);
 | 
			
		||||
    QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main", "Set config file"), "configFilePath");
 | 
			
		||||
    parser.addOption(settingsPathOption);
 | 
			
		||||
    QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main", "Set if instance is not main instance"));
 | 
			
		||||
    parser.addOption(secondaryOption);
 | 
			
		||||
    parser.process(a);
 | 
			
		||||
    #endif
 | 
			
		||||
	//parse comand line
 | 
			
		||||
#ifndef Q_OS_ANDROID
 | 
			
		||||
	QCommandLineParser parser;
 | 
			
		||||
	parser.setApplicationDescription("Smart Home Interface");
 | 
			
		||||
	parser.addHelpOption();
 | 
			
		||||
	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");
 | 
			
		||||
	parser.addOption(hostOption);
 | 
			
		||||
	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"));
 | 
			
		||||
	parser.addOption(serialOption);
 | 
			
		||||
	QCommandLineOption baudOption(QStringList() << "b" << "baud", QCoreApplication::translate("main", "Set Baud Rate"));
 | 
			
		||||
	parser.addOption(baudOption);
 | 
			
		||||
	QCommandLineOption settingsPathOption(QStringList() << "c" << "config", QCoreApplication::translate("main",
 | 
			
		||||
	                                      "Set config file"), "configFilePath");
 | 
			
		||||
	parser.addOption(settingsPathOption);
 | 
			
		||||
	QCommandLineOption secondaryOption(QStringList() << "e" << "secondary", QCoreApplication::translate("main",
 | 
			
		||||
	                                   "Set if instance is not main instance"));
 | 
			
		||||
	parser.addOption(secondaryOption);
 | 
			
		||||
	parser.process(a);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    QIODevice* masterIODevice = nullptr;
 | 
			
		||||
	QIODevice* masterIODevice = nullptr;
 | 
			
		||||
 | 
			
		||||
    #ifndef Q_OS_ANDROID
 | 
			
		||||
    if(parser.isSet(tcpOption))
 | 
			
		||||
    {
 | 
			
		||||
        QTcpSocket* microSocket = new QTcpSocket;
 | 
			
		||||
#ifndef Q_OS_ANDROID
 | 
			
		||||
	if(parser.isSet(tcpOption))
 | 
			
		||||
	{
 | 
			
		||||
		QTcpSocket* microSocket = new QTcpSocket;
 | 
			
		||||
 | 
			
		||||
        int port = 6856;
 | 
			
		||||
        if(parser.isSet(portOption)) port =  parser.value(portOption).toInt();
 | 
			
		||||
		int port = 6856;
 | 
			
		||||
		if(parser.isSet(portOption)) port =  parser.value(portOption).toInt();
 | 
			
		||||
 | 
			
		||||
        QString host("127.0.0.1");
 | 
			
		||||
        if(parser.isSet(hostOption)) host = parser.value(hostOption);
 | 
			
		||||
        std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
 | 
			
		||||
        microSocket->connectToHost(host, port, QIODevice::ReadWrite);
 | 
			
		||||
        if(!microSocket->waitForConnected(1000))
 | 
			
		||||
        {
 | 
			
		||||
            std::cout<<"Can not connect to to Server.\n";
 | 
			
		||||
            QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        masterIODevice = microSocket;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QSerialPort* microPort = new QSerialPort;
 | 
			
		||||
        if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
 | 
			
		||||
        else microPort->setPortName("ttyUSB0");
 | 
			
		||||
		QString host("127.0.0.1");
 | 
			
		||||
		if(parser.isSet(hostOption)) host = parser.value(hostOption);
 | 
			
		||||
		std::cout<<"connecting to "<<host.toStdString()<<':'<<port<<'\n';
 | 
			
		||||
		microSocket->connectToHost(host, port, QIODevice::ReadWrite);
 | 
			
		||||
		if(!microSocket->waitForConnected(1000))
 | 
			
		||||
		{
 | 
			
		||||
			std::cout<<"Can not connect to to Server.\n";
 | 
			
		||||
			QMessageBox::critical(nullptr, "Error", "Can not connect to to Server");
 | 
			
		||||
			return 1;
 | 
			
		||||
		}
 | 
			
		||||
		masterIODevice = microSocket;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QSerialPort* microPort = new QSerialPort;
 | 
			
		||||
		if(parser.isSet(portOption)) microPort->setPortName(parser.value(portOption));
 | 
			
		||||
		else microPort->setPortName("ttyUSB0");
 | 
			
		||||
 | 
			
		||||
        if(parser.isSet(portOption)) microPort->setBaudRate(parser.value(baudOption).toInt());
 | 
			
		||||
        else microPort->setBaudRate(BAUD);
 | 
			
		||||
		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';
 | 
			
		||||
        masterIODevice = microPort;
 | 
			
		||||
    }
 | 
			
		||||
		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;
 | 
			
		||||
        microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
 | 
			
		||||
        if(!microSocket->waitForConnected(1000))
 | 
			
		||||
        {
 | 
			
		||||
            std::cout<<"Can not connect to to Server.\n";
 | 
			
		||||
            return 1;
 | 
			
		||||
        }
 | 
			
		||||
        masterIODevice = microSocket;
 | 
			
		||||
#else
 | 
			
		||||
	QTcpSocket* microSocket = new QTcpSocket;
 | 
			
		||||
	microSocket->connectToHost("10.0.0.1", 6856, QIODevice::ReadWrite);
 | 
			
		||||
	if(!microSocket->waitForConnected(1000))
 | 
			
		||||
	{
 | 
			
		||||
		std::cout<<"Can not connect to to Server.\n";
 | 
			
		||||
		return 1;
 | 
			
		||||
	}
 | 
			
		||||
	masterIODevice = microSocket;
 | 
			
		||||
 | 
			
		||||
        MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "", !parser.isSet(secondaryOption));
 | 
			
		||||
    #endif
 | 
			
		||||
	MainObject mainObject(masterIODevice, parser.isSet(settingsPathOption) ? parser.value(settingsPathOption) : "",
 | 
			
		||||
	                      !parser.isSet(secondaryOption));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    //mainwindow
 | 
			
		||||
    MainWindow w(&mainObject);
 | 
			
		||||
    QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
 | 
			
		||||
    QObject::connect(&w, &MainWindow::sigBrodcast, &mainObject, &MainObject::sendJson);
 | 
			
		||||
	//mainwindow
 | 
			
		||||
	MainWindow w(&mainObject);
 | 
			
		||||
	QObject::connect(&mainObject.micro, SIGNAL(textRecived(QString)), &w, SLOT(changeHeaderLableText(QString)));
 | 
			
		||||
	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!");
 | 
			
		||||
	QObject::connect(&w, &MainWindow::createdItem, &mainObject.items, &ItemStore::addItem);
 | 
			
		||||
	if(!mainObject.micro.connected()) w.changeHeaderLableText("No io debug only!");
 | 
			
		||||
 | 
			
		||||
    w.show();
 | 
			
		||||
	w.show();
 | 
			
		||||
 | 
			
		||||
    int retVal = a.exec();
 | 
			
		||||
	int retVal = a.exec();
 | 
			
		||||
 | 
			
		||||
	if(masterIODevice)
 | 
			
		||||
		delete masterIODevice;
 | 
			
		||||
    return retVal;
 | 
			
		||||
	return retVal;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,56 +2,56 @@
 | 
			
		|||
#include "items/messageitem.h"
 | 
			
		||||
 | 
			
		||||
MainObject::MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent) :
 | 
			
		||||
    QObject(parent),
 | 
			
		||||
    master(masterIn),
 | 
			
		||||
    masterIODevice(ioDevice),
 | 
			
		||||
    ioMultiplexer(masterIODevice),
 | 
			
		||||
    micro(ioMultiplexer.getIoDevice()),
 | 
			
		||||
    broadCast(ioMultiplexer.getIoDevice(), masterIn),
 | 
			
		||||
    settingsPath(settingsPathIn),
 | 
			
		||||
    sunSensorSource(49.884450, 8.650536),
 | 
			
		||||
    powerItem(new PowerItem),
 | 
			
		||||
    rgbItem(new RgbItem(µ, 5487422, "Rgb Lights")),
 | 
			
		||||
    auxItem(new AuxItem(µ, 5487421, "Desk Light"))
 | 
			
		||||
	QObject(parent),
 | 
			
		||||
	master(masterIn),
 | 
			
		||||
	masterIODevice(ioDevice),
 | 
			
		||||
	ioMultiplexer(masterIODevice),
 | 
			
		||||
	micro(ioMultiplexer.getIoDevice()),
 | 
			
		||||
	broadCast(ioMultiplexer.getIoDevice(), masterIn),
 | 
			
		||||
	settingsPath(settingsPathIn),
 | 
			
		||||
	sunSensorSource(49.884450, 8.650536),
 | 
			
		||||
	powerItem(new PowerItem),
 | 
			
		||||
	rgbItem(new RgbItem(µ, 5487422, "Rgb Lights")),
 | 
			
		||||
	auxItem(new AuxItem(µ, 5487421, "Desk Light"))
 | 
			
		||||
 | 
			
		||||
{
 | 
			
		||||
    qDebug()<<"Is master:"<<master;
 | 
			
		||||
    //connect sensors subsystem
 | 
			
		||||
    QObject::connect(µ, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
    QObject::connect(&globalSensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
 | 
			
		||||
    QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
	qDebug()<<"Is master:"<<master;
 | 
			
		||||
	//connect sensors subsystem
 | 
			
		||||
	QObject::connect(µ, &Microcontroller::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
	QObject::connect(&sunSensorSource, &SunSensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
	QObject::connect(&globalSensors, &SensorStore::sensorChangedState, &ocupancySensor, &OcupancySensorSource::sensorEvent);
 | 
			
		||||
	QObject::connect(&ocupancySensor, &OcupancySensorSource::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
 | 
			
		||||
    sunSensorSource.run();
 | 
			
		||||
	sunSensorSource.run();
 | 
			
		||||
 | 
			
		||||
    //connect item store
 | 
			
		||||
    QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
 | 
			
		||||
    QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
 | 
			
		||||
	//connect item store
 | 
			
		||||
	QObject::connect(µ, &Microcontroller::gotRelayList, &items, &ItemStore::addItems);
 | 
			
		||||
	QObject::connect(µ, &Microcontroller::itemChanged, &items, &ItemStore::itemStateChanged);
 | 
			
		||||
 | 
			
		||||
    //special items
 | 
			
		||||
    QObject::connect(powerItem.get(), &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
    powerItem->emmitSensor();
 | 
			
		||||
    items.addItem(rgbItem);
 | 
			
		||||
    items.addItem(auxItem);
 | 
			
		||||
    MessageItem::broadCast = &broadCast;
 | 
			
		||||
	//special items
 | 
			
		||||
	QObject::connect(powerItem.get(), &PowerItem::stateChanged, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
	powerItem->emmitSensor();
 | 
			
		||||
	items.addItem(rgbItem);
 | 
			
		||||
	items.addItem(auxItem);
 | 
			
		||||
	MessageItem::broadCast = &broadCast;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    Relay::setMicrocontroller(µ);
 | 
			
		||||
	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);
 | 
			
		||||
	connect(&broadCast, &BroadCast::gotJson, this, &MainObject::recivedJson);
 | 
			
		||||
	QObject::connect(&broadCast, &BroadCast::gotSensorState, &globalSensors, &SensorStore::sensorGotState);
 | 
			
		||||
	if(master)connect(&broadCast, &BroadCast::jsonRequested, this, &MainObject::sendJson);
 | 
			
		||||
 | 
			
		||||
    if(master) load(getJsonObjectFromDisk(settingsPath, &noSave));
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        broadCast.requestJson();
 | 
			
		||||
        broadCast.requestSensors();
 | 
			
		||||
    }
 | 
			
		||||
	if(master) load(getJsonObjectFromDisk(settingsPath, &noSave));
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		broadCast.requestJson();
 | 
			
		||||
		broadCast.requestSensors();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    #ifndef Q_OS_ANDROID
 | 
			
		||||
        Item::secondaryFlag = !master;
 | 
			
		||||
    #endif
 | 
			
		||||
#ifndef Q_OS_ANDROID
 | 
			
		||||
	Item::secondaryFlag = !master;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MainObject::~MainObject()
 | 
			
		||||
| 
						 | 
				
			
			@ -60,36 +60,36 @@ MainObject::~MainObject()
 | 
			
		|||
 | 
			
		||||
void MainObject::store(QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    items.store(json);
 | 
			
		||||
	items.store(json);
 | 
			
		||||
 | 
			
		||||
    QJsonObject powerObject;
 | 
			
		||||
    powerItem->store(powerObject);
 | 
			
		||||
    json.insert("Power", powerObject);
 | 
			
		||||
    QJsonDocument pwrDoc(powerObject);
 | 
			
		||||
	QJsonObject powerObject;
 | 
			
		||||
	powerItem->store(powerObject);
 | 
			
		||||
	json.insert("Power", powerObject);
 | 
			
		||||
	QJsonDocument pwrDoc(powerObject);
 | 
			
		||||
 | 
			
		||||
    QJsonObject ocupancyObject;
 | 
			
		||||
    ocupancySensor.store(ocupancyObject);
 | 
			
		||||
    json.insert("Ocupancy", ocupancyObject);
 | 
			
		||||
	QJsonObject ocupancyObject;
 | 
			
		||||
	ocupancySensor.store(ocupancyObject);
 | 
			
		||||
	json.insert("Ocupancy", ocupancyObject);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainObject::load(const QJsonObject& json)
 | 
			
		||||
{
 | 
			
		||||
    items.clear();
 | 
			
		||||
    rgbItem->removeAllActors();
 | 
			
		||||
    auxItem->removeAllActors();
 | 
			
		||||
    powerItem->removeAllActors();
 | 
			
		||||
    items.addItem(rgbItem);
 | 
			
		||||
    items.addItem(auxItem);
 | 
			
		||||
    items.load(json);
 | 
			
		||||
    powerItem->load(json["Power"].toObject());
 | 
			
		||||
    ocupancySensor.load(json["Ocupancy"].toObject());
 | 
			
		||||
    qDebug()<<"aray size: "<<json.isEmpty();
 | 
			
		||||
    if(json["Items"].toArray().size() >= 2)
 | 
			
		||||
    {
 | 
			
		||||
        rgbItem->load(json["Items"].toArray()[0].toObject());
 | 
			
		||||
        auxItem->load(json["Items"].toArray()[1].toObject());
 | 
			
		||||
    }
 | 
			
		||||
    micro.requestState();
 | 
			
		||||
	items.clear();
 | 
			
		||||
	rgbItem->removeAllActors();
 | 
			
		||||
	auxItem->removeAllActors();
 | 
			
		||||
	powerItem->removeAllActors();
 | 
			
		||||
	items.addItem(rgbItem);
 | 
			
		||||
	items.addItem(auxItem);
 | 
			
		||||
	items.load(json);
 | 
			
		||||
	powerItem->load(json["Power"].toObject());
 | 
			
		||||
	ocupancySensor.load(json["Ocupancy"].toObject());
 | 
			
		||||
	qDebug()<<"aray size: "<<json.isEmpty();
 | 
			
		||||
	if(json["Items"].toArray().size() >= 2)
 | 
			
		||||
	{
 | 
			
		||||
		rgbItem->load(json["Items"].toArray()[0].toObject());
 | 
			
		||||
		auxItem->load(json["Items"].toArray()[1].toObject());
 | 
			
		||||
	}
 | 
			
		||||
	micro.requestState();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainObject::storeToDisk()
 | 
			
		||||
| 
						 | 
				
			
			@ -106,70 +106,70 @@ void MainObject::recivedJson(const QJsonObject json)
 | 
			
		|||
{
 | 
			
		||||
	if(master && !noSave)
 | 
			
		||||
		storeJsonObjectToDisk(json, settingsPath);
 | 
			
		||||
    load(json);
 | 
			
		||||
	load(json);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainObject::sendJson()
 | 
			
		||||
{
 | 
			
		||||
    QJsonObject json;
 | 
			
		||||
    store(json);
 | 
			
		||||
    broadCast.sendJson(json);
 | 
			
		||||
	QJsonObject json;
 | 
			
		||||
	store(json);
 | 
			
		||||
	broadCast.sendJson(json);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QJsonObject MainObject::getJsonObjectFromDisk(const QString& filePath, bool* error)
 | 
			
		||||
{
 | 
			
		||||
    QFile file;
 | 
			
		||||
	QFile file;
 | 
			
		||||
 | 
			
		||||
    #ifndef Q_OS_ANDROID
 | 
			
		||||
    if(filePath.size() > 0) file.setFileName(filePath);
 | 
			
		||||
    else
 | 
			
		||||
    #endif
 | 
			
		||||
    {
 | 
			
		||||
       file.setFileName(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
 | 
			
		||||
    }
 | 
			
		||||
#ifndef Q_OS_ANDROID
 | 
			
		||||
	if(filePath.size() > 0) file.setFileName(filePath);
 | 
			
		||||
	else
 | 
			
		||||
#endif
 | 
			
		||||
	{
 | 
			
		||||
		file.setFileName(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    file.open(QIODevice::ReadOnly);
 | 
			
		||||
    if(!file.isOpen()) std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QJsonParseError qerror;
 | 
			
		||||
        QJsonDocument document(QJsonDocument::fromJson(file.readAll(), &qerror));
 | 
			
		||||
        file.close();
 | 
			
		||||
        if(qerror.error != QJsonParseError::NoError)
 | 
			
		||||
        {
 | 
			
		||||
            qDebug()<<filePath<<" "<<qerror.errorString();
 | 
			
		||||
            if(error) (*error) = true;
 | 
			
		||||
        }
 | 
			
		||||
        return document.object();
 | 
			
		||||
    }
 | 
			
		||||
    return QJsonObject();
 | 
			
		||||
	file.open(QIODevice::ReadOnly);
 | 
			
		||||
	if(!file.isOpen()) std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QJsonParseError qerror;
 | 
			
		||||
		QJsonDocument document(QJsonDocument::fromJson(file.readAll(), &qerror));
 | 
			
		||||
		file.close();
 | 
			
		||||
		if(qerror.error != QJsonParseError::NoError)
 | 
			
		||||
		{
 | 
			
		||||
			qDebug()<<filePath<<" "<<qerror.errorString();
 | 
			
		||||
			if(error) (*error) = true;
 | 
			
		||||
		}
 | 
			
		||||
		return document.object();
 | 
			
		||||
	}
 | 
			
		||||
	return QJsonObject();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool MainObject::storeJsonObjectToDisk(const QJsonObject& json, QString filePath)
 | 
			
		||||
{
 | 
			
		||||
    #ifndef Q_OS_ANDROID
 | 
			
		||||
    if(filePath.size() == 0)
 | 
			
		||||
    #endif
 | 
			
		||||
    {
 | 
			
		||||
        filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json";
 | 
			
		||||
    }
 | 
			
		||||
    QFile file(filePath + ".out");
 | 
			
		||||
#ifndef Q_OS_ANDROID
 | 
			
		||||
	if(filePath.size() == 0)
 | 
			
		||||
#endif
 | 
			
		||||
	{
 | 
			
		||||
		filePath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation) + "/shinterface.json";
 | 
			
		||||
	}
 | 
			
		||||
	QFile file(filePath + ".out");
 | 
			
		||||
 | 
			
		||||
    qDebug()<<"config file: "<<filePath;
 | 
			
		||||
    file.open(QIODevice::WriteOnly);
 | 
			
		||||
    if(!file.isOpen())
 | 
			
		||||
    {
 | 
			
		||||
       std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
 | 
			
		||||
       return false;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        QJsonDocument document(json);
 | 
			
		||||
        file.write(document.toJson());
 | 
			
		||||
        file.close();
 | 
			
		||||
        QFile::remove(filePath);
 | 
			
		||||
	qDebug()<<"config file: "<<filePath;
 | 
			
		||||
	file.open(QIODevice::WriteOnly);
 | 
			
		||||
	if(!file.isOpen())
 | 
			
		||||
	{
 | 
			
		||||
		std::cerr<<"Can not open config file: "<<filePath.toLatin1().data()<<std::endl;
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		QJsonDocument document(json);
 | 
			
		||||
		file.write(document.toJson());
 | 
			
		||||
		file.close();
 | 
			
		||||
		QFile::remove(filePath);
 | 
			
		||||
		file.rename(filePath);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,53 +35,53 @@
 | 
			
		|||
 | 
			
		||||
class MainObject : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    //io
 | 
			
		||||
    const bool master;
 | 
			
		||||
	//io
 | 
			
		||||
	const bool master;
 | 
			
		||||
 | 
			
		||||
    bool noSave = false;
 | 
			
		||||
	bool noSave = false;
 | 
			
		||||
 | 
			
		||||
    QIODevice * const masterIODevice = nullptr;
 | 
			
		||||
    IoMuliplexer ioMultiplexer;
 | 
			
		||||
	QIODevice * const masterIODevice = nullptr;
 | 
			
		||||
	IoMuliplexer ioMultiplexer;
 | 
			
		||||
 | 
			
		||||
    Microcontroller micro;
 | 
			
		||||
    BroadCast broadCast;
 | 
			
		||||
	Microcontroller micro;
 | 
			
		||||
	BroadCast broadCast;
 | 
			
		||||
 | 
			
		||||
    const QString settingsPath;
 | 
			
		||||
	const QString settingsPath;
 | 
			
		||||
 | 
			
		||||
    //sensors
 | 
			
		||||
    SunSensorSource     sunSensorSource;
 | 
			
		||||
    OcupancySensorSource ocupancySensor;
 | 
			
		||||
	//sensors
 | 
			
		||||
	SunSensorSource     sunSensorSource;
 | 
			
		||||
	OcupancySensorSource ocupancySensor;
 | 
			
		||||
 | 
			
		||||
    //items
 | 
			
		||||
    ItemStore items;
 | 
			
		||||
	//items
 | 
			
		||||
	ItemStore items;
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<PowerItem> powerItem;
 | 
			
		||||
    std::shared_ptr<RgbItem> rgbItem;
 | 
			
		||||
    std::shared_ptr<AuxItem> auxItem;
 | 
			
		||||
	std::shared_ptr<PowerItem> powerItem;
 | 
			
		||||
	std::shared_ptr<RgbItem> rgbItem;
 | 
			
		||||
	std::shared_ptr<AuxItem> auxItem;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
 | 
			
		||||
    static bool storeJsonObjectToDisk(const QJsonObject& json, QString filePath = "");
 | 
			
		||||
	static QJsonObject getJsonObjectFromDisk(const QString& filePath = "", bool* error = nullptr);
 | 
			
		||||
	static bool storeJsonObjectToDisk(const QJsonObject& json, QString filePath = "");
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent = nullptr);
 | 
			
		||||
    ~MainObject();
 | 
			
		||||
	explicit MainObject(QIODevice* ioDevice, const QString& settingsPathIn, const bool masterIn, QObject *parent = nullptr);
 | 
			
		||||
	~MainObject();
 | 
			
		||||
 | 
			
		||||
    void store(QJsonObject& json);
 | 
			
		||||
	void store(QJsonObject& json);
 | 
			
		||||
 | 
			
		||||
    void load(const QJsonObject& json);
 | 
			
		||||
	void load(const QJsonObject& json);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
	void storeToDisk();
 | 
			
		||||
    void sendJson();
 | 
			
		||||
    void recivedJson(const QJsonObject json);
 | 
			
		||||
	void sendJson();
 | 
			
		||||
	void recivedJson(const QJsonObject json);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,104 +7,104 @@ static constexpr bool debug = true;
 | 
			
		|||
 | 
			
		||||
void Microcontroller::relayToggle(int state, int relay)
 | 
			
		||||
{
 | 
			
		||||
    char buffer[8];
 | 
			
		||||
    int length = sprintf(buffer, "%d \n", relay);
 | 
			
		||||
    state ? write("item on ") : write("item off ");
 | 
			
		||||
    write(buffer, length);
 | 
			
		||||
	char buffer[8];
 | 
			
		||||
	int length = sprintf(buffer, "%d \n", relay);
 | 
			
		||||
	state ? write("item on ") : write("item off ");
 | 
			
		||||
	write(buffer, length);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::relayOn(int relay)
 | 
			
		||||
{
 | 
			
		||||
  relayToggle(true, relay);
 | 
			
		||||
	relayToggle(true, relay);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::relayOff(int relay)
 | 
			
		||||
{
 | 
			
		||||
  relayToggle(false, relay);
 | 
			
		||||
	relayToggle(false, relay);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//rgb lights
 | 
			
		||||
 | 
			
		||||
void Microcontroller::rgbOn()
 | 
			
		||||
{
 | 
			
		||||
    write("rgb on\n");
 | 
			
		||||
	write("rgb on\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::rgbOff()
 | 
			
		||||
{
 | 
			
		||||
    write( "rgb off\n");
 | 
			
		||||
	write( "rgb off\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::changeRgbColor(const QColor color)
 | 
			
		||||
{
 | 
			
		||||
    char buffer[64];
 | 
			
		||||
    int length = sprintf(buffer, "rgb set %03d %03d %03d\n", color.red(), color.green(), color.blue());
 | 
			
		||||
        write(buffer, length);
 | 
			
		||||
        std::cout<<buffer;
 | 
			
		||||
    }
 | 
			
		||||
	char buffer[64];
 | 
			
		||||
	int length = sprintf(buffer, "rgb set %03d %03d %03d\n", color.red(), color.green(), color.blue());
 | 
			
		||||
	write(buffer, length);
 | 
			
		||||
	std::cout<<buffer;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    void Microcontroller::setAuxPwm(int duty)
 | 
			
		||||
    {
 | 
			
		||||
    char buffer[64];
 | 
			
		||||
    int length = sprintf(buffer, "aux set %03d\n", duty );
 | 
			
		||||
    write(buffer, length);
 | 
			
		||||
void Microcontroller::setAuxPwm(int duty)
 | 
			
		||||
{
 | 
			
		||||
	char buffer[64];
 | 
			
		||||
	int length = sprintf(buffer, "aux set %03d\n", duty );
 | 
			
		||||
	write(buffer, length);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::write(const QByteArray& buffer)
 | 
			
		||||
{
 | 
			
		||||
    #ifndef Q_OS_ANDROID
 | 
			
		||||
    if constexpr(debug) std::cerr<<buffer.data();
 | 
			
		||||
    #endif
 | 
			
		||||
    if(_port != nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        _port->write(buffer);
 | 
			
		||||
        _port->waitForBytesWritten(1000);
 | 
			
		||||
    }
 | 
			
		||||
    std::this_thread::sleep_for(std::chrono::milliseconds(40));
 | 
			
		||||
#ifndef Q_OS_ANDROID
 | 
			
		||||
	if constexpr(debug) std::cerr<<buffer.data();
 | 
			
		||||
#endif
 | 
			
		||||
	if(_port != nullptr)
 | 
			
		||||
	{
 | 
			
		||||
		_port->write(buffer);
 | 
			
		||||
		_port->waitForBytesWritten(1000);
 | 
			
		||||
	}
 | 
			
		||||
	std::this_thread::sleep_for(std::chrono::milliseconds(40));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::write(char* buffer, const size_t length)
 | 
			
		||||
{
 | 
			
		||||
    #ifndef Q_OS_ANDROID
 | 
			
		||||
    if constexpr(debug) std::cerr<<buffer;
 | 
			
		||||
    #endif
 | 
			
		||||
    if(_port != nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        _port->write(buffer, length);
 | 
			
		||||
        _port->waitForBytesWritten(1000);
 | 
			
		||||
    }
 | 
			
		||||
    std::this_thread::sleep_for(std::chrono::milliseconds(40));
 | 
			
		||||
#ifndef Q_OS_ANDROID
 | 
			
		||||
	if constexpr(debug) std::cerr<<buffer;
 | 
			
		||||
#endif
 | 
			
		||||
	if(_port != nullptr)
 | 
			
		||||
	{
 | 
			
		||||
		_port->write(buffer, length);
 | 
			
		||||
		_port->waitForBytesWritten(1000);
 | 
			
		||||
	}
 | 
			
		||||
	std::this_thread::sleep_for(std::chrono::milliseconds(40));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::setPattern(int pattern)
 | 
			
		||||
{
 | 
			
		||||
        char buffer[4];
 | 
			
		||||
        write("rgb pattern ");
 | 
			
		||||
        int length = sprintf(buffer, "%d\n", pattern);
 | 
			
		||||
        write(buffer, length);
 | 
			
		||||
	char buffer[4];
 | 
			
		||||
	write("rgb pattern ");
 | 
			
		||||
	int length = sprintf(buffer, "%d\n", pattern);
 | 
			
		||||
	write(buffer, length);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::startSunrise()
 | 
			
		||||
{
 | 
			
		||||
    setPattern(4);
 | 
			
		||||
	setPattern(4);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Microcontroller::connected()
 | 
			
		||||
{
 | 
			
		||||
   if(_port != nullptr) return _port->isOpen();
 | 
			
		||||
   else return false;
 | 
			
		||||
	if(_port != nullptr) return _port->isOpen();
 | 
			
		||||
	else return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::requestState()
 | 
			
		||||
{
 | 
			
		||||
   write("state\n");
 | 
			
		||||
	write("state\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//housekeeping
 | 
			
		||||
 | 
			
		||||
Microcontroller::Microcontroller(QIODevice* port)
 | 
			
		||||
{
 | 
			
		||||
    setIODevice(port);
 | 
			
		||||
	setIODevice(port);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Microcontroller::Microcontroller()
 | 
			
		||||
| 
						 | 
				
			
			@ -117,81 +117,82 @@ Microcontroller::~Microcontroller()
 | 
			
		|||
 | 
			
		||||
void Microcontroller::setIODevice(QIODevice *port)
 | 
			
		||||
{
 | 
			
		||||
    _port = port;
 | 
			
		||||
    QObject::connect(_port, &QIODevice::readyRead, this, &Microcontroller::isReadyRead);
 | 
			
		||||
	_port = port;
 | 
			
		||||
	QObject::connect(_port, &QIODevice::readyRead, this, &Microcontroller::isReadyRead);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::shared_ptr<Relay> Microcontroller::processRelayLine(const QString& buffer)
 | 
			
		||||
{
 | 
			
		||||
    QStringList bufferList = buffer.split(' ');
 | 
			
		||||
    if(bufferList.size() >= 9 && buffer.startsWith("ITEM NUMBER:"))
 | 
			
		||||
    {
 | 
			
		||||
        QString name;
 | 
			
		||||
        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  nullptr;
 | 
			
		||||
	QStringList bufferList = buffer.split(' ');
 | 
			
		||||
	if(bufferList.size() >= 9 && buffer.startsWith("ITEM NUMBER:"))
 | 
			
		||||
	{
 | 
			
		||||
		QString name;
 | 
			
		||||
		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  nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::processList(const QString& buffer)
 | 
			
		||||
{
 | 
			
		||||
    QStringList bufferList = buffer.split(' ');
 | 
			
		||||
    if(bufferList.size() >= 8 && buffer.startsWith("ITEM NUMBER:"))
 | 
			
		||||
    {
 | 
			
		||||
        relayList.push_back(processRelayLine(buffer));
 | 
			
		||||
    }
 | 
			
		||||
    else if(buffer.contains("EOL"))
 | 
			
		||||
    {
 | 
			
		||||
        listMode = false;
 | 
			
		||||
        qDebug()<<"got relay list " << relayList.size();
 | 
			
		||||
        gotRelayList(relayList);
 | 
			
		||||
        relayList.clear();
 | 
			
		||||
    }
 | 
			
		||||
    else listMode = false;
 | 
			
		||||
	QStringList bufferList = buffer.split(' ');
 | 
			
		||||
	if(bufferList.size() >= 8 && buffer.startsWith("ITEM NUMBER:"))
 | 
			
		||||
	{
 | 
			
		||||
		relayList.push_back(processRelayLine(buffer));
 | 
			
		||||
	}
 | 
			
		||||
	else if(buffer.contains("EOL"))
 | 
			
		||||
	{
 | 
			
		||||
		listMode = false;
 | 
			
		||||
		qDebug()<<"got relay list " << relayList.size();
 | 
			
		||||
		gotRelayList(relayList);
 | 
			
		||||
		relayList.clear();
 | 
			
		||||
	}
 | 
			
		||||
	else listMode = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::processRelayState(const QString& buffer)
 | 
			
		||||
{
 | 
			
		||||
    itemChanged(static_cast<ItemData>(*processRelayLine(buffer)));
 | 
			
		||||
	itemChanged(static_cast<ItemData>(*processRelayLine(buffer)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::processSensorState(const QString& buffer)
 | 
			
		||||
{
 | 
			
		||||
    Sensor sensor = Sensor::sensorFromString(buffer);
 | 
			
		||||
    if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
 | 
			
		||||
	Sensor sensor = Sensor::sensorFromString(buffer);
 | 
			
		||||
	if(sensor.type != Sensor::TYPE_DUMMY) gotSensorState(sensor);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void Microcontroller::processMicroReturn()
 | 
			
		||||
{
 | 
			
		||||
    if(listMode) processList(_buffer);
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
	if(listMode) processList(_buffer);
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		if(_buffer.startsWith("Items:"))
 | 
			
		||||
        {
 | 
			
		||||
            listMode = true;
 | 
			
		||||
            relayList.clear();
 | 
			
		||||
        }
 | 
			
		||||
        else if(_buffer.startsWith("ITEM NUMBER:"))processRelayState(_buffer);
 | 
			
		||||
        else if(_buffer.startsWith("SENSOR")) processSensorState(_buffer);
 | 
			
		||||
    }
 | 
			
		||||
		{
 | 
			
		||||
			listMode = true;
 | 
			
		||||
			relayList.clear();
 | 
			
		||||
		}
 | 
			
		||||
		else if(_buffer.startsWith("ITEM NUMBER:"))processRelayState(_buffer);
 | 
			
		||||
		else if(_buffer.startsWith("SENSOR")) processSensorState(_buffer);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Microcontroller::isReadyRead()
 | 
			
		||||
{
 | 
			
		||||
    char charBuf;
 | 
			
		||||
    while(_port->getChar(&charBuf))
 | 
			
		||||
    {
 | 
			
		||||
        _buffer.push_back(charBuf);
 | 
			
		||||
        if( _buffer.endsWith('\n') )
 | 
			
		||||
        {
 | 
			
		||||
            _buffer.remove('\n');
 | 
			
		||||
            processMicroReturn();
 | 
			
		||||
            textRecived(_buffer);
 | 
			
		||||
            _buffer.clear();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
	char charBuf;
 | 
			
		||||
	while(_port->getChar(&charBuf))
 | 
			
		||||
	{
 | 
			
		||||
		_buffer.push_back(charBuf);
 | 
			
		||||
		if( _buffer.endsWith('\n') )
 | 
			
		||||
		{
 | 
			
		||||
			_buffer.remove('\n');
 | 
			
		||||
			processMicroReturn();
 | 
			
		||||
			textRecived(_buffer);
 | 
			
		||||
			_buffer.clear();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,69 +21,69 @@
 | 
			
		|||
class Microcontroller : public QObject
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    static constexpr char AMP_RELAY = 0;
 | 
			
		||||
    static constexpr char SENSOR_TEMPERATURE = 1;
 | 
			
		||||
    static constexpr char SENSOR_DOOR = 0 ;
 | 
			
		||||
	static constexpr char AMP_RELAY = 0;
 | 
			
		||||
	static constexpr char SENSOR_TEMPERATURE = 1;
 | 
			
		||||
	static constexpr char SENSOR_DOOR = 0 ;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    bool listMode = false;
 | 
			
		||||
	bool listMode = false;
 | 
			
		||||
 | 
			
		||||
    //uint8_t _auxState = 0;
 | 
			
		||||
	//uint8_t _auxState = 0;
 | 
			
		||||
 | 
			
		||||
    QIODevice* _port = nullptr;
 | 
			
		||||
	QIODevice* _port = nullptr;
 | 
			
		||||
 | 
			
		||||
    std::vector< std::shared_ptr<Item> > relayList;
 | 
			
		||||
	std::vector< std::shared_ptr<Item> > relayList;
 | 
			
		||||
 | 
			
		||||
    QScopedPointer<QEventLoop> loop;
 | 
			
		||||
    QString _buffer;
 | 
			
		||||
	QScopedPointer<QEventLoop> loop;
 | 
			
		||||
	QString _buffer;
 | 
			
		||||
 | 
			
		||||
    void processMicroReturn();
 | 
			
		||||
    void processList(const QString& buffer);
 | 
			
		||||
    void processRelayState(const QString& buffer);
 | 
			
		||||
    void processSensorState(const QString& buffer);
 | 
			
		||||
    std::shared_ptr<Relay> processRelayLine(const QString& buffer);
 | 
			
		||||
	void processMicroReturn();
 | 
			
		||||
	void processList(const QString& buffer);
 | 
			
		||||
	void processRelayState(const QString& buffer);
 | 
			
		||||
	void processSensorState(const QString& buffer);
 | 
			
		||||
	std::shared_ptr<Relay> processRelayLine(const QString& buffer);
 | 
			
		||||
 | 
			
		||||
    void write(char *buffer, const size_t length);
 | 
			
		||||
    void write(const QByteArray& buffer);
 | 
			
		||||
	void write(char *buffer, const size_t length);
 | 
			
		||||
	void write(const QByteArray& buffer);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    Microcontroller(QIODevice* port);
 | 
			
		||||
    Microcontroller();
 | 
			
		||||
    ~Microcontroller();
 | 
			
		||||
    bool connected();
 | 
			
		||||
    void setIODevice(QIODevice* port);
 | 
			
		||||
	Microcontroller(QIODevice* port);
 | 
			
		||||
	Microcontroller();
 | 
			
		||||
	~Microcontroller();
 | 
			
		||||
	bool connected();
 | 
			
		||||
	void setIODevice(QIODevice* port);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void rgbOn();
 | 
			
		||||
    void rgbOff();
 | 
			
		||||
    void changeRgbColor(const QColor color);
 | 
			
		||||
    void setPattern(int pattern);
 | 
			
		||||
    void startSunrise();
 | 
			
		||||
	void rgbOn();
 | 
			
		||||
	void rgbOff();
 | 
			
		||||
	void changeRgbColor(const QColor color);
 | 
			
		||||
	void setPattern(int pattern);
 | 
			
		||||
	void startSunrise();
 | 
			
		||||
 | 
			
		||||
    void requestState();
 | 
			
		||||
	void requestState();
 | 
			
		||||
 | 
			
		||||
    void setAuxPwm(int duty);
 | 
			
		||||
	void setAuxPwm(int duty);
 | 
			
		||||
 | 
			
		||||
    void relayOn(int relay);
 | 
			
		||||
    void relayOff(int relay);
 | 
			
		||||
    void relayToggle(int state, int id);
 | 
			
		||||
	void relayOn(int relay);
 | 
			
		||||
	void relayOff(int relay);
 | 
			
		||||
	void relayToggle(int state, int id);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void isReadyRead();
 | 
			
		||||
	void isReadyRead();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void textRecived(const QString string);
 | 
			
		||||
    void itemChanged(ItemData relay);
 | 
			
		||||
    void auxStateChanged(int value);
 | 
			
		||||
    void gotRelayList(std::vector< std::shared_ptr<Item> >&);
 | 
			
		||||
	void textRecived(const QString string);
 | 
			
		||||
	void itemChanged(ItemData relay);
 | 
			
		||||
	void auxStateChanged(int value);
 | 
			
		||||
	void gotRelayList(std::vector< std::shared_ptr<Item> >&);
 | 
			
		||||
 | 
			
		||||
    void gotSensorState(Sensor sensor);
 | 
			
		||||
	void gotSensorState(Sensor sensor);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // MICROCONTROLLER_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,57 +5,58 @@
 | 
			
		|||
#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);
 | 
			
		||||
	QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void OcupancySensorSource::sensorEvent(Sensor sensor)
 | 
			
		||||
{
 | 
			
		||||
    if(sensor.type == Sensor::TYPE_DOOR && sensor.id == 1 && sensor.field != 0.0f)
 | 
			
		||||
    {
 | 
			
		||||
        if(occupied == false) stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, 1, "Occupancy"));
 | 
			
		||||
        QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
 | 
			
		||||
    }
 | 
			
		||||
	if(sensor.type == Sensor::TYPE_DOOR && sensor.id == 1 && sensor.field != 0.0f)
 | 
			
		||||
	{
 | 
			
		||||
		if(occupied == false) stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, 1, "Occupancy"));
 | 
			
		||||
		QTimer::singleShot(timeoutMs, this, &OcupancySensorSource::Timeout);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void OcupancySensorSource::Timeout()
 | 
			
		||||
{
 | 
			
		||||
    int error = 0;
 | 
			
		||||
    qDebug()<<"testing for occupancy";
 | 
			
		||||
    std::vector<uint64_t> devices = ap::connectedDevices(device_.toLatin1().toStdString(), error);
 | 
			
		||||
    if(error == 0)
 | 
			
		||||
    {
 | 
			
		||||
        bool found = false;
 | 
			
		||||
        for(size_t i = 0; i < devices.size(); ++i)
 | 
			
		||||
        {
 | 
			
		||||
            std::string mac = ap::macAddrToString(devices[i]);
 | 
			
		||||
            if(mac.find(deviceMac_.toLatin1().toStdString()) != std::string::npos)
 | 
			
		||||
            {
 | 
			
		||||
                found = true;
 | 
			
		||||
                qDebug()<<"occupied";
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, found, "Occupancy"));
 | 
			
		||||
        occupied = found;
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, true, "Occupancy"));
 | 
			
		||||
        qDebug()<<"occupancy sensor error "<<error;
 | 
			
		||||
    }
 | 
			
		||||
	int error = 0;
 | 
			
		||||
	qDebug()<<"testing for occupancy";
 | 
			
		||||
	std::vector<uint64_t> devices = ap::connectedDevices(device_.toLatin1().toStdString(), error);
 | 
			
		||||
	if(error == 0)
 | 
			
		||||
	{
 | 
			
		||||
		bool found = false;
 | 
			
		||||
		for(size_t i = 0; i < devices.size(); ++i)
 | 
			
		||||
		{
 | 
			
		||||
			std::string mac = ap::macAddrToString(devices[i]);
 | 
			
		||||
			if(mac.find(deviceMac_.toLatin1().toStdString()) != std::string::npos)
 | 
			
		||||
			{
 | 
			
		||||
				found = true;
 | 
			
		||||
				qDebug()<<"occupied";
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, found, "Occupancy"));
 | 
			
		||||
		occupied = found;
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		stateChanged(Sensor(Sensor::TYPE_OCUPANCY, 0, true, "Occupancy"));
 | 
			
		||||
		qDebug()<<"occupancy sensor error "<<error;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void OcupancySensorSource::store(QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    json["Device"] = device_;
 | 
			
		||||
    json["MacAddres"] = deviceMac_;
 | 
			
		||||
	json["Device"] = device_;
 | 
			
		||||
	json["MacAddres"] = deviceMac_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void OcupancySensorSource::load(const QJsonObject &json)
 | 
			
		||||
{
 | 
			
		||||
    device_ = json["Device"].toString("wlan0");
 | 
			
		||||
    deviceMac_ = json["MacAddres"].toString("60:BE:B5:25:8C:E0");
 | 
			
		||||
	device_ = json["Device"].toString("wlan0");
 | 
			
		||||
	deviceMac_ = json["MacAddres"].toString("60:BE:B5:25:8C:E0");
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,27 +6,28 @@
 | 
			
		|||
 | 
			
		||||
class OcupancySensorSource : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    QString deviceMac_;
 | 
			
		||||
    QString device_;
 | 
			
		||||
    bool occupied = true;
 | 
			
		||||
    static constexpr unsigned timeoutMs = (15 * 60) * 1000;
 | 
			
		||||
	QString deviceMac_;
 | 
			
		||||
	QString device_;
 | 
			
		||||
	bool occupied = true;
 | 
			
		||||
	static constexpr unsigned timeoutMs = (15 * 60) * 1000;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit OcupancySensorSource(QObject *parent = nullptr, const QString& device = "wlan0", const QString& deviceMac = "60:BE:B5:25:8C:E0");
 | 
			
		||||
	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);
 | 
			
		||||
	void store(QJsonObject& json);
 | 
			
		||||
	void load(const QJsonObject& json);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void sensorEvent(Sensor sensor);
 | 
			
		||||
	void sensorEvent(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void Timeout();
 | 
			
		||||
	void Timeout();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void stateChanged(Sensor sensor);
 | 
			
		||||
	void stateChanged(Sensor sensor);
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,44 +6,44 @@ SensorStore globalSensors;
 | 
			
		|||
 | 
			
		||||
SensorStore::SensorStore(QObject *parent): QObject(parent)
 | 
			
		||||
{
 | 
			
		||||
    sensors_.push_back(Sensor(0,1,0,"Front door"));
 | 
			
		||||
    sensors_.push_back(Sensor(0,0,0,"Bedroom door"));
 | 
			
		||||
	sensors_.push_back(Sensor(0,1,0,"Front door"));
 | 
			
		||||
	sensors_.push_back(Sensor(0,0,0,"Bedroom door"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorStore::sensorGotState(const Sensor& sensor)
 | 
			
		||||
{
 | 
			
		||||
    bool exsisting = false;
 | 
			
		||||
    for(unsigned i = 0; i < sensors_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if(sensor.type == sensors_[i].type && sensor.id == sensors_[i].id)
 | 
			
		||||
        {
 | 
			
		||||
            sensors_[i].updateSeen();
 | 
			
		||||
            if(sensors_[i].field != sensor.field)
 | 
			
		||||
            {
 | 
			
		||||
                sensors_[i].field = sensor.field;
 | 
			
		||||
                sensorChangedState(sensor);
 | 
			
		||||
                stateChenged(sensors_);
 | 
			
		||||
            }
 | 
			
		||||
            exsisting = true;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    if(!exsisting)
 | 
			
		||||
    {
 | 
			
		||||
        sensors_.push_back(sensor);
 | 
			
		||||
        sensorChangedState(sensor);
 | 
			
		||||
        stateChenged(sensors_);
 | 
			
		||||
    }
 | 
			
		||||
	bool exsisting = false;
 | 
			
		||||
	for(unsigned i = 0; i < sensors_.size(); ++i)
 | 
			
		||||
	{
 | 
			
		||||
		if(sensor.type == sensors_[i].type && sensor.id == sensors_[i].id)
 | 
			
		||||
		{
 | 
			
		||||
			sensors_[i].updateSeen();
 | 
			
		||||
			if(sensors_[i].field != sensor.field)
 | 
			
		||||
			{
 | 
			
		||||
				sensors_[i].field = sensor.field;
 | 
			
		||||
				sensorChangedState(sensor);
 | 
			
		||||
				stateChenged(sensors_);
 | 
			
		||||
			}
 | 
			
		||||
			exsisting = true;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if(!exsisting)
 | 
			
		||||
	{
 | 
			
		||||
		sensors_.push_back(sensor);
 | 
			
		||||
		sensorChangedState(sensor);
 | 
			
		||||
		stateChenged(sensors_);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    for(unsigned i = 0; i < sensors_.size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        if(sensors_[i].type > 0 && sensors_[i].type < 128 && QDateTime::currentDateTime() > sensors_[i].lastSeen.addSecs(1800))
 | 
			
		||||
        {
 | 
			
		||||
            sensorDeleted(sensors_[i]);
 | 
			
		||||
            stateChenged(sensors_);
 | 
			
		||||
            sensors_.erase(sensors_.begin()+i);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
	for(unsigned i = 0; i < sensors_.size(); ++i)
 | 
			
		||||
	{
 | 
			
		||||
		if(sensors_[i].type > 0 && sensors_[i].type < 128 && QDateTime::currentDateTime() > sensors_[i].lastSeen.addSecs(1800))
 | 
			
		||||
		{
 | 
			
		||||
			sensorDeleted(sensors_[i]);
 | 
			
		||||
			stateChenged(sensors_);
 | 
			
		||||
			sensors_.erase(sensors_.begin()+i);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,91 +9,104 @@ class Sensor
 | 
			
		|||
{
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    static constexpr uint8_t TYPE_DOOR = 0;
 | 
			
		||||
    static constexpr uint8_t TYPE_TEMPERATURE = 1;
 | 
			
		||||
    static constexpr uint8_t TYPE_HUMIDITY = 2;
 | 
			
		||||
    static constexpr uint8_t TYPE_PRESSURE = 3;
 | 
			
		||||
    static constexpr uint8_t TYPE_BRIGHTNESS = 4;
 | 
			
		||||
    static constexpr uint8_t TYPE_BUTTON     = 5;
 | 
			
		||||
    static constexpr uint8_t TYPE_ADC        = 6;
 | 
			
		||||
    static constexpr uint8_t TYPE_LOWBATTERY = 128;
 | 
			
		||||
    static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
 | 
			
		||||
    static constexpr uint8_t TYPE_OCUPANCY = 252;
 | 
			
		||||
    static constexpr uint8_t TYPE_SUN_ALTITUDE = 253;
 | 
			
		||||
    static constexpr uint8_t TYPE_AUDIO_OUTPUT = 254;
 | 
			
		||||
    static constexpr uint8_t TYPE_DUMMY = 255;
 | 
			
		||||
	static constexpr uint8_t TYPE_DOOR = 0;
 | 
			
		||||
	static constexpr uint8_t TYPE_TEMPERATURE = 1;
 | 
			
		||||
	static constexpr uint8_t TYPE_HUMIDITY = 2;
 | 
			
		||||
	static constexpr uint8_t TYPE_PRESSURE = 3;
 | 
			
		||||
	static constexpr uint8_t TYPE_BRIGHTNESS = 4;
 | 
			
		||||
	static constexpr uint8_t TYPE_BUTTON     = 5;
 | 
			
		||||
	static constexpr uint8_t TYPE_ADC        = 6;
 | 
			
		||||
	static constexpr uint8_t TYPE_LOWBATTERY = 128;
 | 
			
		||||
	static constexpr uint8_t TYPE_SHUTDOWN_IMMINENT = 251;
 | 
			
		||||
	static constexpr uint8_t TYPE_OCUPANCY = 252;
 | 
			
		||||
	static constexpr uint8_t TYPE_SUN_ALTITUDE = 253;
 | 
			
		||||
	static constexpr uint8_t TYPE_AUDIO_OUTPUT = 254;
 | 
			
		||||
	static constexpr uint8_t TYPE_DUMMY = 255;
 | 
			
		||||
 | 
			
		||||
    uint8_t type;
 | 
			
		||||
    uint8_t id;
 | 
			
		||||
    float field;
 | 
			
		||||
    QString name;
 | 
			
		||||
    QDateTime lastSeen;
 | 
			
		||||
    bool hidden;
 | 
			
		||||
	uint8_t type;
 | 
			
		||||
	uint8_t id;
 | 
			
		||||
	float field;
 | 
			
		||||
	QString name;
 | 
			
		||||
	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)
 | 
			
		||||
    {
 | 
			
		||||
        lastSeen = QDateTime::currentDateTime();
 | 
			
		||||
        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();}
 | 
			
		||||
    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;
 | 
			
		||||
            return sensor;
 | 
			
		||||
        }
 | 
			
		||||
        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);
 | 
			
		||||
    }
 | 
			
		||||
    inline void generateName()
 | 
			
		||||
    {
 | 
			
		||||
        if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
 | 
			
		||||
        else if(type == TYPE_DOOR)  name = "Door " + QString::number(id);
 | 
			
		||||
        else if(type == TYPE_BUTTON)  name = "Button " + QString::number(id);
 | 
			
		||||
        else if(type == TYPE_AUDIO_OUTPUT)  name = "Speakers " + QString::number(id);
 | 
			
		||||
        else if(type == TYPE_HUMIDITY)  name = "Humidity " + QString::number(id);
 | 
			
		||||
        else if(type == TYPE_SUN_ALTITUDE)  name = "Solar Altitude";
 | 
			
		||||
        else if(type == TYPE_SHUTDOWN_IMMINENT)  name = "Shutdown Imminent";
 | 
			
		||||
        else name = "Sensor Type " + QString::number(type) + " Id " + QString::number(id);
 | 
			
		||||
    }
 | 
			
		||||
	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();
 | 
			
		||||
	}
 | 
			
		||||
	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();
 | 
			
		||||
	}
 | 
			
		||||
	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;
 | 
			
		||||
			return sensor;
 | 
			
		||||
		}
 | 
			
		||||
		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);
 | 
			
		||||
	}
 | 
			
		||||
	inline void generateName()
 | 
			
		||||
	{
 | 
			
		||||
		if(type == TYPE_TEMPERATURE) name = "Temperature " + QString::number(id);
 | 
			
		||||
		else if(type == TYPE_DOOR)  name = "Door " + QString::number(id);
 | 
			
		||||
		else if(type == TYPE_BUTTON)  name = "Button " + QString::number(id);
 | 
			
		||||
		else if(type == TYPE_AUDIO_OUTPUT)  name = "Speakers " + QString::number(id);
 | 
			
		||||
		else if(type == TYPE_HUMIDITY)  name = "Humidity " + QString::number(id);
 | 
			
		||||
		else if(type == TYPE_SUN_ALTITUDE)  name = "Solar Altitude";
 | 
			
		||||
		else if(type == TYPE_SHUTDOWN_IMMINENT)  name = "Shutdown Imminent";
 | 
			
		||||
		else name = "Sensor Type " + QString::number(type) + " Id " + QString::number(id);
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class SensorStore: public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    std::vector<Sensor> sensors_;
 | 
			
		||||
	std::vector<Sensor> sensors_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    SensorStore(QObject *parent = nullptr);
 | 
			
		||||
    virtual ~SensorStore(){}
 | 
			
		||||
	SensorStore(QObject *parent = nullptr);
 | 
			
		||||
	virtual ~SensorStore() {}
 | 
			
		||||
 | 
			
		||||
    inline std::vector<Sensor>* getSensors(){ return &sensors_; }
 | 
			
		||||
	inline std::vector<Sensor>* getSensors()
 | 
			
		||||
	{
 | 
			
		||||
		return &sensors_;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void sensorGotState(const Sensor& sensor);
 | 
			
		||||
	void sensorGotState(const Sensor& sensor);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void stateChenged(std::vector<Sensor> sensors);
 | 
			
		||||
    void sensorChangedState(Sensor sensor);
 | 
			
		||||
    void sensorDeleted(Sensor sensor);
 | 
			
		||||
	void stateChenged(std::vector<Sensor> sensors);
 | 
			
		||||
	void sensorChangedState(Sensor sensor);
 | 
			
		||||
	void sensorDeleted(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,56 +4,56 @@
 | 
			
		|||
 | 
			
		||||
SpeakerSensorSource::SpeakerSensorSource(QString name, QObject *parent) : QObject(parent), name_(name)
 | 
			
		||||
{
 | 
			
		||||
  silenceCount = 0;
 | 
			
		||||
	silenceCount = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SpeakerSensorSource::~SpeakerSensorSource()
 | 
			
		||||
{
 | 
			
		||||
    abort();
 | 
			
		||||
	abort();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SpeakerSensorSource::run()
 | 
			
		||||
{
 | 
			
		||||
    abort();
 | 
			
		||||
    arecord.start( "arecord --disable-softvol -r 8000 -D front -" );
 | 
			
		||||
	abort();
 | 
			
		||||
	arecord.start( "arecord --disable-softvol -r 8000 -D front -" );
 | 
			
		||||
 | 
			
		||||
    connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
    timer.setInterval(500);
 | 
			
		||||
    timer.start();
 | 
			
		||||
	connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
	timer.setInterval(500);
 | 
			
		||||
	timer.start();
 | 
			
		||||
 | 
			
		||||
    stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 1, name_));
 | 
			
		||||
	stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 1, name_));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void SpeakerSensorSource::abort()
 | 
			
		||||
{
 | 
			
		||||
    if(arecord.state() == QProcess::Running)arecord.close();
 | 
			
		||||
    if(timer.isActive())timer.stop();
 | 
			
		||||
	if(arecord.state() == QProcess::Running)arecord.close();
 | 
			
		||||
	if(timer.isActive())timer.stop();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SpeakerSensorSource::doTick()
 | 
			
		||||
{
 | 
			
		||||
    if(arecord.state() == QProcess::Running)
 | 
			
		||||
    {
 | 
			
		||||
       QByteArray buffer = arecord.readAllStandardOutput();
 | 
			
		||||
       //qDebug()<<(int16_t)buffer[0];
 | 
			
		||||
       for(long i = 0; i < buffer.size(); i++)
 | 
			
		||||
       {
 | 
			
		||||
           if((int16_t)buffer.at(i) != -128)
 | 
			
		||||
           {
 | 
			
		||||
              silenceCount = 0;
 | 
			
		||||
           }
 | 
			
		||||
       }
 | 
			
		||||
       if(silenceCount > 40 && state)
 | 
			
		||||
       {
 | 
			
		||||
            stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 0, name_));
 | 
			
		||||
            state = false;
 | 
			
		||||
       }
 | 
			
		||||
       else if(silenceCount == 0 && !state)
 | 
			
		||||
       {
 | 
			
		||||
           stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 1, name_));
 | 
			
		||||
           state = true;
 | 
			
		||||
       }
 | 
			
		||||
       silenceCount++;
 | 
			
		||||
    }
 | 
			
		||||
	if(arecord.state() == QProcess::Running)
 | 
			
		||||
	{
 | 
			
		||||
		QByteArray buffer = arecord.readAllStandardOutput();
 | 
			
		||||
		//qDebug()<<(int16_t)buffer[0];
 | 
			
		||||
		for(long i = 0; i < buffer.size(); i++)
 | 
			
		||||
		{
 | 
			
		||||
			if((int16_t)buffer.at(i) != -128)
 | 
			
		||||
			{
 | 
			
		||||
				silenceCount = 0;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		if(silenceCount > 40 && state)
 | 
			
		||||
		{
 | 
			
		||||
			stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 0, name_));
 | 
			
		||||
			state = false;
 | 
			
		||||
		}
 | 
			
		||||
		else if(silenceCount == 0 && !state)
 | 
			
		||||
		{
 | 
			
		||||
			stateChanged(Sensor(Sensor::TYPE_AUDIO_OUTPUT, 0, 1, name_));
 | 
			
		||||
			state = true;
 | 
			
		||||
		}
 | 
			
		||||
		silenceCount++;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,30 +16,30 @@
 | 
			
		|||
 | 
			
		||||
class SpeakerSensorSource : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    QString name_;
 | 
			
		||||
    bool state = true;
 | 
			
		||||
    QTimer timer;
 | 
			
		||||
	QString name_;
 | 
			
		||||
	bool state = true;
 | 
			
		||||
	QTimer timer;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit SpeakerSensorSource(QString name = "", QObject *parent = nullptr);
 | 
			
		||||
    ~SpeakerSensorSource();
 | 
			
		||||
	explicit SpeakerSensorSource(QString name = "", QObject *parent = nullptr);
 | 
			
		||||
	~SpeakerSensorSource();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void run();
 | 
			
		||||
    void abort();
 | 
			
		||||
	void run();
 | 
			
		||||
	void abort();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void stateChanged(Sensor sensor);
 | 
			
		||||
	void stateChanged(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void doTick();
 | 
			
		||||
	void doTick();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    long silenceCount = 0;
 | 
			
		||||
	long silenceCount = 0;
 | 
			
		||||
 | 
			
		||||
    QProcess arecord;
 | 
			
		||||
	QProcess arecord;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // AMPMANAGER_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,24 +2,24 @@
 | 
			
		|||
 | 
			
		||||
SunSensorSource::SunSensorSource(double lat, double lon, QObject *parent): QObject(parent), sun_(lat, lon)
 | 
			
		||||
{
 | 
			
		||||
    connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
	connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SunSensorSource::run()
 | 
			
		||||
{
 | 
			
		||||
    connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
    timer.setInterval(10000); //10s
 | 
			
		||||
    timer.start();
 | 
			
		||||
    doTick();
 | 
			
		||||
	connect(&timer, SIGNAL(timeout()), this, SLOT(doTick()));
 | 
			
		||||
	timer.setInterval(10000); //10s
 | 
			
		||||
	timer.start();
 | 
			
		||||
	doTick();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void SunSensorSource::abort()
 | 
			
		||||
{
 | 
			
		||||
    if(timer.isActive())timer.stop();
 | 
			
		||||
	if(timer.isActive())timer.stop();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SunSensorSource::doTick()
 | 
			
		||||
{
 | 
			
		||||
    stateChanged(Sensor(Sensor::TYPE_SUN_ALTITUDE, 0, static_cast<float>(sun_.altitude())));
 | 
			
		||||
	stateChanged(Sensor(Sensor::TYPE_SUN_ALTITUDE, 0, static_cast<float>(sun_.altitude())));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,22 +8,22 @@
 | 
			
		|||
 | 
			
		||||
class SunSensorSource : public QObject
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
 | 
			
		||||
    Sun sun_;
 | 
			
		||||
    QTimer timer;
 | 
			
		||||
	Sun sun_;
 | 
			
		||||
	QTimer timer;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit SunSensorSource(double lat, double lon, QObject *parent = nullptr);
 | 
			
		||||
	explicit SunSensorSource(double lat, double lon, QObject *parent = nullptr);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void run();
 | 
			
		||||
    void abort();
 | 
			
		||||
	void run();
 | 
			
		||||
	void abort();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void stateChanged(Sensor sensor);
 | 
			
		||||
	void stateChanged(Sensor sensor);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void doTick();
 | 
			
		||||
	void doTick();
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										55
									
								
								src/sun.cpp
									
										
									
									
									
								
							
							
						
						
									
										55
									
								
								src/sun.cpp
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -13,7 +13,7 @@ public:
 | 
			
		|||
	double utcHour;
 | 
			
		||||
	int    day;
 | 
			
		||||
	int    year;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	JdTime();
 | 
			
		||||
	void update();
 | 
			
		||||
	std::time_t toStdTime();
 | 
			
		||||
| 
						 | 
				
			
			@ -34,21 +34,21 @@ void Sun::JdTime::update()
 | 
			
		|||
 | 
			
		||||
void Sun::JdTime::fromStdTime(std::time_t time)
 | 
			
		||||
{
 | 
			
		||||
    std::tm     ltime = *std::localtime( &time ); 
 | 
			
		||||
	
 | 
			
		||||
	std::tm     ltime = *std::localtime( &time );
 | 
			
		||||
 | 
			
		||||
	localHour = ltime.tm_hour + ltime.tm_min/60.0 + ltime.tm_sec/3600.0;
 | 
			
		||||
	utcHour = localHour - ltime.tm_gmtoff/3600.0;
 | 
			
		||||
	day = ltime.tm_yday;
 | 
			
		||||
	year = ltime.tm_year + 1900;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	std::tm millennium = {0,0,0,1,0,100};
 | 
			
		||||
	std::time_t millenniumTime = std::mktime(&millennium) - timezone;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	daysSinceY2K = (time - millenniumTime)/(60*60*24.0);
 | 
			
		||||
	//std::cout<<"days since y2k: "<<daysSinceY2K<<std::endl;
 | 
			
		||||
	julianDate = daysSinceY2K + JULIAN_DATEATY2K - JULIAN_OFFSET;
 | 
			
		||||
	//std::cout<<"julianDate: "<<julianDate<<std::endl;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	siderialUtcTime = 6.697374558 + 0.06570982441908 * (long)daysSinceY2K + 1.00273790935*utcHour;
 | 
			
		||||
	while(siderialUtcTime < 0)  siderialUtcTime+=24;
 | 
			
		||||
	siderialUtcTime = fmod(siderialUtcTime, 24);
 | 
			
		||||
| 
						 | 
				
			
			@ -58,12 +58,13 @@ std::time_t Sun::JdTime::toStdTime()
 | 
			
		|||
{
 | 
			
		||||
	std::tm millennium = {0,0,0,0,0,100};
 | 
			
		||||
	std::time_t millenniumTime = std::mktime(&millennium)- timezone;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	millenniumTime = millenniumTime + (julianDate-JULIAN_DATEATY2K+JULIAN_OFFSET)*(24*60*60);
 | 
			
		||||
	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)
 | 
			
		||||
| 
						 | 
				
			
			@ -102,13 +104,14 @@ double Sun::solarDeclination(double eclipticLongitude)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
double Sun::hourAngle(double localSolarTime)
 | 
			
		||||
{	
 | 
			
		||||
{
 | 
			
		||||
	return 360/24 * (localSolarTime - 12);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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()
 | 
			
		||||
| 
						 | 
				
			
			@ -119,9 +122,10 @@ double Sun::altitude()
 | 
			
		|||
	double eclipticLongitudeValue = eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue);
 | 
			
		||||
	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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -132,9 +136,10 @@ double Sun::maximumAltitude()
 | 
			
		|||
	double meanSolarAnomalyValue  = meanSolarAnomaly(meanSolarNoonValue);
 | 
			
		||||
	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);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -152,9 +157,10 @@ std::time_t Sun::riseTime()
 | 
			
		|||
	double eclipticLongitudeValue = eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue);
 | 
			
		||||
	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()
 | 
			
		||||
| 
						 | 
				
			
			@ -165,9 +171,10 @@ std::time_t Sun::setTime()
 | 
			
		|||
	double eclipticLongitudeValue = eclipticLongitude(eqOfCenter(meanSolarAnomalyValue), meanSolarAnomalyValue);
 | 
			
		||||
	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();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										42
									
								
								src/sun.h
									
										
									
									
									
								
							
							
						
						
									
										42
									
								
								src/sun.h
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -16,24 +16,24 @@
 | 
			
		|||
class Sun
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
	
 | 
			
		||||
    static constexpr double TO_DEGS = 180.0/M_PI;
 | 
			
		||||
    static constexpr double TO_RADS = M_PI/180.0;
 | 
			
		||||
    static constexpr double SUN_DIA = 0.53; //degrees
 | 
			
		||||
    static constexpr double AIR_REFRACTION  = 34.0/60.0;
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	static constexpr double TO_DEGS = 180.0/M_PI;
 | 
			
		||||
	static constexpr double TO_RADS = M_PI/180.0;
 | 
			
		||||
	static constexpr double SUN_DIA = 0.53; //degrees
 | 
			
		||||
	static constexpr double AIR_REFRACTION  = 34.0/60.0;
 | 
			
		||||
 | 
			
		||||
	static constexpr double ARGUMENT_OF_PERIHELION  = 102.9372;
 | 
			
		||||
	static constexpr double PLANETARY_AXIAL_TILT  = 23.44;
 | 
			
		||||
    
 | 
			
		||||
    class JdTime;
 | 
			
		||||
    
 | 
			
		||||
    double latitude_;
 | 
			
		||||
    double longetude_;
 | 
			
		||||
 | 
			
		||||
	class JdTime;
 | 
			
		||||
 | 
			
		||||
	double latitude_;
 | 
			
		||||
	double longetude_;
 | 
			
		||||
	double altitude_;
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	
 | 
			
		||||
    double nextMeanSolarNoonJD(const JdTime& time);
 | 
			
		||||
 | 
			
		||||
	double nextMeanSolarNoonJD(const JdTime& time);
 | 
			
		||||
	double meanSolarAnomaly(double meanSolarNoon);
 | 
			
		||||
	double eqOfCenter(double meanSolarAnomaly);
 | 
			
		||||
	double eclipticLongitude(double eqOfCenter, double meanSolarAnomaly);
 | 
			
		||||
| 
						 | 
				
			
			@ -43,14 +43,14 @@ private:
 | 
			
		|||
	double hourAngle(double localSolarTime);
 | 
			
		||||
	double equationOfTime(double meanSolarAnomaly, double eclipticLongitude);
 | 
			
		||||
	double localSolarTime(const JdTime& time, double equationOfTime);
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	
 | 
			
		||||
    Sun(double latitude, double longitude, double altitude = 0);
 | 
			
		||||
    double altitude();
 | 
			
		||||
 | 
			
		||||
	Sun(double latitude, double longitude, double altitude = 0);
 | 
			
		||||
	double altitude();
 | 
			
		||||
	double maximumAltitude();
 | 
			
		||||
    double azimuth();
 | 
			
		||||
	double azimuth();
 | 
			
		||||
	double declination();
 | 
			
		||||
    std::time_t riseTime();
 | 
			
		||||
    std::time_t setTime();
 | 
			
		||||
	std::time_t riseTime();
 | 
			
		||||
	std::time_t setTime();
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,7 +6,7 @@
 | 
			
		|||
int main()
 | 
			
		||||
{
 | 
			
		||||
	std::cout<<std::setprecision(15);
 | 
			
		||||
    Sun sun(49.884450, 8.650536);
 | 
			
		||||
	Sun sun(49.884450, 8.650536);
 | 
			
		||||
	std::time_t time = sun.setTime();
 | 
			
		||||
	tm setTime = *localtime(&time);
 | 
			
		||||
	time = sun.riseTime();
 | 
			
		||||
| 
						 | 
				
			
			@ -16,5 +16,5 @@ int main()
 | 
			
		|||
	std::cout<<"current Alt: "<<sun.altitude()<<std::endl;
 | 
			
		||||
	std::cout<<"maximum Alt: "<<sun.maximumAltitude()<<std::endl;
 | 
			
		||||
	std::cout<<"declination: "<<sun.declination()<<std::endl;
 | 
			
		||||
    return 0;
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,108 +5,108 @@
 | 
			
		|||
#include <QSpinBox>
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<AlarmTime> alarm, QWidget *parent):
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    actor_(alarm),
 | 
			
		||||
    ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	actor_(alarm),
 | 
			
		||||
	ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
	init();
 | 
			
		||||
 | 
			
		||||
    widget = new AlarmWidget(alarm, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
	widget = new AlarmWidget(alarm, this);
 | 
			
		||||
	ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<SensorActor> actor, QWidget *parent) :
 | 
			
		||||
QDialog(parent),
 | 
			
		||||
actor_(actor),
 | 
			
		||||
ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
	init();
 | 
			
		||||
 | 
			
		||||
    widget = new SensorActorWidget(actor, &globalSensors, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
	widget = new SensorActorWidget(actor, &globalSensors, this);
 | 
			
		||||
	ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<Regulator> actor, QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    actor_(actor),
 | 
			
		||||
    ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
	init();
 | 
			
		||||
 | 
			
		||||
    widget = new RegulatorWdiget(actor, &globalSensors, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
	widget = new RegulatorWdiget(actor, &globalSensors, this);
 | 
			
		||||
	ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWidget *parent) :
 | 
			
		||||
QDialog(parent),
 | 
			
		||||
actor_(actor),
 | 
			
		||||
ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
	init();
 | 
			
		||||
 | 
			
		||||
    widget = new TimerActorWidget(actor, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
	widget = new TimerActorWidget(actor, this);
 | 
			
		||||
	ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor, QWidget *parent) :
 | 
			
		||||
QDialog(parent),
 | 
			
		||||
actor_(actor),
 | 
			
		||||
ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
	init();
 | 
			
		||||
 | 
			
		||||
    widget = new PolynomalActorWidget(actor, &globalSensors, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
	widget = new PolynomalActorWidget(actor, &globalSensors, this);
 | 
			
		||||
	ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor, QWidget *parent) :
 | 
			
		||||
QDialog(parent),
 | 
			
		||||
actor_(actor),
 | 
			
		||||
ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
    widget = new FactorActorWidget(actor, this);
 | 
			
		||||
    ui->vertlayout->addWidget(widget);
 | 
			
		||||
	init();
 | 
			
		||||
	widget = new FactorActorWidget(actor, this);
 | 
			
		||||
	ui->vertlayout->addWidget(widget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::ActorSettingsDialog(std::shared_ptr<Actor> actor, QWidget *parent) :
 | 
			
		||||
QDialog(parent),
 | 
			
		||||
actor_(actor),
 | 
			
		||||
ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::ActorSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    init();
 | 
			
		||||
	init();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActorSettingsDialog::init()
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(int)));
 | 
			
		||||
    connect(ui->spinBox,  SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
 | 
			
		||||
    connect(ui->pushButton_editItem, &QPushButton::clicked, this, &ActorSettingsDialog::editAsItem);
 | 
			
		||||
    ui->spinBox->hide();
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	connect(ui->comboBox_action, SIGNAL(currentIndexChanged(int)), this, SLOT(changeAction(int)));
 | 
			
		||||
	connect(ui->spinBox,  SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int)));
 | 
			
		||||
	connect(ui->pushButton_editItem, &QPushButton::clicked, this, &ActorSettingsDialog::editAsItem);
 | 
			
		||||
	ui->spinBox->hide();
 | 
			
		||||
 | 
			
		||||
    ui->spinBox->setValue(actor_->getTriggerValue());
 | 
			
		||||
    if(actor_->getTriggerValue() == 0) ui->comboBox_action->setCurrentIndex(0);
 | 
			
		||||
    else if(actor_->getTriggerValue() == 1) ui->comboBox_action->setCurrentIndex(1);
 | 
			
		||||
    else ui->comboBox_action->setCurrentIndex(2);
 | 
			
		||||
	ui->spinBox->setValue(actor_->getTriggerValue());
 | 
			
		||||
	if(actor_->getTriggerValue() == 0) ui->comboBox_action->setCurrentIndex(0);
 | 
			
		||||
	else if(actor_->getTriggerValue() == 1) 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");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ActorSettingsDialog::~ActorSettingsDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActorSettingsDialog::editAsItem()
 | 
			
		||||
{
 | 
			
		||||
    ItemSettingsDialog itemSettingsDiag(actor_, this);
 | 
			
		||||
    itemSettingsDiag.exec();
 | 
			
		||||
	ItemSettingsDialog itemSettingsDiag(actor_, this);
 | 
			
		||||
	itemSettingsDiag.exec();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActorSettingsDialog::valueChanged(int value)
 | 
			
		||||
{
 | 
			
		||||
    actor_->setTriggerValue(value);
 | 
			
		||||
	actor_->setTriggerValue(value);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ActorSettingsDialog::hideCancle([[maybe_unused]] const bool hide)
 | 
			
		||||
| 
						 | 
				
			
			@ -116,13 +116,13 @@ void ActorSettingsDialog::hideCancle([[maybe_unused]] const bool hide)
 | 
			
		|||
 | 
			
		||||
void ActorSettingsDialog::changeAction(int index)
 | 
			
		||||
{
 | 
			
		||||
         if(index == 0) actor_->setTriggerValue(0);
 | 
			
		||||
    else if(index == 1) actor_->setTriggerValue(1);
 | 
			
		||||
    else if(index == 2)
 | 
			
		||||
    {
 | 
			
		||||
             ui->spinBox->show();
 | 
			
		||||
             actor_->setTriggerValue(ui->spinBox->value());
 | 
			
		||||
    }
 | 
			
		||||
    if(index != 2)ui->spinBox->hide();
 | 
			
		||||
	if(index == 0) actor_->setTriggerValue(0);
 | 
			
		||||
	else if(index == 1) actor_->setTriggerValue(1);
 | 
			
		||||
	else if(index == 2)
 | 
			
		||||
	{
 | 
			
		||||
		ui->spinBox->show();
 | 
			
		||||
		actor_->setTriggerValue(ui->spinBox->value());
 | 
			
		||||
	}
 | 
			
		||||
	if(index != 2)ui->spinBox->hide();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,40 +10,41 @@
 | 
			
		|||
#include "actorwidgets/polynomalactorwidget.h"
 | 
			
		||||
#include "actorwidgets/factoractorwidget.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class ActorSettingsDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ActorSettingsDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    std::shared_ptr<Actor> actor_;
 | 
			
		||||
    QWidget* widget;
 | 
			
		||||
	std::shared_ptr<Actor> actor_;
 | 
			
		||||
	QWidget* widget;
 | 
			
		||||
 | 
			
		||||
    void init();
 | 
			
		||||
	void init();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    ActorSettingsDialog(std::shared_ptr<AlarmTime> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(std::shared_ptr<SensorActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(std::shared_ptr<Regulator> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ActorSettingsDialog(std::shared_ptr<Actor> actor, QWidget *parent);
 | 
			
		||||
    ~ActorSettingsDialog();
 | 
			
		||||
	ActorSettingsDialog(std::shared_ptr<AlarmTime> actor, QWidget *parent = nullptr);
 | 
			
		||||
	ActorSettingsDialog(std::shared_ptr<SensorActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
	ActorSettingsDialog(std::shared_ptr<Regulator> actor, QWidget *parent = nullptr);
 | 
			
		||||
	ActorSettingsDialog(std::shared_ptr<TimerActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
	ActorSettingsDialog(std::shared_ptr<PolynomalActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
	ActorSettingsDialog(std::shared_ptr<MultiFactorActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
	ActorSettingsDialog(std::shared_ptr<Actor> actor, QWidget *parent);
 | 
			
		||||
	~ActorSettingsDialog();
 | 
			
		||||
 | 
			
		||||
    void hideCancle(const bool hide);
 | 
			
		||||
	void hideCancle(const bool hide);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void changeAction(int index);
 | 
			
		||||
    void valueChanged(int value);
 | 
			
		||||
    void editAsItem();
 | 
			
		||||
	void changeAction(int index);
 | 
			
		||||
	void valueChanged(int value);
 | 
			
		||||
	void editAsItem();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::ActorSettingsDialog *ui;
 | 
			
		||||
	Ui::ActorSettingsDialog *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ACTORSETTINGSDIALOG_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,73 +2,73 @@
 | 
			
		|||
#include "ui_alarmwidget.h"
 | 
			
		||||
 | 
			
		||||
AlarmWidget::AlarmWidget(std::shared_ptr<AlarmTime> alarm, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    alarm_(alarm),
 | 
			
		||||
    ui(new Ui::AlarmWidget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	alarm_(alarm),
 | 
			
		||||
	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->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());
 | 
			
		||||
 | 
			
		||||
    if(alarm_->getRepeat() == AlarmTime::REPEAT_NEVER)
 | 
			
		||||
    {
 | 
			
		||||
        ui->radioButton->setEnabled(false);
 | 
			
		||||
        ui->radioButton_2->setEnabled(false);
 | 
			
		||||
        ui->radioButton_3->setEnabled(false);
 | 
			
		||||
        ui->radioButton_4->setEnabled(false);
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ui->checkBox->setChecked(true);
 | 
			
		||||
        ui->radioButton->setEnabled(true);
 | 
			
		||||
        ui->radioButton_2->setEnabled(true);
 | 
			
		||||
        ui->radioButton_3->setEnabled(true);
 | 
			
		||||
        ui->radioButton_4->setEnabled(true);
 | 
			
		||||
    }
 | 
			
		||||
	if(alarm_->getRepeat() == AlarmTime::REPEAT_NEVER)
 | 
			
		||||
	{
 | 
			
		||||
		ui->radioButton->setEnabled(false);
 | 
			
		||||
		ui->radioButton_2->setEnabled(false);
 | 
			
		||||
		ui->radioButton_3->setEnabled(false);
 | 
			
		||||
		ui->radioButton_4->setEnabled(false);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		ui->checkBox->setChecked(true);
 | 
			
		||||
		ui->radioButton->setEnabled(true);
 | 
			
		||||
		ui->radioButton_2->setEnabled(true);
 | 
			
		||||
		ui->radioButton_3->setEnabled(true);
 | 
			
		||||
		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->dateTimeEdit, &QDateTimeEdit::dateTimeChanged, alarm.get(), &AlarmTime::changeTime);
 | 
			
		||||
	connect(ui->dateTimeEdit, &QDateTimeEdit::dateTimeChanged, alarm.get(), &AlarmTime::changeTime);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AlarmWidget::~AlarmWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
{
 | 
			
		||||
    if(state)
 | 
			
		||||
    {
 | 
			
		||||
        ui->radioButton->setEnabled(true);
 | 
			
		||||
        ui->radioButton_2->setEnabled(true);
 | 
			
		||||
        ui->radioButton_3->setEnabled(true);
 | 
			
		||||
        ui->radioButton_4->setEnabled(true);
 | 
			
		||||
        setRepeatingType();
 | 
			
		||||
    }
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        alarm_->setRepeat(AlarmTime::REPEAT_NEVER);
 | 
			
		||||
        ui->radioButton->setEnabled(false);
 | 
			
		||||
        ui->radioButton_2->setEnabled(false);
 | 
			
		||||
        ui->radioButton_3->setEnabled(false);
 | 
			
		||||
        ui->radioButton_4->setEnabled(false);
 | 
			
		||||
    }
 | 
			
		||||
	if(state)
 | 
			
		||||
	{
 | 
			
		||||
		ui->radioButton->setEnabled(true);
 | 
			
		||||
		ui->radioButton_2->setEnabled(true);
 | 
			
		||||
		ui->radioButton_3->setEnabled(true);
 | 
			
		||||
		ui->radioButton_4->setEnabled(true);
 | 
			
		||||
		setRepeatingType();
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		alarm_->setRepeat(AlarmTime::REPEAT_NEVER);
 | 
			
		||||
		ui->radioButton->setEnabled(false);
 | 
			
		||||
		ui->radioButton_2->setEnabled(false);
 | 
			
		||||
		ui->radioButton_3->setEnabled(false);
 | 
			
		||||
		ui->radioButton_4->setEnabled(false);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,26 +5,27 @@
 | 
			
		|||
#include <memory>
 | 
			
		||||
#include "../../actors/alarmtime.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class AlarmWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class AlarmWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<AlarmTime> alarm_;
 | 
			
		||||
	std::shared_ptr<AlarmTime> alarm_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit AlarmWidget(std::shared_ptr<AlarmTime>  alarm, QWidget *parent = nullptr);
 | 
			
		||||
    ~AlarmWidget();
 | 
			
		||||
	explicit AlarmWidget(std::shared_ptr<AlarmTime>  alarm, QWidget *parent = nullptr);
 | 
			
		||||
	~AlarmWidget();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void toggleRepeating(int state);
 | 
			
		||||
    void setRepeatingType();
 | 
			
		||||
	void toggleRepeating(int state);
 | 
			
		||||
	void setRepeatingType();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::AlarmWidget *ui;
 | 
			
		||||
	Ui::AlarmWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ALARMWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,82 +3,82 @@
 | 
			
		|||
#include "../actorsettingsdialog.h"
 | 
			
		||||
 | 
			
		||||
FactorActorWidget::FactorActorWidget(std::shared_ptr<MultiFactorActor> actor, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    actor_(actor),
 | 
			
		||||
    ui(new Ui::FactorActorWidget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::FactorActorWidget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    ui->comboBox->setCurrentText(actor_->getFactorDirection() ? "True" : "False");
 | 
			
		||||
    ui->spinBox->setValue(actor_->getPreCancleTime());
 | 
			
		||||
    if(actor_->getFactorActor()) ui->label_FactorActor->setText(actor_->getFactorActor()->getName());
 | 
			
		||||
    connect(ui->pushButton, &QPushButton::clicked, this, &FactorActorWidget::createFactorActor);
 | 
			
		||||
    connect(ui->comboBox_Direcion, &QComboBox::currentTextChanged, this, &FactorActorWidget::setDirection);
 | 
			
		||||
    connect(ui->spinBox,  qOverload<int>(&QSpinBox::valueChanged), this, &FactorActorWidget::setPreCancleTime);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	ui->comboBox->setCurrentText(actor_->getFactorDirection() ? "True" : "False");
 | 
			
		||||
	ui->spinBox->setValue(actor_->getPreCancleTime());
 | 
			
		||||
	if(actor_->getFactorActor()) ui->label_FactorActor->setText(actor_->getFactorActor()->getName());
 | 
			
		||||
	connect(ui->pushButton, &QPushButton::clicked, this, &FactorActorWidget::createFactorActor);
 | 
			
		||||
	connect(ui->comboBox_Direcion, &QComboBox::currentTextChanged, this, &FactorActorWidget::setDirection);
 | 
			
		||||
	connect(ui->spinBox,  qOverload<int>(&QSpinBox::valueChanged), this, &FactorActorWidget::setPreCancleTime);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FactorActorWidget::~FactorActorWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FactorActorWidget::createFactorActor()
 | 
			
		||||
{
 | 
			
		||||
    ActorSettingsDialog* dialog = nullptr;
 | 
			
		||||
    std::shared_ptr<Actor> actor = nullptr;
 | 
			
		||||
	ActorSettingsDialog* dialog = nullptr;
 | 
			
		||||
	std::shared_ptr<Actor> actor = nullptr;
 | 
			
		||||
 | 
			
		||||
    if(ui->comboBox->currentText() == "Alarm")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
 | 
			
		||||
        actor = alarm;
 | 
			
		||||
        dialog = new ActorSettingsDialog(alarm, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Sensor")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<SensorActor> sensorActor =  std::shared_ptr<SensorActor>(new SensorActor());
 | 
			
		||||
        actor = sensorActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(sensorActor, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Timer" )
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor());
 | 
			
		||||
        actor = timerActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(timerActor, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Regulator")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator());
 | 
			
		||||
        actor = regulator;
 | 
			
		||||
        dialog = new ActorSettingsDialog(regulator, this);
 | 
			
		||||
    }
 | 
			
		||||
	if(ui->comboBox->currentText() == "Alarm")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
 | 
			
		||||
		actor = alarm;
 | 
			
		||||
		dialog = new ActorSettingsDialog(alarm, this);
 | 
			
		||||
	}
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Sensor")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<SensorActor> sensorActor =  std::shared_ptr<SensorActor>(new SensorActor());
 | 
			
		||||
		actor = sensorActor;
 | 
			
		||||
		dialog = new ActorSettingsDialog(sensorActor, this);
 | 
			
		||||
	}
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Timer" )
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor());
 | 
			
		||||
		actor = timerActor;
 | 
			
		||||
		dialog = new ActorSettingsDialog(timerActor, this);
 | 
			
		||||
	}
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Regulator")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator());
 | 
			
		||||
		actor = regulator;
 | 
			
		||||
		dialog = new ActorSettingsDialog(regulator, this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Polynomal")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor());
 | 
			
		||||
        actor = polynomalActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
    }
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Polynomal")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor());
 | 
			
		||||
		actor = polynomalActor;
 | 
			
		||||
		dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(dialog != nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        dialog->setParent(this);
 | 
			
		||||
        dialog->show();
 | 
			
		||||
        if(dialog->exec() == QDialog::Accepted)
 | 
			
		||||
        {
 | 
			
		||||
            actor_->setFactorActor(actor);
 | 
			
		||||
            ui->label_FactorActor->setText(actor->getName());
 | 
			
		||||
        }
 | 
			
		||||
        delete dialog;
 | 
			
		||||
    }
 | 
			
		||||
	if(dialog != nullptr)
 | 
			
		||||
	{
 | 
			
		||||
		dialog->setParent(this);
 | 
			
		||||
		dialog->show();
 | 
			
		||||
		if(dialog->exec() == QDialog::Accepted)
 | 
			
		||||
		{
 | 
			
		||||
			actor_->setFactorActor(actor);
 | 
			
		||||
			ui->label_FactorActor->setText(actor->getName());
 | 
			
		||||
		}
 | 
			
		||||
		delete dialog;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FactorActorWidget::setDirection(const QString& type)
 | 
			
		||||
{
 | 
			
		||||
    if(type == "True") actor_->setFactorDirection(true);
 | 
			
		||||
    else actor_->setFactorDirection(false);
 | 
			
		||||
	if(type == "True") actor_->setFactorDirection(true);
 | 
			
		||||
	else actor_->setFactorDirection(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FactorActorWidget::setPreCancleTime(int time)
 | 
			
		||||
{
 | 
			
		||||
    actor_->setPreCancleTime(time);
 | 
			
		||||
	actor_->setPreCancleTime(time);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,27 +4,28 @@
 | 
			
		|||
#include <QWidget>
 | 
			
		||||
#include "../../actors/factoractor.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class FactorActorWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class FactorActorWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<MultiFactorActor> actor_;
 | 
			
		||||
	std::shared_ptr<MultiFactorActor> actor_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit FactorActorWidget(std::shared_ptr<MultiFactorActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ~FactorActorWidget();
 | 
			
		||||
	explicit FactorActorWidget(std::shared_ptr<MultiFactorActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
	~FactorActorWidget();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void createFactorActor();
 | 
			
		||||
    void setDirection(const QString& direction);
 | 
			
		||||
    void setPreCancleTime(int time);
 | 
			
		||||
	void createFactorActor();
 | 
			
		||||
	void setDirection(const QString& direction);
 | 
			
		||||
	void setPreCancleTime(int time);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::FactorActorWidget *ui;
 | 
			
		||||
	Ui::FactorActorWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // FACTORACTORWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,48 +1,50 @@
 | 
			
		|||
#include "polynomalactorwidget.h"
 | 
			
		||||
#include "ui_polynomalactorwidget.h"
 | 
			
		||||
 | 
			
		||||
PolynomalActorWidget::PolynomalActorWidget(std::shared_ptr<PolynomalActor> actor, SensorStore* sensors, QWidget *parent):
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    sensors_(sensors),
 | 
			
		||||
    actor_(actor),
 | 
			
		||||
    ui(new Ui::PolynomalActorWidget)
 | 
			
		||||
PolynomalActorWidget::PolynomalActorWidget(std::shared_ptr<PolynomalActor> actor, SensorStore* sensors,
 | 
			
		||||
        QWidget *parent):
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	sensors_(sensors),
 | 
			
		||||
	actor_(actor),
 | 
			
		||||
	ui(new Ui::PolynomalActorWidget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    if(sensors)ui->listView->sensorsChanged(*(sensors->getSensors()));
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ui->listView->hide();
 | 
			
		||||
        ui->label->hide();
 | 
			
		||||
    }
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	if(sensors)ui->listView->sensorsChanged(*(sensors->getSensors()));
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		ui->listView->hide();
 | 
			
		||||
		ui->label->hide();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    double pow3, pow2, pow1, pow0;
 | 
			
		||||
	double pow3, pow2, pow1, pow0;
 | 
			
		||||
 | 
			
		||||
    actor_->getCoeffiancts(pow3, pow2, pow1, pow0);
 | 
			
		||||
	actor_->getCoeffiancts(pow3, pow2, pow1, pow0);
 | 
			
		||||
 | 
			
		||||
    ui->doubleSpinBox_pow0->setValue(pow0);
 | 
			
		||||
    ui->doubleSpinBox_pow1->setValue(pow1);
 | 
			
		||||
    ui->doubleSpinBox_pow2->setValue(pow2);
 | 
			
		||||
    ui->doubleSpinBox_pow3->setValue(pow3);
 | 
			
		||||
	ui->doubleSpinBox_pow0->setValue(pow0);
 | 
			
		||||
	ui->doubleSpinBox_pow1->setValue(pow1);
 | 
			
		||||
	ui->doubleSpinBox_pow2->setValue(pow2);
 | 
			
		||||
	ui->doubleSpinBox_pow3->setValue(pow3);
 | 
			
		||||
 | 
			
		||||
    connect(ui->doubleSpinBox_pow3, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
    connect(ui->doubleSpinBox_pow2, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
    connect(ui->doubleSpinBox_pow1, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
    connect(ui->doubleSpinBox_pow0, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
    connect(ui->listView, &SensorListWidget::clicked, this, &PolynomalActorWidget::setSensor);
 | 
			
		||||
	connect(ui->doubleSpinBox_pow3, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
	connect(ui->doubleSpinBox_pow2, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
	connect(ui->doubleSpinBox_pow1, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
	connect(ui->doubleSpinBox_pow0, &QDoubleSpinBox::editingFinished, this, &PolynomalActorWidget::setPow);
 | 
			
		||||
	connect(ui->listView, &SensorListWidget::clicked, this, &PolynomalActorWidget::setSensor);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
PolynomalActorWidget::~PolynomalActorWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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)
 | 
			
		||||
{
 | 
			
		||||
    actor_->setSensor(sensors_->getSensors()->at(index.row()));
 | 
			
		||||
	actor_->setSensor(sensors_->getSensors()->at(index.row()));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,27 +4,29 @@
 | 
			
		|||
#include <QWidget>
 | 
			
		||||
#include "../../actors/polynomalactor.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class PolynomalActorWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class PolynomalActorWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    SensorStore* sensors_;
 | 
			
		||||
    std::shared_ptr<PolynomalActor> actor_;
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
	SensorStore* sensors_;
 | 
			
		||||
	std::shared_ptr<PolynomalActor> actor_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit PolynomalActorWidget(std::shared_ptr<PolynomalActor> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
 | 
			
		||||
    ~PolynomalActorWidget();
 | 
			
		||||
	explicit PolynomalActorWidget(std::shared_ptr<PolynomalActor> regulator, SensorStore* sensors = nullptr,
 | 
			
		||||
	                              QWidget *parent = nullptr);
 | 
			
		||||
	~PolynomalActorWidget();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void setPow();
 | 
			
		||||
    void setSensor(const QModelIndex &index);
 | 
			
		||||
	void setPow();
 | 
			
		||||
	void setSensor(const QModelIndex &index);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::PolynomalActorWidget *ui;
 | 
			
		||||
	Ui::PolynomalActorWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // POLYNOMALACTORWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,45 +4,45 @@
 | 
			
		|||
 | 
			
		||||
RegulatorWdiget::~RegulatorWdiget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
RegulatorWdiget::RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    regulator_(regulator),
 | 
			
		||||
    sensors_(sensors),
 | 
			
		||||
    ui(new Ui::RegulatorWdiget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	regulator_(regulator),
 | 
			
		||||
	sensors_(sensors),
 | 
			
		||||
	ui(new Ui::RegulatorWdiget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    if(sensors)ui->listView->sensorsChanged(*(sensors->getSensors()));
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ui->listView->hide();
 | 
			
		||||
        ui->label->hide();
 | 
			
		||||
    }
 | 
			
		||||
    ui->doubleSpinBox_setPoint->setValue(regulator->getSetPoint());
 | 
			
		||||
    ui->doubleSpinBox_band->setValue(regulator->getBand());
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	if(sensors)ui->listView->sensorsChanged(*(sensors->getSensors()));
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		ui->listView->hide();
 | 
			
		||||
		ui->label->hide();
 | 
			
		||||
	}
 | 
			
		||||
	ui->doubleSpinBox_setPoint->setValue(regulator->getSetPoint());
 | 
			
		||||
	ui->doubleSpinBox_band->setValue(regulator->getBand());
 | 
			
		||||
 | 
			
		||||
    connect(ui->listView, &SensorListWidget::clicked, this, &RegulatorWdiget::setSensor);
 | 
			
		||||
    connect(ui->doubleSpinBox_setPoint, SIGNAL(valueChanged(double)),  this, SLOT(setPoint(double)));
 | 
			
		||||
    connect(ui->doubleSpinBox_band, SIGNAL(valueChanged(double)), this, SLOT(setBand(double)));
 | 
			
		||||
	connect(ui->listView, &SensorListWidget::clicked, this, &RegulatorWdiget::setSensor);
 | 
			
		||||
	connect(ui->doubleSpinBox_setPoint, SIGNAL(valueChanged(double)),  this, SLOT(setPoint(double)));
 | 
			
		||||
	connect(ui->doubleSpinBox_band, SIGNAL(valueChanged(double)), this, SLOT(setBand(double)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RegulatorWdiget::setPoint(double in)
 | 
			
		||||
{
 | 
			
		||||
    regulator_->setPoint(in);
 | 
			
		||||
	regulator_->setPoint(in);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RegulatorWdiget::setBand(double band)
 | 
			
		||||
{
 | 
			
		||||
    regulator_->setBand(band);
 | 
			
		||||
	regulator_->setBand(band);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void RegulatorWdiget::setSensor(const QModelIndex &index)
 | 
			
		||||
{
 | 
			
		||||
    regulator_->setSensor(sensors_->getSensors()->at(index.row()));
 | 
			
		||||
    setPoint(sensors_->getSensors()->at(index.row()).field);
 | 
			
		||||
    ui->doubleSpinBox_setPoint->setValue(sensors_->getSensors()->at(index.row()).field);
 | 
			
		||||
	regulator_->setSensor(sensors_->getSensors()->at(index.row()));
 | 
			
		||||
	setPoint(sensors_->getSensors()->at(index.row()).field);
 | 
			
		||||
	ui->doubleSpinBox_setPoint->setValue(sensors_->getSensors()->at(index.row()).field);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,29 +4,31 @@
 | 
			
		|||
#include <QWidget>
 | 
			
		||||
#include "../../actors/regulator.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class RegulatorWdiget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class RegulatorWdiget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<Regulator> regulator_;
 | 
			
		||||
    SensorStore* sensors_;
 | 
			
		||||
	std::shared_ptr<Regulator> regulator_;
 | 
			
		||||
	SensorStore* sensors_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
 | 
			
		||||
    ~RegulatorWdiget();
 | 
			
		||||
	explicit RegulatorWdiget(std::shared_ptr<Regulator> regulator, SensorStore* sensors = nullptr,
 | 
			
		||||
	                         QWidget *parent = nullptr);
 | 
			
		||||
	~RegulatorWdiget();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void setPoint(double in);
 | 
			
		||||
    void setBand(double band);
 | 
			
		||||
    void setSensor(const QModelIndex &index);
 | 
			
		||||
	void setPoint(double in);
 | 
			
		||||
	void setBand(double band);
 | 
			
		||||
	void setSensor(const QModelIndex &index);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::RegulatorWdiget *ui;
 | 
			
		||||
	Ui::RegulatorWdiget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // REGULATORWDIGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,49 +4,49 @@
 | 
			
		|||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
SensorActorWidget::SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    sensorActor_(sensorActor),
 | 
			
		||||
    sensors_(sensors),
 | 
			
		||||
    ui(new Ui::SensorActorWidget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	sensorActor_(sensorActor),
 | 
			
		||||
	sensors_(sensors),
 | 
			
		||||
	ui(new Ui::SensorActorWidget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    if(sensors)ui->listView->sensorsChanged(*(sensors->getSensors()));
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        ui->listView->hide();
 | 
			
		||||
        ui->label->hide();
 | 
			
		||||
    }
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	if(sensors)ui->listView->sensorsChanged(*(sensors->getSensors()));
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		ui->listView->hide();
 | 
			
		||||
		ui->label->hide();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) ui->comboBox_slope->setCurrentIndex(0);
 | 
			
		||||
    else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) ui->comboBox_slope->setCurrentIndex(1);
 | 
			
		||||
    else if(sensorActor_->getSloap() == SensorActor::SLOPE_BOTH) ui->comboBox_slope->setCurrentIndex(2);
 | 
			
		||||
	if(sensorActor_->getSloap() == SensorActor::SLOPE_UP) ui->comboBox_slope->setCurrentIndex(0);
 | 
			
		||||
	else if(sensorActor_->getSloap() == SensorActor::SLOPE_DOWN) 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());
 | 
			
		||||
 | 
			
		||||
    connect(ui->listView, &SensorListWidget::clicked, this, &SensorActorWidget::setSensor);
 | 
			
		||||
    connect(ui->doubleSpinBox_threshold, SIGNAL(valueChanged(double)),  this, SLOT(setThreshold(double)));
 | 
			
		||||
    connect(ui->comboBox_slope, SIGNAL(currentIndexChanged(int)), this, SLOT(setSlope(int)));
 | 
			
		||||
	connect(ui->listView, &SensorListWidget::clicked, this, &SensorActorWidget::setSensor);
 | 
			
		||||
	connect(ui->doubleSpinBox_threshold, SIGNAL(valueChanged(double)),  this, SLOT(setThreshold(double)));
 | 
			
		||||
	connect(ui->comboBox_slope, SIGNAL(currentIndexChanged(int)), this, SLOT(setSlope(int)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SensorActorWidget::~SensorActorWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorActorWidget::setThreshold(double in)
 | 
			
		||||
{
 | 
			
		||||
    sensorActor_->setThreshold(in);
 | 
			
		||||
	sensorActor_->setThreshold(in);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorActorWidget::setSlope(int index)
 | 
			
		||||
{
 | 
			
		||||
    if(index == 0) sensorActor_->setSloap(SensorActor::SLOPE_UP);
 | 
			
		||||
    else if(index == 1) sensorActor_->setSloap(SensorActor::SLOPE_DOWN);
 | 
			
		||||
    else if(index == 2) sensorActor_->setSloap(SensorActor::SLOPE_BOTH);
 | 
			
		||||
	if(index == 0) sensorActor_->setSloap(SensorActor::SLOPE_UP);
 | 
			
		||||
	else if(index == 1) sensorActor_->setSloap(SensorActor::SLOPE_DOWN);
 | 
			
		||||
	else if(index == 2) sensorActor_->setSloap(SensorActor::SLOPE_BOTH);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorActorWidget::setSensor(const QModelIndex &index)
 | 
			
		||||
{
 | 
			
		||||
    sensorActor_->setSensor(sensors_->getSensors()->at(index.row()));
 | 
			
		||||
    qDebug()<<"Selected "<<sensors_->getSensors()->at(index.row()).name;
 | 
			
		||||
	sensorActor_->setSensor(sensors_->getSensors()->at(index.row()));
 | 
			
		||||
	qDebug()<<"Selected "<<sensors_->getSensors()->at(index.row()).name;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,29 +5,31 @@
 | 
			
		|||
#include <QItemSelection>
 | 
			
		||||
#include "../../actors/sensoractor.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class SensorActorWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class SensorActorWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<SensorActor> sensorActor_;
 | 
			
		||||
    SensorStore* sensors_;
 | 
			
		||||
	std::shared_ptr<SensorActor> sensorActor_;
 | 
			
		||||
	SensorStore* sensors_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors = nullptr, QWidget *parent = nullptr);
 | 
			
		||||
    ~SensorActorWidget();
 | 
			
		||||
	explicit SensorActorWidget(std::shared_ptr<SensorActor> sensorActor, SensorStore* sensors = nullptr,
 | 
			
		||||
	                           QWidget *parent = nullptr);
 | 
			
		||||
	~SensorActorWidget();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void setThreshold(double in);
 | 
			
		||||
    void setSlope(int index);
 | 
			
		||||
    void setSensor(const QModelIndex &index);
 | 
			
		||||
	void setThreshold(double in);
 | 
			
		||||
	void setSlope(int index);
 | 
			
		||||
	void setSensor(const QModelIndex &index);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::SensorActorWidget *ui;
 | 
			
		||||
	Ui::SensorActorWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // SENSORACTORWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,17 +4,17 @@
 | 
			
		|||
#include <QSpinBox>
 | 
			
		||||
 | 
			
		||||
TimerActorWidget::TimerActorWidget(std::shared_ptr<TimerActor> actor, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    ui(new Ui::TimerActorWidget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	ui(new Ui::TimerActorWidget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
    ui->spinBox->setValue(actor->getTimeout());
 | 
			
		||||
	ui->spinBox->setValue(actor->getTimeout());
 | 
			
		||||
 | 
			
		||||
    connect(ui->spinBox, SIGNAL(valueChanged(int)), actor.get(), SLOT(setTimeout(int)));
 | 
			
		||||
	connect(ui->spinBox, SIGNAL(valueChanged(int)), actor.get(), SLOT(setTimeout(int)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TimerActorWidget::~TimerActorWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,20 +4,21 @@
 | 
			
		|||
#include <QWidget>
 | 
			
		||||
#include "../../actors/timeractor.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class TimerActorWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class TimerActorWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit TimerActorWidget(std::shared_ptr<TimerActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
    ~TimerActorWidget();
 | 
			
		||||
	explicit TimerActorWidget(std::shared_ptr<TimerActor> actor, QWidget *parent = nullptr);
 | 
			
		||||
	~TimerActorWidget();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::TimerActorWidget *ui;
 | 
			
		||||
	Ui::TimerActorWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // TIMERACTORWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,49 +5,49 @@
 | 
			
		|||
#include "itemsettingswidgets/systemitemsettingswidget.h"
 | 
			
		||||
 | 
			
		||||
ItemCreationDialog::ItemCreationDialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    ui(new Ui::ItemCreationDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	ui(new Ui::ItemCreationDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    std::shared_ptr<MessageItem> messageItem(new MessageItem);
 | 
			
		||||
    item = messageItem;
 | 
			
		||||
    widget = new MessageItemSettingsWidget(messageItem, this);
 | 
			
		||||
    ui->verticalLayout->addWidget(widget);
 | 
			
		||||
    connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ItemCreationDialog::itemTypeChanged);
 | 
			
		||||
    connect(ui->lineEdit, &QLineEdit::textChanged, this, &ItemCreationDialog::itemNameChanged);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	std::shared_ptr<MessageItem> messageItem(new MessageItem);
 | 
			
		||||
	item = messageItem;
 | 
			
		||||
	widget = new MessageItemSettingsWidget(messageItem, this);
 | 
			
		||||
	ui->verticalLayout->addWidget(widget);
 | 
			
		||||
	connect(ui->comboBox, &QComboBox::currentTextChanged, this, &ItemCreationDialog::itemTypeChanged);
 | 
			
		||||
	connect(ui->lineEdit, &QLineEdit::textChanged, this, &ItemCreationDialog::itemNameChanged);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ItemCreationDialog::~ItemCreationDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
    delete widget;
 | 
			
		||||
	delete ui;
 | 
			
		||||
	delete widget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemCreationDialog::itemTypeChanged(const QString& type)
 | 
			
		||||
{
 | 
			
		||||
    ui->verticalLayout->removeWidget(widget);
 | 
			
		||||
    delete widget;
 | 
			
		||||
    if(type == "Message")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<MessageItem> messageItem(new MessageItem);
 | 
			
		||||
        item = messageItem;
 | 
			
		||||
        widget = new MessageItemSettingsWidget(messageItem, this);
 | 
			
		||||
        ui->verticalLayout->addWidget(widget);
 | 
			
		||||
    }
 | 
			
		||||
    if(type == "System")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<SystemItem> systemItem(new SystemItem);
 | 
			
		||||
        item = systemItem;
 | 
			
		||||
        widget = new SystemItemSettingsWidget(systemItem, this);
 | 
			
		||||
        ui->verticalLayout->addWidget(widget);
 | 
			
		||||
    }
 | 
			
		||||
	ui->verticalLayout->removeWidget(widget);
 | 
			
		||||
	delete widget;
 | 
			
		||||
	if(type == "Message")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<MessageItem> messageItem(new MessageItem);
 | 
			
		||||
		item = messageItem;
 | 
			
		||||
		widget = new MessageItemSettingsWidget(messageItem, this);
 | 
			
		||||
		ui->verticalLayout->addWidget(widget);
 | 
			
		||||
	}
 | 
			
		||||
	if(type == "System")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<SystemItem> systemItem(new SystemItem);
 | 
			
		||||
		item = systemItem;
 | 
			
		||||
		widget = new SystemItemSettingsWidget(systemItem, this);
 | 
			
		||||
		ui->verticalLayout->addWidget(widget);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemCreationDialog::itemNameChanged(const QString& name)
 | 
			
		||||
{
 | 
			
		||||
    if(item)
 | 
			
		||||
    {
 | 
			
		||||
        item->setName(name);
 | 
			
		||||
    }
 | 
			
		||||
	if(item)
 | 
			
		||||
	{
 | 
			
		||||
		item->setName(name);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,29 +5,30 @@
 | 
			
		|||
#include <memory>
 | 
			
		||||
#include "../items/item.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class ItemCreationDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ItemCreationDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    QWidget* widget;
 | 
			
		||||
	QWidget* widget;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ItemCreationDialog(QWidget *parent = nullptr);
 | 
			
		||||
    ~ItemCreationDialog();
 | 
			
		||||
	explicit ItemCreationDialog(QWidget *parent = nullptr);
 | 
			
		||||
	~ItemCreationDialog();
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<Item> item;
 | 
			
		||||
	std::shared_ptr<Item> item;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void itemTypeChanged(const QString& type);
 | 
			
		||||
    void itemNameChanged(const QString& name);
 | 
			
		||||
	void itemTypeChanged(const QString& type);
 | 
			
		||||
	void itemNameChanged(const QString& name);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::ItemCreationDialog *ui;
 | 
			
		||||
	Ui::ItemCreationDialog *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ITEMCREATIONDIALOG_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,52 +4,52 @@
 | 
			
		|||
#include "../items/messageitem.h"
 | 
			
		||||
 | 
			
		||||
ItemScrollBox::ItemScrollBox(QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    ui(new Ui::RelayScrollBox)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	ui(new Ui::RelayScrollBox)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture);
 | 
			
		||||
    QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	QScroller::grabGesture(ui->scrollArea, QScroller::TouchGesture);
 | 
			
		||||
	QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ItemScrollBox::~ItemScrollBox()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemScrollBox::addItem(std::weak_ptr<Item> item)
 | 
			
		||||
{
 | 
			
		||||
    if(auto workItem  = item.lock())
 | 
			
		||||
    {
 | 
			
		||||
        if(dynamic_cast<AuxItem*>(workItem.get()))
 | 
			
		||||
        {
 | 
			
		||||
            widgets_.push_back(new ItemWidget(item, true));
 | 
			
		||||
        }
 | 
			
		||||
        else if(dynamic_cast<MessageItem*>(workItem.get()))
 | 
			
		||||
        {
 | 
			
		||||
            widgets_.push_back(new ItemWidget(item, false, true));
 | 
			
		||||
        }
 | 
			
		||||
        else
 | 
			
		||||
        {
 | 
			
		||||
            widgets_.push_back(new ItemWidget(item));
 | 
			
		||||
        }
 | 
			
		||||
        ui->relayWidgetVbox->addWidget(widgets_.back());
 | 
			
		||||
        connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
 | 
			
		||||
        connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
 | 
			
		||||
    }
 | 
			
		||||
	if(auto workItem  = item.lock())
 | 
			
		||||
	{
 | 
			
		||||
		if(dynamic_cast<AuxItem*>(workItem.get()))
 | 
			
		||||
		{
 | 
			
		||||
			widgets_.push_back(new ItemWidget(item, true));
 | 
			
		||||
		}
 | 
			
		||||
		else if(dynamic_cast<MessageItem*>(workItem.get()))
 | 
			
		||||
		{
 | 
			
		||||
			widgets_.push_back(new ItemWidget(item, false, true));
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
			widgets_.push_back(new ItemWidget(item));
 | 
			
		||||
		}
 | 
			
		||||
		ui->relayWidgetVbox->addWidget(widgets_.back());
 | 
			
		||||
		connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::deleteRequest);
 | 
			
		||||
		connect(widgets_.back(), &ItemWidget::deleteRequest, this, &ItemScrollBox::removeItem);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemScrollBox::removeItem(const ItemData& item)
 | 
			
		||||
{
 | 
			
		||||
    for(unsigned i = 0; i < widgets_.size(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        if(widgets_[i]->controles(item))
 | 
			
		||||
        {
 | 
			
		||||
            ui->relayWidgetVbox->removeWidget(widgets_[i]);
 | 
			
		||||
            delete widgets_[i];
 | 
			
		||||
            widgets_.erase(widgets_.begin()+i);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
	for(unsigned i = 0; i < widgets_.size(); i++)
 | 
			
		||||
	{
 | 
			
		||||
		if(widgets_[i]->controles(item))
 | 
			
		||||
		{
 | 
			
		||||
			ui->relayWidgetVbox->removeWidget(widgets_[i]);
 | 
			
		||||
			delete widgets_[i];
 | 
			
		||||
			widgets_.erase(widgets_.begin()+i);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,33 +11,34 @@
 | 
			
		|||
#include "../items/itemstore.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class RelayScrollBox;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ItemScrollBox : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    std::vector< ItemWidget* > widgets_;
 | 
			
		||||
	std::vector< ItemWidget* > widgets_;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void deleteRequest(const ItemData& item);
 | 
			
		||||
	void deleteRequest(const ItemData& item);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ItemScrollBox(QWidget *parent = nullptr);
 | 
			
		||||
    ~ItemScrollBox();
 | 
			
		||||
	explicit ItemScrollBox(QWidget *parent = nullptr);
 | 
			
		||||
	~ItemScrollBox();
 | 
			
		||||
 | 
			
		||||
    void setItemStore(ItemStore* itemStore);
 | 
			
		||||
	void setItemStore(ItemStore* itemStore);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void addItem(std::weak_ptr<Item> item);
 | 
			
		||||
    void removeItem(const ItemData& item);
 | 
			
		||||
	void addItem(std::weak_ptr<Item> item);
 | 
			
		||||
	void removeItem(const ItemData& item);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::RelayScrollBox *ui;
 | 
			
		||||
	Ui::RelayScrollBox *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // RELAYSCROLLBOX_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
 #include "itemsettingsdialog.h"
 | 
			
		||||
#include "itemsettingsdialog.h"
 | 
			
		||||
#include "ui_itemsettingsdialog.h"
 | 
			
		||||
#include "actorsettingsdialog.h"
 | 
			
		||||
#include "../actors/alarmtime.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -14,174 +14,174 @@
 | 
			
		|||
#include<memory>
 | 
			
		||||
 | 
			
		||||
ItemSettingsDialog::ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    item_(item),
 | 
			
		||||
    ui(new Ui::ItemSettingsDialog)
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	item_(item),
 | 
			
		||||
	ui(new Ui::ItemSettingsDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
    setModal(false);
 | 
			
		||||
	setModal(false);
 | 
			
		||||
 | 
			
		||||
    ui->label_name->setText(item_->getName());
 | 
			
		||||
    ui->checkBox_Override->setChecked(item_->getOverride());
 | 
			
		||||
	ui->label_name->setText(item_->getName());
 | 
			
		||||
	ui->checkBox_Override->setChecked(item_->getOverride());
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
 | 
			
		||||
    {
 | 
			
		||||
        itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
 | 
			
		||||
    }
 | 
			
		||||
    else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
 | 
			
		||||
    {
 | 
			
		||||
        itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem);
 | 
			
		||||
    }
 | 
			
		||||
    else if(std::shared_ptr<SystemItem> sysItem = std::dynamic_pointer_cast<SystemItem>(item_))
 | 
			
		||||
    {
 | 
			
		||||
        itemSpecificWidget_ = new SystemItemSettingsWidget(sysItem);
 | 
			
		||||
    }
 | 
			
		||||
	if(std::shared_ptr<Relay> relay = std::dynamic_pointer_cast<Relay>(item_))
 | 
			
		||||
	{
 | 
			
		||||
		itemSpecificWidget_ = new RelayItemSettingsWidget(relay);
 | 
			
		||||
	}
 | 
			
		||||
	else if(std::shared_ptr<MessageItem> msgItem = std::dynamic_pointer_cast<MessageItem>(item_))
 | 
			
		||||
	{
 | 
			
		||||
		itemSpecificWidget_ = new MessageItemSettingsWidget(msgItem);
 | 
			
		||||
	}
 | 
			
		||||
	else if(std::shared_ptr<SystemItem> sysItem = std::dynamic_pointer_cast<SystemItem>(item_))
 | 
			
		||||
	{
 | 
			
		||||
		itemSpecificWidget_ = new SystemItemSettingsWidget(sysItem);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    if(itemSpecificWidget_)
 | 
			
		||||
    {
 | 
			
		||||
       ui->verticalLayout_2->addWidget(itemSpecificWidget_);
 | 
			
		||||
    }
 | 
			
		||||
	if(itemSpecificWidget_)
 | 
			
		||||
	{
 | 
			
		||||
		ui->verticalLayout_2->addWidget(itemSpecificWidget_);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    connect(ui->pushButton_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor);
 | 
			
		||||
    connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
 | 
			
		||||
    connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
 | 
			
		||||
    connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride);
 | 
			
		||||
	connect(ui->pushButton_add, &QPushButton::clicked, this, &ItemSettingsDialog::addActor);
 | 
			
		||||
	connect(ui->pushButton_remove, &QPushButton::clicked, this, &ItemSettingsDialog::removeActor);
 | 
			
		||||
	connect(ui->pushButton_edit, &QPushButton::clicked, this, &ItemSettingsDialog::editActor);
 | 
			
		||||
	connect(ui->checkBox_Override, &QPushButton::clicked, this, &ItemSettingsDialog::changeOverride);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
 | 
			
		||||
     ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
 | 
			
		||||
     ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
 | 
			
		||||
    loadActorList();
 | 
			
		||||
	ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Actor"));
 | 
			
		||||
	ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Action"));
 | 
			
		||||
	ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Enabled"));
 | 
			
		||||
	ui->tableWidget->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
 | 
			
		||||
	ui->tableWidget->horizontalHeader()->resizeSection(1, 60);
 | 
			
		||||
	ui->tableWidget->horizontalHeader()->resizeSection(2, 75);
 | 
			
		||||
	loadActorList();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ItemSettingsDialog::~ItemSettingsDialog()
 | 
			
		||||
{
 | 
			
		||||
    if(itemSpecificWidget_) delete itemSpecificWidget_;
 | 
			
		||||
    delete ui;
 | 
			
		||||
	if(itemSpecificWidget_) delete itemSpecificWidget_;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemSettingsDialog::changeOverride()
 | 
			
		||||
{
 | 
			
		||||
    item_->setOverride(ui->checkBox_Override->isChecked());
 | 
			
		||||
	item_->setOverride(ui->checkBox_Override->isChecked());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemSettingsDialog::loadActorList()
 | 
			
		||||
{
 | 
			
		||||
    //ui->listWidget->clear();
 | 
			
		||||
    ui->tableWidget->setRowCount(item_->getActors().size());
 | 
			
		||||
	//ui->listWidget->clear();
 | 
			
		||||
	ui->tableWidget->setRowCount(item_->getActors().size());
 | 
			
		||||
 | 
			
		||||
    for(unsigned i = 0; i < item_->getActors().size(); i++)
 | 
			
		||||
    {
 | 
			
		||||
        ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName()));
 | 
			
		||||
        ui->tableWidget->setItem(i, 1, new QTableWidgetItem(item_->getActors()[i]->actionName()));
 | 
			
		||||
        ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
 | 
			
		||||
    }
 | 
			
		||||
	for(unsigned i = 0; i < item_->getActors().size(); i++)
 | 
			
		||||
	{
 | 
			
		||||
		ui->tableWidget->setItem(i, 0, new QTableWidgetItem(item_->getActors()[i]->getName()));
 | 
			
		||||
		ui->tableWidget->setItem(i, 1, new QTableWidgetItem(item_->getActors()[i]->actionName()));
 | 
			
		||||
		ui->tableWidget->setItem(i, 2, new QTableWidgetItem(item_->getActors()[i]->isActive() ? "Y" : "N"));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemSettingsDialog::addActor()
 | 
			
		||||
{
 | 
			
		||||
    ActorSettingsDialog* dialog = nullptr;
 | 
			
		||||
    std::shared_ptr<Actor> actor = nullptr;
 | 
			
		||||
	ActorSettingsDialog* dialog = nullptr;
 | 
			
		||||
	std::shared_ptr<Actor> actor = nullptr;
 | 
			
		||||
 | 
			
		||||
    if(ui->comboBox->currentText() == "Alarm")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
 | 
			
		||||
        actor = alarm;
 | 
			
		||||
        dialog = new ActorSettingsDialog(alarm, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Sensor")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
 | 
			
		||||
        actor = sensorActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(sensorActor, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Timer" )
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
 | 
			
		||||
        actor = timerActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(timerActor, this);
 | 
			
		||||
    }
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Regulator")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator);
 | 
			
		||||
        actor = regulator;
 | 
			
		||||
        dialog = new ActorSettingsDialog(regulator, this);
 | 
			
		||||
    }
 | 
			
		||||
	if(ui->comboBox->currentText() == "Alarm")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<AlarmTime> alarm = std::shared_ptr<AlarmTime>(new AlarmTime);
 | 
			
		||||
		actor = alarm;
 | 
			
		||||
		dialog = new ActorSettingsDialog(alarm, this);
 | 
			
		||||
	}
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Sensor")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<SensorActor> sensorActor = std::shared_ptr<SensorActor>(new SensorActor);
 | 
			
		||||
		actor = sensorActor;
 | 
			
		||||
		dialog = new ActorSettingsDialog(sensorActor, this);
 | 
			
		||||
	}
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Timer" )
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<TimerActor> timerActor = std::shared_ptr<TimerActor>(new TimerActor);
 | 
			
		||||
		actor = timerActor;
 | 
			
		||||
		dialog = new ActorSettingsDialog(timerActor, this);
 | 
			
		||||
	}
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Regulator")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<Regulator> regulator = std::shared_ptr<Regulator>(new Regulator);
 | 
			
		||||
		actor = regulator;
 | 
			
		||||
		dialog = new ActorSettingsDialog(regulator, this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Polynomal")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor);
 | 
			
		||||
        actor = polynomalActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
    }
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Polynomal")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<PolynomalActor> polynomalActor = std::shared_ptr<PolynomalActor>(new PolynomalActor);
 | 
			
		||||
		actor = polynomalActor;
 | 
			
		||||
		dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    else if(ui->comboBox->currentText() == "Multi Factor")
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(new MultiFactorActor);
 | 
			
		||||
        actor = polynomalActor;
 | 
			
		||||
        dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
    }
 | 
			
		||||
	else if(ui->comboBox->currentText() == "Multi Factor")
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<MultiFactorActor> polynomalActor = std::shared_ptr<MultiFactorActor>(new MultiFactorActor);
 | 
			
		||||
		actor = polynomalActor;
 | 
			
		||||
		dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if(dialog != nullptr)
 | 
			
		||||
    {
 | 
			
		||||
        dialog->setParent(this);
 | 
			
		||||
        dialog->show();
 | 
			
		||||
        if(dialog->exec() == QDialog::Accepted)
 | 
			
		||||
        {
 | 
			
		||||
            item_->addActor(actor);
 | 
			
		||||
            loadActorList();
 | 
			
		||||
        }
 | 
			
		||||
        delete dialog;
 | 
			
		||||
    }
 | 
			
		||||
	if(dialog != nullptr)
 | 
			
		||||
	{
 | 
			
		||||
		dialog->setParent(this);
 | 
			
		||||
		dialog->show();
 | 
			
		||||
		if(dialog->exec() == QDialog::Accepted)
 | 
			
		||||
		{
 | 
			
		||||
			item_->addActor(actor);
 | 
			
		||||
			loadActorList();
 | 
			
		||||
		}
 | 
			
		||||
		delete dialog;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemSettingsDialog::removeActor()
 | 
			
		||||
{
 | 
			
		||||
    if(item_->getActors().size() > ui->tableWidget->currentRow())
 | 
			
		||||
    {
 | 
			
		||||
       item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
 | 
			
		||||
       loadActorList();
 | 
			
		||||
    }
 | 
			
		||||
	if(item_->getActors().size() > ui->tableWidget->currentRow())
 | 
			
		||||
	{
 | 
			
		||||
		item_->removeActor(item_->getActors().at(ui->tableWidget->currentRow()));
 | 
			
		||||
		loadActorList();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemSettingsDialog::editActor()
 | 
			
		||||
{
 | 
			
		||||
    if(item_->getActors().size() > ui->tableWidget->currentRow())
 | 
			
		||||
    {
 | 
			
		||||
        std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
 | 
			
		||||
	if(item_->getActors().size() > ui->tableWidget->currentRow())
 | 
			
		||||
	{
 | 
			
		||||
		std::shared_ptr<Actor> actor = item_->getActors()[ui->tableWidget->currentRow()];
 | 
			
		||||
 | 
			
		||||
        std::shared_ptr<AlarmTime> alarmTime = std::dynamic_pointer_cast<AlarmTime>(actor);
 | 
			
		||||
        std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
 | 
			
		||||
        std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
 | 
			
		||||
        std::shared_ptr<TimerActor> timerActor = std::dynamic_pointer_cast<TimerActor>(actor);
 | 
			
		||||
        std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
 | 
			
		||||
        std::shared_ptr<MultiFactorActor> factorActor = std::dynamic_pointer_cast<MultiFactorActor>(actor);
 | 
			
		||||
		std::shared_ptr<AlarmTime> alarmTime = std::dynamic_pointer_cast<AlarmTime>(actor);
 | 
			
		||||
		std::shared_ptr<Regulator> regulator = std::dynamic_pointer_cast<Regulator>(actor);
 | 
			
		||||
		std::shared_ptr<SensorActor> sensorActor = std::dynamic_pointer_cast<SensorActor>(actor);
 | 
			
		||||
		std::shared_ptr<TimerActor> timerActor = std::dynamic_pointer_cast<TimerActor>(actor);
 | 
			
		||||
		std::shared_ptr<PolynomalActor> polynomalActor = std::dynamic_pointer_cast<PolynomalActor>(actor);
 | 
			
		||||
		std::shared_ptr<MultiFactorActor> factorActor = std::dynamic_pointer_cast<MultiFactorActor>(actor);
 | 
			
		||||
 | 
			
		||||
        ActorSettingsDialog* dialog;
 | 
			
		||||
		ActorSettingsDialog* dialog;
 | 
			
		||||
 | 
			
		||||
        if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
 | 
			
		||||
        else if(regulator)  dialog = new ActorSettingsDialog(regulator, this);
 | 
			
		||||
        else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this);
 | 
			
		||||
        else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
 | 
			
		||||
        else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
        else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this);
 | 
			
		||||
        else dialog = new ActorSettingsDialog(actor, this);
 | 
			
		||||
        dialog->setParent(this);
 | 
			
		||||
        dialog->show();
 | 
			
		||||
        dialog->exec();
 | 
			
		||||
		if(alarmTime) dialog = new ActorSettingsDialog(alarmTime, this);
 | 
			
		||||
		else if(regulator)  dialog = new ActorSettingsDialog(regulator, this);
 | 
			
		||||
		else if(sensorActor) dialog = new ActorSettingsDialog(sensorActor, this);
 | 
			
		||||
		else if(timerActor) dialog = new ActorSettingsDialog(timerActor, this);
 | 
			
		||||
		else if(polynomalActor) dialog = new ActorSettingsDialog(polynomalActor, this);
 | 
			
		||||
		else if(factorActor) dialog = new ActorSettingsDialog(factorActor, this);
 | 
			
		||||
		else dialog = new ActorSettingsDialog(actor, this);
 | 
			
		||||
		dialog->setParent(this);
 | 
			
		||||
		dialog->show();
 | 
			
		||||
		dialog->exec();
 | 
			
		||||
 | 
			
		||||
        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, 1)->setText(item_->getActors()[i]->actionName());
 | 
			
		||||
            ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
		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, 1)->setText(item_->getActors()[i]->actionName());
 | 
			
		||||
			ui->tableWidget->item(i, 2)->setText(item_->getActors()[i]->isActive() ? "Y" : "N");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,32 +6,33 @@
 | 
			
		|||
#include <memory>
 | 
			
		||||
#include "../items/relay.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class ItemSettingsDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ItemSettingsDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    std::shared_ptr<Item> item_;
 | 
			
		||||
    QWidget* itemSpecificWidget_ = nullptr;
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
	std::shared_ptr<Item> item_;
 | 
			
		||||
	QWidget* itemSpecificWidget_ = nullptr;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    void loadActorList();
 | 
			
		||||
	void loadActorList();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr);
 | 
			
		||||
    ~ItemSettingsDialog();
 | 
			
		||||
	explicit ItemSettingsDialog(std::shared_ptr<Item> item, QWidget *parent = nullptr);
 | 
			
		||||
	~ItemSettingsDialog();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void removeActor();
 | 
			
		||||
    void addActor();
 | 
			
		||||
    void editActor();
 | 
			
		||||
    void changeOverride();
 | 
			
		||||
	void removeActor();
 | 
			
		||||
	void addActor();
 | 
			
		||||
	void editActor();
 | 
			
		||||
	void changeOverride();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::ItemSettingsDialog *ui;
 | 
			
		||||
	Ui::ItemSettingsDialog *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // RELAYSETTINGSDIALOG_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,41 +5,44 @@
 | 
			
		|||
#include <QDebug>
 | 
			
		||||
 | 
			
		||||
MessageItemSettingsWidget::MessageItemSettingsWidget(std::weak_ptr<MessageItem> item, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    item_(item),
 | 
			
		||||
    ui(new Ui::MessageItemSettingsWidget)
 | 
			
		||||
	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());
 | 
			
		||||
    }
 | 
			
		||||
	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"));});
 | 
			
		||||
	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);
 | 
			
		||||
    }
 | 
			
		||||
	if(auto workingItem = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		workingItem->setMessage(text);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MessageItemSettingsWidget::setAlert(const QString &in)
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingItem = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        workingItem->setAlert(in);
 | 
			
		||||
    }
 | 
			
		||||
	if(auto workingItem = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		workingItem->setAlert(in);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MessageItemSettingsWidget::~MessageItemSettingsWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,26 +5,27 @@
 | 
			
		|||
#include <memory>
 | 
			
		||||
#include "../../items/messageitem.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class MessageItemSettingsWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class MessageItemSettingsWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    std::weak_ptr<MessageItem> item_;
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
	std::weak_ptr<MessageItem> item_;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void setText(const QString& text);
 | 
			
		||||
    void setAlert(const QString &in);
 | 
			
		||||
	void setText(const QString& text);
 | 
			
		||||
	void setAlert(const QString &in);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit MessageItemSettingsWidget(std::weak_ptr<MessageItem> item, QWidget *parent = nullptr);
 | 
			
		||||
    ~MessageItemSettingsWidget();
 | 
			
		||||
	explicit MessageItemSettingsWidget(std::weak_ptr<MessageItem> item, QWidget *parent = nullptr);
 | 
			
		||||
	~MessageItemSettingsWidget();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::MessageItemSettingsWidget *ui;
 | 
			
		||||
	Ui::MessageItemSettingsWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // MESSAGEITEMSETTINGSWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -3,19 +3,19 @@
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
RelayItemSettingsWidget::RelayItemSettingsWidget(std::weak_ptr<Relay> relay, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    ui(new Ui::RelayItemSettingsWidget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	ui(new Ui::RelayItemSettingsWidget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    auto relayPtr = relay.lock();
 | 
			
		||||
    if(relayPtr)
 | 
			
		||||
    {
 | 
			
		||||
        ui->label_ID->setText(QString::number(relayPtr->getId()));
 | 
			
		||||
        ui->label_Addr->setText(QString::number(relayPtr->getAddress(),2));
 | 
			
		||||
    }
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	auto relayPtr = relay.lock();
 | 
			
		||||
	if(relayPtr)
 | 
			
		||||
	{
 | 
			
		||||
		ui->label_ID->setText(QString::number(relayPtr->getId()));
 | 
			
		||||
		ui->label_Addr->setText(QString::number(relayPtr->getAddress(),2));
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RelayItemSettingsWidget::~RelayItemSettingsWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,20 +5,21 @@
 | 
			
		|||
#include <memory>
 | 
			
		||||
#include "../../items/relay.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class RelayItemSettingsWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class RelayItemSettingsWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit RelayItemSettingsWidget(std::weak_ptr<Relay> relay, QWidget *parent = nullptr);
 | 
			
		||||
    ~RelayItemSettingsWidget();
 | 
			
		||||
	explicit RelayItemSettingsWidget(std::weak_ptr<Relay> relay, QWidget *parent = nullptr);
 | 
			
		||||
	~RelayItemSettingsWidget();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::RelayItemSettingsWidget *ui;
 | 
			
		||||
	Ui::RelayItemSettingsWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // RELAYITEMSETTINGSWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,39 +2,39 @@
 | 
			
		|||
#include "ui_systemitemsettingswidget.h"
 | 
			
		||||
 | 
			
		||||
SystemItemSettingsWidget::SystemItemSettingsWidget(std::weak_ptr<SystemItem> item, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    item_(item),
 | 
			
		||||
    ui(new Ui::SystemItemSettingsWidget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	item_(item),
 | 
			
		||||
	ui(new Ui::SystemItemSettingsWidget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    if(auto itemPtr = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        ui->lineEdit_on->setText(itemPtr->getOnCommand());
 | 
			
		||||
        ui->lineEdit_off->setText(itemPtr->getOffCommand());
 | 
			
		||||
    }
 | 
			
		||||
    else setDisabled(true);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	if(auto itemPtr = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		ui->lineEdit_on->setText(itemPtr->getOnCommand());
 | 
			
		||||
		ui->lineEdit_off->setText(itemPtr->getOffCommand());
 | 
			
		||||
	}
 | 
			
		||||
	else setDisabled(true);
 | 
			
		||||
 | 
			
		||||
    connect(ui->lineEdit_on, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOn);
 | 
			
		||||
    connect(ui->lineEdit_off, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOff);
 | 
			
		||||
	connect(ui->lineEdit_on, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOn);
 | 
			
		||||
	connect(ui->lineEdit_off, &QLineEdit::textChanged, this, &SystemItemSettingsWidget::setOff);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SystemItemSettingsWidget::setOn(const QString& in)
 | 
			
		||||
{
 | 
			
		||||
    if(auto itemPtr = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        itemPtr->setOnCommand(in);
 | 
			
		||||
    }
 | 
			
		||||
	if(auto itemPtr = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		itemPtr->setOnCommand(in);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SystemItemSettingsWidget::setOff(const QString& in)
 | 
			
		||||
{
 | 
			
		||||
    if(auto itemPtr = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        itemPtr->setOffCommand(in);
 | 
			
		||||
    }
 | 
			
		||||
	if(auto itemPtr = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		itemPtr->setOffCommand(in);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
SystemItemSettingsWidget::~SystemItemSettingsWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,26 +5,27 @@
 | 
			
		|||
#include <memory>
 | 
			
		||||
#include "../../items/systemitem.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class SystemItemSettingsWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class SystemItemSettingsWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
    std::weak_ptr<SystemItem> item_;
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
	std::weak_ptr<SystemItem> item_;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    void setOn(const QString &in);
 | 
			
		||||
    void setOff(const QString &in);
 | 
			
		||||
	void setOn(const QString &in);
 | 
			
		||||
	void setOff(const QString &in);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit SystemItemSettingsWidget(std::weak_ptr<SystemItem> item, QWidget *parent = nullptr);
 | 
			
		||||
    ~SystemItemSettingsWidget();
 | 
			
		||||
	explicit SystemItemSettingsWidget(std::weak_ptr<SystemItem> item, QWidget *parent = nullptr);
 | 
			
		||||
	~SystemItemSettingsWidget();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::SystemItemSettingsWidget *ui;
 | 
			
		||||
	Ui::SystemItemSettingsWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // SYSTEMITEMSETTINGSWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,105 +6,105 @@
 | 
			
		|||
#include <QSlider>
 | 
			
		||||
 | 
			
		||||
ItemWidget::ItemWidget(std::weak_ptr<Item> item, bool analog, bool nameOnly, QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    item_(item),
 | 
			
		||||
    ui(new Ui::ItemWidget)
 | 
			
		||||
	QWidget(parent),
 | 
			
		||||
	item_(item),
 | 
			
		||||
	ui(new Ui::ItemWidget)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
    if(analog)
 | 
			
		||||
    {
 | 
			
		||||
        ui->horizontalSpacer->changeSize(0,0);
 | 
			
		||||
        ui->checkBox->hide();
 | 
			
		||||
    }
 | 
			
		||||
    else if(nameOnly)
 | 
			
		||||
    {
 | 
			
		||||
        ui->checkBox->hide();
 | 
			
		||||
        ui->slider->hide();
 | 
			
		||||
    }
 | 
			
		||||
    else ui->slider->hide();
 | 
			
		||||
	if(analog)
 | 
			
		||||
	{
 | 
			
		||||
		ui->horizontalSpacer->changeSize(0,0);
 | 
			
		||||
		ui->checkBox->hide();
 | 
			
		||||
	}
 | 
			
		||||
	else if(nameOnly)
 | 
			
		||||
	{
 | 
			
		||||
		ui->checkBox->hide();
 | 
			
		||||
		ui->slider->hide();
 | 
			
		||||
	}
 | 
			
		||||
	else ui->slider->hide();
 | 
			
		||||
 | 
			
		||||
    if(auto workingRelay = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        ui->checkBox->setChecked(workingRelay->getValue());
 | 
			
		||||
	if(auto workingRelay = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		ui->checkBox->setChecked(workingRelay->getValue());
 | 
			
		||||
 | 
			
		||||
        ui->label->setText(workingRelay->getName());
 | 
			
		||||
		ui->label->setText(workingRelay->getName());
 | 
			
		||||
 | 
			
		||||
        if(analog)connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
 | 
			
		||||
        else connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
 | 
			
		||||
        connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
 | 
			
		||||
        connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
 | 
			
		||||
        connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
 | 
			
		||||
		if(analog)connect(ui->slider, &QSlider::valueChanged, this, &ItemWidget::moveToValue);
 | 
			
		||||
		else connect(ui->checkBox, &QCheckBox::toggled, this, &ItemWidget::moveToState);
 | 
			
		||||
		connect(ui->pushButton, &QPushButton::clicked, this, &ItemWidget::showSettingsDialog);
 | 
			
		||||
		connect(workingRelay.get(), &Relay::valueChanged, this, &ItemWidget::stateChanged);
 | 
			
		||||
		connect(ui->pushButton_Remove, &QPushButton::clicked, this, &ItemWidget::deleteItem);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    else disable();
 | 
			
		||||
	}
 | 
			
		||||
	else disable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::deleteItem()
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingItem = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        deleteRequest(*workingItem);
 | 
			
		||||
    }
 | 
			
		||||
	if(auto workingItem = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		deleteRequest(*workingItem);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::moveToValue(int value)
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingItem = item_.lock()) workingItem->setValue(value);
 | 
			
		||||
    else disable();
 | 
			
		||||
	if(auto workingItem = item_.lock()) workingItem->setValue(value);
 | 
			
		||||
	else disable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::moveToState(bool state)
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingItem = item_.lock()) workingItem->setValue(state);
 | 
			
		||||
    else disable();
 | 
			
		||||
	if(auto workingItem = item_.lock()) workingItem->setValue(state);
 | 
			
		||||
	else disable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::disable()
 | 
			
		||||
{
 | 
			
		||||
    ui->checkBox->setEnabled(false);
 | 
			
		||||
    ui->label->setEnabled(false);
 | 
			
		||||
    ui->slider->setEnabled(false);
 | 
			
		||||
    ui->pushButton_Remove->setEnabled(false);
 | 
			
		||||
	ui->checkBox->setEnabled(false);
 | 
			
		||||
	ui->label->setEnabled(false);
 | 
			
		||||
	ui->slider->setEnabled(false);
 | 
			
		||||
	ui->pushButton_Remove->setEnabled(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool ItemWidget::controles(const ItemData& relay)
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingRelay = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        if(relay == *workingRelay) return  true;
 | 
			
		||||
        else return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
	if(auto workingRelay = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		if(relay == *workingRelay) return  true;
 | 
			
		||||
		else return false;
 | 
			
		||||
	}
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::showSettingsDialog()
 | 
			
		||||
{
 | 
			
		||||
    if(auto workingRelay = item_.lock())
 | 
			
		||||
    {
 | 
			
		||||
        ItemSettingsDialog dialog(workingRelay, this);
 | 
			
		||||
        dialog.exec();
 | 
			
		||||
    }
 | 
			
		||||
    else disable();
 | 
			
		||||
	if(auto workingRelay = item_.lock())
 | 
			
		||||
	{
 | 
			
		||||
		ItemSettingsDialog dialog(workingRelay, this);
 | 
			
		||||
		dialog.exec();
 | 
			
		||||
	}
 | 
			
		||||
	else disable();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
std::weak_ptr<Item> ItemWidget::getItem()
 | 
			
		||||
{
 | 
			
		||||
    return item_;
 | 
			
		||||
	return item_;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ItemWidget::stateChanged(int state)
 | 
			
		||||
{
 | 
			
		||||
    qDebug()<<"widget got state "<<state;
 | 
			
		||||
    ui->slider->blockSignals(true);
 | 
			
		||||
    ui->slider->setValue(state);
 | 
			
		||||
    ui->slider->blockSignals(false);
 | 
			
		||||
    ui->checkBox->blockSignals(true);
 | 
			
		||||
    ui->checkBox->setChecked(state);
 | 
			
		||||
    ui->checkBox->blockSignals(false);
 | 
			
		||||
	qDebug()<<"widget got state "<<state;
 | 
			
		||||
	ui->slider->blockSignals(true);
 | 
			
		||||
	ui->slider->setValue(state);
 | 
			
		||||
	ui->slider->blockSignals(false);
 | 
			
		||||
	ui->checkBox->blockSignals(true);
 | 
			
		||||
	ui->checkBox->setChecked(state);
 | 
			
		||||
	ui->checkBox->blockSignals(false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ItemWidget::~ItemWidget()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,40 +6,41 @@
 | 
			
		|||
#include "itemsettingsdialog.h"
 | 
			
		||||
#include "../items/item.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class ItemWidget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class ItemWidget : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
private:
 | 
			
		||||
    std::weak_ptr<Item> item_;
 | 
			
		||||
	std::weak_ptr<Item> item_;
 | 
			
		||||
 | 
			
		||||
    void disable();
 | 
			
		||||
	void disable();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void deleteRequest(const ItemData& item);
 | 
			
		||||
	void deleteRequest(const ItemData& item);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void showSettingsDialog();
 | 
			
		||||
    void moveToState(bool state);
 | 
			
		||||
    void moveToValue(int value);
 | 
			
		||||
    void deleteItem();
 | 
			
		||||
	void showSettingsDialog();
 | 
			
		||||
	void moveToState(bool state);
 | 
			
		||||
	void moveToValue(int value);
 | 
			
		||||
	void deleteItem();
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit ItemWidget(std::weak_ptr<Item> item, bool analog = false,  bool nameOnly = false, QWidget *parent = nullptr);
 | 
			
		||||
    std::weak_ptr<Item> getItem();
 | 
			
		||||
    bool controles(const ItemData& relay);
 | 
			
		||||
    ~ItemWidget();
 | 
			
		||||
	explicit ItemWidget(std::weak_ptr<Item> item, bool analog = false,  bool nameOnly = false, QWidget *parent = nullptr);
 | 
			
		||||
	std::weak_ptr<Item> getItem();
 | 
			
		||||
	bool controles(const ItemData& relay);
 | 
			
		||||
	~ItemWidget();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void stateChanged(int state);
 | 
			
		||||
	void stateChanged(int state);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::ItemWidget *ui;
 | 
			
		||||
	Ui::ItemWidget *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // RELAYWIDGET_H
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -7,13 +7,13 @@
 | 
			
		|||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
 | 
			
		||||
    QMainWindow(parent),
 | 
			
		||||
    ui(new Ui::MainWindow),
 | 
			
		||||
    colorChooser(this),
 | 
			
		||||
    _micro(&mainObject->micro),
 | 
			
		||||
    _powerItem(mainObject->powerItem)
 | 
			
		||||
	QMainWindow(parent),
 | 
			
		||||
	ui(new Ui::MainWindow),
 | 
			
		||||
	colorChooser(this),
 | 
			
		||||
	_micro(&mainObject->micro),
 | 
			
		||||
	_powerItem(mainObject->powerItem)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
	if(!mainObject->master)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -25,47 +25,47 @@ MainWindow::MainWindow(MainObject * const mainObject, QWidget *parent) :
 | 
			
		|||
		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()));
 | 
			
		||||
 | 
			
		||||
    //Relays
 | 
			
		||||
    if(mainObject->master)connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
 | 
			
		||||
    else
 | 
			
		||||
    {
 | 
			
		||||
        connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
 | 
			
		||||
        connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestSensors);
 | 
			
		||||
    }
 | 
			
		||||
    connect(&mainObject->items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
 | 
			
		||||
    connect(&mainObject->items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
 | 
			
		||||
	//Relays
 | 
			
		||||
	if(mainObject->master)connect(ui->pushButton_refesh, &QPushButton::clicked, _micro, &Microcontroller::requestState);
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestJson);
 | 
			
		||||
		connect(ui->pushButton_refesh, &QPushButton::clicked, &mainObject->broadCast, &BroadCast::requestSensors);
 | 
			
		||||
	}
 | 
			
		||||
	connect(&mainObject->items, &ItemStore::itemAdded, ui->relayList, &ItemScrollBox::addItem);
 | 
			
		||||
	connect(&mainObject->items, &ItemStore::itemDeleted, ui->relayList, &ItemScrollBox::removeItem);
 | 
			
		||||
 | 
			
		||||
    for(size_t i = 0; i < mainObject->items.getItems()->size(); ++i)
 | 
			
		||||
    {
 | 
			
		||||
        ui->relayList->addItem(mainObject->items.getItems()->at(i));
 | 
			
		||||
    }
 | 
			
		||||
	for(size_t i = 0; i < mainObject->items.getItems()->size(); ++i)
 | 
			
		||||
	{
 | 
			
		||||
		ui->relayList->addItem(mainObject->items.getItems()->at(i));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    //Sensors
 | 
			
		||||
    ui->sensorListView->setShowHidden(false);
 | 
			
		||||
    ui->sensorListView->sensorsChanged(*globalSensors.getSensors());
 | 
			
		||||
    connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
 | 
			
		||||
	//Sensors
 | 
			
		||||
	ui->sensorListView->setShowHidden(false);
 | 
			
		||||
	ui->sensorListView->sensorsChanged(*globalSensors.getSensors());
 | 
			
		||||
	connect(&globalSensors, &SensorStore::stateChenged, ui->sensorListView, &SensorListWidget::sensorsChanged);
 | 
			
		||||
 | 
			
		||||
    //RGB Leds
 | 
			
		||||
	//RGB Leds
 | 
			
		||||
	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->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);
 | 
			
		||||
	connect(ui->pushButton_addItem, &QPushButton::clicked, this, &MainWindow::showItemCreationDialog);
 | 
			
		||||
	connect(ui->relayList, &ItemScrollBox::deleteRequest, &mainObject->items, &ItemStore::removeItem);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
MainWindow::~MainWindow()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::showPowerItemDialog()
 | 
			
		||||
{
 | 
			
		||||
    ItemSettingsDialog diag(std::shared_ptr<Item>(_powerItem), this);
 | 
			
		||||
    diag.show();
 | 
			
		||||
    diag.exec();
 | 
			
		||||
	ItemSettingsDialog diag(std::shared_ptr<Item>(_powerItem), this);
 | 
			
		||||
	diag.show();
 | 
			
		||||
	diag.exec();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::saved()
 | 
			
		||||
| 
						 | 
				
			
			@ -75,25 +75,25 @@ void MainWindow::saved()
 | 
			
		|||
 | 
			
		||||
void MainWindow::slotChangedRgb(const QColor color)
 | 
			
		||||
{
 | 
			
		||||
    _micro->changeRgbColor(color);
 | 
			
		||||
	_micro->changeRgbColor(color);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::showItemCreationDialog()
 | 
			
		||||
{
 | 
			
		||||
    ItemCreationDialog diag(this);
 | 
			
		||||
    diag.show();
 | 
			
		||||
    if(diag.exec())
 | 
			
		||||
    {
 | 
			
		||||
        createdItem(diag.item);
 | 
			
		||||
    }
 | 
			
		||||
	ItemCreationDialog diag(this);
 | 
			
		||||
	diag.show();
 | 
			
		||||
	if(diag.exec())
 | 
			
		||||
	{
 | 
			
		||||
		createdItem(diag.item);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void MainWindow::changeHeaderLableText(QString string)
 | 
			
		||||
{
 | 
			
		||||
    if(string.size() > 28)
 | 
			
		||||
    {
 | 
			
		||||
        string.remove(28, string.size()-(28));
 | 
			
		||||
        string.append("...");
 | 
			
		||||
    }
 | 
			
		||||
    ui->label_serialRecive->setText(string);
 | 
			
		||||
	if(string.size() > 28)
 | 
			
		||||
	{
 | 
			
		||||
		string.remove(28, string.size()-(28));
 | 
			
		||||
		string.append("...");
 | 
			
		||||
	}
 | 
			
		||||
	ui->label_serialRecive->setText(string);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,33 +23,33 @@ class MainWindow;
 | 
			
		|||
 | 
			
		||||
class MainWindow : public QMainWindow
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit MainWindow(MainObject * const mainObject, QWidget *parent = nullptr);
 | 
			
		||||
    ~MainWindow();
 | 
			
		||||
	explicit MainWindow(MainObject * const mainObject, QWidget *parent = nullptr);
 | 
			
		||||
	~MainWindow();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::MainWindow *ui;
 | 
			
		||||
	Ui::MainWindow *ui;
 | 
			
		||||
 | 
			
		||||
    QColorDialog colorChooser;
 | 
			
		||||
	QColorDialog colorChooser;
 | 
			
		||||
 | 
			
		||||
    Microcontroller *_micro;
 | 
			
		||||
	Microcontroller *_micro;
 | 
			
		||||
 | 
			
		||||
    std::shared_ptr<PowerItem> _powerItem;
 | 
			
		||||
	std::shared_ptr<PowerItem> _powerItem;
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    void sigBrodcast();
 | 
			
		||||
	void sigBrodcast();
 | 
			
		||||
	void sigSave();
 | 
			
		||||
    void createdItem(std::shared_ptr<Item> item);
 | 
			
		||||
	void createdItem(std::shared_ptr<Item> item);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
 | 
			
		||||
    //RGB
 | 
			
		||||
    void slotChangedRgb(const QColor color);
 | 
			
		||||
    void showPowerItemDialog();
 | 
			
		||||
    void showItemCreationDialog();
 | 
			
		||||
	//RGB
 | 
			
		||||
	void slotChangedRgb(const QColor color);
 | 
			
		||||
	void showPowerItemDialog();
 | 
			
		||||
	void showItemCreationDialog();
 | 
			
		||||
	void saved();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,69 +4,71 @@
 | 
			
		|||
#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);
 | 
			
		||||
    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"));
 | 
			
		||||
	setColumnCount(2);
 | 
			
		||||
	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"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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()));
 | 
			
		||||
	sensorsChanged(*(sensorStore.getSensors()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
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++;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    size_t listLen = 0;
 | 
			
		||||
    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)
 | 
			
		||||
    {
 | 
			
		||||
        if(showHidden_ || !sensors[i].hidden)
 | 
			
		||||
        {
 | 
			
		||||
            QString itemString;
 | 
			
		||||
            itemString.append(QString::number(sensors[i].field));
 | 
			
		||||
            itemString.append(' ');
 | 
			
		||||
	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++;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	size_t listLen = 0;
 | 
			
		||||
	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)
 | 
			
		||||
	{
 | 
			
		||||
		if(showHidden_ || !sensors[i].hidden)
 | 
			
		||||
		{
 | 
			
		||||
			QString itemString;
 | 
			
		||||
			itemString.append(QString::number(sensors[i].field));
 | 
			
		||||
			itemString.append(' ');
 | 
			
		||||
 | 
			
		||||
            if(sensors[i].type == Sensor::TYPE_DOOR)
 | 
			
		||||
            {
 | 
			
		||||
                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\"");
 | 
			
		||||
                else itemString.append("\"Silent\"");
 | 
			
		||||
            }
 | 
			
		||||
			if(sensors[i].type == Sensor::TYPE_DOOR)
 | 
			
		||||
			{
 | 
			
		||||
				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\"");
 | 
			
		||||
				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));
 | 
			
		||||
            ++row;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
			setItem(static_cast<int>(row), 0, new QTableWidgetItem(sensors[i].name + (sensors[i].hidden ? "(H)" : "")));
 | 
			
		||||
			setItem(static_cast<int>(row), 1, new QTableWidgetItem(itemString));
 | 
			
		||||
			++row;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SensorListWidget::setShowHidden(const bool showHidden)
 | 
			
		||||
{
 | 
			
		||||
    showHidden_=showHidden;
 | 
			
		||||
	showHidden_=showHidden;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,19 +5,19 @@
 | 
			
		|||
 | 
			
		||||
class SensorListWidget : public QTableWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
    bool showHidden_;
 | 
			
		||||
	bool showHidden_;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
    SensorListWidget(const bool showHidden = true, QWidget *parent = nullptr);
 | 
			
		||||
    SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr);
 | 
			
		||||
    virtual ~SensorListWidget(){}
 | 
			
		||||
    void setShowHidden(const bool showHidden);
 | 
			
		||||
	SensorListWidget(const bool showHidden = true, QWidget *parent = nullptr);
 | 
			
		||||
	SensorListWidget(SensorStore& sensorStore, const bool showHidden = true, QWidget* parent = nullptr);
 | 
			
		||||
	virtual ~SensorListWidget() {}
 | 
			
		||||
	void setShowHidden(const bool showHidden);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
    void sensorsChanged(std::vector<Sensor> sensors);
 | 
			
		||||
	void sensorsChanged(std::vector<Sensor> sensors);
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue