summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoyeon <boyeon.son@samsung.com>2019-08-27 14:00:02 +0900
committerBoyeon <boyeon.son@samsung.com>2019-08-27 14:00:49 +0900
commit11f716aa906fc294f0822693a273c613cc99a19a (patch)
tree6729d80e4e6de095e47ed9f78278b57e7a43f0f5
parent0b45430da216dc4265d783af260e67f6e29bd1b1 (diff)
downloadst-things-light-11f716aa906fc294f0822693a273c613cc99a19a.tar.gz
st-things-light-11f716aa906fc294f0822693a273c613cc99a19a.tar.bz2
st-things-light-11f716aa906fc294f0822693a273c613cc99a19a.zip
Change the validation logic for resource_led
Change-Id: I90071ba0eca5c6bceb723a4941a3fec799d30344
-rwxr-xr-xinc/resource/resource_led.h6
-rwxr-xr-xsrc/resource/resource_led.c26
2 files changed, 17 insertions, 15 deletions
diff --git a/inc/resource/resource_led.h b/inc/resource/resource_led.h
index 2a49a34..4adf22f 100755
--- a/inc/resource/resource_led.h
+++ b/inc/resource/resource_led.h
@@ -17,12 +17,6 @@
#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_led.c b/src/resource/resource_led.c
index cc4dca6..4d5d15d 100755
--- a/src/resource/resource_led.c
+++ b/src/resource/resource_led.c
@@ -15,10 +15,15 @@
*/
#include <peripheral_io.h>
-
#include "resource/resource_led.h"
#include "log.h"
+typedef enum {
+ LED_HANDLE_ERROR_NONE = 0, /**< Successful */
+ LED_HANDLE_ERROR_NOT_OPEN,
+ LED_HANDLE_ERROR_INVALID_PIN
+} led_handle_error_e;
+
static peripheral_gpio_h g_sensor_h = NULL;
static int g_pin_num = -1;
@@ -75,14 +80,17 @@ void resource_close_led(void)
int resource_write_led(int pin_num, int write_value)
{
int ret = PERIPHERAL_ERROR_NONE;
-
- if (_resource_validate_led(pin_num) == LED_HANDLE_ERROR_NOT_OPEN) {
- ret = resource_open_led(pin_num);
- retv_if(ret < 0, -1);
- }
- if (_resource_validate_led(pin_num) == LED_HANDLE_ERROR_INVALID_PIN) {
- _E("Invalid pin number.");
- return -1;
+ int ret_valid = LED_HANDLE_ERROR_NONE;
+
+ ret_valid = _resource_validate_led(pin_num);
+ if (ret_valid != LED_HANDLE_ERROR_NONE) {
+ if (ret_valid == LED_HANDLE_ERROR_NOT_OPEN) {
+ ret = resource_open_led(pin_num);
+ retv_if(ret != PERIPHERAL_ERROR_NONE, -1);
+ } else if (ret_valid == LED_HANDLE_ERROR_INVALID_PIN) {
+ _E("Invalid pin number.");
+ return -1;
+ }
}
ret = peripheral_gpio_write(g_sensor_h, write_value);