gpt4 book ai didi

c++ - cec 代码不适用于 libcec 4

转载 作者:太空宇宙 更新时间:2023-11-04 12:19:15 27 4
gpt4 key购买 nike

我在 raspberry pi 1 上运行 stretch。repo 中只有 libcec4 和 libcec4-dev 可用。

我从 github 中找到的简单代码基于旧版本的 libcec。

// Build command:
// g++-4.8 -std=gnu++0x -fPIC -g -Wall -march=armv6 -mfpu=vfp -mfloat-abi=hard -isystem /opt/vc/include/ -isystem /opt/vc/include/interface/vcos/pthreads/ -isystem /opt/vc/include/interface/vmcs_host/linux/ -I/usr/local/include -L /opt/vc/lib -lcec -lbcm_host -ldl cec-simplest.cpp -o cec-simplest
//#CXXFLAGS=-I/usr/local/include
//#LINKFLAGS=-lcec -ldl
#include <libcec/cec.h>

// cecloader.h uses std::cout _without_ including iosfwd or iostream
// Furthermore is uses cout and not std::cout
#include <iostream>
using std::cout;
using std::endl;
#include <libcec/cecloader.h>

#include "bcm_host.h"
//#LINKFLAGS=-lbcm_host

#include <algorithm> // for std::min

// The main loop will just continue until a ctrl-C is received
#include <signal.h>
bool exit_now = false;
void handle_signal(int signal)
{
exit_now = true;
}


//CEC::CBCecKeyPressType
int on_keypress(void* not_used, const CEC::cec_keypress msg)
{
std::string key;
switch( msg.keycode )
{
case CEC::CEC_USER_CONTROL_CODE_SELECT: { key = "select"; break; }
case CEC::CEC_USER_CONTROL_CODE_UP: { key = "up"; break; }
case CEC::CEC_USER_CONTROL_CODE_DOWN: { key = "down"; break; }
case CEC::CEC_USER_CONTROL_CODE_LEFT: { key = "left"; break; }
case CEC::CEC_USER_CONTROL_CODE_RIGHT: { key = "right"; break; }
default: break;
};

std::cout << "on_keypress: " << static_cast<int>(msg.keycode) << " " << key << std::endl;
return 0;
}


int main(int argc, char* argv[])
{
// Install the ctrl-C signal handler
if( SIG_ERR == signal(SIGINT, handle_signal) )
{
std::cerr << "Failed to install the SIGINT signal handler\n";
return 1;
}

// Initialise the graphics pipeline for the raspberry pi. Yes, this is necessary.
bcm_host_init();

// Set up the CEC config and specify the keypress callback function
CEC::ICECCallbacks cec_callbacks;
CEC::libcec_configuration cec_config;
cec_config.Clear();
cec_callbacks.Clear();

const std::string devicename("CECExample");
devicename.copy(cec_config.strDeviceName, std::min(devicename.size(),13u) );

cec_config.clientVersion = CEC::LIBCEC_VERSION_CURRENT;
cec_config.bActivateSource = 0;
cec_config.callbacks = &cec_callbacks;
cec_config.deviceTypes.Add(CEC::CEC_DEVICE_TYPE_RECORDING_DEVICE);

cec_callbacks.CBCecKeyPress = &on_keypress;

// Get a cec adapter by initialising the cec library
CEC::ICECAdapter* cec_adapter = LibCecInitialise(&cec_config);
if( !cec_adapter )
{
std::cerr << "Failed loading libcec.so\n";
return 1;
}

// Try to automatically determine the CEC devices
CEC::cec_adapter devices[10];
int8_t devices_found = cec_adapter->FindAdapters(devices, 10, NULL);
if( devices_found <= 0)
{
std::cerr << "Could not automatically determine the cec adapter devices\n";
UnloadLibCec(cec_adapter);
return 1;
}

// Open a connection to the zeroth CEC device
if( !cec_adapter->Open(devices[0].comm) )
{
std::cerr << "Failed to open the CEC device on port " << devices[0].comm << std::endl;
UnloadLibCec(cec_adapter);
return 1;
}

// Loop until ctrl-C occurs
while( !exit_now )
{
// nothing to do. All happens in the CEC callback on another thread
sleep(1);
}

// Close down and cleanup
cec_adapter->Close();
UnloadLibCec(cec_adapter);

return 0;
}

