Initial version
[apps/native/rcc.git] / src / model.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.h"
25 #include "model/model_infrared_motion_sensor.h"
26 #include "model/model_infrared_obstacle_avoidance_sensor.h"
27
28 struct _model_s {
29         sensor_type_e sensor_type;
30 };
31 static struct _model_s model_s;
32
33 void model_fini(void)
34 {
35         switch (model_s.sensor_type) {
36         case SENSOR_TYPE_ULTRASONIC:
37                 break;
38         case SENSOR_TYPE_INFRARED_MOTION:
39                 model_fini_infrared_motion_sensor();
40                 break;
41         case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
42                 model_fini_infrared_obstacle_avoidance_sensor();
43                 break;
44         default:
45                 break;
46         }
47 }
48
49 int model_init(sensor_type_e sensor_type)
50 {
51         int ret = 0;
52         model_s.sensor_type = sensor_type;
53
54         switch (sensor_type) {
55         case SENSOR_TYPE_ULTRASONIC:
56                 break;
57         case SENSOR_TYPE_INFRARED_MOTION:
58                 ret = model_init_infrared_motion_sensor();
59                 break;
60         case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
61                 ret = model_init_infrared_obstacle_avoidance_sensor();
62                 break;
63         default:
64                 break;
65         }
66
67         goto_if(ret != 0, error);
68
69         return 0;
70
71 error:
72         model_fini();
73         return -1;
74 }
75
76 int model_alloc(void **data)
77 {
78         switch (model_s.sensor_type) {
79         case SENSOR_TYPE_ULTRASONIC:
80                 break;
81         case SENSOR_TYPE_INFRARED_MOTION:
82         case SENSOR_TYPE_INFRARED_OBSTACLE_AVOIDANCE:
83                 _E("No function for allocation");
84                 break;
85         default:
86                 break;
87         }
88
89         return 0;
90 }
91
92 int model_read_int_value(int *out_value)
93 {
94         int ret = 0;
95
96         switch (model_s.sensor_type) {
97         case SENSOR_TYPE_ULTRASONIC:
98                 ret = model_read_infrared_obstacle_avoidance_sensor(out_value);
99                 break;
100         case SENSOR_TYPE_INFRARED_MOTION:
101                 ret = model_read_infrared_motion_sensor(out_value);
102                 break;
103         default:
104                 break;
105         }
106
107         if (ret < 0) {
108                 _E("Something wrong in the result[%d]", ret);
109                 return -1;
110         }
111
112         return 0;
113 }
114
115 int model_write(void *data)
116 {
117         switch (model_s.sensor_type) {
118         case SENSOR_TYPE_ULTRASONIC:
119         case SENSOR_TYPE_INFRARED_MOTION:
120                 _E("No function for writing");
121                 break;
122         default:
123                 break;
124         }
125
126         return 0;
127 }