Commit 5ce4342a authored by Langston Ball's avatar Langston Ball

ref #2794 - Delete unused classes, fix bug with updating some bulbs.

parent 99cee425
......@@ -34,7 +34,6 @@ using namespace DCE;
#include <QJsonDocument>
#include <QStringList>
#include <huecontrollerhardware.h>
#include <huebulb.h>
#include <pthread.h>
#include <QtGui/QColor>
#include <math.h>
......@@ -514,9 +513,12 @@ void HueController::CreateChildren()
for (int n = 0; n < hueBulbs.size(); n++){
if(hueBulbs.at(n)->getController()->getIpAddress() == p.at(0)&& hueBulbs.at(n)->id()==deviceID ){
QVariantMap mapping =QJsonDocument::fromBinaryData(QString::fromStdString(pDeviceData_Impl_Child->mapParameters_Find(DEVICEDATA_UnitNo_CONST)).toLocal8Bit()).object().toVariantMap();
hueBulbs.at(n)->setColorMap(mapping.value("color").toMap());
hueBulbs.at(n)->setLinuxmceId(linuxmceID);
hueBulbs.at(n)->setBrightness(0);
hueBulbs.at(n)->setPowerOn(false);
hueBulbs.at(n)->setDeviceTemplate(pDeviceData_Impl_Child->m_dwPK_DeviceTemplate );
qDebug() << "Linked existing light with linuxmce db. " << hueBulbs.at(n)->displayName();
}
}
......@@ -1389,11 +1391,16 @@ void HueController::checkLightInformation()
void HueController::handleCheckLightInformation(QNetworkReply *reply)
{
QVariantMap p = QJsonDocument::fromBinaryData(reply->readAll()).object().toVariantMap();
QByteArray rep = reply->readAll();
QVariantMap p = QJsonDocument::fromJson(rep).object().toVariantMap();
if(p.isEmpty()){
qDebug() << " Empty Reply !" ;
}
foreach(AbstractWirelessBulb*b, hueBulbs){
b->proccessStateInformation(p.value(QString::number(b->id())).toMap());
// qDebug() << Q_FUNC_INFO << " light " << b->displayName();
if(m_updateStatus){
......@@ -1535,16 +1542,19 @@ void HueController::handleLightEvent(int whichEvent)
this->m_pEvent->SendMessage(st);
}
}
void HueController::handleMotionSensorEvent(Message *m)
{
qDebug() << Q_FUNC_INFO;
{
this->m_pEvent->SendMessage(m);
}
void HueController::handleLightMessage(Message *m)
{
this->m_pEvent->SendMessage(m);
}
void HueController::getScreenSaverColor()
{
// char *pData="";
......
......@@ -24,8 +24,8 @@
#include <QVariant>
#include <QTimer>
#include <QUrl>
#include "abstractwirelessbulb.h"
#include <huecontrollerhardware.h>
#include <huebulb.h>
#include <huemotionsensor.h>
#include <huedaynightsensor.h>
#include "../huecommand.h"
......@@ -207,6 +207,7 @@ public slots:
HueControllerHardware* getController(int index) {return hueControllers.at(index); }
void handleLightEvent(int whichEvent);
void handleMotionSensorEvent(DCE::Message * m);
void handleLightMessage(DCE::Message * m);
private slots:
bool addMessageToQueue(QUrl msg, QVariant params);
......
......@@ -40,13 +40,10 @@ SOURCES += ../Main.cpp \
../../Gen_Devices/HueControllerBase.cpp \
../HueController.cpp \
huecontrollerhardware.cpp \
huebulb.cpp \
../huecommand.cpp \
abstractwirelessbulb.cpp \
hueluxbulb.cpp \
huemotionsensor.cpp \
huedaynightsensor.cpp \
huetemperaturesensor.cpp
huedaynightsensor.cpp
HEADERS += \
../../DCE/DeviceData_Base.h \
......@@ -64,10 +61,7 @@ HEADERS += \
../../Gen_Devices/HueControllerBase.h \
../HueController.h \
huecontrollerhardware.h \
huebulb.h \
../huecommand.h \
abstractwirelessbulb.h \
hueluxbulb.h \
huemotionsensor.h \
huedaynightsensor.h \
huetemperaturesensor.h
huedaynightsensor.h
......@@ -3,6 +3,10 @@
#include "Message.h"
#include "pluto_main/Define_EventParameter.h"
#include "pluto_main/Define_Event.h"
#include "Gen_Devices/AllCommandsRequests.h"
#include "QJsonDocument"
#include "QJsonObject"
#include <math.h>
AbstractWirelessBulb::AbstractWirelessBulb(HueControllerHardware *p_controller, QObject *parent) :
QObject(parent),
......@@ -10,8 +14,13 @@ AbstractWirelessBulb::AbstractWirelessBulb(HueControllerHardware *p_controller,
m_CurrentLevel(0.0),
m_powerOn(false),
m_brightness(0),
m_room(-1)
m_room(-1),
m_implementsColor(false),
m_implementsColorTemp(false)
{
conversionVar = ceil(65280 / 360);
m_rgbColor.setRgb(0,0,0);
m_hslColor = m_rgbColor.toHsl();
if(mp_controller){
//qDebug() << Q_FUNC_INFO << "contoller IP::" << mp_controller->getIpAddress();
......@@ -101,8 +110,7 @@ void AbstractWirelessBulb::setPowerOn(bool powerOn)
return;
if(stateChanged){
emit dceMessage(EVENT_Device_OnOff_CONST);
qDebug() << QString("%1 Light Changed, sending event").arg(displayName());
emit dceMessage(EVENT_Device_OnOff_CONST);
}
......@@ -171,7 +179,107 @@ void AbstractWirelessBulb::setController(HueControllerHardware *c)
void AbstractWirelessBulb::proccessStateInformation(QVariantMap d)
{
Q_UNUSED(d);
QVariantMap stateInfo = d["state"].toMap();
setDisplayName(d["name"].toString());
setOnline(stateInfo["reachable"].toBool());
setPowerOn(stateInfo["on"].toBool());
setSoftwareVersion(d["swversion"].toString());
setLightModel(d["modelid"].toString());
setLightType(d["type"].toString());
setAlert(stateInfo["alert"].toString());
setEffect(stateInfo["effect"].toString());
setCurrentLevel(stateInfo["bri"].toUInt()/2.55);
switch (m_deviceTemplate) {
case DEVICETEMPLATE_Hue_Lightbulb_CONST :
setCurrentColor(stateInfo);
break;
case DEVICETEMPLATE_Hue_Light_Strips_CONST :
setCurrentColor(stateInfo);
setCurrentLevel(stateInfo["bri"].toUInt()/2.55);
break;
case DEVICETEMPLATE_Hue_Lux_Bulb_CONST :
setCurrentColor(stateInfo);
setCurrentLevel(stateInfo["bri"].toUInt()/2.55);
break;
case DEVICETEMPLATE_Connected_A19_60w_Equivalent_CONST :
setBrightness(stateInfo["bri"].toDouble());
break;
default:
break;
}
}
int AbstractWirelessBulb::getCurrentColorTemp() const
{
return currentColorTemp;
}
void AbstractWirelessBulb::setCurrentColorTemp(int value)
{
currentColorTemp = value;
}
bool AbstractWirelessBulb::getImplementsColorTemp() const
{
return m_implementsColorTemp;
}
void AbstractWirelessBulb::setImplementsColorTemp(bool implementsColorTemp)
{
m_implementsColorTemp = implementsColorTemp;
}
bool AbstractWirelessBulb::getImplementsColor() const
{
return m_implementsColor;
}
void AbstractWirelessBulb::setImplementsColor(bool implementsColor)
{
m_implementsColor = implementsColor;
}
QVariantMap AbstractWirelessBulb::getCurrentColor() const
{
return currentColor;
}
void AbstractWirelessBulb::setCurrentColor(const QVariantMap &value)
{
m_hslColor = QColor::fromHsl( int(value["hue"].toInt() / conversionVar), value["sat"].toInt(), value["bri"].toInt() );
m_rgbColor = m_hslColor.toRgb();
currentColorTemp = value["ct"].toInt();
QVariantMap out;
out.insert("red", QVariant::fromValue(m_rgbColor.red()));
out.insert("blue", m_rgbColor.blue());
out.insert("green", m_rgbColor.blue());
}
long AbstractWirelessBulb::getDeviceTemplate() const
{
return m_deviceTemplate;
}
void AbstractWirelessBulb::setDeviceTemplate(long deviceTemplate)
{
m_deviceTemplate = deviceTemplate;
switch (m_deviceTemplate) {
case DEVICETEMPLATE_Hue_Lightbulb_CONST :
case DEVICETEMPLATE_Hue_Light_Strips_CONST :
setImplementsColor(true);
setImplementsColorTemp(true);
break;
case DEVICETEMPLATE_Hue_Lux_Bulb_CONST :
setImplementsColorTemp(true);
break;
default:
break;
}
}
int AbstractWirelessBulb::getRoom() const
{
......@@ -198,14 +306,20 @@ void AbstractWirelessBulb::setLightType(const QString &lightType)
emit lightTypeChanged();
}
QVariant AbstractWirelessBulb::getColorMap() const
QVariantMap AbstractWirelessBulb::getColorMap() const
{
return m_colorMap;
QVariantMap ret;
ret.insert("defaultColor", defaultColor);
ret.insert("alertColor", alertColor);
ret.insert("currentColor", currentColor);
return ret;
}
void AbstractWirelessBulb::setColorMap(const QVariant &colorMap)
void AbstractWirelessBulb::setColorMap(const QVariantMap &colorMap)
{
m_colorMap = colorMap;
defaultColor = colorMap.value("defaultColor").toMap();
alertColor = colorMap.value("alertColor").toMap();
}
quint8 AbstractWirelessBulb::getBrightness() const
......@@ -228,21 +342,6 @@ void AbstractWirelessBulb::setBrightness(const quint8 &brightness)
emit dceMessage(EVENT_State_Changed_CONST);
}
int AbstractWirelessBulb::getBlueLevel() const
{
return m_blueLevel;
}
int AbstractWirelessBulb::getGreenLevel() const
{
return m_greenLevel;
}
int AbstractWirelessBulb::getRedLevel() const
{
return m_redLevel;
}
QString AbstractWirelessBulb::uniqueId() const
{
return m_uniqueId;
......@@ -256,25 +355,9 @@ void AbstractWirelessBulb::setUniqueId(const QString &uniqueId)
void AbstractWirelessBulb::setRgb(int r, int g, int b)
{
bool changed=false;
if(m_redLevel!=r) {
m_redLevel=r;
changed=true;
}
if(m_greenLevel!=g){
m_greenLevel = g;
changed=true;
}
m_rgbColor = QColor::fromRgb(r,g,b);
emit rgbColorChanged();
if(m_blueLevel!=b){
m_blueLevel=b;
changed=true;
}
if(changed){
emit rgbColorChanged();
}
}
QString AbstractWirelessBulb::manufacturerName() const
......
......@@ -5,6 +5,7 @@
#include <qcolor.h>
#include <qmap.h>
#include "huecontrollerhardware.h"
#include "Gen_Devices/AllCommandsRequests.h"
#include <QVariantMap>
#include <Message.h>
......@@ -92,8 +93,8 @@ public:
quint8 getBrightness() const;
void setBrightness(const quint8 &brightness);
QVariant getColorMap() const;
void setColorMap(const QVariant &colorMap);
QVariantMap getColorMap() const;
void setColorMap(const QVariantMap &colorMap);
QString getLightType() const;
void setLightType(const QString &lightType);
......@@ -101,6 +102,21 @@ public:
int getRoom() const;
void setRoom(int room);
long getDeviceTemplate() const;
void setDeviceTemplate(long deviceTemplate);
QVariantMap getCurrentColor() const;
void setCurrentColor(const QVariantMap &value);
bool getImplementsColor() const;
void setImplementsColor(bool implementsColor);
bool getImplementsColorTemp() const;
void setImplementsColorTemp(bool implementsColorTemp);
int getCurrentColorTemp() const;
void setCurrentColorTemp(int value);
signals:
void serialNumberChanged();
void displayNameChanged();
......@@ -122,6 +138,7 @@ signals:
void lightTypeChanged();
void roomChanged();
void dceMessage(int t);
void dataEvent(DCE::PreformedCommand *cmd );
public slots:
HueControllerHardware * getController();
......@@ -151,19 +168,30 @@ private:
QString m_effect;
QString m_alert;
bool m_online;
int m_redLevel;
int m_greenLevel;
int m_blueLevel;
int m_room;
int m_currentColorTemp;
QColor m_rgbColor;
QColor m_hslColor;
long m_deviceTemplate;
bool m_implementsColor;
bool m_implementsColorTemp;
int currentColorTemp;
QString m_lightType;
QVariant m_colorMap;
QVariantMap currentColor;
QVariantMap alertColor;
QVariantMap defaultColor;
HueControllerHardware *mp_controller;
QMap<QString, int> deviceMap;
double conversionVar;
};
#endif // ABSTRACTWIRELESSBULB_H
#include "huebulb.h"
#include <QDebug>
#include <QVariant>
HueBulb::HueBulb(HueControllerHardware *hw): resetColor("#90C638")
{
setController(hw);
}
void HueBulb::proccessStateInformation(QVariantMap d)
{
// qDebug() << Q_FUNC_INFO << QString("Device %1").arg(linuxmceId());
// qDebug() << d["name"];
QVariantMap stateInfo = d["state"].toMap();
setDisplayName(d["name"].toString());
setOnline(stateInfo["reachable"].toBool());
setPowerOn(stateInfo["on"].toBool());
setSoftwareVersion(d["swversion"].toString());
setLightModel(d["modelid"].toString());
setLightType(d["type"].toString());
if(powerOn()){
setBrightness(stateInfo["bri"].toDouble());
setCurrentLevel(stateInfo["bri"].toUInt()/2.55);
setAlert(stateInfo["alert"].toString());
setEffect(stateInfo["effect"].toString());
}
// qDebug() << "\n\r";
}
#ifndef HUEBULB_H
#define HUEBULB_H
//On bool On/Off state of the light. On=true, Off=false
//Bri uint8 Brightness of the light. This is a scale from the minimum brightness the light is capable of, 0, to the maximum capable brightness, 255. Note a brightness of 0 is not off.
//Hue uint16w Hue of the light. This is a wrapping value between 0 and 65535. Both 0 and 65535 are red, 25500 is green and 46920 is blue.
//sat uint8 Saturation of the light. 255 is the most saturated (colored) and 0 is the least saturated (white).
//xy list 2..2 of float 4 The x and y coordinates of a color in CIE color space.
//The first entry is the x coordinate and the second entry is the y coordinate. Both x and y are between 0 and 1.
//ct uint16 The Mired Color temperature of the light. 2012 connected lights are capable of 153 (6500K) to 500 (2000K).
//alert string The alert effect, which is a temporary change to the bulb’s state. This can take one of the following values:
//“none” – The light is not performing an alert effect.
//“select” – The light is performing one breathe cycle.
//“lselect” – The light is performing breathe cycles for 30 seconds or until an "alert": "none" command is received.
//Note that in version 1.0 this contains the last alert sent to the light and not its current state. This will be changed to contain the current state in an upcoming patch.
//effect string The dynamic effect of the light, can either be “none” or “colorloop”.
//If set to colorloop, the light will cycle through all hues using the current brightness and saturation settings.
//colormode string 2, 2 Indicates the color mode in which the light is working, this is the last command type it received. Values are “hs” for Hue and Saturation, “xy” for XY and “ct” for Color Temperature. This parameter is only present when the light supports at least one of the values.
//reachable bool Indicates if a light can be reached by the bridge. Currently always returns true, functionality will be added in a future patch.
#include <QObject>
#include <QMap>
#include <abstractwirelessbulb.h>
class QVariant;
class HueBulb : public AbstractWirelessBulb
{
Q_OBJECT
public:
explicit HueBulb(HueControllerHardware *hw);
HueBulb(){}
QString resetColor;
signals:
public slots:
void proccessStateInformation(QVariantMap d);
};
#endif // HUEBULB_H
#include "hueluxbulb.h"
#include <QDebug>
#include <QVariant>
HueLuxBulb::HueLuxBulb(HueControllerHardware *hw)
{
setController(hw);
setBrightness(0);
}
void HueLuxBulb::proccessStateInformation(QVariantMap d)
{
QVariantMap stateInfo = d["state"].toMap();
setDisplayName(d["name"].toString());
setBrightness(stateInfo["bri"].toDouble());
setCurrentLevel(stateInfo["bri"].toUInt()/2.55);
setOnline(stateInfo["reachable"].toBool());
setPowerOn(stateInfo["on"].toBool());
setAlert(stateInfo["alert"].toString());
setEffect(stateInfo["effect"].toString());
setSoftwareVersion(d["swversion"].toString());
setLightModel(d["modelid"].toString());
setLightType(d["type"].toString());
}
#ifndef HUELUXBULB_H
#define HUELUXBULB_H
#include <QObject>
#include <QMap>
#include "abstractwirelessbulb.h"
class QVariant;
class HueLuxBulb : public AbstractWirelessBulb
{
Q_OBJECT
public:
explicit HueLuxBulb(HueControllerHardware *hw);
HueLuxBulb(){}
signals:
public slots:
void proccessStateInformation(QVariantMap d);
};
#endif // HUELUXBULB_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