summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoyeon <boyeon.son@samsung.com>2019-08-23 20:18:01 +0900
committerBoyeon <boyeon.son@samsung.com>2019-08-23 20:18:01 +0900
commit71be3d8daf587a2a5221dcda7d16227577bd8578 (patch)
treebd1596446510f6018abd9ac0b258c104d4d70971
parent167afb497c6ab6109c00ac87bb5cce0c8f42138c (diff)
downloadst-things-light-71be3d8daf587a2a5221dcda7d16227577bd8578.tar.gz
st-things-light-71be3d8daf587a2a5221dcda7d16227577bd8578.tar.bz2
st-things-light-71be3d8daf587a2a5221dcda7d16227577bd8578.zip
Change resouce_led
Change-Id: Ia1d97170510ccfc14f6d898d4236a19d4e0a478f
-rwxr-xr-xinc/resource/resource_infrared_motion.h8
-rwxr-xr-xinc/resource/resource_led.h6
-rwxr-xr-xsrc/resource/resource_infrared_motion.c32
-rwxr-xr-xsrc/resource/resource_led.c60
-rw-r--r--tizen-manifest.xml2
5 files changed, 71 insertions, 37 deletions
diff --git a/inc/resource/resource_infrared_motion.h b/inc/resource/resource_infrared_motion.h
index 993a973..60565a7 100755
--- a/inc/resource/resource_infrared_motion.h
+++ b/inc/resource/resource_infrared_motion.h
@@ -18,10 +18,10 @@
#define __RESOURCE_INFRARED_MOTION_H__
typedef enum {
- PERIPHERAL_HANDLE_ERROR_NONE = 0, /**< Successful */
- PERIPHERAL_HANDLE_ERROR_NOT_OPEN,
- PERIPHERAL_HANDLE_ERROR_INVALID_PIN
-} peripheral_handle_error_e;
+ MOTION_HANDLE_ERROR_NONE = 0, /**< Successful */
+ MOTION_HANDLE_ERROR_NOT_OPEN,
+ MOTION_HANDLE_ERROR_INVALID_PIN
+} resource_infrared_motion_handle_error_e;
typedef void (*resource_infrared_motion_interrupted_cb) (uint32_t motion_value, void *user_data);
diff --git a/inc/resource/resource_led.h b/inc/resource/resource_led.h
index 4adf22f..2a49a34 100755
--- a/inc/resource/resource_led.h
+++ b/inc/resource/resource_led.h
@@ -17,6 +17,12 @@
#ifndef __RESOURCE_LED_H__
#define __RESOURCE_LED_H__
+typedef enum {
+ LED_HANDLE_ERROR_NONE = 0, /**< Successful */
+ LED_HANDLE_ERROR_NOT_OPEN,
+ LED_HANDLE_ERROR_INVALID_PIN
+} resource_led_handle_error_e;
+
/**
* @brief Writes value of gpio connected led light
* @param[in] pin_num The gpio pin number for the led light
diff --git a/src/resource/resource_infrared_motion.c b/src/resource/resource_infrared_motion.c
index 2879221..650494a 100755
--- a/src/resource/resource_infrared_motion.c
+++ b/src/resource/resource_infrared_motion.c
@@ -26,13 +26,13 @@ static resource_infrared_motion_interrupted_data *g_interrupted_data = NULL;
int _resource_validate_infrared_motion(int pin_num)
{
- int ret = PERIPHERAL_HANDLE_ERROR_NONE;
+ int ret = MOTION_HANDLE_ERROR_NONE;
if (!g_sensor_h)
{
- ret = PERIPHERAL_HANDLE_ERROR_NOT_OPEN;
+ ret = MOTION_HANDLE_ERROR_NOT_OPEN;
} else if (g_pin_num != pin_num) {
- ret = PERIPHERAL_HANDLE_ERROR_INVALID_PIN;
+ ret = MOTION_HANDLE_ERROR_INVALID_PIN;
}
return ret;
@@ -66,10 +66,11 @@ int resource_read_infrared_motion(int pin_num, uint32_t *out_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (_resource_validate_infrared_motion(pin_num) == PERIPHERAL_HANDLE_ERROR_NOT_OPEN) {
- resource_open_infrared_motion(pin_num);
+ if (_resource_validate_infrared_motion(pin_num) == MOTION_HANDLE_ERROR_NOT_OPEN) {
+ ret = resource_open_infrared_motion(pin_num);
+ retv_if(ret < 0, -1);
}
- if (_resource_validate_infrared_motion(pin_num) == PERIPHERAL_HANDLE_ERROR_INVALID_PIN) {
+ if (_resource_validate_infrared_motion(pin_num) == MOTION_HANDLE_ERROR_INVALID_PIN) {
_E("Invalid pin number.");
return -1;
}
@@ -98,13 +99,13 @@ void resource_close_infrared_motion(void)
void _resoucre_motion_interrupted_cb (peripheral_gpio_h gpio, peripheral_error_e error, void *user_data)
{
+ int ret = PERIPHERAL_ERROR_NONE;
+
if (!g_sensor_h) return;
if (g_interrupted_data->is_called_first_time) {
- error = peripheral_gpio_read(g_sensor_h, &g_interrupted_data->motion_value);
- if (error) {
- return;
- }
+ ret = peripheral_gpio_read(g_sensor_h, &g_interrupted_data->motion_value);
+ if (ret) return;
g_interrupted_data->is_called_first_time = 0;
} else {
@@ -122,10 +123,11 @@ int resource_set_interrupted_cb_infrared_motion(int pin_num, resource_infrared_m
g_interrupted_data = calloc(1, sizeof(resource_infrared_motion_interrupted_data));
}
- if (_resource_validate_infrared_motion(pin_num) == PERIPHERAL_HANDLE_ERROR_NOT_OPEN) {
- resource_open_infrared_motion(pin_num);
+ if (_resource_validate_infrared_motion(pin_num) == MOTION_HANDLE_ERROR_NOT_OPEN) {
+ ret = resource_open_infrared_motion(pin_num);
+ retv_if(ret < 0, -1);
}
- if (_resource_validate_infrared_motion(pin_num) == PERIPHERAL_HANDLE_ERROR_INVALID_PIN) {
+ if (_resource_validate_infrared_motion(pin_num) == MOTION_HANDLE_ERROR_INVALID_PIN) {
_E("Invalid pin number.");
return -1;
}
@@ -153,11 +155,11 @@ int resource_unset_interrupted_cb_infrared_motion(int pin_num)
g_interrupted_data = NULL;
}
- if (_resource_validate_infrared_motion(pin_num) == PERIPHERAL_HANDLE_ERROR_NOT_OPEN) {
+ if (_resource_validate_infrared_motion(pin_num) == MOTION_HANDLE_ERROR_NOT_OPEN) {
_E("No open handle.");
return -1;
}
- else if (_resource_validate_infrared_motion(pin_num) == PERIPHERAL_HANDLE_ERROR_INVALID_PIN) {
+ else if (_resource_validate_infrared_motion(pin_num) == MOTION_HANDLE_ERROR_INVALID_PIN) {
_E("Invalid pin number.");
return -1;
}
diff --git a/src/resource/resource_led.c b/src/resource/resource_led.c
index 242cf73..53bc8a5 100755
--- a/src/resource/resource_led.c
+++ b/src/resource/resource_led.c
@@ -16,11 +16,50 @@
#include <peripheral_io.h>
+#include "resource/resource_led.h"
#include "log.h"
static peripheral_gpio_h g_sensor_h = NULL;
static int g_pin_num = -1;
+int _resource_validate_led(int pin_num)
+{
+ int ret = LED_HANDLE_ERROR_NONE;
+
+ if (!g_sensor_h)
+ {
+ ret = LED_HANDLE_ERROR_NOT_OPEN;
+ } else if (g_pin_num != pin_num) {
+ ret = LED_HANDLE_ERROR_INVALID_PIN;
+ }
+
+ return ret;
+}
+
+int resource_open_led(int pin_num)
+{
+ peripheral_gpio_h temp = NULL;
+
+ int ret = peripheral_gpio_open(pin_num, &temp);
+ if (ret) {
+ peripheral_gpio_close(temp);
+ _E("peripheral_gpio_open failed.");
+ return -1;
+ }
+
+ ret = peripheral_gpio_set_direction(temp, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
+ if (ret) {
+ peripheral_gpio_close(temp);
+ _E("peripheral_gpio_set_direction failed.");
+ return -1;
+ }
+
+ g_sensor_h = temp;
+ g_pin_num = pin_num;
+
+ return 0;
+}
+
void resource_close_led(void)
{
if (!g_sensor_h) return;
@@ -37,24 +76,11 @@ int resource_write_led(int pin_num, int write_value)
{
int ret = PERIPHERAL_ERROR_NONE;
- if (!g_sensor_h) {
- peripheral_gpio_h temp = NULL;
-
- ret = peripheral_gpio_open(pin_num, &temp);
- retv_if(ret, -1);
-
- ret = peripheral_gpio_set_direction(temp, PERIPHERAL_GPIO_DIRECTION_OUT_INITIALLY_LOW);
- if (ret) {
- peripheral_gpio_close(temp);
- _E("peripheral_gpio_set_direction failed.");
- return -1;
- }
-
- g_sensor_h = temp;
- g_pin_num = pin_num;
+ if (_resource_validate_led(pin_num) == LED_HANDLE_ERROR_NOT_OPEN) {
+ ret = resource_open_led(pin_num);
+ retv_if(ret < 0, -1);
}
-
- if (g_pin_num != pin_num) {
+ if (_resource_validate_led(pin_num) == LED_HANDLE_ERROR_INVALID_PIN) {
_E("Invalid pin number.");
return -1;
}
diff --git a/tizen-manifest.xml b/tizen-manifest.xml
index 26e3a1e..b2f056f 100644
--- a/tizen-manifest.xml
+++ b/tizen-manifest.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="5.0" package="org.example.smart-light" version="1.0.0">
<profile name="iot-headless"/>
- <service-application appid="org.example.smart-light" exec="smart-light" multiple="false" nodisplay="true" on-boot="true" taskmanage="false" type="capp">
+ <service-application appid="org.example.smart-light" exec="smart-light" multiple="false" nodisplay="true" on-boot="false" taskmanage="false" type="capp">
<label>smart-light</label>
<icon>icon.png</icon>
<metadata key="http://tizen.org/iot/metadata/master" value="shared/res/master.json"/>