cec: added bWait parameter to volume change methods.
[deb_libcec.git] / src / lib / LibCECC.cpp
CommitLineData
abbca718
LOK
1/*
2 * This file is part of the libCEC(R) library.
3 *
4 * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
6 *
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
8 *
9 * This program is dual-licensed; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 *
23 *
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
26 *
27 * For more information contact:
28 * Pulse-Eight Licensing <license@pulse-eight.com>
29 * http://www.pulse-eight.com/
30 * http://www.pulse-eight.net/
31 */
32
761dcc45
LOK
33#include <cec.h>
34#include <cecc.h>
abbca718
LOK
35
36using namespace CEC;
37using namespace std;
38
39/*!
40 * C interface implementation
41 */
42//@{
2abe74eb 43ICECAdapter *cec_parser;
abbca718 44
91499042 45int cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress)
abbca718 46{
2abe74eb 47 cec_parser = (ICECAdapter *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress);
02ee2c68 48 return (cec_parser != NULL) ? 1 : 0;
abbca718
LOK
49}
50
f8513317
LOK
51int cec_init_typed(const char *strDeviceName, cec_device_type_list devicesTypes)
52{
53 cec_parser = (ICECAdapter *) CECInit(strDeviceName, devicesTypes);
54 return (cec_parser != NULL) ? 1 : 0;
55}
56
5f39c4d8
LOK
57void cec_destroy(void)
58{
59 cec_close();
25701fa6 60 CECDestroy(cec_parser);
5f39c4d8
LOK
61 cec_parser = NULL;
62}
63
02ee2c68 64int cec_open(const char *strPort, uint32_t iTimeout)
abbca718
LOK
65{
66 if (cec_parser)
67 return cec_parser->Open(strPort, iTimeout);
68 return false;
69}
70
5f39c4d8 71void cec_close(void)
f99bc831 72{
f99bc831 73 if (cec_parser)
5f39c4d8 74 cec_parser->Close();
f99bc831
LOK
75}
76
25701fa6 77int8_t cec_find_adapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */)
abbca718
LOK
78{
79 if (cec_parser)
25701fa6 80 return cec_parser->FindAdapters(deviceList, iBufSize, strDevicePath);
2abe74eb 81 return -1;
abbca718
LOK
82}
83
02ee2c68 84int cec_ping_adapters(void)
abbca718
LOK
85{
86 if (cec_parser)
02ee2c68
LOK
87 return cec_parser->PingAdapter() ? 1 : 0;
88 return -1;
abbca718
LOK
89}
90
02ee2c68 91int cec_start_bootloader(void)
abbca718
LOK
92{
93 if (cec_parser)
02ee2c68
LOK
94 return cec_parser->StartBootloader() ? 1 : 0;
95 return -1;
abbca718
LOK
96}
97
25701fa6 98int8_t cec_get_min_version(void)
abbca718
LOK
99{
100 if (cec_parser)
d75be19b 101 return cec_parser->GetMinLibVersion();
2abe74eb 102 return -1;
abbca718
LOK
103}
104
d75be19b 105int8_t cec_get_lib_version_major(void)
abbca718
LOK
106{
107 if (cec_parser)
d75be19b 108 return cec_parser->GetLibVersionMajor();
2abe74eb 109 return -1;
abbca718
LOK
110}
111
eafd9bed
LOK
112int8_t cec_get_lib_version_minor(void)
113{
114 if (cec_parser)
115 return cec_parser->GetLibVersionMinor();
116 return -1;
117}
118
02ee2c68 119int cec_get_next_log_message(cec_log_message *message)
abbca718
LOK
120{
121 if (cec_parser)
02ee2c68
LOK
122 return cec_parser->GetNextLogMessage(message) ? 1 : 0;
123 return -1;
abbca718
LOK
124}
125
02ee2c68 126int cec_get_next_keypress(cec_keypress *key)
abbca718
LOK
127{
128 if (cec_parser)
02ee2c68
LOK
129 return cec_parser->GetNextKeypress(key) ? 1 : 0;
130 return -1;
abbca718
LOK
131}
132
02ee2c68 133int cec_get_next_command(cec_command *command)
825ddb96
LOK
134{
135 if (cec_parser)
02ee2c68
LOK
136 return cec_parser->GetNextCommand(command) ? 1 : 0;
137 return -1;
825ddb96
LOK
138}
139
f958766e 140int cec_transmit(const CEC::cec_command *data)
abbca718
LOK
141{
142 if (cec_parser)
f958766e 143 return cec_parser->Transmit(*data) ? 1 : 0;
02ee2c68 144 return -1;
abbca718
LOK
145}
146
2492216a 147int cec_set_logical_address(cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */)
abbca718
LOK
148{
149 if (cec_parser)
02ee2c68
LOK
150 return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0;
151 return -1;
6dfe9213
LOK
152}
153
2492216a
LOK
154int cec_set_physical_address(uint16_t iPhysicalAddress /* = CEC_DEFAULT_PHYSICAL_ADDRESS */)
155{
156 if (cec_parser)
157 return cec_parser->SetPhysicalAddress(iPhysicalAddress) ? 1 : 0;
158 return -1;
159}
160
02ee2c68 161int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */)
6dfe9213
LOK
162{
163 if (cec_parser)
02ee2c68
LOK
164 return cec_parser->PowerOnDevices(address) ? 1 : 0;
165 return -1;
abbca718
LOK
166}
167
02ee2c68 168int cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */)
abbca718
LOK
169{
170 if (cec_parser)
02ee2c68
LOK
171 return cec_parser->StandbyDevices(address) ? 1 : 0;
172 return -1;
abbca718
LOK
173}
174
02ee2c68 175int cec_set_active_view(void)
abbca718
LOK
176{
177 if (cec_parser)
02ee2c68
LOK
178 return cec_parser->SetActiveView() ? 1 : 0;
179 return -1;
abbca718
LOK
180}
181
18203d17
LOK
182int cec_set_active_source(cec_device_type type)
183{
184 if (cec_parser)
185 return cec_parser->SetActiveSource(type) ? 1 : 0;
186 return -1;
187}
188
02ee2c68 189int cec_set_inactive_view(void)
abbca718
LOK
190{
191 if (cec_parser)
02ee2c68
LOK
192 return cec_parser->SetInactiveView() ? 1 : 0;
193 return -1;
abbca718
LOK
194}
195
1969b140
LOK
196int cec_set_osd_string(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage)
197{
198 if (cec_parser)
199 return cec_parser->SetOSDString(iLogicalAddress, duration, strMessage) ? 1 : 0;
200 return -1;
201}
202
8b7e5ff6
LOK
203int cec_switch_monitoring(int bEnable)
204{
205 if (cec_parser)
206 return cec_parser->SwitchMonitoring(bEnable == 1) ? 1 : 0;
207 return -1;
208}
209
6a1c0009
LOK
210cec_version cec_get_device_cec_version(cec_logical_address iLogicalAddress)
211{
212 if (cec_parser)
213 return cec_parser->GetDeviceCecVersion(iLogicalAddress);
214 return CEC_VERSION_UNKNOWN;
215}
216
a3269a0a
LOK
217int cec_get_device_menu_language(cec_logical_address iLogicalAddress, cec_menu_language *language)
218{
219 if (cec_parser)
220 return cec_parser->GetDeviceMenuLanguage(iLogicalAddress, language) ? 1 : 0;
221 return -1;
222}
223
44c74256
LOK
224uint64_t cec_get_device_vendor_id(cec_logical_address iLogicalAddress)
225{
226 if (cec_parser)
227 return cec_parser->GetDeviceVendorId(iLogicalAddress);
228 return 0;
229}
230
e55f3f70
LOK
231cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress)
232{
233 if (cec_parser)
234 return cec_parser->GetDevicePowerStatus(iLogicalAddress);
235 return CEC_POWER_STATUS_UNKNOWN;
236}
237
57f45e6c
LOK
238int cec_poll_device(cec_logical_address iLogicalAddress)
239{
240 if (cec_parser)
6d858ba4
LOK
241 return cec_parser->PollDevice(iLogicalAddress) ? 1 : 0;
242 return -1;
243}
244
245cec_logical_addresses cec_get_active_devices(void)
246{
247 cec_logical_addresses addresses;
248 if (cec_parser)
249 addresses = cec_parser->GetActiveDevices();
250 return addresses;
251}
252
253int cec_is_active_device(cec_logical_address iAddress)
254{
255 if (cec_parser)
256 return cec_parser->IsActiveDevice(iAddress) ? 1 : 0;
257 return -1;
258}
259
260int cec_is_active_device_type(cec_device_type type)
261{
262 if (cec_parser)
263 return cec_parser->IsActiveDeviceType(type) ? 1 : 0;
57f45e6c
LOK
264 return -1;
265}
266
16b1e052
LOK
267int cec_set_hdmi_port(uint8_t iPort)
268{
269 if (cec_parser)
270 return cec_parser->SetHDMIPort(iPort) ? 1 : 0;
271 return -1;
272}
273
9f332fe2 274int cec_volume_up(int bWait /* = 1 */)
04e637f9
LOK
275{
276 if (cec_parser)
9f332fe2 277 return cec_parser->VolumeUp(bWait == 1);
04e637f9
LOK
278 return -1;
279}
280
9f332fe2 281int cec_volume_down(int bWait /* = 1 */)
04e637f9
LOK
282{
283 if (cec_parser)
9f332fe2 284 return cec_parser->VolumeDown(bWait == 1);
04e637f9
LOK
285 return -1;
286}
287
9f332fe2 288int cec_mute_audio(int bWait /* = 1 */)
04e637f9
LOK
289{
290 if (cec_parser)
9f332fe2 291 return cec_parser->MuteAudio(bWait == 1);
04e637f9
LOK
292 return -1;
293}
294
abbca718 295//@}