| 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 | |
| 33 | #include <cec.h> |
| 34 | #include <cecc.h> |
| 35 | |
| 36 | using namespace CEC; |
| 37 | using namespace std; |
| 38 | |
| 39 | /*! |
| 40 | * C interface implementation |
| 41 | */ |
| 42 | //@{ |
| 43 | ICECAdapter *cec_parser; |
| 44 | |
| 45 | int cec_init(const char *strDeviceName, cec_logical_address iLogicalAddress, uint16_t iPhysicalAddress) |
| 46 | { |
| 47 | cec_parser = (ICECAdapter *) CECCreate(strDeviceName, iLogicalAddress, iPhysicalAddress); |
| 48 | return (cec_parser != NULL) ? 1 : 0; |
| 49 | } |
| 50 | |
| 51 | int 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 | |
| 57 | void cec_destroy(void) |
| 58 | { |
| 59 | cec_close(); |
| 60 | CECDestroy(cec_parser); |
| 61 | cec_parser = NULL; |
| 62 | } |
| 63 | |
| 64 | int cec_open(const char *strPort, uint32_t iTimeout) |
| 65 | { |
| 66 | if (cec_parser) |
| 67 | return cec_parser->Open(strPort, iTimeout); |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | void cec_close(void) |
| 72 | { |
| 73 | if (cec_parser) |
| 74 | cec_parser->Close(); |
| 75 | } |
| 76 | |
| 77 | int8_t cec_find_adapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath /* = NULL */) |
| 78 | { |
| 79 | if (cec_parser) |
| 80 | return cec_parser->FindAdapters(deviceList, iBufSize, strDevicePath); |
| 81 | return -1; |
| 82 | } |
| 83 | |
| 84 | int cec_ping_adapters(void) |
| 85 | { |
| 86 | if (cec_parser) |
| 87 | return cec_parser->PingAdapter() ? 1 : 0; |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | int cec_start_bootloader(void) |
| 92 | { |
| 93 | if (cec_parser) |
| 94 | return cec_parser->StartBootloader() ? 1 : 0; |
| 95 | return -1; |
| 96 | } |
| 97 | |
| 98 | int8_t cec_get_min_version(void) |
| 99 | { |
| 100 | if (cec_parser) |
| 101 | return cec_parser->GetMinLibVersion(); |
| 102 | return -1; |
| 103 | } |
| 104 | |
| 105 | int8_t cec_get_lib_version_major(void) |
| 106 | { |
| 107 | if (cec_parser) |
| 108 | return cec_parser->GetLibVersionMajor(); |
| 109 | return -1; |
| 110 | } |
| 111 | |
| 112 | int8_t cec_get_lib_version_minor(void) |
| 113 | { |
| 114 | if (cec_parser) |
| 115 | return cec_parser->GetLibVersionMinor(); |
| 116 | return -1; |
| 117 | } |
| 118 | |
| 119 | int cec_get_next_log_message(cec_log_message *message) |
| 120 | { |
| 121 | if (cec_parser) |
| 122 | return cec_parser->GetNextLogMessage(message) ? 1 : 0; |
| 123 | return -1; |
| 124 | } |
| 125 | |
| 126 | int cec_get_next_keypress(cec_keypress *key) |
| 127 | { |
| 128 | if (cec_parser) |
| 129 | return cec_parser->GetNextKeypress(key) ? 1 : 0; |
| 130 | return -1; |
| 131 | } |
| 132 | |
| 133 | int cec_get_next_command(cec_command *command) |
| 134 | { |
| 135 | if (cec_parser) |
| 136 | return cec_parser->GetNextCommand(command) ? 1 : 0; |
| 137 | return -1; |
| 138 | } |
| 139 | |
| 140 | int cec_transmit(const CEC::cec_command *data) |
| 141 | { |
| 142 | if (cec_parser) |
| 143 | return cec_parser->Transmit(*data) ? 1 : 0; |
| 144 | return -1; |
| 145 | } |
| 146 | |
| 147 | int cec_set_logical_address(cec_logical_address iLogicalAddress /* = CECDEVICE_PLAYBACKDEVICE1 */) |
| 148 | { |
| 149 | if (cec_parser) |
| 150 | return cec_parser->SetLogicalAddress(iLogicalAddress) ? 1 : 0; |
| 151 | return -1; |
| 152 | } |
| 153 | |
| 154 | int 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 | |
| 161 | int cec_power_on_devices(cec_logical_address address /* = CECDEVICE_TV */) |
| 162 | { |
| 163 | if (cec_parser) |
| 164 | return cec_parser->PowerOnDevices(address) ? 1 : 0; |
| 165 | return -1; |
| 166 | } |
| 167 | |
| 168 | int cec_standby_devices(cec_logical_address address /* = CECDEVICE_BROADCAST */) |
| 169 | { |
| 170 | if (cec_parser) |
| 171 | return cec_parser->StandbyDevices(address) ? 1 : 0; |
| 172 | return -1; |
| 173 | } |
| 174 | |
| 175 | int cec_set_active_view(void) |
| 176 | { |
| 177 | if (cec_parser) |
| 178 | return cec_parser->SetActiveView() ? 1 : 0; |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | int 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 | |
| 189 | int cec_set_deck_control_mode(cec_deck_control_mode mode, int bSendUpdate) { |
| 190 | if (cec_parser) |
| 191 | return cec_parser->SetDeckControlMode(mode, bSendUpdate == 1) ? 1 : 0; |
| 192 | return -1; |
| 193 | } |
| 194 | |
| 195 | int cec_set_deck_info(cec_deck_info info, int bSendUpdate) { |
| 196 | if (cec_parser) |
| 197 | return cec_parser->SetDeckInfo(info, bSendUpdate == 1) ? 1 : 0; |
| 198 | return -1; |
| 199 | |
| 200 | } |
| 201 | |
| 202 | int cec_set_inactive_view(void) |
| 203 | { |
| 204 | if (cec_parser) |
| 205 | return cec_parser->SetInactiveView() ? 1 : 0; |
| 206 | return -1; |
| 207 | } |
| 208 | |
| 209 | int cec_set_menu_state(cec_menu_state state, int bSendUpdate) { |
| 210 | if (cec_parser) |
| 211 | return cec_parser->SetMenuState(state, bSendUpdate == 1) ? 1 : 0; |
| 212 | return -1; |
| 213 | } |
| 214 | |
| 215 | int cec_set_osd_string(cec_logical_address iLogicalAddress, cec_display_control duration, const char *strMessage) |
| 216 | { |
| 217 | if (cec_parser) |
| 218 | return cec_parser->SetOSDString(iLogicalAddress, duration, strMessage) ? 1 : 0; |
| 219 | return -1; |
| 220 | } |
| 221 | |
| 222 | int cec_switch_monitoring(int bEnable) |
| 223 | { |
| 224 | if (cec_parser) |
| 225 | return cec_parser->SwitchMonitoring(bEnable == 1) ? 1 : 0; |
| 226 | return -1; |
| 227 | } |
| 228 | |
| 229 | cec_version cec_get_device_cec_version(cec_logical_address iLogicalAddress) |
| 230 | { |
| 231 | if (cec_parser) |
| 232 | return cec_parser->GetDeviceCecVersion(iLogicalAddress); |
| 233 | return CEC_VERSION_UNKNOWN; |
| 234 | } |
| 235 | |
| 236 | int cec_get_device_menu_language(cec_logical_address iLogicalAddress, cec_menu_language *language) |
| 237 | { |
| 238 | if (cec_parser) |
| 239 | return cec_parser->GetDeviceMenuLanguage(iLogicalAddress, language) ? 1 : 0; |
| 240 | return -1; |
| 241 | } |
| 242 | |
| 243 | uint64_t cec_get_device_vendor_id(cec_logical_address iLogicalAddress) |
| 244 | { |
| 245 | if (cec_parser) |
| 246 | return cec_parser->GetDeviceVendorId(iLogicalAddress); |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | uint16_t cec_get_device_physical_address(cec_logical_address iLogicalAddress) |
| 251 | { |
| 252 | if (cec_parser) |
| 253 | return cec_parser->GetDevicePhysicalAddress(iLogicalAddress); |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | cec_power_status cec_get_device_power_status(cec_logical_address iLogicalAddress) |
| 258 | { |
| 259 | if (cec_parser) |
| 260 | return cec_parser->GetDevicePowerStatus(iLogicalAddress); |
| 261 | return CEC_POWER_STATUS_UNKNOWN; |
| 262 | } |
| 263 | |
| 264 | int cec_poll_device(cec_logical_address iLogicalAddress) |
| 265 | { |
| 266 | if (cec_parser) |
| 267 | return cec_parser->PollDevice(iLogicalAddress) ? 1 : 0; |
| 268 | return -1; |
| 269 | } |
| 270 | |
| 271 | cec_logical_addresses cec_get_active_devices(void) |
| 272 | { |
| 273 | cec_logical_addresses addresses; |
| 274 | addresses.Clear(); |
| 275 | if (cec_parser) |
| 276 | addresses = cec_parser->GetActiveDevices(); |
| 277 | return addresses; |
| 278 | } |
| 279 | |
| 280 | int cec_is_active_device(cec_logical_address iAddress) |
| 281 | { |
| 282 | if (cec_parser) |
| 283 | return cec_parser->IsActiveDevice(iAddress) ? 1 : 0; |
| 284 | return -1; |
| 285 | } |
| 286 | |
| 287 | int cec_is_active_device_type(cec_device_type type) |
| 288 | { |
| 289 | if (cec_parser) |
| 290 | return cec_parser->IsActiveDeviceType(type) ? 1 : 0; |
| 291 | return -1; |
| 292 | } |
| 293 | |
| 294 | int cec_set_hdmi_port(cec_logical_address iBaseDevice, uint8_t iPort) |
| 295 | { |
| 296 | if (cec_parser) |
| 297 | return cec_parser->SetHDMIPort(iBaseDevice, iPort) ? 1 : 0; |
| 298 | return -1; |
| 299 | } |
| 300 | |
| 301 | int cec_volume_up(int bWait) |
| 302 | { |
| 303 | if (cec_parser) |
| 304 | return cec_parser->VolumeUp(bWait == 1); |
| 305 | return -1; |
| 306 | } |
| 307 | |
| 308 | int cec_volume_down(int bWait) |
| 309 | { |
| 310 | if (cec_parser) |
| 311 | return cec_parser->VolumeDown(bWait == 1); |
| 312 | return -1; |
| 313 | } |
| 314 | |
| 315 | int cec_mute_audio(int bWait) |
| 316 | { |
| 317 | if (cec_parser) |
| 318 | return cec_parser->MuteAudio(bWait == 1); |
| 319 | return -1; |
| 320 | } |
| 321 | |
| 322 | int cec_send_keypress(cec_logical_address iDestination, cec_user_control_code key, int bWait) |
| 323 | { |
| 324 | if (cec_parser) |
| 325 | return cec_parser->SendKeypress(iDestination, key, bWait == 1) ? 1 : 0; |
| 326 | return -1; |
| 327 | } |
| 328 | |
| 329 | int cec_send_key_release(cec_logical_address iDestination, int bWait) |
| 330 | { |
| 331 | if (cec_parser) |
| 332 | return cec_parser->SendKeyRelease(iDestination, bWait == 1) ? 1 : 0; |
| 333 | return -1; |
| 334 | } |
| 335 | |
| 336 | cec_osd_name cec_get_osd_name(cec_logical_address iAddress) |
| 337 | { |
| 338 | cec_osd_name retVal; |
| 339 | retVal.device = iAddress; |
| 340 | retVal.name[0] = 0; |
| 341 | |
| 342 | if (cec_parser) |
| 343 | retVal = cec_parser->GetOSDName(iAddress); |
| 344 | |
| 345 | return retVal; |
| 346 | } |
| 347 | |
| 348 | int cec_enable_physical_address_detection(void) |
| 349 | { |
| 350 | return cec_parser ? (cec_parser->EnablePhysicalAddressDetection() ? 1 : 0) : -1; |
| 351 | } |
| 352 | |
| 353 | //@} |