Do not open functions for closing GPIO 19/138519/1
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 89fc1c8ad6415b64fd2522b30ec3f0712590ff5a..68986dcca24231462b87720dd549da0e45bf7419 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 e95198bf5e412c1c3761e206bf5f39bc7883b425..44946a336b78ee361cc7bb820582cf13c9bbd91b 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 fa996338fcf18045bf28274ff0aecae2c24530f3..f76315886e73c26e8cc8b58cd6aefbd43330ae94 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 3e6f420c8717dba3dad8e5165ef8590a98c35ba0..fcd8c31d6c137ab2504ce2d2d6f87222d61d882a 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 e209a805e486233b60c29f1f8549f98e4f1f8ae3..f7a5ea26c8c056cce2443fc2298b636cade9bed1 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 29fdd009113c99d841865dfd6d97211ab36d1168..76f5071777a365f548beb1693d9d2eb1795a29d2 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 1844db6cdfce9d8eadbeee5686aaa0c235d2b07b..ae6746bba83cea15c026f0a2ea7bf5fd09397ab9 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 69a040e52e2ded69bad1f1a75a6b0954633c78f8..b84b259eb21d9c1ba6221f3608ea10dd8a3cbb9c 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 7d499614699da349d3c4b484a1b2675b85ffc640..a9764a85c1a02548f1f2d1ac286ce9e925dcd461 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 e5b5dda443a41cce99eec8841d3aaed60f86480a..01c69cb3f5738ae1bae059e934f06fea0a248346 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 d8e86e331f9c3d97a54ee9e7c1eeed8501d2a0e3..40d9854cdc44a18fd238dc2dfd3a89073bc117cd 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 f95d4ed13ab5ff27332ee9128b541d89bb8c8168..43e6f12a50f290a7f8bcf567c05124dc72723f58 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 a8ba4ba5390dc54765d052b3cfed35b9cc2f0314..eeeff581c1b544145c9bc6fc96acc7d6cf37dbd9 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 c39792079389499c3dce3845b58478ba756352e9..1dae2926a4bcc3dca380eb125d904ad1a9d86ec8 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...");