From 914824c907822f61ac274bf977ab544e1b9a0dac Mon Sep 17 00:00:00 2001 From: Jin Yoon Date: Wed, 12 Jul 2017 20:03:23 +0900 Subject: [PATCH] Do not open functions for closing GPIO Change-Id: I98044ce96dfdde8273a585a4db11b0cc4798f6a8 --- inc/resource.h | 10 ++++++++ inc/resource/resource_illuminance_sensor.h | 1 - .../resource_illuminance_sensor_internal.h | 28 ++++++++++++++++++++++ inc/resource/resource_infrared_motion_sensor.h | 1 - .../resource_infrared_motion_sensor_internal.h | 27 +++++++++++++++++++++ .../resource_infrared_obstacle_avoidance_sensor.h | 1 - ...e_infrared_obstacle_avoidance_sensor_internal.h | 27 +++++++++++++++++++++ inc/resource/resource_touch_sensor.h | 1 - inc/resource/resource_touch_sensor_internal.h | 27 +++++++++++++++++++++ inc/resource/resource_ultrasonic_sensor.h | 1 - inc/resource/resource_ultrasonic_sensor_internal.h | 27 +++++++++++++++++++++ inc/resource_internal.h | 1 + src/controller.c | 4 +--- src/resource.c | 14 +++++++++++ src/resource/resource_illuminance_sensor.c | 2 +- src/resource/resource_infrared_motion_sensor.c | 3 ++- .../resource_infrared_obstacle_avoidance_sensor.c | 2 +- src/resource/resource_touch_sensor.c | 2 +- src/resource/resource_ultrasonic_sensor.c | 4 ++-- 19 files changed, 169 insertions(+), 14 deletions(-) create mode 100644 inc/resource/resource_illuminance_sensor_internal.h create mode 100644 inc/resource/resource_infrared_motion_sensor_internal.h create mode 100644 inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h create mode 100644 inc/resource/resource_touch_sensor_internal.h create mode 100644 inc/resource/resource_ultrasonic_sensor_internal.h diff --git a/inc/resource.h b/inc/resource.h index 89fc1c8..68986dc 100644 --- a/inc/resource.h +++ b/inc/resource.h @@ -25,10 +25,20 @@ #include #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__ */ diff --git a/inc/resource/resource_illuminance_sensor.h b/inc/resource/resource_illuminance_sensor.h index e95198b..44946a3 100644 --- a/inc/resource/resource_illuminance_sensor.h +++ b/inc/resource/resource_illuminance_sensor.h @@ -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 index 0000000..f5e83a9 --- /dev/null +++ b/inc/resource/resource_illuminance_sensor_internal.h @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * 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__ */ + diff --git a/inc/resource/resource_infrared_motion_sensor.h b/inc/resource/resource_infrared_motion_sensor.h index fa99633..f763158 100644 --- a/inc/resource/resource_infrared_motion_sensor.h +++ b/inc/resource/resource_infrared_motion_sensor.h @@ -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 index 0000000..56a31e8 --- /dev/null +++ b/inc/resource/resource_infrared_motion_sensor_internal.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * 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__ */ diff --git a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h index 3e6f420..fcd8c31 100644 --- a/inc/resource/resource_infrared_obstacle_avoidance_sensor.h +++ b/inc/resource/resource_infrared_obstacle_avoidance_sensor.h @@ -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 index 0000000..c638ca6 --- /dev/null +++ b/inc/resource/resource_infrared_obstacle_avoidance_sensor_internal.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * 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__ */ diff --git a/inc/resource/resource_touch_sensor.h b/inc/resource/resource_touch_sensor.h index e209a80..f7a5ea2 100644 --- a/inc/resource/resource_touch_sensor.h +++ b/inc/resource/resource_touch_sensor.h @@ -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 index 0000000..60578fd --- /dev/null +++ b/inc/resource/resource_touch_sensor_internal.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * 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__ */ diff --git a/inc/resource/resource_ultrasonic_sensor.h b/inc/resource/resource_ultrasonic_sensor.h index 29fdd00..76f5071 100644 --- a/inc/resource/resource_ultrasonic_sensor.h +++ b/inc/resource/resource_ultrasonic_sensor.h @@ -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 index 0000000..03558ba --- /dev/null +++ b/inc/resource/resource_ultrasonic_sensor_internal.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Contact: Jin Yoon + * Geunsun Lee + * Eunyoung Lee + * Junkyu Han + * + * 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__ */ diff --git a/inc/resource_internal.h b/inc/resource_internal.h index 1844db6..ae6746b 100644 --- a/inc/resource_internal.h +++ b/inc/resource_internal.h @@ -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__ */ diff --git a/src/controller.c b/src/controller.c index 69a040e..b84b259 100644 --- a/src/controller.c +++ b/src/controller.c @@ -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); } diff --git a/src/resource.c b/src/resource.c index 7d49961..a9764a8 100644 --- a/src/resource.c +++ b/src/resource.c @@ -20,6 +20,8 @@ */ #include + +#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(); +} diff --git a/src/resource/resource_illuminance_sensor.c b/src/resource/resource_illuminance_sensor.c index e5b5dda..01c69cb 100644 --- a/src/resource/resource_illuminance_sensor.c +++ b/src/resource/resource_illuminance_sensor.c @@ -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); diff --git a/src/resource/resource_infrared_motion_sensor.c b/src/resource/resource_infrared_motion_sensor.c index d8e86e3..40d9854 100644 --- a/src/resource/resource_infrared_motion_sensor.c +++ b/src/resource/resource_infrared_motion_sensor.c @@ -29,9 +29,10 @@ 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; } diff --git a/src/resource/resource_infrared_obstacle_avoidance_sensor.c b/src/resource/resource_infrared_obstacle_avoidance_sensor.c index f95d4ed..43e6f12 100644 --- a/src/resource/resource_infrared_obstacle_avoidance_sensor.c +++ b/src/resource/resource_infrared_obstacle_avoidance_sensor.c @@ -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); diff --git a/src/resource/resource_touch_sensor.c b/src/resource/resource_touch_sensor.c index a8ba4ba..eeeff58 100644 --- a/src/resource/resource_touch_sensor.c +++ b/src/resource/resource_touch_sensor.c @@ -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); diff --git a/src/resource/resource_ultrasonic_sensor.c b/src/resource/resource_ultrasonic_sensor.c index c397920..1dae292 100644 --- a/src/resource/resource_ultrasonic_sensor.c +++ b/src/resource/resource_ultrasonic_sensor.c @@ -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..."); -- 2.7.4