Skip to content

Commit

Permalink
fixed: v4 compatiblity
Browse files Browse the repository at this point in the history
only the main lib is fully compatible.
LibCecSharp is initialised differently now
  • Loading branch information
opdenkamp committed Jul 10, 2020
1 parent 26febbf commit 0aae238
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 87 deletions.
18 changes: 17 additions & 1 deletion include/cec.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,13 @@ namespace CEC
*/
virtual uint8_t VolumeDown(bool bSendRelease = true) = 0;

#if CEC_LIB_VERSION_MAJOR >= 5
/*!
* @brief Toggles the mute status of an audiosystem, if it's present
* @return The new audio status.
*/
virtual uint8_t MuteAudio(void) = 0;
#endif

/*!
* @brief Send a keypress to a device on the CEC bus.
Expand Down Expand Up @@ -318,7 +320,19 @@ namespace CEC
/*!
* @return True if this CEC adapter can save the user configuration, false otherwise.
*/
#if CEC_LIB_VERSION_MAJOR >= 5
virtual bool CanSaveConfiguration(void) = 0;
#else
virtual bool CanPersistConfiguration(void) = 0;

/*!
* @deprecated Use SetConfiguration() instead
* @brief Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported)
* @brief configuration The configuration to store.
* @return True when the configuration was persisted, false otherwise.
*/
virtual bool PersistConfiguration(libcec_configuration *configuration) = 0;
#endif

/*!
* @brief Tell libCEC to poll for active devices on the bus.
Expand All @@ -339,6 +353,7 @@ namespace CEC
*/
virtual bool GetDeviceInformation(const char *strPort, libcec_configuration *config, uint32_t iTimeoutMs = 10000) = 0;

#if CEC_LIB_VERSION_MAJOR >= 5
/*!
* @brief Set and enable the callback methods
* @param callbacks The callbacks to set.
Expand All @@ -352,7 +367,7 @@ namespace CEC
* @return True if disabled, false otherwise.
*/
virtual bool DisableCallbacks(void) = 0;

#else
/*!
* @deprecated
* @brief Set and enable the callback methods.
Expand All @@ -361,6 +376,7 @@ namespace CEC
* @return True when enabled, false otherwise.
*/
virtual bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks) = 0;
#endif

