2fb11adffc79fba71d18edee6c31e2689ead783d
[apps/native/rcc.git] / src / model / model_touch_sensor.c
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Jin Yoon <jinny.yoon@samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <unistd.h>
20 #include <peripheral_io.h>
21 #include <sys/time.h>
22
23 #include "log.h"
24 #include "model/model_touch_sensor.h"
25
26 #define GPIO_NUM 4
27
28 struct model_touch_sensor {
29         peripheral_gpio_h gpio;
30 };
31 static struct model_touch_sensor model_touch_sensor_s;
32
33 void model_fini_touch_sensor(void)
34 {
35         _I("Touch Sensor is finishing...");
36
37         if (model_touch_sensor_s.gpio)
38                 peripheral_gpio_close(model_touch_sensor_s.gpio);
39 }
40
41 int model_init_touch_sensor(void)
42 {
43         int ret = 0;
44
45         _I("Touch is initializing...");
46
47         /* GPIO for Ultrasonic Sensor's Transmit */
48         ret = peripheral_gpio_open(GPIO_NUM, &model_touch_sensor_s.gpio);
49         retv_if(ret != 0, -1);
50         retv_if(!model_touch_sensor_s.gpio, -1);
51
52         ret = peripheral_gpio_set_direction(model_touch_sensor_s.gpio, PERIPHERAL_GPIO_DIRECTION_IN);
53         goto_if(ret != 0, error);
54
55         return 0;
56
57 error:
58         model_fini_touch_sensor();
59         return -1;
60 }
61
62 int model_read_touch_sensor(int *out_value)
63 {
64         int ret = 0;
65
66         ret = peripheral_gpio_read(model_touch_sensor_s.gpio, out_value);
67         retv_if(ret < 0, -1);
68
69         _I("Touch Sensor Value : %d", *out_value);
70
71         return 0;
72 }