它不使用 libcec4 和 libcec4-dev 编译并抛出这些错误::

cec-simplest.cpp: In function ‘int main(int, char**)’:
cec-simplest.cpp:76:19: error: ‘CEC::ICECCallbacks {aka struct CEC::ICECCallbacks}’ has no member named ‘CBCecKeyPress’; did you mean ‘keyPress’?
cec_callbacks.CBCecKeyPress = &on_keypress;
^~~~~~~~~~~~~
cec-simplest.cpp:88:41: error: ‘class CEC::ICECAdapter’ has no member named ‘FindAdapters’; did you mean ‘PingAdapter’?
int8_t devices_found = cec_adapter->FindAdapters(devices, 10, NULL);

当我将 CBCecKeyPress 重命名为 keyPress 并将 FindAdapters 重命名为 PingAdapter 时,我遇到了这些错误::

cec-simplest.cpp: In function ‘int main(int, char**)’:
cec-simplest.cpp:76:33: error: invalid conversion from ‘int (*)(void*, CEC::cec_keypress)’ to ‘void (*)(void*, const cec_keypress*) {aka void (*)(void*, const CEC::cec_keypress*)}’ [-fpermissive]
cec_callbacks.keyPress = &on_keypress;
^~~~~~~~~~~~
cec-simplest.cpp:88:70: error: no matching function for call to ‘CEC::ICECAdapter::PingAdapter(CEC::cec_adapter [10], int, NULL)’
int8_t devices_found = cec_adapter->PingAdapter(devices, 10, NULL);
^
In file included from cec-simplest.cpp:5:0:
/usr/include/libcec/cec.h:77:18: note: candidate: virtual bool CEC::ICECAdapter::PingAdapter()
virtual bool PingAdapter(void) = 0;
^~~~~~~~~~~
/usr/include/libcec/cec.h:77:18: note: candidate expects 0 arguments, 3 provided

我从 /usr/include/libcec/cectypes.h 中得到的关于 keyPress 的一些信息::

typedef struct cec_keypress
{
cec_user_control_code keycode; /**< the keycode */
unsigned int duration; /**< the duration of the keypress */
} cec_keypress;


typedef struct ICECCallbacks
{
void (CEC_CDECL* keyPress)(void* cbparam, const cec_keypress* key);

/*!
* @brief Transfer a CEC command from libCEC to the client.
* @param cbparam Callback parameter provided when the callbacks were set up
* @param command The command to transfer.
*/

void Clear(void)
{
keyPress = nullptr;

没有可用于 libcec 的文档。

我需要做哪些修改才能使其与 libcec4 一起使用?

最佳答案

我是您询问的代码的作者。我知道你问这个问题已经一年了,但我只是偶然发现了这个 stackoverflow 问题,因为我自己正在寻找解决方案!哈哈。幸好我自己解决了这个问题。

我已经更新了 github 代码以工作 https://github.com/DrGeoff/cec_simplest我写了一篇关于代码 https://drgeoffathome.wordpress.com/2018/10/07/a-simple-libcec4-example-for-the-raspberry-pi/ 的博文

简而言之,这些是我必须做出的改变。首先,on_keypress 函数现在传递一个指向 cec_keypress 消息的指针,而不是消息的按值拷贝。下一个变化是 CEC 框架将回调函数的名称从 CBCecKeyPress 更改为简单的 keyPress。同样,FindAdapters 函数现在是 DetectAdapters(不是您尝试过的 PingAdapters)。最后,DetectAdapters 函数填充 cec_adapter_descriptor 数组而不是 cec_adapter,它对 Open< 有影响/em> 调用 strComName 而不是简单的 comm

关于c++ - cec 代码不适用于 libcec 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46493851/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com