Do not open functions for closing GPIO
authorJin Yoon <jinny.yoon@samsung.com>
Wed, 12 Jul 2017 11:03:23 +0000 (20:03 +0900)
committerJin Yoon <jinny.yoon@samsung.com>
Wed, 12 Jul 2017 11:03:23 +0000 (20:03 +0900)
Change-Id: I98044ce96dfdde8273a585a4db11b0cc4798f6a8

19 files changed:
inc/resource.h
inc/resource/resource_illuminance_sensor.h
inc/resource/resource_illuminance_sensor_internal.h [new file with mode: 0644]
inc/resource/resource_infrared_motion_sensor.h
inc/resource/resource_infrared_motion_sensor_internal.h [new file with mode: 0644]
inc/resource/resource_infrared_obstacle_avoidance_sensor.h
inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h [new file with mode: 0644]
inc/resource/resource_touch_sensor.h
inc/resource/resource_touch_sensor_internal.h [new file with mode: 0644]
inc/resource/resource_ultrasonic_sensor.h
inc/resource/resource_ultrasonic_sensor_internal.h [new file with mode: 0644]
inc/resource_internal.h
src/controller.c
src/resource.c
src/resource/resource_illuminance_sensor.c
src/resource/resource_infrared_motion_sensor.c
src/resource/resource_infrared_obstacle_avoidance_sensor.c
src/resource/resource_touch_sensor.c
src/resource/resource_ultrasonic_sensor.c

index 89fc1c8..68986dc 100644 (file)
 #include <peripheral_io.h>
 
 #include "resource_internal.h"
+
 #include "resource/resource_illuminance_sensor.h"
+#include "resource/resource_illuminance_sensor_internal.h"
+
 #include "resource/resource_infrared_motion_sensor.h"
+#include "resource/resource_infrared_motion_sensor_internal.h"
+
 #include "resource/resource_infrared_obstacle_avoidance_sensor.h"
+#include "resource/resource_infrared_obstacle_avoidance_sensor_internal.h"
+
 #include "resource/resource_touch_sensor.h"
+#include "resource/resource_touch_sensor_internal.h"
+
 #include "resource/resource_ultrasonic_sensor.h"
+#include "resource/resource_ultrasonic_sensor_internal.h"
 
 #endif /* __POSITION_FINDER_RESOURCE_H__ */
index e95198b..44946a3 100644 (file)
@@ -24,7 +24,6 @@
 
 /* You have to use this illuminance sensor ONLY ONE in the pi board */
 extern int resource_read_illuminance_sensor(int i2c_bus, int *out_value);
-extern void resource_close_illuminance_sensor(void);
 
 #endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_H__ */
 
diff --git a/inc/resource/resource_illuminance_sensor_internal.h b/inc/resource/resource_illuminance_sensor_internal.h
new file mode 100644 (file)
index 0000000..f5e83a9
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__
+
+extern void resource_close_illuminance_sensor(void);
+
+#endif /* __POSITION_FINDER_RESOURCE_ILLUMINANCE_SENSOR_INTERNAL_H__ */
+
index fa99633..f763158 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__
 #define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__
 
-extern void resource_close_infrared_motion_sensor(int sensor_index);
 extern int resource_read_infrared_motion_sensor(int pin_num, int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_H__ */
diff --git a/inc/resource/resource_infrared_motion_sensor_internal.h b/inc/resource/resource_infrared_motion_sensor_internal.h
new file mode 100644 (file)
index 0000000..56a31e8
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__
+
+extern void resource_close_infrared_motion_sensor(int sensor_index);
+
+#endif /* __POSITION_FINDER_RESOURCE_INFRARED_MOTION_SENSOR_INTERNAL_H__ */
index 3e6f420..fcd8c31 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
 #define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__
 
-extern void resource_close_infrared_obstacle_avoidance_sensor(int pin_num);
 extern int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_H__ */
diff --git a/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h b/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h
new file mode 100644 (file)
index 0000000..c638ca6
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__
+
+extern void resource_close_infrared_obstacle_avoidance_sensor(int pin_num);
+
+#endif /* __POSITION_FINDER_RESOURCE_INFRARED_OBSTACLE_AVOIDANCE_SENSOR_INTERNAL_H__ */
index e209a80..f7a5ea2 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__
 #define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__
 
-extern void resource_close_touch_sensor(int pin_num);
 extern int resource_read_touch_sensor(int pin_num, int *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_H__ */
diff --git a/inc/resource/resource_touch_sensor_internal.h b/inc/resource/resource_touch_sensor_internal.h
new file mode 100644 (file)
index 0000000..60578fd
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__
+
+extern void resource_close_touch_sensor(int pin_num);
+
+#endif /* __POSITION_FINDER_RESOURCE_TOUCH_SENSOR_INTERNAL_H__ */
index 29fdd00..76f5071 100644 (file)
@@ -22,7 +22,6 @@
 #ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__
 #define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__
 
-extern void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num);
 extern int resource_read_ultrasonic_sensor(int echo_pin_num, int trig_pin_num, double *out_value);
 
 #endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_H__ */
diff --git a/inc/resource/resource_ultrasonic_sensor_internal.h b/inc/resource/resource_ultrasonic_sensor_internal.h
new file mode 100644 (file)
index 0000000..03558ba
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Jin Yoon <jinny.yoon@samsung.com>
+ *          Geunsun Lee <gs86.lee@samsung.com>
+ *          Eunyoung Lee <ey928.lee@samsung.com>
+ *          Junkyu Han <junkyu.han@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__
+#define __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__
+
+extern void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num);
+
+#endif /* __POSITION_FINDER_RESOURCE_ULTRASONIC_SENSOR_INTERNAL_H__ */
index 1844db6..ae6746b 100644 (file)
@@ -33,5 +33,6 @@ struct _resource_s {
 typedef struct _resource_s resource_s;
 
 extern resource_s *resource_get_info(int pin_num);
+extern void resource_close_all(void);
 
 #endif /* __POSITION_FINDER_RESOURCE_INTERNAL_H__ */
index 69a040e..b84b259 100644 (file)
@@ -108,9 +108,7 @@ static void service_app_terminate(void *data)
                        ecore_timer_del(ad->getter_timer[i]);
                }
        }
