2 * Copyright (c) 2016-2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include "peripheral_io.h"
21 #include "peripheral_gdbus.h"
22 #include "peripheral_common.h"
23 #include "peripheral_internal.h"
24 #include "peripheral_io_gdbus.h"
26 PeripheralIoGdbusPwm *pwm_proxy = NULL;
28 void pwm_proxy_init(void)
32 if (pwm_proxy != NULL)
35 pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync(
37 G_DBUS_PROXY_FLAGS_NONE,
38 PERIPHERAL_GDBUS_NAME,
39 PERIPHERAL_GDBUS_PWM_PATH,
44 void pwm_proxy_deinit()
47 g_object_unref(pwm_proxy);
52 int peripheral_gdbus_pwm_open(peripheral_pwm_h dev, int device, int channel)
55 gint32 ret = PERIPHERAL_ERROR_NONE;
57 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
59 /* TODO: Need to reorganize arguments */
60 if (peripheral_io_gdbus_pwm_call_open_sync(
67 _E("Error in %s() : %s\n", __func__, error->message);
69 return PERIPHERAL_ERROR_UNKNOWN;
75 int peripheral_gdbus_pwm_close(peripheral_pwm_h dev)
78 gint32 ret = PERIPHERAL_ERROR_NONE;
80 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
82 /* TODO: Need to reorganize arguments */
83 if (peripheral_io_gdbus_pwm_call_close_sync(
90 _E("Error in %s() : %s\n", __func__, error->message);
92 return PERIPHERAL_ERROR_UNKNOWN;
98 int peripheral_gdbus_pwm_set_period(peripheral_pwm_h dev, int period)
100 GError *error = NULL;
101 gint32 ret = PERIPHERAL_ERROR_NONE;
103 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
105 /* TODO: Need to reorganize arguments */
106 if (peripheral_io_gdbus_pwm_call_set_period_sync(
114 _E("Error in %s() : %s\n", __func__, error->message);
116 return PERIPHERAL_ERROR_UNKNOWN;
122 int peripheral_gdbus_pwm_get_period(peripheral_pwm_h dev, int *period)
124 GError *error = NULL;
125 gint32 ret = PERIPHERAL_ERROR_NONE;
127 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
129 /* TODO: Need to reorganize arguments */
130 if (peripheral_io_gdbus_pwm_call_get_period_sync(
138 _E("Error in %s() : %s\n", __func__, error->message);
140 return PERIPHERAL_ERROR_UNKNOWN;
146 int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h dev, int duty_cycle)
148 GError *error = NULL;
149 gint32 ret = PERIPHERAL_ERROR_NONE;
151 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
153 /* TODO: Need to reorganize arguments */
154 if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
162 _E("Error in %s() : %s\n", __func__, error->message);
164 return PERIPHERAL_ERROR_UNKNOWN;
170 int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h dev, int *duty_cycle)
172 GError *error = NULL;
173 gint32 ret = PERIPHERAL_ERROR_NONE;
175 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
177 /* TODO: Need to reorganize arguments */
178 if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync(
186 _E("Error in %s() : %s\n", __func__, error->message);
188 return PERIPHERAL_ERROR_UNKNOWN;
194 int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h dev, peripheral_pwm_state_e enable)
196 GError *error = NULL;
197 gint32 ret = PERIPHERAL_ERROR_NONE;
199 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
201 /* TODO: Need to reorganize arguments */
202 if (peripheral_io_gdbus_pwm_call_set_enable_sync(
210 _E("Error in %s() : %s\n", __func__, error->message);
212 return PERIPHERAL_ERROR_UNKNOWN;