tizen 5.0 update
[apps/native/illuminance-sensor.git] / src / capability / capability_illuminancemeasurement.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 #include <peripheral_io.h>
20 #include <stdint.h>
21
22 #include <stdlib.h>
23 #include <time.h>
24
25 static const char *PROP_ILLUMINANCE = "illuminance";
26
27 extern int resource_read_illuminance_sensor(uint16_t *out_value);
28
29 bool handle_get_request_on_resource_capability_illuminancemeasurement_main_0(smartthings_payload_h resp_payload, void *user_data)
30 {
31         int ret = PERIPHERAL_ERROR_NONE;
32         int error = SMARTTHINGS_RESOURCE_ERROR_NONE;
33         uint16_t sensor_data;
34
35         _D("Received a GET request for Sensor");
36
37         ret = resource_read_illuminance_sensor(&sensor_data);
38         if (ret != PERIPHERAL_ERROR_NONE) {
39                 _E("resource_read_illuminance_sensor() failed, [%d]", ret);
40                 return false;
41         }
42         error = smartthings_payload_set_int(resp_payload, PROP_ILLUMINANCE, (int)sensor_data);
43         if (error != SMARTTHINGS_RESOURCE_ERROR_NONE)
44                 _E("smartthings_payload_set_int() failed, [%d]", error);
45
46         return true;
47 }
48