From 988de7b930e56f4acc1d03afd5e01cea9b67754f Mon Sep 17 00:00:00 2001 From: Lars Op den Kamp Date: Mon, 28 Nov 2011 13:05:57 +0100 Subject: [PATCH] cec: new libCEC methods added to LibCecSharp. fixed some compiler warnings --- src/LibCecSharp/LibCecSharp.cpp | 159 ++++++++++++++++++++++++++++++- src/lib/CECProcessor.cpp | 3 +- src/lib/LibCEC.cpp | 1 + src/lib/LibCECC.cpp | 1 + src/lib/devices/CECBusDevice.cpp | 2 +- src/testclient/main.cpp | 6 +- 6 files changed, 166 insertions(+), 6 deletions(-) diff --git a/src/LibCecSharp/LibCecSharp.cpp b/src/LibCecSharp/LibCecSharp.cpp index 0aec2ff..6e4895e 100644 --- a/src/LibCecSharp/LibCecSharp.cpp +++ b/src/LibCecSharp/LibCecSharp.cpp @@ -144,6 +144,90 @@ public enum class CecDeckInfo OtherStatus = 0x1F }; +public enum class CecUserControlCode +{ + Select = 0x00, + Up = 0x01, + Down = 0x02, + Left = 0x03, + Right = 0x04, + RightUp = 0x05, + RightDown = 0x06, + LeftUp = 0x07, + LeftDown = 0x08, + RootMenu = 0x09, + SetupMenu = 0x0A, + ContentsMenu = 0x0B, + FavoriteMenu = 0x0C, + Exit = 0x0D, + Number0 = 0x20, + Number1 = 0x21, + Number2 = 0x22, + Number3 = 0x23, + Number4 = 0x24, + Number5 = 0x25, + Number6 = 0x26, + Number7 = 0x27, + Number8 = 0x28, + Number9 = 0x29, + Dot = 0x2A, + Enter = 0x2B, + Clear = 0x2C, + NextFavorite = 0x2F, + ChannelUp = 0x30, + ChannelDown = 0x31, + PreviousChannel = 0x32, + SoundSelect = 0x33, + InputSelect = 0x34, + DisplayInformation = 0x35, + Help = 0x36, + PageUp = 0x37, + PageDown = 0x38, + Power = 0x40, + VolumeUp = 0x41, + VolumeDown = 0x42, + Mute = 0x43, + Play = 0x44, + Stop = 0x45, + Pause = 0x46, + Record = 0x47, + Rewind = 0x48, + FastForward = 0x49, + Eject = 0x4A, + Forward = 0x4B, + Backward = 0x4C, + StopRecord = 0x4D, + PauseRecord = 0x4E, + Angle = 0x50, + SubPicture = 0x51, + VideoOnDemand = 0x52, + ElectronicProgramGuide = 0x53, + TimerProgramming = 0x54, + InitialConfiguration = 0x55, + PlayFunction = 0x60, + PausePlayFunction = 0x61, + RecordFunction = 0x62, + PauseRecordFunction = 0x63, + StopFunction = 0x64, + MuteFunction = 0x65, + RestoreVolumeFunction = 0x66, + TuneFunction = 0x67, + SelectMediaFunction = 0x68, + SelectAVInputFunction = 0x69, + SelectAudioInputFunction = 0x6A, + PowerToggleFunction = 0x6B, + PowerOffFunction = 0x6C, + PowerOnFunction = 0x6D, + F1Blue = 0x71, + F2Red = 0X72, + F3Green = 0x73, + F4Yellow = 0x74, + F5 = 0x75, + Data = 0x76, + Max = 0x76, + Unknown +}; + public ref class CecAdapter { public: @@ -170,6 +254,19 @@ public: property array ^ Types; }; +public ref class CecLogicalAddresses +{ +public: + CecLogicalAddresses(void) + { + Addresses = gcnew array(16); + for (unsigned int iPtr = 0; iPtr < 16; iPtr++) + Addresses[iPtr] = CecLogicalAddress::Unregistered; + } + + property array ^ Addresses; +}; + public ref class CecDatapacket { public: @@ -525,6 +622,66 @@ public: return (CecPowerStatus) m_libCec->GetDevicePowerStatus((cec_logical_address) logicalAddress); } + CecLogicalAddresses ^ GetActiveDevices(void) + { + CecLogicalAddresses ^ retVal = gcnew CecLogicalAddresses(); + unsigned int iDevices = 0; + + cec_logical_addresses activeDevices = m_libCec->GetActiveDevices(); + + for (uint8_t iPtr = 0; iPtr < 16; iPtr++) + if (activeDevices[iPtr]) + retVal->Addresses[iDevices++] = (CecLogicalAddress)iPtr; + + return retVal; + } + + bool IsActiveDevice(CecLogicalAddress logicalAddress) + { + return m_libCec->IsActiveDevice((cec_logical_address)logicalAddress); + } + + bool IsActiveDeviceType(CecDeviceType type) + { + return m_libCec->IsActiveDeviceType((cec_device_type)type); + } + + bool SetHDMIPort(uint8_t port) + { + return m_libCec->SetHDMIPort(port); + } + + uint8_t VolumeUp(bool wait) + { + return m_libCec->VolumeUp(wait); + } + + uint8_t VolumeDown(bool wait) + { + return m_libCec->VolumeDown(wait); + } + + uint8_t MuteAudio(bool wait) + { + return m_libCec->MuteAudio(wait); + } + + bool SendKeypress(CecLogicalAddress destination, CecUserControlCode key, bool wait) + { + return m_libCec->SendKeypress((cec_logical_address)destination, (cec_user_control_code)key, wait); + } + + bool SendKeyRelease(CecLogicalAddress destination, bool wait) + { + return m_libCec->SendKeyRelease((cec_logical_address)destination, wait); + } + + String ^ GetOSDName(CecLogicalAddress logicalAddress) + { + cec_osd_name osd = m_libCec->GetOSDName((cec_logical_address) logicalAddress); + return gcnew String(osd.name); + } + private: - ICECAdapter * m_libCec; + ICECAdapter *m_libCec; }; diff --git a/src/lib/CECProcessor.cpp b/src/lib/CECProcessor.cpp index 8c95da7..772f1e2 100644 --- a/src/lib/CECProcessor.cpp +++ b/src/lib/CECProcessor.cpp @@ -273,7 +273,7 @@ void *CCECProcessor::Process(void) m_controller->CheckKeypressTimeout(); - for (unsigned int iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) + for (uint8_t iDevicePtr = 0; iDevicePtr < 16; iDevicePtr++) { if (!m_logicalAddresses[iDevicePtr]) m_busDevices[iDevicePtr]->PollVendorId(); @@ -767,6 +767,7 @@ void CCECProcessor::ParseCommand(cec_command &command) cec_logical_addresses CCECProcessor::GetActiveDevices(void) { cec_logical_addresses addresses; + addresses.Clear(); for (unsigned int iPtr = 0; iPtr < 15; iPtr++) { if (m_busDevices[iPtr]->GetStatus() == CEC_DEVICE_STATUS_PRESENT) diff --git a/src/lib/LibCEC.cpp b/src/lib/LibCEC.cpp index 92f00c3..5247487 100644 --- a/src/lib/LibCEC.cpp +++ b/src/lib/LibCEC.cpp @@ -261,6 +261,7 @@ bool CLibCEC::PollDevice(cec_logical_address iAddress) cec_logical_addresses CLibCEC::GetActiveDevices(void) { cec_logical_addresses addresses; + addresses.Clear(); if (m_cec) addresses = m_cec->GetActiveDevices(); return addresses; diff --git a/src/lib/LibCECC.cpp b/src/lib/LibCECC.cpp index 54b82f9..e71cd11 100644 --- a/src/lib/LibCECC.cpp +++ b/src/lib/LibCECC.cpp @@ -245,6 +245,7 @@ int cec_poll_device(cec_logical_address iLogicalAddress) cec_logical_addresses cec_get_active_devices(void) { cec_logical_addresses addresses; + addresses.Clear(); if (cec_parser) addresses = cec_parser->GetActiveDevices(); return addresses; diff --git a/src/lib/devices/CECBusDevice.cpp b/src/lib/devices/CECBusDevice.cpp index 52d71df..b54e0a5 100644 --- a/src/lib/devices/CECBusDevice.cpp +++ b/src/lib/devices/CECBusDevice.cpp @@ -790,7 +790,7 @@ bool CCECBusDevice::SendKeypress(cec_user_control_code key, bool bWait /* = fals CLockObject lock(&m_transmitMutex); cec_command command; cec_command::Format(command, m_processor->GetLogicalAddress(), m_iLogicalAddress, CEC_OPCODE_USER_CONTROL_PRESSED); - command.parameters.PushBack(key); + command.parameters.PushBack((uint8_t)key); if (bWait) { diff --git a/src/testclient/main.cpp b/src/testclient/main.cpp index d8daa8d..0a7a9be 100644 --- a/src/testclient/main.cpp +++ b/src/testclient/main.cpp @@ -371,7 +371,7 @@ int main (int argc, char *argv[]) { if (argc >= iArgPtr + 2) { - iHDMIPort= atoi(argv[iArgPtr + 1]); + iHDMIPort = (int8_t)atoi(argv[iArgPtr + 1]); cout << "using HDMI port '" << iHDMIPort << "'" << endl; ++iArgPtr; } @@ -561,7 +561,7 @@ int main (int argc, char *argv[]) string strvalue; if (GetWord(input, strvalue)) { - parser->SetHDMIPort(atoi(strvalue.c_str())); + parser->SetHDMIPort((uint8_t)atoi(strvalue.c_str())); } } else if (command == "pa") @@ -738,7 +738,7 @@ int main (int argc, char *argv[]) { cout << "listing active devices:" << endl; cec_logical_addresses addresses = parser->GetActiveDevices(); - for (unsigned iPtr = 0; iPtr < 16; iPtr++) + for (uint8_t iPtr = 0; iPtr < 16; iPtr++) if (addresses[iPtr]) cout << "logical address " << iPtr << endl; } -- 2.34.1