2 * This file is part of the libCEC(R) library.
4 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited. All rights reserved.
5 * libCEC(R) is an original work, containing original code.
7 * libCEC(R) is a trademark of Pulse-Eight Limited.
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.
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.
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.
24 * Alternatively, you can license this library under a commercial license,
25 * please contact Pulse-Eight Licensing for more information.
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/
33 #include "CecSharpTypes.h"
36 using namespace System
;
37 using namespace System::Runtime::InteropServices
;
39 using namespace msclr::interop
;
43 public ref
class LibCecSharp
: public CecCallbackMethods
46 LibCecSharp(String
^ strDeviceName
, CecDeviceTypeList
^ deviceTypes
)
48 marshal_context
^ context
= gcnew
marshal_context();
49 m_bHasCallbacks
= false;
50 const char* strDeviceNameC
= context
->marshal_as
<const char*>(strDeviceName
);
52 cec_device_type_list types
;
53 for (unsigned int iPtr
= 0; iPtr
< 5; iPtr
++)
54 types
.types
[iPtr
] = (cec_device_type
)deviceTypes
->Types
[iPtr
];
55 m_libCec
= (ICECAdapter
*) CECInit(strDeviceNameC
, types
);
74 array
<CecAdapter
^> ^ FindAdapters(String
^ path
)
76 cec_adapter
*devices
= new cec_adapter
[10];
78 marshal_context
^ context
= gcnew
marshal_context();
79 const char* strPathC
= path
->Length
> 0 ? context
->marshal_as
<const char*>(path
) : NULL
;
81 uint8_t iDevicesFound
= m_libCec
->FindAdapters(devices
, 10, NULL
);
83 array
<CecAdapter
^> ^ adapters
= gcnew array
<CecAdapter
^>(iDevicesFound
);
84 for (unsigned int iPtr
= 0; iPtr
< iDevicesFound
; iPtr
++)
85 adapters
[iPtr
] = gcnew
CecAdapter(gcnew
String(devices
[iPtr
].path
), gcnew
String(devices
[iPtr
].comm
));
92 bool Open(String
^ strPort
, int iTimeoutMs
)
94 marshal_context
^ context
= gcnew
marshal_context();
95 const char* strPortC
= context
->marshal_as
<const char*>(strPort
);
96 bool bReturn
= m_libCec
->Open(strPortC
, iTimeoutMs
);
106 virtual bool EnableCallbacks(CecCallbackMethods
^ callbacks
) override
108 if (m_libCec
&& CecCallbackMethods::EnableCallbacks(callbacks
))
109 return m_libCec
->EnableCallbacks(NULL
, &g_cecCallbacks
);
114 bool PingAdapter(void)
116 return m_libCec
->PingAdapter();
119 bool StartBootloader(void)
121 return m_libCec
->StartBootloader();
124 int GetMinLibVersion(void)
126 return m_libCec
->GetMinLibVersion();
129 int GetLibVersionMajor(void)
131 return m_libCec
->GetLibVersionMajor();
134 int GetLibVersionMinor(void)
136 return m_libCec
->GetLibVersionMinor();
139 CecLogMessage
^ GetNextLogMessage(void)
142 if (m_libCec
->GetNextLogMessage(&msg
))
144 return gcnew
CecLogMessage(gcnew
String(msg
.message
), (CecLogLevel
)msg
.level
, msg
.time
);
147 return gcnew
CecLogMessage();
150 CecKeypress
^ GetNextKeypress(void)
153 if (m_libCec
->GetNextKeypress(&key
))
155 return gcnew
CecKeypress(key
.keycode
, key
.duration
);
158 return gcnew
CecKeypress();
161 CecCommand
^ GetNextCommand(void)
164 if (m_libCec
->GetNextCommand(&command
))
166 CecCommand
^ retVal
= gcnew
CecCommand((CecLogicalAddress
)command
.initiator
, (CecLogicalAddress
)command
.destination
, command
.ack
== 1 ? true : false, command
.eom
== 1 ? true : false, (CecOpcode
)command
.opcode
, command
.transmit_timeout
);
167 for (uint8_t iPtr
= 0; iPtr
< command
.parameters
.size
; iPtr
++)
168 retVal
->Parameters
->PushBack(command
.parameters
[iPtr
]);
172 return gcnew
CecCommand();
175 bool Transmit(CecCommand
^ command
)
177 cec_command ccommand
;
178 cec_command::Format(ccommand
, (cec_logical_address
)command
->Initiator
, (cec_logical_address
)command
->Destination
, (cec_opcode
)command
->Opcode
);
179 ccommand
.transmit_timeout
= command
->TransmitTimeout
;
180 ccommand
.eom
= command
->Eom
;
181 ccommand
.ack
= command
->Ack
;
182 for (unsigned int iPtr
= 0; iPtr
< command
->Parameters
->Size
; iPtr
++)
183 ccommand
.parameters
.PushBack(command
->Parameters
->Data
[iPtr
]);
185 return m_libCec
->Transmit(ccommand
);
188 bool SetLogicalAddress(CecLogicalAddress logicalAddress
)
190 return m_libCec
->SetLogicalAddress((cec_logical_address
) logicalAddress
);
193 bool SetPhysicalAddress(int16_t physicalAddress
)
195 return m_libCec
->SetPhysicalAddress(physicalAddress
);
198 bool PowerOnDevices(CecLogicalAddress logicalAddress
)
200 return m_libCec
->PowerOnDevices((cec_logical_address
) logicalAddress
);
203 bool StandbyDevices(CecLogicalAddress logicalAddress
)
205 return m_libCec
->StandbyDevices((cec_logical_address
) logicalAddress
);
208 bool PollDevice(CecLogicalAddress logicalAddress
)
210 return m_libCec
->PollDevice((cec_logical_address
) logicalAddress
);
213 bool SetActiveSource(CecDeviceType type
)
215 return m_libCec
->SetActiveSource((cec_device_type
) type
);
218 bool SetDeckControlMode(CecDeckControlMode mode
, bool sendUpdate
)
220 return m_libCec
->SetDeckControlMode((cec_deck_control_mode
) mode
, sendUpdate
);
223 bool SetDeckInfo(CecDeckInfo info
, bool sendUpdate
)
225 return m_libCec
->SetDeckInfo((cec_deck_info
) info
, sendUpdate
);
228 bool SetInactiveView(void)
230 return m_libCec
->SetInactiveView();
233 bool SetMenuState(CecMenuState state
, bool sendUpdate
)
235 return m_libCec
->SetMenuState((cec_menu_state
) state
, sendUpdate
);
238 bool SetOSDString(CecLogicalAddress logicalAddress
, CecDisplayControl duration
, String
^ message
)
240 marshal_context
^ context
= gcnew
marshal_context();
241 const char* strMessageC
= context
->marshal_as
<const char*>(message
);
243 bool bReturn
= m_libCec
->SetOSDString((cec_logical_address
) logicalAddress
, (cec_display_control
) duration
, strMessageC
);
249 bool SwitchMonitoring(bool enable
)
251 return m_libCec
->SwitchMonitoring(enable
);
254 CecVersion
GetDeviceCecVersion(CecLogicalAddress logicalAddress
)
256 return (CecVersion
) m_libCec
->GetDeviceCecVersion((cec_logical_address
) logicalAddress
);
259 String
^ GetDeviceMenuLanguage(CecLogicalAddress logicalAddress
)
261 cec_menu_language lang
;
262 if (m_libCec
->GetDeviceMenuLanguage((cec_logical_address
) logicalAddress
, &lang
))
264 return gcnew
String(lang
.language
);
267 return gcnew
String("");
270 CecVendorId
GetDeviceVendorId(CecLogicalAddress logicalAddress
)
272 return (CecVendorId
)m_libCec
->GetDeviceVendorId((cec_logical_address
) logicalAddress
);
275 CecPowerStatus
GetDevicePowerStatus(CecLogicalAddress logicalAddress
)
277 return (CecPowerStatus
) m_libCec
->GetDevicePowerStatus((cec_logical_address
) logicalAddress
);
280 CecLogicalAddresses
^ GetActiveDevices(void)
282 CecLogicalAddresses
^ retVal
= gcnew
CecLogicalAddresses();
283 unsigned int iDevices
= 0;
285 cec_logical_addresses activeDevices
= m_libCec
->GetActiveDevices();
287 for (uint8_t iPtr
= 0; iPtr
< 16; iPtr
++)
288 if (activeDevices
[iPtr
])
289 retVal
->Addresses
[iDevices
++] = (CecLogicalAddress
)iPtr
;
294 bool IsActiveDevice(CecLogicalAddress logicalAddress
)
296 return m_libCec
->IsActiveDevice((cec_logical_address
)logicalAddress
);
299 bool IsActiveDeviceType(CecDeviceType type
)
301 return m_libCec
->IsActiveDeviceType((cec_device_type
)type
);
304 bool SetHDMIPort(CecLogicalAddress address
, uint8_t port
)
306 return m_libCec
->SetHDMIPort((cec_logical_address
)address
, port
);
309 uint8_t VolumeUp(bool wait
)
311 return m_libCec
->VolumeUp(wait
);
314 uint8_t VolumeDown(bool wait
)
316 return m_libCec
->VolumeDown(wait
);
319 uint8_t MuteAudio(bool wait
)
321 return m_libCec
->MuteAudio(wait
);
324 bool SendKeypress(CecLogicalAddress destination
, CecUserControlCode key
, bool wait
)
326 return m_libCec
->SendKeypress((cec_logical_address
)destination
, (cec_user_control_code
)key
, wait
);
329 bool SendKeyRelease(CecLogicalAddress destination
, bool wait
)
331 return m_libCec
->SendKeyRelease((cec_logical_address
)destination
, wait
);
334 String
^ GetDeviceOSDName(CecLogicalAddress logicalAddress
)
336 cec_osd_name osd
= m_libCec
->GetDeviceOSDName((cec_logical_address
) logicalAddress
);
337 return gcnew
String(osd
.name
);
340 CecLogicalAddress
GetActiveSource()
342 return (CecLogicalAddress
)m_libCec
->GetActiveSource();
345 bool IsActiveSource(CecLogicalAddress logicalAddress
)
347 return m_libCec
->IsActiveSource((cec_logical_address
)logicalAddress
);
350 uint16_t GetDevicePhysicalAddress(CecLogicalAddress iAddress
)
352 return m_libCec
->GetDevicePhysicalAddress((cec_logical_address
)iAddress
);
355 String
^ ToString(CecLogicalAddress iAddress
)
357 const char *retVal
= m_libCec
->ToString((cec_logical_address
)iAddress
);
358 return gcnew
String(retVal
);
361 String
^ ToString(CecVendorId iVendorId
)
363 const char *retVal
= m_libCec
->ToString((cec_vendor_id
)iVendorId
);
364 return gcnew
String(retVal
);
367 String
^ ToString(CecVersion iVersion
)
369 const char *retVal
= m_libCec
->ToString((cec_version
)iVersion
);
370 return gcnew
String(retVal
);
373 String
^ ToString(CecPowerStatus iState
)
375 const char *retVal
= m_libCec
->ToString((cec_power_status
)iState
);
376 return gcnew
String(retVal
);
379 String
^ ToString(CecMenuState iState
)
381 const char *retVal
= m_libCec
->ToString((cec_menu_state
)iState
);
382 return gcnew
String(retVal
);
385 String
^ ToString(CecDeckControlMode iMode
)
387 const char *retVal
= m_libCec
->ToString((cec_deck_control_mode
)iMode
);
388 return gcnew
String(retVal
);
391 String
^ ToString(CecDeckInfo status
)
393 const char *retVal
= m_libCec
->ToString((cec_deck_info
)status
);
394 return gcnew
String(retVal
);
397 String
^ ToString(CecOpcode opcode
)
399 const char *retVal
= m_libCec
->ToString((cec_opcode
)opcode
);
400 return gcnew
String(retVal
);
403 String
^ ToString(CecSystemAudioStatus mode
)
405 const char *retVal
= m_libCec
->ToString((cec_system_audio_status
)mode
);
406 return gcnew
String(retVal
);
409 String
^ ToString(CecAudioStatus status
)
411 const char *retVal
= m_libCec
->ToString((cec_audio_status
)status
);
412 return gcnew
String(retVal
);
416 ICECAdapter
* m_libCec
;