35 lines
816 B
C++
35 lines
816 B
C++
#include "poweritem.h"
|
|
#include <QProcess>
|
|
#include <QApplication>
|
|
#include <QDebug>
|
|
|
|
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));
|
|
PowerItem::setValue(true);
|
|
hidden_ = true;
|
|
type_ = ITEM_VALUE_NO_VALUE;
|
|
}
|
|
|
|
void PowerItem::enactValue(uint8_t value)
|
|
{
|
|
if(!value)
|
|
{
|
|
qDebug()<<"shutdown";
|
|
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", QStringList());
|
|
}
|
|
|
|
void PowerItem::store(QJsonObject& json)
|
|
{
|
|
json["Type"] = "Power";
|
|
Item::store(json);
|
|
}
|