Commit b445d7ac authored by Langston Ball's avatar Langston Ball

ref #2794 - Motion sensor device creation.

parent 86b905a2
This diff is collapsed.
......@@ -20,14 +20,14 @@
#include "Gen_Devices/HueControllerBase.h"
//<-dceag-d-e->
#include <QObject>
#include <qjson/serializer.h>
#include <qjson/parser.h>
#include <QNetworkAccessManager>
#include <QVariant>
#include <QTimer>
#include <QUrl>
#include <huecontrollerhardware.h>
#include <huebulb.h>
#include <huemotionsensor.h>
#include <huedaynightsensor.h>
#include "../huecommand.h"
//<-dceag-decl-b->
......@@ -41,7 +41,9 @@ class HueController : public HueController_Command
public:
// Public member variables
QList<HueControllerHardware*> hueControllers;
QList<HueBulb*> hueBulbs;
QList<AbstractWirelessBulb*> hueBulbs;
QList<HueMotionSensor*> hueMotionSensors;
//<-dceag-const-b->
......@@ -59,7 +61,7 @@ public:
void initBridgeConnection();
bool findControllers();
void getScreenSaverColor();
bool setupController(int controllerIndex);
......@@ -202,8 +204,9 @@ public slots:
void processDataStore(const QByteArray data);
HueControllerHardware* getController(int index) {return hueControllers.at(index); }
void handleDeviceEvent(int whichEvent);
HueControllerHardware* getController(int index) {return hueControllers.at(index); }
void handleLightEvent(int whichEvent);
void handleMotionSensorEvent(DCE::Message * m);
private slots:
bool addMessageToQueue(QUrl msg, QVariant params);
......@@ -212,12 +215,11 @@ private slots:
bool downloadControllerConfig(QUrl deviceIp);
void updateDevice(AbstractWirelessBulb *b, int d);
void checkLightInformation();
void handleCheckLightInformation(QNetworkReply * reply);
private:
QNetworkAccessManager * linkButtonManager;
QNetworkAccessManager * commandManager;
QNetworkAccessManager * poller;
bool m_updateStatus;
bool mb_isNew;
......@@ -228,10 +230,18 @@ private:
QString authUser;
QTimer *mp_linkButtonTimer;
QTimer *mp_pollTimer;
QTimer *mp_cmdTimer;
QTimer *mp_lightRefreshTimer;
QTimer *mp_sensorRefreshTimer;
QTimer *mp_queueCommandTimer;
QList<HueCommand*> cmdQueue;
QHash <QString, HueMotionSensor* > motionSensorHash;
QNetworkAccessManager * linkButtonManager;
QNetworkAccessManager * commandManager;
QNetworkAccessManager * poller;
HueDayNightSensor * m_dayNightSensor;
static const char getGroups[]; /*!< Get all groups \note get */
static const char getAllLights[]; /*!< Get all lights \note get */
......
......@@ -43,7 +43,10 @@ SOURCES += ../Main.cpp \
huebulb.cpp \
../huecommand.cpp \
abstractwirelessbulb.cpp \
hueluxbulb.cpp
hueluxbulb.cpp \
huemotionsensor.cpp \
huedaynightsensor.cpp \
huetemperaturesensor.cpp
HEADERS += \
../../DCE/DeviceData_Base.h \
......@@ -64,4 +67,7 @@ HEADERS += \
huebulb.h \
../huecommand.h \
abstractwirelessbulb.h \
hueluxbulb.h
hueluxbulb.h \
huemotionsensor.h \
huedaynightsensor.h \
huetemperaturesensor.h
......@@ -12,11 +12,11 @@ AbstractWirelessBulb::AbstractWirelessBulb(HueControllerHardware *p_controller,
m_brightness(0),
m_room(-1)
{
qDebug() << Q_FUNC_INFO << "ctor";
if(mp_controller){
qDebug() << Q_FUNC_INFO << "contoller IP::" << mp_controller->getIpAddress();
//qDebug() << Q_FUNC_INFO << "contoller IP::" << mp_controller->getIpAddress();
} else {
qDebug() << Q_FUNC_INFO << "invalid controller!";
//qDebug() << Q_FUNC_INFO << "invalid controller!";
}
}
......@@ -168,6 +168,11 @@ void AbstractWirelessBulb::setController(HueControllerHardware *c)
{
mp_controller=c;
}
void AbstractWirelessBulb::proccessStateInformation(QVariantMap d)
{
Q_UNUSED(d);
}
int AbstractWirelessBulb::getRoom() const
{
return m_room;
......
......@@ -17,6 +17,7 @@ public:
enum BulbType{
PHILLIPS_HUE,
PHILLIPS_HUE_LUX,
PHILLIPS_HUE_WHITE,
PHILLIPS_HUE_LIGHTSTRIPS,
PHILLIPS_HUE_BLOOM,
CREE_WIRELESS_LED
......@@ -126,7 +127,7 @@ public slots:
HueControllerHardware * getController();
void setController(HueControllerHardware * c);
virtual void proccessStateInformation(QVariantMap d)=0;
virtual void proccessStateInformation(QVariantMap d);
virtual void resetColor() { setColor(QColor("#90C638")); }
......@@ -161,7 +162,7 @@ private:
HueControllerHardware *mp_controller;
QMap<QString, int> deviceMap;
QMap<QString, int> deviceMap;
};
......
#include "huedaynightsensor.h"
HueDayNightSensor::HueDayNightSensor(QObject *parent) : QObject(parent)
{
}
#ifndef HUEDAYNIGHTSENSOR_H
#define HUEDAYNIGHTSENSOR_H
#include <QObject>
class HueDayNightSensor : public QObject
{
Q_OBJECT
public:
explicit HueDayNightSensor(QObject *parent = 0);
signals:
public slots:
};
#endif // HUEDAYNIGHTSENSOR_H
\ No newline at end of file
#include "huemotionsensor.h"
#include "Message.h"
#include "pluto_main/Define_EventParameter.h"
#include "pluto_main/Define_Event.h"
#include "QVariantMap"
#include "Gen_Devices/AllCommandsRequests.h"
#include "huecontrollerhardware.h"
HueMotionSensor::HueMotionSensor(HueControllerHardware *p_controller, QObject *parent) :
QObject(parent), m_controller(p_controller)
{
}
QString HueMotionSensor::status() const
{
return m_status;
}
void HueMotionSensor::setStatus(const QString &status)
{
m_status = status;
}
QString HueMotionSensor::description() const
{
return m_description;
}
void HueMotionSensor::setDescription(const QString &description)
{
m_description = description;
}
QString HueMotionSensor::name() const
{
return m_name;
}
void HueMotionSensor::setName(const QString &name)
{
m_name = name;
}
QString HueMotionSensor::type() const
{
return m_type;
}
void HueMotionSensor::setType(const QString &type)
{
m_type = type;
}
QString HueMotionSensor::modelId() const
{
return m_modelId;
}
void HueMotionSensor::setModelId(const QString &modelId)
{
m_modelId = modelId;
}
QString HueMotionSensor::manufacturer() const
{
return m_manufacturer;
}
void HueMotionSensor::setManufacturer(const QString &manufacturer)
{
m_manufacturer = manufacturer;
}
QString HueMotionSensor::productId() const
{
return m_productId;
}
void HueMotionSensor::setProductId(const QString &productId)
{
m_productId = productId;
}
QString HueMotionSensor::uniqueId() const
{
return m_uniqueId;
}
void HueMotionSensor::setUniqueId(const QString &uniqueId)
{
m_uniqueId = uniqueId;
}
QString HueMotionSensor::swConfigId() const
{
return m_swConfigId;
}
void HueMotionSensor::setSwConfigId(const QString &swConfigId)
{
m_swConfigId = swConfigId;
}
bool HueMotionSensor::presenceDetected() const
{
return m_presenceDetected;
}
void HueMotionSensor::setPresenceDetected(bool presenceDetected)
{
m_presenceDetected = presenceDetected;
emit presenceDetectedChanged(m_presenceDetected);
DCE::Message * m = new DCE::Message(
linuxmceId(),
DEVICEID_EVENTMANAGER,
DCE::PRIORITY_NORMAL,
DCE::MESSAGETYPE_EVENT,
EVENT_Sensor_Tripped_CONST,
1,
EVENTPARAMETER_Tripped_CONST,
m_presenceDetected ? "1" : "0"
);
emit notifyEvent(m);
}
bool HueMotionSensor::enabled() const
{
return m_enabled;
}
void HueMotionSensor::setEnabled(bool enabled)
{
m_enabled = enabled;
}
int HueMotionSensor::batteryLevel() const
{
return m_batteryLevel;
}
void HueMotionSensor::setBatteryLevel(int batteryLevel)
{
m_batteryLevel = batteryLevel;
emit batteryLevelChanged(m_batteryLevel);
}
QString HueMotionSensor::alert() const
{
return m_alert;
}
void HueMotionSensor::setAlert(const QString &alert)
{
m_alert = alert;
}
bool HueMotionSensor::reachable() const
{
return m_reachable;
}
void HueMotionSensor::setReachable(bool reachable)
{
m_reachable = reachable;
}
int HueMotionSensor::sensitivity() const
{
return m_sensitivity;
}
void HueMotionSensor::setSensitivity(int sensitivity)
{
m_sensitivity = sensitivity;
}
QString HueMotionSensor::lastUpdated() const
{
return m_lastUpdated;
}
void HueMotionSensor::setLastUpdated(const QString &lastUpdated)
{
m_lastUpdated = lastUpdated;
}
void HueMotionSensor::setTempSensor(int id, QVariantMap obj)
{
tempSensor.setId(id);
tempSensor.setTemp(obj.value("state").toMap().value("temperature").toInt());
}
void HueMotionSensor::setLightSensor(int id, QVariantMap obj)
{
lightSensor.setId(id);
lightSensor.setDark(obj.value("state").toMap().value("dark").toBool());
lightSensor.setDaylight(obj.value("state").toMap().value("daylight").toBool());
lightSensor.setLightLevel(obj.value("state").toMap().value("lightlevel").toInt());
lightSensor.setDarkThreshold(obj.value("config").toMap().value("tholddark").toInt());
lightSensor.setThresholdOffset(obj.value("config").toMap().value("tholdoffset").toInt());
}
HueControllerHardware *HueMotionSensor::controller() const
{
return m_controller;
}
void HueMotionSensor::setController(HueControllerHardware *controller)
{
m_controller = controller;
}
int HueMotionSensor::hueId() const
{
return m_hueId;
}
void HueMotionSensor::setHueId(int hueId)
{
m_hueId = hueId;
}
int HueMotionSensor::linuxmceId() const
{
return m_linuxmceId;
}
void HueMotionSensor::setLinuxmceId(int linuxmceId)
{
m_linuxmceId = linuxmceId;
}
int ZLLTemp::temp() const
{
return m_temp;
}
void ZLLTemp::setTemp(int temp)
{
m_temp = ( (temp*.01) * 9.0) / 5.0 + 32;
}
int ZLLTemp::id() const
{
return m_id;
}
void ZLLTemp::setId(int id)
{
m_id = id;
}
int ZLLLightLevel::id() const
{
return m_id;
}
void ZLLLightLevel::setId(int id)
{
m_id = id;
}
int ZLLLightLevel::darkThreshold() const
{
return m_darkThreshold;
}
void ZLLLightLevel::setDarkThreshold(long darkThreshold)
{
m_darkThreshold = darkThreshold;
}
int ZLLLightLevel::thresholdOffset() const
{
return m_thresholdOffset;
}
void ZLLLightLevel::setThresholdOffset(long thresholdOffset)
{
m_thresholdOffset = thresholdOffset;
}
int ZLLLightLevel::lightLevel() const
{
return m_lightLevel;
}
void ZLLLightLevel::setLightLevel(long lightLevel)
{
m_lightLevel = lightLevel;
}
bool ZLLLightLevel::dark() const
{
return m_dark;
}
void ZLLLightLevel::setDark(bool dark)
{
m_dark = dark;
}
bool ZLLLightLevel::daylight() const
{
return m_daylight;
}
void ZLLLightLevel::setDaylight(bool daylight)
{
m_daylight = daylight;
}
#ifndef HUEMOTIONSENSOR_H
#define HUEMOTIONSENSOR_H
#include <QObject>
#include <QVariantMap>
class HueControllerHardware;
namespace DCE {
class Message;
}
class ZLLTemp: public QObject{
Q_OBJECT
public:
ZLLTemp(){}
~ZLLTemp(){}
int temp() const;
void setTemp(int temp);
int id() const;
void setId(int id);
private:
int m_temp;
int m_id;
};
class ZLLLightLevel: public QObject{
Q_OBJECT
public:
ZLLLightLevel(){}
~ZLLLightLevel(){}
int id() const;
void setId(int id);
int darkThreshold() const;
void setDarkThreshold(long darkThreshold);
int thresholdOffset() const;
void setThresholdOffset(long thresholdOffset);
int lightLevel() const;
void setLightLevel(long lightLevel);
bool dark() const;
void setDark(bool dark);
bool daylight() const;
void setDaylight(bool daylight);
private:
int m_id;
int m_darkThreshold;
int m_thresholdOffset;
int m_lightLevel;
bool m_dark;
bool m_daylight;
};
class HueMotionSensor : public QObject
{
Q_OBJECT
public:
explicit HueMotionSensor(HueControllerHardware *p_controller, QObject * parent=0);
int hueId() const;
void setHueId(int hueId);
HueControllerHardware *controller() const;
void setController(HueControllerHardware *controller);
signals:
void batteryLevelChanged(int batteryLevel);
void enabledChanged(bool enabled);
void presenceDetectedChanged(bool presenceDetected);
void notifyEvent(DCE::Message * m);
public slots:
int linuxmceId() const;
void setLinuxmceId(int linuxmceId);
QString status() const;
void setStatus(const QString &status);
QString description() const;
void setDescription(const QString &description);
QString name() const;
void setName(const QString &name);
QString type() const;
void setType(const QString &type);
QString modelId() const;
void setModelId(const QString &modelId);
QString manufacturer() const;
void setManufacturer(const QString &manufacturer);
QString productId() const;
void setProductId(const QString &productId);
QString uniqueId() const;
void setUniqueId(const QString &uniqueId);
QString swConfigId() const;
void setSwConfigId(const QString &swConfigId);
bool presenceDetected() const;
void setPresenceDetected(bool presenceDetected);
bool enabled() const;
void setEnabled(bool enabled);
int batteryLevel() const;
void setBatteryLevel(int batteryLevel);
QString alert() const;
void setAlert(const QString &alert);
bool reachable() const;
void setReachable(bool reachable);
int sensitivity() const;
void setSensitivity(int sensitivity);
QString lastUpdated() const;
void setLastUpdated(const QString &lastUpdated);
void setTempSensor(int id, QVariantMap obj);
void setLightSensor(int id, QVariantMap obj);
protected:
QString m_status;
QString m_description;
QString m_name;
QString m_type;
QString m_modelId;
QString m_manufacturer;
QString m_productId;
QString m_uniqueId;
QString m_swConfigId;
bool m_presenceDetected;
bool m_enabled;
int m_batteryLevel;
QString m_alert;
bool m_reachable;
int m_sensitivity;
int m_sensitivityMax;
QString m_lastUpdated;
int m_linuxmceId;
int m_hueId;
ZLLLightLevel lightSensor;
ZLLTemp tempSensor;
HueControllerHardware * m_controller;
};
#endif // HUEMOTIONSENSOR_H
#include "huetemperaturesensor.h"
HueTemperatureSensor::HueTemperatureSensor(QObject *parent) : QObject(parent)
{
}
int HueTemperatureSensor::getMi_temp() const
{
return mi_temp;
}
void HueTemperatureSensor::setMi_temp(int value)
{
mi_temp = value;
}
#ifndef HUETEMPERATURESENSOR_H
#define HUETEMPERATURESENSOR_H
#include <QObject>
class HueTemperatureSensor : public QObject
{
Q_OBJECT
public:
explicit HueTemperatureSensor(QObject *parent = 0);
int getMi_temp() const;
void setMi_temp(int value);
signals:
public slots:
private:
int mi_temp;
};
#endif // HUETEMPERATURESENSOR_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment