tizen 5.0 migration
[apps/native/co2-meter.git] / src / capability / capability_airqualitysensor.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "smartthings_resource.h"
18 #include "log.h"
19
20 static const char *PROP_AIRQUALITY = "airQuality";
21 static const char *PROP_RANGE = "range";
22 static double g_range[2] = { 0, 10000. };
23 static size_t g_length = 2;
24 int32_t g_co2_sensor_value = 400;
25
26 extern int resource_update_co2_sensor_value(void);
27
28 bool handle_get_request_on_resource_capability_airqualitysensor_main_0(smartthings_payload_h resp_payload, void *user_data)
29 {
30         int error = SMARTTHINGS_RESOURCE_ERROR_NONE;
31
32         g_co2_sensor_value = resource_update_co2_sensor_value();
33         error = smartthings_payload_set_int(resp_payload, PROP_AIRQUALITY, g_co2_sensor_value);
34         if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
35                 _E("smartthings_payload_set_int() failed, [%d]", error);
36                 return false;
37         }
38
39         error = smartthings_payload_set_double_array(resp_payload, PROP_RANGE, (double*)&g_range, g_length);
40         if (error != SMARTTHINGS_RESOURCE_ERROR_NONE) {
41                 _E("smartthings_payload_set_double_array() failed, [%d]", error);
42                 return false;
43         }
44
45         return true;
46 }