summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorboyeon-son <bson1012@gmail.com>2018-08-17 13:17:52 +0900
committerboyeon-son <bson1012@gmail.com>2018-08-17 13:17:52 +0900
commit86eedfff9a40b6ea127af3deb91ca645c14048f4 (patch)
treece3da72d7e4cb1a1563ee0a30303f1b69e6d7f1d
parent4e5e22d770b089034ef32cc0b9b1ba886a575b78 (diff)
downloadrcc-86eedfff9a40b6ea127af3deb91ca645c14048f4.tar.gz
rcc-86eedfff9a40b6ea127af3deb91ca645c14048f4.tar.bz2
rcc-86eedfff9a40b6ea127af3deb91ca645c14048f4.zip
Change the close functions for resource
-rw-r--r--basic-final/src/controller.c4
-rw-r--r--basic-final/src/resource/resource_infrared_motion_sensor.c26
-rw-r--r--basic-final/src/resource/resource_led.c26
-rw-r--r--basic-init/src/resource/resource_infrared_motion_sensor.c26
-rw-r--r--basic-init/src/resource/resource_led.c26
-rw-r--r--smartthings-final/src/controller.c4
-rw-r--r--smartthings-final/src/resource/resource_infrared_motion_sensor.c26
-rw-r--r--smartthings-final/src/resource/resource_led.c27
-rw-r--r--smartthings-init/src/resource/resource_infrared_motion_sensor.c26
-rw-r--r--smartthings-init/src/resource/resource_led.c27
10 files changed, 148 insertions, 70 deletions
diff --git a/basic-final/src/controller.c b/basic-final/src/controller.c
index c59a597..b8bc134 100644
--- a/basic-final/src/controller.c
+++ b/basic-final/src/controller.c
@@ -83,8 +83,8 @@ static void service_app_terminate(void *data)
ecore_timer_del(ad->getter_timer);
// TODO: Close infrared motion & led resources
- resource_close_infrared_motion_sensor(46);
- resource_close_led(130);
+ resource_close_infrared_motion_sensor();
+ resource_close_led();
// TODO: Free data resource
free(ad);
diff --git a/basic-final/src/resource/resource_infrared_motion_sensor.c b/basic-final/src/resource/resource_infrared_motion_sensor.c
index a17230a..d5a2dd1 100644
--- a/basic-final/src/resource/resource_infrared_motion_sensor.c
+++ b/basic-final/src/resource/resource_infrared_motion_sensor.c
@@ -23,22 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_infrared_motion_sensor(int pin_num)
+void resource_close_infrared_motion_sensor(void)
{
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("Infrared Motion Sensor is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -51,10 +55,16 @@ int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_read(sensor_h, out_value);
+ ret = peripheral_gpio_read(g_sensor_h, out_value);
retv_if(ret < 0, -1);
return 0;
diff --git a/basic-final/src/resource/resource_led.c b/basic-final/src/resource/resource_led.c
index 5b325b5..ba3e4a1 100644
--- a/basic-final/src/resource/resource_led.c
+++ b/basic-final/src/resource/resource_led.c
@@ -23,22 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_led(int pin_num)
+void resource_close_led(void)
{
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("LED is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_write_led(int pin_num, int write_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -51,10 +55,16 @@ int resource_write_led(int pin_num, int write_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_write(sensor_h, write_value);
+ ret = peripheral_gpio_write(g_sensor_h, write_value);
retv_if(ret < 0, -1);
_I("LED Value : %s", write_value ? "ON":"OFF");
diff --git a/basic-init/src/resource/resource_infrared_motion_sensor.c b/basic-init/src/resource/resource_infrared_motion_sensor.c
index a17230a..d5a2dd1 100644
--- a/basic-init/src/resource/resource_infrared_motion_sensor.c
+++ b/basic-init/src/resource/resource_infrared_motion_sensor.c
@@ -23,22 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_infrared_motion_sensor(int pin_num)
+void resource_close_infrared_motion_sensor(void)
{
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("Infrared Motion Sensor is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -51,10 +55,16 @@ int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_read(sensor_h, out_value);
+ ret = peripheral_gpio_read(g_sensor_h, out_value);
retv_if(ret < 0, -1);
return 0;
diff --git a/basic-init/src/resource/resource_led.c b/basic-init/src/resource/resource_led.c
index 5b325b5..ba3e4a1 100644
--- a/basic-init/src/resource/resource_led.c
+++ b/basic-init/src/resource/resource_led.c
@@ -23,22 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_led(int pin_num)
+void resource_close_led(void)
{
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("LED is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_write_led(int pin_num, int write_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -51,10 +55,16 @@ int resource_write_led(int pin_num, int write_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_write(sensor_h, write_value);
+ ret = peripheral_gpio_write(g_sensor_h, write_value);
retv_if(ret < 0, -1);
_I("LED Value : %s", write_value ? "ON":"OFF");
diff --git a/smartthings-final/src/controller.c b/smartthings-final/src/controller.c
index 143080d..fe3f282 100644
--- a/smartthings-final/src/controller.c
+++ b/smartthings-final/src/controller.c
@@ -329,8 +329,8 @@ static void service_app_terminate(void *user_data)
sensor_data_free(ad->led_data);
// TODO: Close Motion and LED resources
- resource_close_infrared_motion_sensor(46);
- resource_close_led(130);
+ resource_close_infrared_motion_sensor();
+ resource_close_led();
// TODO: Free app data
free(ad);
diff --git a/smartthings-final/src/resource/resource_infrared_motion_sensor.c b/smartthings-final/src/resource/resource_infrared_motion_sensor.c
index a17230a..d5a2dd1 100644
--- a/smartthings-final/src/resource/resource_infrared_motion_sensor.c
+++ b/smartthings-final/src/resource/resource_infrared_motion_sensor.c
@@ -23,22 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_infrared_motion_sensor(int pin_num)
+void resource_close_infrared_motion_sensor(void)
{
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("Infrared Motion Sensor is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -51,10 +55,16 @@ int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_read(sensor_h, out_value);
+ ret = peripheral_gpio_read(g_sensor_h, out_value);
retv_if(ret < 0, -1);
return 0;
diff --git a/smartthings-final/src/resource/resource_led.c b/smartthings-final/src/resource/resource_led.c
index e0e39be..ba3e4a1 100644
--- a/smartthings-final/src/resource/resource_led.c
+++ b/smartthings-final/src/resource/resource_led.c
@@ -23,23 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_led(int pin_num)
+void resource_close_led(void)
{
-
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("LED is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_write_led(int pin_num, int write_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -52,10 +55,16 @@ int resource_write_led(int pin_num, int write_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_write(sensor_h, write_value);
+ ret = peripheral_gpio_write(g_sensor_h, write_value);
retv_if(ret < 0, -1);
_I("LED Value : %s", write_value ? "ON":"OFF");
diff --git a/smartthings-init/src/resource/resource_infrared_motion_sensor.c b/smartthings-init/src/resource/resource_infrared_motion_sensor.c
index a17230a..d5a2dd1 100644
--- a/smartthings-init/src/resource/resource_infrared_motion_sensor.c
+++ b/smartthings-init/src/resource/resource_infrared_motion_sensor.c
@@ -23,22 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_infrared_motion_sensor(int pin_num)
+void resource_close_infrared_motion_sensor(void)
{
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("Infrared Motion Sensor is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -51,10 +55,16 @@ int resource_read_infrared_motion_sensor(int pin_num, uint32_t *out_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_read(sensor_h, out_value);
+ ret = peripheral_gpio_read(g_sensor_h, out_value);
retv_if(ret < 0, -1);
return 0;
diff --git a/smartthings-init/src/resource/resource_led.c b/smartthings-init/src/resource/resource_led.c
index e0e39be..ba3e4a1 100644
--- a/smartthings-init/src/resource/resource_led.c
+++ b/smartthings-init/src/resource/resource_led.c
@@ -23,23 +23,26 @@
#include "log.h"
-static peripheral_gpio_h sensor_h = NULL;
+static peripheral_gpio_h g_sensor_h = NULL;
+static int g_pin_num = -1;
-void resource_close_led(int pin_num)
+void resource_close_led(void)
{
-
- if (!sensor_h) return;
+ if (!g_sensor_h) return;
_I("LED is finishing...");
- peripheral_gpio_close(sensor_h);
- sensor_h = NULL;
+
+ peripheral_gpio_close(g_sensor_h);
+
+ g_sensor_h = NULL;
+ g_pin_num = -1;
}
int resource_write_led(int pin_num, int write_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!sensor_h) {
+ if (!g_sensor_h) {
peripheral_gpio_h temp = NULL;
ret = peripheral_gpio_open(pin_num, &temp);
@@ -52,10 +55,16 @@ int resource_write_led(int pin_num, int write_value)
return -1;
}
- sensor_h = temp;
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+ }
+
+ if (g_pin_num != pin_num) {
+ _E("Invalid pin number.");
+ return -1;
}
- ret = peripheral_gpio_write(sensor_h, write_value);
+ ret = peripheral_gpio_write(g_sensor_h, write_value);
retv_if(ret < 0, -1);
_I("LED Value : %s", write_value ? "ON":"OFF");