2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Contact: Jin Yoon <jinny.yoon@samsung.com>
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <peripheral_io.h>
25 #include "model/model_ultrasonic_sensor.h"
26 #include "model/model_infrared_motion_sensor.h"
27 #include "model/model_infrared_obstacle_avoidance_sensor.h"
28 #include "model/model_touch_sensor.h"
31 sensor_type_e sensor_type;
33 static struct _model_s model_s;
37 switch (model_s.sensor_type) {
38 case SENSOR_TYPE_ULTRASONIC:
39 model_fini_ultrasonic_sensor();
41 case SENSOR_TYPE_INFRARED_MOTION:
42 model_fini_infrared_motion_sensor();
44 case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
45 model_fini_infrared_obstacle_avoidance_sensor();
47 case SENSOR_TYPE_TOUCH:
48 model_fini_touch_sensor();
55 int model_init(sensor_type_e sensor_type)
58 model_s.sensor_type = sensor_type;
60 switch (sensor_type) {
61 case SENSOR_TYPE_ULTRASONIC:
62 ret = model_init_ultrasonic_sensor();
64 case SENSOR_TYPE_INFRARED_MOTION:
65 ret = model_init_infrared_motion_sensor();
67 case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
68 ret = model_init_infrared_obstacle_avoidance_sensor();
70 case SENSOR_TYPE_TOUCH:
71 model_init_touch_sensor();
77 goto_if(ret != 0, error);
86 int model_alloc(void **data)
88 switch (model_s.sensor_type) {
89 case SENSOR_TYPE_ULTRASONIC:
91 case SENSOR_TYPE_INFRARED_MOTION:
92 case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
93 case SENSOR_TYPE_TOUCH:
94 _E("No function for allocation");
103 int model_read_int_value(int *out_value)
107 switch (model_s.sensor_type) {
108 case SENSOR_TYPE_ULTRASONIC:
109 ret = model_read_infrared_obstacle_avoidance_sensor(out_value);
111 case SENSOR_TYPE_INFRARED_MOTION:
112 ret = model_read_infrared_motion_sensor(out_value);
114 case SENSOR_TYPE_TOUCH:
115 ret = model_read_touch_sensor(out_value);
122 _E("Something wrong in the result[%d]", ret);
129 int model_read_double_value(double *out_value)
133 switch (model_s.sensor_type) {
134 case SENSOR_TYPE_ULTRASONIC:
135 ret = model_read_ultrasonic_sensor(out_value);
138 _E("There is no data to retrieve");
143 _E("Something wrong in the result[%d]", ret);
150 int model_write(void *data)
152 switch (model_s.sensor_type) {
153 case SENSOR_TYPE_ULTRASONIC:
154 case SENSOR_TYPE_INFRARED_MOTION:
155 case SENSOR_TYPE_TOUCH:
156 _E("No function for writing");