Skip to content

Latest commit

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

CecSharp

A .net class library to facilitate HDMI-CEC communications.

Overview

This library can be used to create and parse HDMI Version 1.4 compliant CEC-messages for communication with HDMI-CEC devices. It can be used on top of other communication protocols and libraries which support CEC hardware, such as kwikwai HDMI-CEC AV-controllers or Pulse-Eight's USB-CEC adapter.

Installing via NuGet

Install-Package AleRoe.CecSharp

Basic Usage

CecSharp provides an object model for dealing with HDMI-CEC messages as well as emulating a HDMI-CEC device. The static CecMessageBuilder class can be used to create arbitrary HDMI-CEC frames which can be used to control devices on the HDMI-CEC bus. The CecDevice class represents a HDMI-CEC enabled device capable of responding to incoming HDMI-CEC messages via the ProcessCecMessage method.

CecDevice

To emulate a HDMI-CEC device, create a new CecDevice instance, specifying the device type, name, vendor, physical- and logical address. Use the ProcessCecMessage() and ToCec()methods to get the appropriate response depending on the device settings. Not all input messages will generate a response (like UserControlPressed, UserControlReleased or StandBy and messages not intended for this device) and instead return CecMessage.None.

// create devicevardevice=newCecDevice(DeviceType.PlaybackDevice,"OsdName",99999,PhysicalAddress.Parse("2.1.0.0"),LogicalAddress.Tuner3);// create a CecMessage from an incoming CEC-frame// i.e. a request to a device to return its physical address. (Directly addressed)varframe="07:83";varmessage=CecMessage.Parse(frame);// process the message to get the appropriate responsevarresponse=device.ProcessCecMessage(message).ToCec();// returns a ReportPhysicalAddress broadcast message which can be sent as a response// response = "7F:84:21:00:04"

CecMessageBuilder

In order to create arbitrary CEC-frames, use the static CecMessageBuilder class to build CecMessage structs.

publicstaticclassCecMessageBuilder{publicstaticCecMessageGivePhysicalAddress(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageReportPhysicalAddress(LogicalAddresssource,DeviceTypedeviceType,PhysicalAddressphysicalAddress);publicstaticCecMessageReportAudioStatus(LogicalAddresssource,LogicalAddressdestination,AudioMuteStatusstatus,intvalue);publicstaticCecMessageSetSystemAudioMode(LogicalAddresssource,LogicalAddressdestination,SystemAudioStatusstatus);publicstaticCecMessageDeviceVendorId(LogicalAddresssource,intvendorId);publicstaticCecMessageSetOsdName(LogicalAddresssource,LogicalAddressdestination,stringosdName);publicstaticCecMessageMenuStatus(LogicalAddresssource,LogicalAddressdestination,MenuStatusstate);publicstaticCecMessageInactiveSource(LogicalAddresssource,PhysicalAddressphysicalAddress);publicstaticCecMessageActiveSource(LogicalAddresssource,PhysicalAddressphysicalAddress);publicstaticCecMessageFeatureAbort(LogicalAddresssource,LogicalAddressdestination,CommandopCode,AbortReasonreason);publicstaticCecMessageCecVersion(LogicalAddresssource,LogicalAddressdestination,CecVersionversion);publicstaticCecMessageReportPowerStatus(LogicalAddresssource,LogicalAddressdestination,PowerStatusstatus);publicstaticCecMessagePolling(LogicalAddresssource);publicstaticCecMessageSetMenuLanguage(LogicalAddresssource,[NotNull]stringlanguage);publicstaticCecMessageGetMenuLanguage(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageSetOSDString(LogicalAddresssource,DisplayControldisplayControl,[NotNull]stringosdString);publicstaticCecMessageGiveOsdName(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageRequestActiveSource(LogicalAddresssource);publicstaticCecMessageSetStreamPath(PhysicalAddressphysicalAddress);publicstaticCecMessageRoutingChange(LogicalAddresssource,PhysicalAddressoriginalAddress,PhysicalAddressnewAddress);publicstaticCecMessageRoutingInformation(LogicalAddresssource,PhysicalAddressphysicalAddress);publicstaticCecMessageGiveDevicePowerStatus(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageGiveDeviceVendorId(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageVendorCommand(LogicalAddresssource,LogicalAddressdestination,byte[]data);publicstaticCecMessageVendorCommand(LogicalAddresssource,LogicalAddressdestination,stringdata);publicstaticCecMessageVendorCommandWithId(LogicalAddresssource,LogicalAddressdestination,intvendorId,byte[]data);publicstaticCecMessageVendorCommandWithId(LogicalAddresssource,LogicalAddressdestination,intvendorId,stringdata);publicstaticCecMessageVendorRemoteButtonDown(LogicalAddresssource,LogicalAddressdestination,byte[]data);publicstaticCecMessageVendorRemoteButtonDown(LogicalAddresssource,LogicalAddressdestination,stringdata);publicstaticCecMessageVendorRemoteButtonUp(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageStandby(LogicalAddresssource,LogicalAddressdestination);publicstaticCecMessageUserControlPressed(LogicalAddresssource,LogicalAddressdestination,UiCommandcommand);publicstaticCecMessageUserControlReleased(LogicalAddresssource,LogicalAddressdestination);}

Use the .ToCec() extension method to get the actual CEC-Message.

usingAleRoe.CecSharp;usingAleRoe.CecSharp.Extensions;varmessage=CecMessageBuilder.ActiveSource(LogicalAddress.Unregistered,PhysicalAddress.Parse("2.0.0.0"));varcec=message.ToCec();// cec = "FF:82:20:00"

Update v2.0.0

Library now targets net 8.0 only.

Update v1.4.0

Support for netstandard 2.1 removed. Library now targets net 7.0 only.

Update v1.2.0

CecSharp now fully supports the following HDMI-CEC features and their related commands for both CecMessageBuilder and ProcessCecMessage (where applicable):

  • System Information
  • OSD Display
  • Device OSD Name Transfer
  • Device Power Status
  • Routing Control
  • Vendor Specific Command
  • System Standby
  • Device Menu Control
  • Abort

Feedback

Please let me know if you are using this library and have any suggestions or questions.

About

A .net class library to facilitate HDMI-CEC communications.

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages