Add initial version of Sensors plugin, see #96
This commit is contained in:
parent
7738dc69d0
commit
51e87ffa88
10 changed files with 342 additions and 0 deletions
|
@ -12,6 +12,7 @@ SET(BUILD_PLUGIN_DBUS FALSE CACHE BOOL "Build plugin 'DBus'")
|
|||
SET(BUILD_PLUGIN_LIVE FALSE CACHE BOOL "Build plugin 'Telldus Live!'")
|
||||
SET(BUILD_PLUGIN_XPL FALSE CACHE BOOL "Build plugin 'xPL'")
|
||||
SET(BUILD_PLUGIN_SCHEDULERGUISIMPLE FALSE CACHE BOOL "Build plugin 'Simple Scheduler GUI'")
|
||||
SET(BUILD_PLUGIN_SENSORS FALSE CACHE BOOL "Build plugin 'Sensors'")
|
||||
|
||||
ADD_SUBDIRECTORY(telldus)
|
||||
|
||||
|
@ -35,6 +36,10 @@ IF(BUILD_PLUGIN_LIVE)
|
|||
ADD_SUBDIRECTORY(Live)
|
||||
ENDIF(BUILD_PLUGIN_LIVE)
|
||||
|
||||
IF(BUILD_PLUGIN_SENSORS)
|
||||
ADD_SUBDIRECTORY(Sensors)
|
||||
ENDIF()
|
||||
|
||||
IF(BUILD_PLUGIN_XPL)
|
||||
ADD_SUBDIRECTORY(xPL)
|
||||
ENDIF(BUILD_PLUGIN_XPL)
|
||||
|
|
28
telldus-gui/Plugins/Sensors/CMakeLists.txt
Normal file
28
telldus-gui/Plugins/Sensors/CMakeLists.txt
Normal file
|
@ -0,0 +1,28 @@
|
|||
SET(REQUIRE_PLUGIN_QML TRUE PARENT_SCOPE)
|
||||
SET(REQUIRE_PLUGIN_SETTINGS TRUE PARENT_SCOPE)
|
||||
|
||||
SET( Plugin_NAME "sensors" )
|
||||
|
||||
|
||||
SET( Plugin_SRCS
|
||||
sensor.cpp
|
||||
sensorsplugin.cpp
|
||||
)
|
||||
|
||||
SET( Plugin_HDRS
|
||||
sensorsplugin.h
|
||||
)
|
||||
|
||||
SET( Plugin_MOC_HDRS
|
||||
sensor.h
|
||||
)
|
||||
|
||||
SET( Plugin_PATH "com.telldus.sensors" )
|
||||
|
||||
SET( Plugin_EXTRA
|
||||
icon.png
|
||||
main.qml
|
||||
qmldir
|
||||
)
|
||||
|
||||
INCLUDE( ../TelldusCenterPlugin.cmake NO_POLICY_SCOPE )
|
79
telldus-gui/Plugins/Sensors/__init__.js
Normal file
79
telldus-gui/Plugins/Sensors/__init__.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
/** Sensors **/
|
||||
__setupPackage__( __extension__ );
|
||||
|
||||
__postInit__ = function() {
|
||||
application.allDoneLoading.connect( com.telldus.sensors.init );
|
||||
}
|
||||
|
||||
com.telldus.sensors = function() {
|
||||
var sensorList = new com.telldus.qml.array();
|
||||
|
||||
function init() {
|
||||
var sensorData = 0;
|
||||
while(sensorData = com.telldus.core.sensor()) {
|
||||
var p = sensorData["protocol"];
|
||||
var m = sensorData["model"];
|
||||
var id = sensorData["sensorId"];
|
||||
var types = sensorData["dataTypes"];
|
||||
|
||||
var tryFetchValue = function(p, m, id, types, type) {
|
||||
if (types & type) {
|
||||
sensorValue = com.telldus.core.sensorValue(p, m, id, type);
|
||||
sensorEvent(p, m, id, type, sensorValue["value"], sensorValue["timestamp"]);
|
||||
}
|
||||
}
|
||||
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_TEMPERATURE);
|
||||
tryFetchValue(p, m, id, types, com.telldus.core.TELLSTICK_HUMIDITY);
|
||||
|
||||
}
|
||||
|
||||
//com.telldus.core.sensorEvent.connect(sensorEvent);
|
||||
view = new com.telldus.qml.view({
|
||||
});
|
||||
|
||||
view.setProperty('sensorModel', sensorList);
|
||||
view.load("main.qml");
|
||||
application.addWidget("sensors.gui", "icon.png", view);
|
||||
}
|
||||
|
||||
function sensorEvent(protocol, model, id, dataType, value, timestamp) {
|
||||
var sensor = 0;
|
||||
for (var i = 0; i < sensorList.length; ++i) {
|
||||
if (sensorList.get(i).protocol != protocol) {
|
||||
continue;
|
||||
}
|
||||
if (sensorList.get(i).model != model) {
|
||||
continue;
|
||||
}
|
||||
if (sensorList.get(i).id != id) {
|
||||
continue;
|
||||
}
|
||||
sensor = sensorList.get(i);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!sensor) {
|
||||
sensor = new com.telldus.sensors.sensor();
|
||||
sensor.protocol = protocol;
|
||||
sensor.model = model;
|
||||
sensor.id = id;
|
||||
sensorList.push(sensor);
|
||||
print("Create new");
|
||||
} else {
|
||||
print("Update");
|
||||
}
|
||||
|
||||
if (dataType == com.telldus.core.TELLSTICK_TEMPERATURE) {
|
||||
sensor.temperature = value;
|
||||
} else if (dataType == com.telldus.core.TELLSTICK_HUMIDITY) {
|
||||
sensor.humidity = value;
|
||||
}
|
||||
|
||||
print("Sensor event", protocol, model, id, dataType, value, timestamp);
|
||||
}
|
||||
|
||||
return { //Public functions
|
||||
init:init
|
||||
}
|
||||
|
||||
}();
|
BIN
telldus-gui/Plugins/Sensors/icon.png
Normal file
BIN
telldus-gui/Plugins/Sensors/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
20
telldus-gui/Plugins/Sensors/main.qml
Normal file
20
telldus-gui/Plugins/Sensors/main.qml
Normal file
|
@ -0,0 +1,20 @@
|
|||
import Qt 4.7
|
||||
|
||||
Item {
|
||||
id: main
|
||||
|
||||
Column {
|
||||
Repeater {
|
||||
model: sensorModel
|
||||
delegate: Row {
|
||||
spacing: 10
|
||||
Text { text: modelData.name }
|
||||
Text { text: modelData.protocol }
|
||||
Text { text: modelData.model }
|
||||
Text { text: modelData.temperature + '°C'; visible: modelData.hasTemperature }
|
||||
Text { text: modelData.humidity + "%"; visible: modelData.hasHumidity }
|
||||
}
|
||||
}
|
||||
anchors.fill: parent
|
||||
}
|
||||
}
|
0
telldus-gui/Plugins/Sensors/qmldir
Normal file
0
telldus-gui/Plugins/Sensors/qmldir
Normal file
97
telldus-gui/Plugins/Sensors/sensor.cpp
Normal file
97
telldus-gui/Plugins/Sensors/sensor.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
#include "sensor.h"
|
||||
|
||||
class Sensor::PrivateData {
|
||||
public:
|
||||
bool hasTemperature, hasHumidity;
|
||||
int id;
|
||||
QString model, name, protocol, temperature, humidity;
|
||||
QDateTime lastUpdated;
|
||||
};
|
||||
|
||||
Sensor::Sensor(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
d = new PrivateData;
|
||||
d->hasTemperature = false;
|
||||
d->hasHumidity = false;
|
||||
d->id = 0;
|
||||
}
|
||||
|
||||
Sensor::~Sensor() {
|
||||
delete d;
|
||||
}
|
||||
|
||||
QString Sensor::humidity() const {
|
||||
return d->humidity;
|
||||
}
|
||||
|
||||
void Sensor::setHumidity(const QString &humidity) {
|
||||
d->humidity = humidity;
|
||||
d->hasHumidity = true;
|
||||
emit humidityChanged();
|
||||
emit hasHumidityChanged();
|
||||
}
|
||||
|
||||
bool Sensor::hasHumidity() const {
|
||||
return d->hasHumidity;
|
||||
}
|
||||
|
||||
int Sensor::id() const {
|
||||
return d->id;
|
||||
}
|
||||
|
||||
void Sensor::setId(int id) {
|
||||
d->id = id;
|
||||
emit idChanged();
|
||||
}
|
||||
|
||||
QDateTime Sensor::lastUpdated() const {
|
||||
return d->lastUpdated;
|
||||
}
|
||||
|
||||
void Sensor::setLastUpdated(const QDateTime &lastUpdated) {
|
||||
d->lastUpdated = lastUpdated;
|
||||
emit lastUpdatedChanged();
|
||||
}
|
||||
|
||||
QString Sensor::model() const {
|
||||
return d->model;
|
||||
}
|
||||
|
||||
void Sensor::setModel(const QString &model) {
|
||||
d->model = model;
|
||||
emit modelChanged();
|
||||
}
|
||||
|
||||
QString Sensor::name() const {
|
||||
return d->name;
|
||||
}
|
||||
|
||||
void Sensor::setName(const QString &name) {
|
||||
d->name = name;
|
||||
emit nameChanged();
|
||||
}
|
||||
|
||||
QString Sensor::protocol() const {
|
||||
return d->protocol;
|
||||
}
|
||||
|
||||
void Sensor::setProtocol(const QString &protocol) {
|
||||
d->protocol = protocol;
|
||||
emit protocolChanged();
|
||||
}
|
||||
|
||||
QString Sensor::temperature() const {
|
||||
return d->temperature;
|
||||
}
|
||||
|
||||
void Sensor::setTemperature(const QString &temperature) {
|
||||
d->temperature = temperature;
|
||||
d->hasTemperature = true;
|
||||
emit temperatureChanged();
|
||||
emit hasTemperatureChanged();
|
||||
}
|
||||
|
||||
bool Sensor::hasTemperature() const {
|
||||
return d->hasTemperature;
|
||||
}
|
66
telldus-gui/Plugins/Sensors/sensor.h
Normal file
66
telldus-gui/Plugins/Sensors/sensor.h
Normal file
|
@ -0,0 +1,66 @@
|
|||
#ifndef SENSOR_H
|
||||
#define SENSOR_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMetaType>
|
||||
#include <QVariantMap>
|
||||
#include <QDateTime>
|
||||
|
||||
class Sensor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool hasHumidity READ hasHumidity NOTIFY hasHumidityChanged)
|
||||
Q_PROPERTY(bool hasTemperature READ hasTemperature NOTIFY hasTemperatureChanged)
|
||||
Q_PROPERTY(QString humidity READ humidity WRITE setHumidity NOTIFY humidityChanged)
|
||||
Q_PROPERTY(int id READ id WRITE setId NOTIFY idChanged)
|
||||
Q_PROPERTY(QDateTime lastUpdated READ lastUpdated WRITE setLastUpdated NOTIFY lastUpdatedChanged)
|
||||
Q_PROPERTY(QString model READ model WRITE setModel NOTIFY modelChanged)
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(QString protocol READ protocol WRITE setProtocol NOTIFY protocolChanged)
|
||||
Q_PROPERTY(QString temperature READ temperature WRITE setTemperature NOTIFY temperatureChanged)
|
||||
public:
|
||||
explicit Sensor(QObject *parent = 0);
|
||||
~Sensor();
|
||||
|
||||
QString humidity() const;
|
||||
void setHumidity(const QString &humidity);
|
||||
bool hasHumidity() const;
|
||||
|
||||
int id() const;
|
||||
void setId(int id);
|
||||
|
||||
QDateTime lastUpdated() const;
|
||||
void setLastUpdated(const QDateTime &lastUpdated);
|
||||
|
||||
QString model() const;
|
||||
void setModel(const QString &model);
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
QString protocol() const;
|
||||
void setProtocol(const QString &protocol);
|
||||
|
||||
QString temperature() const;
|
||||
void setTemperature(const QString &temperature);
|
||||
bool hasTemperature() const;
|
||||
|
||||
signals:
|
||||
void idChanged();
|
||||
void hasHumidityChanged();
|
||||
void hasTemperatureChanged();
|
||||
void humidityChanged();
|
||||
void lastUpdatedChanged();
|
||||
void modelChanged();
|
||||
void nameChanged();
|
||||
void protocolChanged();
|
||||
void temperatureChanged();
|
||||
|
||||
private:
|
||||
class PrivateData;
|
||||
PrivateData *d;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(Sensor*)
|
||||
|
||||
#endif // SENSOR_H
|
31
telldus-gui/Plugins/Sensors/sensorsplugin.cpp
Normal file
31
telldus-gui/Plugins/Sensors/sensorsplugin.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "sensorsplugin.h"
|
||||
#include "sensor.h"
|
||||
#include <QScriptEngine>
|
||||
|
||||
QScriptValue SensorCTor(QScriptContext *context, QScriptEngine *engine) {
|
||||
if (!context->isCalledAsConstructor()) {
|
||||
return engine->undefinedValue();
|
||||
}
|
||||
return engine->newQObject(new Sensor(), QScriptEngine::ScriptOwnership);
|
||||
}
|
||||
|
||||
SensorsPlugin::SensorsPlugin ( QObject * parent )
|
||||
:QScriptExtensionPlugin( parent )
|
||||
{
|
||||
}
|
||||
|
||||
SensorsPlugin::~SensorsPlugin() {
|
||||
}
|
||||
|
||||
void SensorsPlugin::initialize ( const QString & key, QScriptEngine * engine ) {
|
||||
if (key == "com.telldus.sensors") {
|
||||
QScriptValue qml = engine->globalObject().property("com").property("telldus").property("sensors");
|
||||
qml.setProperty("sensor", engine->newFunction(SensorCTor));
|
||||
}
|
||||
}
|
||||
|
||||
QStringList SensorsPlugin::keys () const {
|
||||
return QStringList() << "com.telldus.sensors";
|
||||
}
|
||||
|
||||
Q_EXPORT_PLUGIN2(SensorsInterface, SensorsPlugin)
|
16
telldus-gui/Plugins/Sensors/sensorsplugin.h
Normal file
16
telldus-gui/Plugins/Sensors/sensorsplugin.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef SENSORSPLUGIN_H
|
||||
#define SENSORSPLUGIN_H
|
||||
|
||||
#include <QScriptExtensionPlugin>
|
||||
|
||||
class SensorsPlugin : public QScriptExtensionPlugin {
|
||||
public:
|
||||
SensorsPlugin ( QObject * parent = 0 );
|
||||
~SensorsPlugin ();
|
||||
|
||||
virtual void initialize ( const QString & key, QScriptEngine * engine );
|
||||
virtual QStringList keys () const;
|
||||
};
|
||||
|
||||
|
||||
#endif // SENSORSPLUGIN_H
|
Loading…
Add table
Add a link
Reference in a new issue