A simple libCEC example for the Raspberry Pi

After getting the libcec test client (cec-client) to run my thoughts turned to incorporating CEC control into my own code.  The source code for cec-client is 1145 lines long, according to sloccount, which takes a bit of time to get your head around. By tossing away almost all of cec-client’s features I have managed to create a 75 sloc example which is much easier to understand. The source code for this really short example can be found on github . 

The basic idea of the program is

  1. Initialise libcec
  2. Give libcec a callback that will handle the CEC keypresses
  3. Go to sleep until ctrl-c finishes the program

Any keys pressed on your remote control then wake up the callback function which I creatively called on_keypress.

Advertisements
Tagged with: , , ,
Posted in Uncategorized
3 comments on “A simple libCEC example for the Raspberry Pi
  1. Peter says:

    Hello DrGeoff,

    I tried to compile the file but everytime I got the erro:

    undefined reference to symbol ‘dlsym@@glibc_2.4’

    Do you know what this is?

    Thanks

    • Hi Peter,

      The short answer is that you haven’t linked against the dynamic linking loader.

      Just in case you are interested in how I figured that out: the words “undefined reference to symbol” are the tip off that the linking stage is where the problem is. The next bit is the actual symbol that is missing. So it would appear that dlsym from the glibc library has not been found. My next step would be to do “man dlsym” to get some more hints. If you do that you will find in the synopsis section “Link with -ldl”. So you need to make sure that you have “-ldl” in the compiler command that is doing the building.

      Did you use my build.sh script from the github repo? If not then take a look at that. You will notice that I did specify “-ldl” as part of the command line.

      If the build.sh is what failed for you then I’ll look deeper at the problem.

      Good luck,
      Geoff

  2. Sascha says:

    Thank you very much for this example! With this example i understand how to write a program to get the actual status from my tv.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: