tizen 5.0 migration
[apps/native/blind-motor.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 <stdint.h>
20
21 static const char *PROP_ILLUMINANCE = "illuminance";
22
23 extern uint16_t get_sensor_value(void);
24 extern void set_auto_motor_driving(uint16_t lux_value);
25
26 bool handle_get_request_on_resource_capability_illuminancemeasurement_main_0(smartthings_payload_h resp_payload, void *user_data)
27 {
28         uint16_t sensor_value = 0;
29         int error = SMARTTHINGS_RESOURCE_ERROR_NONE;
30
31         //DBG("Received a GET request on %s\n", req_msg->resource_uri);
32
33         // get illuminance sensor value
34         sensor_value = get_sensor_value();
35         set_auto_motor_driving(sensor_value);
36
37         // set sensor value
38         error = smartthings_payload_set_int(resp_payload, PROP_ILLUMINANCE, sensor_value);
39         if (error != SMARTTHINGS_RESOURCE_ERROR_NONE)
40                 _E("smartthings_payload_set_int() failed, [%d]", error);
41
42         return true;
43 }
44