Change argument of pwm gdbus method 68/129468/3
authorjino.cho <jino.cho@samsung.com>
Tue, 16 May 2017 11:49:28 +0000 (20:49 +0900)
committerjino.cho <jino.cho@samsung.com>
Tue, 16 May 2017 23:44:25 +0000 (08:44 +0900)
- The pwm methods will pass handle instead of device informations.
- The pwm enable(set/get) functions were modified.

Change-Id: I54aa6444f6d22f1ba9ee1bf30391d2c04ff9a4f7
Signed-off-by: jino.cho <jino.cho@samsung.com>
include/peripheral_gdbus_pwm.h
include/peripheral_internal.h
include/peripheral_io.h
src/peripheral_gdbus_pwm.c
src/peripheral_io.xml
src/peripheral_pwm.c
test/peripheral-io-test.c

index 9b6dc02..7096af2 100644 (file)
@@ -27,5 +27,6 @@ int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period);
 int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle);
 int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle);
 int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable);
+int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable);
 
 #endif /* __PERIPHERAL_GDBUS_PWM_H__ */
index 290fb28..85263aa 100644 (file)
@@ -34,6 +34,13 @@ struct _peripheral_i2c_s {
 };
 
 /**
+ * @brief Internal struct for pwm context
+ */
+struct _peripheral_pwm_s {
+       uint handle;
+};
+
+/**
  * @brief Internal struct for uart context
  */
 struct _peripheral_uart_s {
index e9ee0ea..c6838e7 100644 (file)
@@ -369,14 +369,6 @@ int peripheral_i2c_write(peripheral_i2c_h i2c, uint8_t *data, int length);
  * @{
  */
 
-struct _peripheral_pwm_s {
-       int device;
-       int channel;
-       int period;
-       int duty_cycle;
-       int enabled;
-};
-
 /**
  * @brief The handle to the pwm device
  * @since_tizen 4.0
@@ -401,9 +393,9 @@ int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle);
 
 int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle);
 
-int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, peripheral_pwm_state_e enable);
+int peripheral_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable);
 
-int peripheral_pwm_is_enabled(peripheral_pwm_h pwm);
+int peripheral_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable);
 
 /**
 * @}
index 76cc7a9..76f4a5b 100644 (file)
@@ -61,6 +61,7 @@ int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel)
                        pwm_proxy,
                        device,
                        channel,
+                       &pwm->handle,
                        &ret,
                        NULL,
                        &error) == FALSE) {
@@ -82,8 +83,7 @@ int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm)
        /* TODO: Need to reorganize arguments */
        if (peripheral_io_gdbus_pwm_call_close_sync(
                        pwm_proxy,
-                       pwm->device,
-                       pwm->channel,
+                       pwm->handle,
                        &ret,
                        NULL,
                        &error) == FALSE) {
@@ -105,8 +105,7 @@ int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period)
        /* TODO: Need to reorganize arguments */
        if (peripheral_io_gdbus_pwm_call_set_period_sync(
                        pwm_proxy,
-                       pwm->device,
-                       pwm->channel,
+                       pwm->handle,
                        period,
                        &ret,
                        NULL,
@@ -129,9 +128,8 @@ int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period)
        /* TODO: Need to reorganize arguments */
        if (peripheral_io_gdbus_pwm_call_get_period_sync(
                        pwm_proxy,
-                       pwm->device,
-                       pwm->channel,
-                       period,
+                       pwm->handle,
+                       (gint*)period,
                        &ret,
                        NULL,
                        &error) == FALSE) {
@@ -153,8 +151,7 @@ int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
        /* TODO: Need to reorganize arguments */
        if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
                        pwm_proxy,
-                       pwm->device,
-                       pwm->channel,
+                       pwm->handle,
                        duty_cycle,
                        &ret,
                        NULL,
@@ -177,9 +174,8 @@ int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle)
        /* TODO: Need to reorganize arguments */
        if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync(
                        pwm_proxy,
-                       pwm->device,
-                       pwm->channel,
-                       duty_cycle,
+                       pwm->handle,
+                       (gint*)duty_cycle,
                        &ret,
                        NULL,
                        &error) == FALSE) {
@@ -201,8 +197,7 @@ int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e
        /* TODO: Need to reorganize arguments */
        if (peripheral_io_gdbus_pwm_call_set_enable_sync(
                        pwm_proxy,
-                       pwm->device,
-                       pwm->channel,
+                       pwm->handle,
                        enable,
                        &ret,
                        NULL,
@@ -214,3 +209,26 @@ int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e
 
        return ret;
 }
+
+int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable)
+{
+       GError *error = NULL;
+       peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
+
+       if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
+
+       if (peripheral_io_gdbus_pwm_call_get_enable_sync(
+                       pwm_proxy,
+                       pwm->handle,
+                       (gint*)enable,
+                       &ret,
+                       NULL,
+                       &error) == FALSE) {
+               _E("%s", error->message);
+               g_error_free(error);
+               return PERIPHERAL_ERROR_UNKNOWN;
+       }
+
+       return ret;
+}
+
index c6343c4..285c6f5 100644 (file)
                <method name="Open">
                        <arg type="i" name="device" direction="in"/>
                        <arg type="i" name="channel" direction="in"/>
+                       <arg type="u" name="handle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
                <method name="Close">
-                       <arg type="i" name="device" direction="in"/>
-                       <arg type="i" name="channel" direction="in"/>
-                       <arg type="i" name="result" direction="out"/>
-               </method>
-               <method name="GetDutyCycle">
-                       <arg type="i" name="device" direction="in"/>
-                       <arg type="i" name="channel" direction="in"/>
-                       <arg type="i" name="duty_cycle" direction="out"/>
+                       <arg type="u" name="handle" direction="in"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
-               <method name="SetDutyCycle">
-                       <arg type="i" name="device" direction="in"/>
-                       <arg type="i" name="channel" direction="in"/>
-                       <arg type="i" name="duty_cycle" direction="in"/>
+               <method name="SetPeriod">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="period" direction="in"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
                <method name="GetPeriod">
-                       <arg type="i" name="device" direction="in"/>
-                       <arg type="i" name="channel" direction="in"/>
+                       <arg type="u" name="handle" direction="in"/>
                        <arg type="i" name="period" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
-               <method name="SetPeriod">
-                       <arg type="i" name="device" direction="in"/>
-                       <arg type="i" name="channel" direction="in"/>
-                       <arg type="i" name="period" direction="in"/>
+               <method name="SetDutyCycle">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="duty_cycle" direction="in"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
+               <method name="GetDutyCycle">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="duty_cycle" direction="out"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
                <method name="SetEnable">
-                       <arg type="i" name="device" direction="in"/>
-                       <arg type="i" name="channel" direction="in"/>
+                       <arg type="u" name="handle" direction="in"/>
                        <arg type="i" name="enable" direction="in"/>
                        <arg type="i" name="result" direction="out"/>
                </method>
+               <method name="GetEnable">
+                       <arg type="u" name="handle" direction="in"/>
+                       <arg type="i" name="enable" direction="out"/>
+                       <arg type="i" name="result" direction="out"/>
+               </method>
        </interface>
        <interface name="org.tizen.peripheral_io.uart">
                <method name="Open">
index a7c4206..45f29fc 100644 (file)
 #include "peripheral_io.h"
 #include "peripheral_gdbus_pwm.h"
 #include "peripheral_common.h"
+#include "peripheral_internal.h"
 
 #define PWM_ENABLE     1
 #define PWM_DISABLE    0
 
 int peripheral_pwm_open(int device, int channel, peripheral_pwm_h* pwm)
 {
-       peripheral_pwm_h dev = NULL;
+       peripheral_pwm_h handle;
        int ret = PERIPHERAL_ERROR_NONE;
 
        assert(device >= 0);
        assert(channel >= 0);
 
        /* Initialize */
-       dev = (peripheral_pwm_h)malloc(sizeof(struct _peripheral_pwm_s));
+       handle = (peripheral_pwm_h)calloc(1, sizeof(struct _peripheral_pwm_s));
 
-       if (dev == NULL) {
+       if (handle == NULL) {
                _E("Failed to allocate peripheral_pwm_h");
                return PERIPHERAL_ERROR_OUT_OF_MEMORY;
        }
 
        pwm_proxy_init();
 
-       dev->device = device;
-       dev->channel = channel;
-
-       ret = peripheral_gdbus_pwm_open(dev, device, channel);
+       ret = peripheral_gdbus_pwm_open(handle, device, channel);
 
        if (ret != PERIPHERAL_ERROR_NONE) {
                _E("PWM open error (%d, %d)", device, channel);
-               free(dev);
-               dev = NULL;
+               free(handle);
+               handle = NULL;
        }
-       *pwm = dev;
+       *pwm = handle;
 
        return ret;
 }
@@ -76,69 +74,42 @@ int peripheral_pwm_close(peripheral_pwm_h pwm)
 
 int peripheral_pwm_set_period(peripheral_pwm_h pwm, int period)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       ret = peripheral_gdbus_pwm_set_period(pwm, period);
+       if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       if (ret != PERIPHERAL_ERROR_NONE)
-               pwm->period = period;
-
-       return ret;
+       return peripheral_gdbus_pwm_set_period(pwm, period);
 }
 
 int peripheral_pwm_get_period(peripheral_pwm_h pwm, int *period)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
+       if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_gdbus_pwm_get_period(pwm, period);
-
-       if (ret != PERIPHERAL_ERROR_NONE)
-               pwm->period = *period;
-
-       return ret;
+       return peripheral_gdbus_pwm_get_period(pwm, period);
 }
 
 int peripheral_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       ret = peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
+       if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       if (ret != PERIPHERAL_ERROR_NONE)
-               pwm->duty_cycle = duty_cycle;
-
-       return ret;
+       return peripheral_gdbus_pwm_set_duty_cycle(pwm, duty_cycle);
 }
 
 int peripheral_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
+       if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       ret = peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
-
-       if (ret != PERIPHERAL_ERROR_NONE)
-               pwm->duty_cycle = *duty_cycle;
-
-       return ret;
+       return peripheral_gdbus_pwm_get_duty_cycle(pwm, duty_cycle);
 }
 
