2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "smartthings_resource.h"
20 static const char* PROP_TEMPERATURE = "temperature";
21 static const char* PROP_RANGE = "range";
22 static const char* PROP_UNITS = "units";
24 static double g_temperature = 0;
25 static double g_range[2] = { 0, 5000. };
26 static size_t g_length = 2;
27 static char g_unit[4] = "mV";
29 extern void resource_init_co2_sensor(void);
30 extern int resource_get_co2_sensor_parameter(void);
31 extern void resource_set_sensor_parameter(int zero_volts);
33 bool handle_get_request_on_resource_capability_thermostatcoolingsetpoint_main_0(smartthings_payload_h resp_payload, void *user_data)
35 int error = SMARTTHINGS_RESOURCE_ERROR_NONE;
37 if (0 == g_temperature) {
38 g_temperature = (double)resource_get_co2_sensor_parameter();
39 error = smartthings_payload_set_double(resp_payload, PROP_TEMPERATURE, g_temperature);
40 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
41 _E("smartthings_payload_set_double() failed, [%d]", error);
46 error = smartthings_payload_set_double_array(resp_payload, PROP_RANGE, (double*)&g_range, g_length);
47 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
48 _E("smartthings_payload_set_double_array() failed, [%d]", error);
52 error = smartthings_payload_set_string(resp_payload, PROP_UNITS, g_unit);
53 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
54 _E("smartthings_payload_set_string() failed, [%d]", error);
61 bool handle_set_request_on_resource_capability_thermostatcoolingsetpoint_main_0(smartthings_payload_h payload, smartthings_payload_h resp_payload, void *user_data)
63 int error = SMARTTHINGS_RESOURCE_ERROR_NONE;
66 error = smartthings_payload_get_double(payload, PROP_TEMPERATURE, &dvalue);
67 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
68 _E("smartthings_payload_get_double() failed, [%d]", error);
71 g_temperature = dvalue;
72 resource_set_sensor_parameter((int32_t)g_temperature);
73 resource_init_co2_sensor();
75 error = smartthings_payload_set_double(resp_payload, PROP_TEMPERATURE, dvalue);
76 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
77 _E("smartthings_payload_set_double() failed, [%d]", error);
81 char *str_value = NULL;
82 error = smartthings_payload_get_string(payload, PROP_UNITS, &str_value);
83 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
84 _E("smartthings_payload_get_string() failed, [%d]", error);
88 error = smartthings_payload_set_string(resp_payload, PROP_UNITS, g_unit);
89 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
90 _E("smartthings_payload_set_string() failed, [%d]", error);
96 double davalue[2] = { 0, };
98 error = smartthings_payload_get_double_array(payload, PROP_RANGE, (double**)&davalue, &dlength);
99 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
100 _E("smartthings_payload_get_double_array() failed, [%d]", error);
104 error = smartthings_payload_set_double_array(resp_payload, PROP_RANGE, g_range, g_length);
105 if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
106 _E("smartthings_payload_set_double_array() failed, [%d]", error);