8fc83798acf5cd2682f80fa68bc79e873dcd1ea0
[platform/upstream/iotivity.git] / service / resource-manipulation / src / resourceContainer / examples / HueSampleBundle / src / HueLight.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include "HueLight.h"
22
23 #include <iostream>
24
25 using namespace OIC::Service;
26
27 HueLight::HueLight(){
28
29 }
30
31 HueLight::HueLight(HueConnector* connector, std::string address){
32     m_address = address;
33     m_connector = connector;
34     initAttributes();
35 }
36
37 HueLight::~HueLight(){
38
39 }
40
41 string HueLight::getAttribute(string attributeName){
42
43 }
44
45 void HueLight::initAttributes(){
46     BundleResource::setAttribute("on-off", "false");
47     BundleResource::setAttribute("dim", "0");
48     BundleResource::setAttribute("color", "0");
49     /*m_mapAttributes.insert(std::pair<string, string>("on-off", "false"));
50     m_mapAttributes.insert(std::pair<string, string>("dim", "0"));
51     m_mapAttributes.insert(std::pair<string, string>("color", "0"));*/
52 }
53
54 void HueLight::setAttribute(string attributeName, string value){
55     cout << "HueLight::setAttribute setting " << attributeName << " to " << value << std::endl;
56
57
58     if(attributeName == "on-off"){
59         m_connector->transmit(this->m_address + "/state", "{\"on\":" + value + "}");
60     }
61
62     if(attributeName == "dim"){
63         //m_connector->transmit(this->m_address + "/state", "{\"bri\":" + (value * 2.5) + "}");
64         m_connector->transmit(this->m_address + "/state", "{\"bri\":" + value + "}");
65     }
66
67     if(attributeName == "color"){
68         //m_connector->transmit(this->m_address+ "/state", "{\"hue\":" + (value * 650)  + "}");
69         m_connector->transmit(this->m_address+ "/state", "{\"hue\":" + value   + "}");
70     }
71 }
72