-int peripheral_pwm_set_enabled(peripheral_pwm_h pwm, peripheral_pwm_state_e enable)
+int peripheral_pwm_set_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e enable)
 {
-       int ret = PERIPHERAL_ERROR_NONE;
-
-       ret = peripheral_gdbus_pwm_set_enable(pwm, enable);
-
-       if (ret != PERIPHERAL_ERROR_NONE)
-               pwm->enabled = enable;
+       if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
-       return PERIPHERAL_ERROR_NONE;
+       return peripheral_gdbus_pwm_set_enable(pwm, enable);
 }
 
-int peripheral_pwm_is_enabled(peripheral_pwm_h pwm)
+int peripheral_pwm_get_enable(peripheral_pwm_h pwm, peripheral_pwm_state_e *enable)
 {
-       if (pwm->enabled == PWM_ENABLE)
-               return PWM_ENABLE;
-       else
-               return PWM_DISABLE;
-}
+       if (pwm == NULL) return PERIPHERAL_ERROR_INVALID_PARAMETER;
 
+       return peripheral_gdbus_pwm_get_enable(pwm, enable);
+}
index 699be4a..dae9170 100644 (file)
@@ -227,7 +227,7 @@ int pwm_test_led(void)
        peripheral_pwm_open(device, channel, &dev);
        peripheral_pwm_set_period(dev, period); /* period: nanosecond */
        peripheral_pwm_set_duty_cycle(dev, duty_cycle); /* duty_cycle: nanosecond */