/*!
* @brief Changes the active HDMI port.
Expand Down
10 changes: 10 additions & 0 deletions include/cecc.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ extern DECLSPEC void libcec_destroy(libcec_connection_t connection);
extern DECLSPEC int libcec_open(libcec_connection_t connection, const char* strPort, uint32_t iTimeout);
extern DECLSPEC void libcec_close(libcec_connection_t connection);
extern DECLSPEC void libcec_clear_configuration(CEC_NAMESPACE libcec_configuration* configuration);
#if CEC_LIB_VERSION_MAJOR >= 5
extern DECLSPEC int libcec_set_callbacks(libcec_connection_t connection, CEC_NAMESPACE ICECCallbacks* callbacks, void* cbParam);
extern DECLSPEC int libcec_disabled_callbacks(libcec_connection_t connection);
#else
extern DECLSPEC int libcec_enable_callbacks(libcec_connection_t connection, void* cbParam, CEC_NAMESPACE ICECCallbacks* callbacks);
#endif
extern DECLSPEC int8_t libcec_find_adapters(libcec_connection_t connection, CEC_NAMESPACE cec_adapter* deviceList, uint8_t iBufSize, const char* strDevicePath);
extern DECLSPEC int libcec_ping_adapters(libcec_connection_t connection);
extern DECLSPEC int libcec_start_bootloader(libcec_connection_t connection);
Expand Down Expand Up @@ -85,15 +88,22 @@ extern DECLSPEC int libcec_is_active_device_type(libcec_connection_t connection,
extern DECLSPEC int libcec_set_hdmi_port(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address baseDevice, uint8_t iPort);
extern DECLSPEC int libcec_volume_up(libcec_connection_t connection, int bSendRelease);
extern DECLSPEC int libcec_volume_down(libcec_connection_t connection, int bSendRelease);
#if CEC_LIB_VERSION_MAJOR >= 5
extern DECLSPEC int libcec_mute_audio(libcec_connection_t connection, int bSendRelease);
#endif
extern DECLSPEC int libcec_send_keypress(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iDestination, CEC_NAMESPACE cec_user_control_code key, int bWait);
extern DECLSPEC int libcec_send_key_release(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iDestination, int bWait);
extern DECLSPEC int libcec_get_device_osd_name(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iAddress, CEC_NAMESPACE cec_osd_name name);
extern DECLSPEC int libcec_set_stream_path_logical(libcec_connection_t connection, CEC_NAMESPACE cec_logical_address iAddress);
extern DECLSPEC int libcec_set_stream_path_physical(libcec_connection_t connection, uint16_t iPhysicalAddress);
extern DECLSPEC CEC_NAMESPACE cec_logical_addresses libcec_get_logical_addresses(libcec_connection_t connection);
extern DECLSPEC int libcec_get_current_configuration(libcec_connection_t connection, CEC_NAMESPACE libcec_configuration* configuration);
#if CEC_LIB_VERSION_MAJOR >= 5
extern DECLSPEC int libcec_can_save_configuration(libcec_connection_t connection);
#else
extern DECLSPEC int libcec_can_persist_configuration(libcec_connection_t connection);
extern DECLSPEC int libcec_persist_configuration(libcec_connection_t connection, CEC_NAMESPACE libcec_configuration* configuration);
#endif
extern DECLSPEC int libcec_set_configuration(libcec_connection_t connection, const CEC_NAMESPACE libcec_configuration* configuration);
extern DECLSPEC void libcec_rescan_devices(libcec_connection_t connection);
extern DECLSPEC int libcec_is_libcec_active_source(libcec_connection_t connection);
Expand Down
25 changes: 25 additions & 0 deletions project/nsis/cec-tray.nsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Section "libCEC Tray" SecTray
SetShellVarContext current
SectionIn 1

; Copy to the installation directory
SetOutPath "$INSTDIR\x86\netfx"
File "..\build\x86\cec-tray.exe"
SetOutPath "$INSTDIR\x64\netfx"
File /nonfatal "..\build\amd64\cec-tray.exe"

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
SetOutPath "$INSTDIR"

CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
${If} ${RunningX64}
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x64\netfx\cec-tray.exe" \
"" "$INSTDIR\x64\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
"" "Start libCEC Tray (x64)."
${Else}
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x86\netfx\cec-tray.exe" \
"" "$INSTDIR\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
"" "Start libCEC Tray."
${EndIf}
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
42 changes: 11 additions & 31 deletions project/nsis/sections.nsh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Section "libCEC for .Net Framework" SecDotNet
SetOutPath "$INSTDIR\x86\netfx"
File "..\build\x86\LibCecSharp.dll"
File "..\build\x86\LibCecSharp.xml"
File "..\build\x86\CecSharpTester.exe"
File /nonfatal "..\build\x86\CecSharpTester.exe"

${If} ${RunningX64}
; Moved to netfx subdir
Expand Down Expand Up @@ -139,11 +139,11 @@ Section "libCEC for .Net Core" SecDotNetCore
File "..\build\x86\netcore\LibCecSharpCore.dll"
File "..\build\x86\netcore\LibCecSharpCore.runtimeconfig.json"
File "..\build\x86\netcore\LibCecSharpCore.xml"
File "..\build\x86\netcore\CecSharpCoreTester.exe"
File "..\build\x86\netcore\CecSharpCoreTester.deps.json"
File "..\build\x86\netcore\CecSharpCoreTester.dll"
File "..\build\x86\netcore\CecSharpCoreTester.runtimeconfig.json"
File "..\build\x86\netcore\Ijwhost.dll"
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.exe"
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.deps.json"
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.dll"
File /nonfatal "..\build\x86\netcore\CecSharpCoreTester.runtimeconfig.json"
File /nonfatal "..\build\x86\netcore\Ijwhost.dll"

${If} ${RunningX64}
SetOutPath "$INSTDIR\x64\netcore"
Expand All @@ -159,31 +159,9 @@ Section "libCEC for .Net Core" SecDotNetCore
${EndIf}
SectionEnd

Section "libCEC Tray" SecTray
SetShellVarContext current
SectionIn 1

; Copy to the installation directory
SetOutPath "$INSTDIR\x86\netfx"
File "..\build\x86\cec-tray.exe"
SetOutPath "$INSTDIR\x64\netfx"
File /nonfatal "..\build\amd64\cec-tray.exe"

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
SetOutPath "$INSTDIR"

CreateDirectory "$SMPROGRAMS\$StartMenuFolder"
${If} ${RunningX64}
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x64\netfx\cec-tray.exe" \
"" "$INSTDIR\x64\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
"" "Start libCEC Tray (x64)."
${Else}
CreateShortCut "$SMPROGRAMS\$StartMenuFolder\cec-tray.lnk" "$INSTDIR\x86\netfx\cec-tray.exe" \
"" "$INSTDIR\netfx\cec-tray.exe" 0 SW_SHOWNORMAL \
"" "Start libCEC Tray."
${EndIf}
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd
!ifdef NSISDOTNETAPPS
!include "nsis\cec-tray.nsh"
!endif

Section "libCEC client (cec-client)" SecCecClient
SetShellVarContext current
Expand Down Expand Up @@ -309,13 +287,15 @@ SectionEnd

; Required options
Function .onSelChange
!ifdef NSISDOTNETAPPS
${If} ${SectionIsSelected} ${SecTray}
!define /math MYSECTIONFLAGS ${SF_SELECTED} | ${SF_RO}
!insertmacro SetSectionFlag ${SecDotNet} ${MYSECTIONFLAGS}
!undef MYSECTIONFLAGS
${Else}
!insertmacro ClearSectionFlag ${SecDotNet} ${SF_RO}
${EndIf}
!endif

${If} ${SectionIsSelected} ${SecPythonCecClient}
!define /math MYSECTIONFLAGS ${SF_SELECTED} | ${SF_RO}
Expand Down
2 changes: 2 additions & 0 deletions src/dotnetlib/CecSharpTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ namespace CecSharp
On = 1
};

#if CEC_LIB_VERSION_MAJOR >= 5
/// <summary>
/// A setting that can be enabled, disabled or not changed
/// </summary>
Expand All @@ -1145,6 +1146,7 @@ namespace CecSharp
/// </summary>
NotSet = 2
};
#endif

/// <summary>
/// Type of adapter to which libCEC is connected
Expand Down
33 changes: 27 additions & 6 deletions src/dotnetlib/LibCecSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ namespace CecSharp
/// <returns>True when a connection was opened, false otherwise.</returns>
bool Open(String ^ strPort, int iTimeoutMs)
{
if (!m_libCec) {
if (!m_libCec)
return false;
}
marshal_context ^ context = gcnew marshal_context();
const char* strPortC = context->marshal_as<const char*>(strPort);
bool bReturn = m_libCec->Open(strPortC, iTimeoutMs);
Expand All @@ -125,22 +124,31 @@ namespace CecSharp
/// </summary>
void Close(void)
{
if (m_libCec) {
if (!!m_libCec)
m_libCec->Close();
}
}

void EnableCallbacks(void)
{
if (m_libCec) {
if (!!m_libCec)
{
#if CEC_LIB_VERSION_MAJOR >= 5
m_libCec->SetCallbacks(GetLibCecCallbacks(), m_callbacks->Get());
#else
m_libCec->EnableCallbacks(m_callbacks->Get(), GetLibCecCallbacks());
#endif
}
}

void DisableCallbacks(void)
{
if (m_libCec) {
if (!!m_libCec)
{
#if CEC_LIB_VERSION_MAJOR >= 5
m_libCec->DisableCallbacks();
#else
m_libCec->EnableCallbacks(nullptr, nullptr);
#endif
}
}

Expand Down Expand Up @@ -606,11 +614,24 @@ namespace CecSharp
/// Check whether the CEC adapter can save a configuration.
/// </summary>
/// <returns>True when this CEC adapter can save the user configuration, false otherwise.</returns>
#if CEC_LIB_VERSION_MAJOR >= 5
bool CanSaveConfiguration(void)
{
return !!m_libCec &&
m_libCec->CanSaveConfiguration();
}
#else
bool CanPersistConfiguration(void)
{
return !!m_libCec &&
m_libCec->CanPersistConfiguration();
}

bool PersistConfiguration(LibCECConfiguration ^configuration)
{
return SetConfiguration(configuration);
}
#endif

/// <summary>
/// Change libCEC's configuration. Store it updated settings in the eeprom of the device (if supported)
Expand Down
20 changes: 20 additions & 0 deletions src/libcec/LibCEC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bool CLibCEC::PingAdapter(void)
return m_client ? m_client->PingAdapter() : false;
}

#if CEC_LIB_VERSION_MAJOR >= 5
bool CLibCEC::SetCallbacks(ICECCallbacks *callbacks, void *cbParam)
{
return !!m_client ? m_client->EnableCallbacks(cbParam, callbacks) : false;
Expand All @@ -139,6 +140,12 @@ bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)
{
return SetCallbacks(callbacks, cbParam);
}
#else
bool CLibCEC::EnableCallbacks(void *cbParam, ICECCallbacks *callbacks)
{
return !!m_client ? m_client->EnableCallbacks(cbParam, callbacks) : false;
}
#endif

bool CLibCEC::GetCurrentConfiguration(libcec_configuration *configuration)
{
Expand All @@ -150,11 +157,22 @@ bool CLibCEC::SetConfiguration(const libcec_configuration *configuration)
return m_client ? m_client->SetConfiguration(*configuration) : false;
}

#if CEC_LIB_VERSION_MAJOR >= 5
bool CLibCEC::CanSaveConfiguration(void)
#else
bool CLibCEC::CanPersistConfiguration(void)
#endif
{
return m_client ? m_client->CanSaveConfiguration() : false;
}

#if CEC_LIB_VERSION_MAJOR < 5
bool CLibCEC::PersistConfiguration(libcec_configuration *configuration)
{
return SetConfiguration(configuration);
}
#endif

void CLibCEC::RescanActiveDevices(void)
{
if (m_client)
Expand Down Expand Up @@ -290,12 +308,14 @@ uint8_t CLibCEC::VolumeDown(bool bSendRelease /* = true */)
return m_client ? m_client->SendVolumeDown(bSendRelease) : (uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
}