-       resource_close_infrared_motion_sensor(GPIO_INFRARED_MOTION_NUM_1);
-       resource_close_ultrasonic_sensor(GPIO_ULTRASONIC_TRIG_NUM_1, GPIO_ULTRASONIC_ECHO_NUM_1);
-       resource_close_illuminance_sensor();
+       resource_close_all();
        free(ad);
 }
 
index 7d49961..a9764a8 100644 (file)
@@ -20,6 +20,8 @@
  */
 
 #include <peripheral_io.h>
+
+#include "log.h"
 #include "resource.h"
 
 static resource_s resource_info[PIN_MAX] = { 0, };
@@ -28,3 +30,15 @@ resource_s *resource_get_info(int pin_num)
 {
        return &resource_info[pin_num];
 }
+
+void resource_close_all(void)
+{
+       int i = 0;
+       for (i = 0; i < PIN_MAX; i++) {
+               if (!resource_info[i].opened) continue;
+               _I("GPIO[%d] is closing...", i);
+               peripheral_gpio_close(resource_info[i].sensor_h);
+               resource_info[i].opened = 0;
+       }
+       resource_close_illuminance_sensor();
+}
index e5b5dda..01c69cb 100644 (file)
@@ -40,7 +40,7 @@ static struct {
 
 void resource_close_illuminance_sensor(void)
 {
-       ret_if(!resource_sensor_s.opened);
+       if (!resource_sensor_s.opened) return;
 
        _I("Infrared Motion Sensor is finishing...");
        peripheral_i2c_close(resource_sensor_s.sensor_h);
index d8e86e3..40d9854 100644 (file)
 
 void resource_close_infrared_motion_sensor(int pin_num)
 {
-       ret_if(!resource_get_info(pin_num)->opened);
+       if (!resource_get_info(pin_num)->opened) return;
 
        _I("Infrared Motion Sensor is finishing...");
+       peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
        resource_get_info(pin_num)->opened = 0;
 }
 
index f95d4ed..43e6f12 100644 (file)
@@ -29,7 +29,7 @@
 
 void resource_close_infrared_obstacle_avoidance_sensor(int pin_num)
 {
-       ret_if(!resource_get_info(pin_num)->opened);
+       if (!resource_get_info(pin_num)->opened) return;
 
        _I("Infrared Obstacle Avoidance Sensor is finishing...");
        peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
index a8ba4ba..eeeff58 100644 (file)
@@ -29,7 +29,7 @@
 
 void resource_close_touch_sensor(int pin_num)
 {
-       ret_if(!resource_get_info(pin_num)->opened);
+       if (!resource_get_info(pin_num)->opened) return;
 
        _I("Touch Sensor is finishing...");
        peripheral_gpio_close(resource_get_info(pin_num)->sensor_h);
index c397920..1dae292 100644 (file)
@@ -29,8 +29,8 @@
 
 void resource_close_ultrasonic_sensor(int echo_pin_num, int trig_pin_num)
 {
-       ret_if(!resource_get_info(echo_pin_num)->opened);
-       ret_if(!resource_get_info(trig_pin_num)->opened);
+       if (!resource_get_info(echo_pin_num)->opened) return;
+       if (!resource_get_info(trig_pin_num)->opened) return;
 
        _I("Ultrasonic sensor is finishing...");