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) {
33 g_object_ref(pwm_proxy);
37 pwm_proxy = peripheral_io_gdbus_pwm_proxy_new_for_bus_sync(
39 G_DBUS_PROXY_FLAGS_NONE,
40 PERIPHERAL_GDBUS_NAME,
41 PERIPHERAL_GDBUS_PWM_PATH,
46 void pwm_proxy_deinit()
49 g_object_unref(pwm_proxy);
50 if (!G_IS_OBJECT(pwm_proxy))
55 int peripheral_gdbus_pwm_open(peripheral_pwm_h pwm, int device, int channel)
58 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
60 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
62 if (peripheral_io_gdbus_pwm_call_open_sync(
70 _E("%s", error->message);
72 return PERIPHERAL_ERROR_UNKNOWN;
78 int peripheral_gdbus_pwm_close(peripheral_pwm_h pwm)
81 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
83 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
85 if (peripheral_io_gdbus_pwm_call_close_sync(
91 _E("%s", error->message);
93 return PERIPHERAL_ERROR_UNKNOWN;
99 int peripheral_gdbus_pwm_set_period(peripheral_pwm_h pwm, int period)
101 GError *error = NULL;
102 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
104 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
106 if (peripheral_io_gdbus_pwm_call_set_period_sync(
113 _E("%s", error->message);
115 return PERIPHERAL_ERROR_UNKNOWN;
121 int peripheral_gdbus_pwm_get_period(peripheral_pwm_h pwm, int *period)
123 GError *error = NULL;
124 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
127 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
129 if (peripheral_io_gdbus_pwm_call_get_period_sync(
136 _E("%s", error->message);
138 return PERIPHERAL_ERROR_UNKNOWN;
146 int peripheral_gdbus_pwm_set_duty_cycle(peripheral_pwm_h pwm, int duty_cycle)
148 GError *error = NULL;
149 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
151 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
153 if (peripheral_io_gdbus_pwm_call_set_duty_cycle_sync(
160 _E("%s", error->message);
162 return PERIPHERAL_ERROR_UNKNOWN;
168 int peripheral_gdbus_pwm_get_duty_cycle(peripheral_pwm_h pwm, int *duty_cycle)
170 GError *error = NULL;
171 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
174 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
176 if (peripheral_io_gdbus_pwm_call_get_duty_cycle_sync(
183 _E("%s", error->message);
185 return PERIPHERAL_ERROR_UNKNOWN;
193 int peripheral_gdbus_pwm_set_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e polarity)
195 GError *error = NULL;
196 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
198 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
200 if (peripheral_io_gdbus_pwm_call_set_polarity_sync(
207 _E("%s", error->message);
209 return PERIPHERAL_ERROR_UNKNOWN;
215 int peripheral_gdbus_pwm_get_polarity(peripheral_pwm_h pwm, peripheral_pwm_polarity_e *polarity)
217 GError *error = NULL;
218 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
221 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
223 if (peripheral_io_gdbus_pwm_call_get_polarity_sync(
230 _E("%s", error->message);
232 return PERIPHERAL_ERROR_UNKNOWN;
236 *polarity = PERIPHERAL_PWM_POLARITY_NORMAL;
238 *polarity = PERIPHERAL_PWM_POLARITY_INVERSED;
243 int peripheral_gdbus_pwm_set_enable(peripheral_pwm_h pwm, bool enable)
245 GError *error = NULL;
246 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
248 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
250 if (peripheral_io_gdbus_pwm_call_set_enable_sync(
257 _E("%s", error->message);
259 return PERIPHERAL_ERROR_UNKNOWN;
265 int peripheral_gdbus_pwm_get_enable(peripheral_pwm_h pwm, bool *enable)
267 GError *error = NULL;
268 peripheral_error_e ret = PERIPHERAL_ERROR_NONE;
271 if (pwm_proxy == NULL) return PERIPHERAL_ERROR_UNKNOWN;
273 if (peripheral_io_gdbus_pwm_call_get_enable_sync(
280 _E("%s", error->message);
282 return PERIPHERAL_ERROR_UNKNOWN;