#if CEC_LIB_VERSION_MAJOR >= 5
uint8_t CLibCEC::MuteAudio(void)
{
return !!m_client ?
m_client->SendMuteAudio() :
(uint8_t)CEC_AUDIO_VOLUME_STATUS_UNKNOWN;
}
#endif

bool CLibCEC::SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait /* = true */)
{
Expand Down
9 changes: 9 additions & 0 deletions src/libcec/LibCEC.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ namespace CEC

bool Open(const char *strPort, uint32_t iTimeout = CEC_DEFAULT_CONNECT_TIMEOUT);
void Close(void);
#if CEC_LIB_VERSION_MAJOR >= 5
bool SetCallbacks(ICECCallbacks *callbacks, void *cbParam);
bool DisableCallbacks(void);
#endif
bool EnableCallbacks(void *cbParam, ICECCallbacks *callbacks);
int8_t FindAdapters(cec_adapter *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL);
int8_t DetectAdapters(cec_adapter_descriptor *deviceList, uint8_t iBufSize, const char *strDevicePath = NULL, bool bQuickScan = false);
Expand Down Expand Up @@ -96,7 +98,9 @@ namespace CEC
bool SetHDMIPort(cec_logical_address iBaseDevice, uint8_t iPort = CEC_DEFAULT_HDMI_PORT);
uint8_t VolumeUp(bool bSendRelease = true);
uint8_t VolumeDown(bool bSendRelease = true);
#if CEC_LIB_VERSION_MAJOR >= 5
uint8_t MuteAudio(void);
#endif
bool SendKeypress(cec_logical_address iDestination, cec_user_control_code key, bool bWait = true);
bool SendKeyRelease(cec_logical_address iDestination, bool bWait = true);
std::string GetDeviceOSDName(cec_logical_address iAddress);
Expand All @@ -107,7 +111,12 @@ namespace CEC
cec_logical_addresses GetLogicalAddresses(void);
bool GetCurrentConfiguration(libcec_configuration *configuration);
bool SetConfiguration(const libcec_configuration *configuration);
#if CEC_LIB_VERSION_MAJOR >= 5
bool CanSaveConfiguration(void);
#else
bool CanPersistConfiguration(void);
bool PersistConfiguration(libcec_configuration *configuration);
#endif
void RescanActiveDevices(void);
bool IsLibCECActiveSource(void);

Expand Down
Loading

0 comments on commit 0aae238

Please sign in to comment.