summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEunyoung Lee <ey928.lee@samsung.com>2017-08-23 14:35:01 +0900
committerEunyoung Lee <ey928.lee@samsung.com>2017-08-23 14:44:49 +0900
commitd673c0b292e334e7fc0dbe814f6c81940b4bbcda (patch)
treeac66fc12142a5b85d4a583c3650d4f420b74c20b
parenta107e25c9bb5e2a88943db4843c32a16c0c172a2 (diff)
downloadposition-finder-server-d673c0b292e334e7fc0dbe814f6c81940b4bbcda.tar.gz
position-finder-server-d673c0b292e334e7fc0dbe814f6c81940b4bbcda.tar.bz2
position-finder-server-d673c0b292e334e7fc0dbe814f6c81940b4bbcda.zip
Modified to use close function of each sensor when closing resource
Change-Id: I5eb994ac5c22823cdfef2e15c7741241e6ce36ba
-rw-r--r--inc/resource_internal.h1
-rw-r--r--src/resource.c7
-rw-r--r--src/resource/resource_infrared_motion_sensor.c1
-rw-r--r--src/resource/resource_infrared_obstacle_avoidance_sensor.c1
-rw-r--r--src/resource/resource_led.c1
-rw-r--r--src/resource/resource_touch_sensor.c1
-rw-r--r--src/resource/resource_ultrasonic_sensor.c18
7 files changed, 22 insertions, 8 deletions
diff --git a/inc/resource_internal.h b/inc/resource_internal.h
index 5ef6cce..4b06c0d 100644
--- a/inc/resource_internal.h
+++ b/inc/resource_internal.h
@@ -36,6 +36,7 @@
struct _resource_s {
int opened;
peripheral_gpio_h sensor_h;
+ void (*close) (int);
};
typedef struct _resource_s resource_s;
diff --git a/src/resource.c b/src/resource.c
index 5bb335f..2183850 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -24,7 +24,7 @@
#include "log.h"
#include "resource.h"
-static resource_s resource_info[PIN_MAX] = { 0, };
+static resource_s resource_info[PIN_MAX] = { {0, NULL, NULL}, };
resource_s *resource_get_info(int pin_num)
{
@@ -37,8 +37,9 @@ void resource_close_all(void)
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;
+
+ if (resource_info[i].close)
+ resource_info[i].close(i);
}
resource_close_illuminance_sensor();
}
diff --git a/src/resource/resource_infrared_motion_sensor.c b/src/resource/resource_infrared_motion_sensor.c
index 40308a3..6caaf9e 100644
--- a/src/resource/resource_infrared_motion_sensor.c
+++ b/src/resource/resource_infrared_motion_sensor.c
@@ -48,6 +48,7 @@ int resource_read_infrared_motion_sensor(int pin_num, int *out_value)
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_infrared_motion_sensor;
}
ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
diff --git a/src/resource/resource_infrared_obstacle_avoidance_sensor.c b/src/resource/resource_infrared_obstacle_avoidance_sensor.c
index bb57940..29ef463 100644
--- a/src/resource/resource_infrared_obstacle_avoidance_sensor.c
+++ b/src/resource/resource_infrared_obstacle_avoidance_sensor.c
@@ -48,6 +48,7 @@ int resource_read_infrared_obstacle_avoidance_sensor(int pin_num, int *out_value
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_infrared_obstacle_avoidance_sensor;
}
ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c
index aa5e170..136a9e9 100644
--- a/src/resource/resource_led.c
+++ b/src/resource/resource_led.c
@@ -47,6 +47,7 @@ int resource_write_led(int pin_num, int write_value)
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_led;
}
ret = peripheral_gpio_write(resource_get_info(pin_num)->sensor_h, write_value);
diff --git a/src/resource/resource_touch_sensor.c b/src/resource/resource_touch_sensor.c
index 2b75e62..07be4be 100644
--- a/src/resource/resource_touch_sensor.c
+++ b/src/resource/resource_touch_sensor.c
@@ -50,6 +50,7 @@ int resource_read_touch_sensor(int pin_num, int *out_value)
retv_if(ret != 0, -1);
resource_get_info(pin_num)->opened = 1;
+ resource_get_info(pin_num)->close = resource_close_touch_sensor;
}
ret = peripheral_gpio_read(resource_get_info(pin_num)->sensor_h, out_value);
diff --git a/src/resource/resource_ultrasonic_sensor.c b/src/resource/resource_ultrasonic_sensor.c
index 9b908e0..d749503 100644
--- a/src/resource/resource_ultrasonic_sensor.c
+++ b/src/resource/resource_ultrasonic_sensor.c
@@ -28,17 +28,23 @@
#include "log.h"
#include "resource_internal.h"
-void resource_close_ultrasonic_sensor(int trig_pin_num, int echo_pin_num)
+void resource_close_ultrasonic_sensor_trig(int trig_pin_num)
{
- if (!resource_get_info(echo_pin_num)->opened) return;
if (!resource_get_info(trig_pin_num)->opened) return;
- _I("Ultrasonic sensor is finishing...");
+ _I("Ultrasonic sensor's trig is finishing...");
peripheral_gpio_close(resource_get_info(trig_pin_num)->sensor_h);
- peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
-
resource_get_info(trig_pin_num)->opened = 0;
+}
+
+void resource_close_ultrasonic_sensor_echo(int echo_pin_num)
+{
+ if (!resource_get_info(echo_pin_num)->opened) return;
+
+ _I("Ultrasonic sensor's echo is finishing...");
+
+ peripheral_gpio_close(resource_get_info(echo_pin_num)->sensor_h);
resource_get_info(echo_pin_num)->opened = 0;
}
@@ -85,6 +91,7 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource
retv_if(ret != 0, -1);
resource_get_info(trig_pin_num)->opened = 1;
+ resource_get_info(trig_pin_num)->close = resource_close_ultrasonic_sensor_trig;
}
if (!resource_get_info(echo_pin_num)->opened) {
@@ -100,6 +107,7 @@ int resource_read_ultrasonic_sensor(int trig_pin_num, int echo_pin_num, resource
retv_if(ret != 0, -1);
resource_get_info(echo_pin_num)->opened = 1;
+ resource_get_info(echo_pin_num)->close = resource_close_ultrasonic_sensor_echo;
}
if (resource_get_info(echo_pin_num)->sensor_h) {