-       peripheral_pwm_set_enabled(dev, 1);     /* 0: disable, 1: enable */
+       peripheral_pwm_set_enable(dev, 1);      /* 0: disable, 1: enable */
 
        while (cnt < 5) {
                for (set_duty_cycle = period; set_duty_cycle > 0; set_duty_cycle -= 50) {
@@ -248,7 +248,7 @@ int pwm_test_led(void)
                }
                cnt++;
        }
-       peripheral_pwm_set_enabled(dev, 0);     /* 0: disable, 1: enable */
+       peripheral_pwm_set_enable(dev, 0);      /* 0: disable, 1: enable */
        peripheral_pwm_close(dev);
 
        return 0;
@@ -285,12 +285,12 @@ int pwm_test_motor(void)
                        printf("set degree: %d\n", degree[idx]);
                        peripheral_pwm_set_period(dev, period);
                        peripheral_pwm_set_duty_cycle(dev, duty_cycle);
-                       peripheral_pwm_set_enabled(dev, 1);             /* 0: disable, 1: enable */
+                       peripheral_pwm_set_enable(dev, 1);              /* 0: disable, 1: enable */
                        usleep(500000);
                }
        }
 
-       peripheral_pwm_set_enabled(dev, 0);     /* 0: disable, 1: enable */
+       peripheral_pwm_set_enable(dev, 0);      /* 0: disable, 1: enable */
        peripheral_pwm_close(dev);
 
        return 0;