public virtual void ShowDialog(CecConfigGUI gui, CecLogicalAddress address, ref LibCecSharp lib, bool devicePresent, CecVendorId vendor, bool isActiveSource, ushort physicalAddress, CecVersion version, CecPowerStatus power, string osdName, string menuLanguage) { DeviceInformation di = new DeviceInformation(Gui, Address, ref Lib, devicePresent, vendor, isActiveSource, physicalAddress, version, power, osdName, menuLanguage); Gui.DisplayDialog(di, false); }
public virtual void ShowDialog(CecLogicalAddress address, ref LibCecSharp lib, bool devicePresent, CecVendorId vendor, bool isActiveSource, ushort physicalAddress, CecVersion version, CecPowerStatus power, string osdName, string menuLanguage) { DeviceInformation di = new DeviceInformation(_controller, _address, ref _lib, devicePresent, vendor, isActiveSource, physicalAddress, version, power, osdName, menuLanguage); _controller.DisplayDialog(di, false); }
public override void Process() { CecVendorId vendor = CecVendorId.Unknown; bool isActiveSource = false; ushort physicalAddress = 0xFFFF; CecVersion version = CecVersion.Unknown; CecPowerStatus power = CecPowerStatus.Unknown; string osdName = Resources.unknown; string menuLanguage = Resources.unknown; SendEvent(UpdateEventType.StatusText, string.Format(Resources.action_check_device_present, _lib.ToString(_address))); SendEvent(UpdateEventType.ProgressBar, 10); bool devicePresent = _lib.IsActiveDevice(_address); if (devicePresent) { SendEvent(UpdateEventType.StatusText, Resources.action_requesting_vendor_id); SendEvent(UpdateEventType.ProgressBar, 20); vendor = _lib.GetDeviceVendorId(_address); SendEvent(UpdateEventType.StatusText, Resources.action_requesting_active_source_state); SendEvent(UpdateEventType.ProgressBar, 30); isActiveSource = _lib.IsActiveSource(_address); SendEvent(UpdateEventType.StatusText, Resources.action_requesting_physical_address); SendEvent(UpdateEventType.ProgressBar, 40); physicalAddress = _lib.GetDevicePhysicalAddress(_address); SendEvent(UpdateEventType.StatusText, Resources.action_requesting_cec_version); SendEvent(UpdateEventType.ProgressBar, 50); version = _lib.GetDeviceCecVersion(_address); SendEvent(UpdateEventType.StatusText, Resources.action_requesting_power_status); SendEvent(UpdateEventType.ProgressBar, 60); power = _lib.GetDevicePowerStatus(_address); SendEvent(UpdateEventType.StatusText, Resources.action_requesting_osd_name); SendEvent(UpdateEventType.ProgressBar, 70); osdName = _lib.GetDeviceOSDName(_address); SendEvent(UpdateEventType.StatusText, Resources.action_requesting_menu_language); SendEvent(UpdateEventType.ProgressBar, 80); menuLanguage = _lib.GetDeviceMenuLanguage(_address); } SendEvent(UpdateEventType.StatusText, Resources.action_showing_device_information); SendEvent(UpdateEventType.ProgressBar, 90); SendEvent(UpdateEventType.ProcessCompleted, true); ShowDialog(_address, ref _lib, devicePresent, vendor, isActiveSource, physicalAddress, version, power, osdName, menuLanguage); SendEvent(UpdateEventType.StatusText, Resources.ready); SendEvent(UpdateEventType.ProgressBar, 100); }
public override void Process() { CecVendorId vendor = CecVendorId.Unknown; bool isActiveSource = false; ushort physicalAddress = 0xFFFF; CecVersion version = CecVersion.Unknown; CecPowerStatus power = CecPowerStatus.Unknown; string osdName = "unknown"; string menuLanguage = "unknown"; SendEvent(UpdateEventType.StatusText, "Checking device presense..."); SendEvent(UpdateEventType.ProgressBar, 10); bool devicePresent = Lib.IsActiveDevice(Address); if (devicePresent) { SendEvent(UpdateEventType.StatusText, "Requesting the vendor ID..."); SendEvent(UpdateEventType.ProgressBar, 20); vendor = Lib.GetDeviceVendorId(Address); SendEvent(UpdateEventType.StatusText, "Requesting active source state..."); SendEvent(UpdateEventType.ProgressBar, 30); isActiveSource = Lib.IsActiveSource(Address); SendEvent(UpdateEventType.StatusText, "Requesting physical address..."); SendEvent(UpdateEventType.ProgressBar, 40); physicalAddress = Lib.GetDevicePhysicalAddress(Address); SendEvent(UpdateEventType.StatusText, "Requesting CEC version..."); SendEvent(UpdateEventType.ProgressBar, 50); version = Lib.GetDeviceCecVersion(Address); SendEvent(UpdateEventType.StatusText, "Requesting power status..."); SendEvent(UpdateEventType.ProgressBar, 60); power = Lib.GetDevicePowerStatus(Address); SendEvent(UpdateEventType.StatusText, "Requesting OSD name..."); SendEvent(UpdateEventType.ProgressBar, 70); osdName = Lib.GetDeviceOSDName(Address); SendEvent(UpdateEventType.StatusText, "Requesting menu language..."); SendEvent(UpdateEventType.ProgressBar, 80); menuLanguage = Lib.GetDeviceMenuLanguage(Address); } SendEvent(UpdateEventType.StatusText, "Showing device information"); SendEvent(UpdateEventType.ProgressBar, 90); SendEvent(UpdateEventType.ProcessCompleted, true); ShowDialog(Gui, Address, ref Lib, devicePresent, vendor, isActiveSource, physicalAddress, version, power, osdName, menuLanguage); SendEvent(UpdateEventType.StatusText, "Ready."); SendEvent(UpdateEventType.ProgressBar, 100); }
public DeviceInformation(CECController controller, CecLogicalAddress address, ref LibCecSharp lib, bool devicePresent, CecVendorId vendor, bool isActiveSource, ushort physicalAddress, CecVersion version, CecPowerStatus power, string osdName, string menuLanguage) { _controller = controller; _lib = lib; Address = address; InitializeComponent(); lDevice.Text = lib.ToString(address); lLogicalAddress.Text = String.Format("{0,1:X}", (int)address); Update(devicePresent, vendor, isActiveSource, physicalAddress, version, power, osdName, menuLanguage); }
public void Update(bool devicePresent, CecVendorId vendor, bool isActiveSource, ushort physicalAddress, CecVersion version, CecPowerStatus power, string osdName, string menuLanguage) { SetControlText(lPhysicalAddress, String.Format("{0,4:X}", physicalAddress)); SetControlText(lDevicePresent, devicePresent ? Resources.yes : Resources.no); SetControlVisible(lActiveSource, isActiveSource); SetControlVisible(lInactiveSource, !isActiveSource); SetControlText(lVendor, vendor != CecVendorId.Unknown ? _lib.ToString(vendor) : Resources.unknown); SetControlText(lCecVersion, _lib.ToString(version)); SetControlText(lPowerStatus, _lib.ToString(power)); SetControlText(lOsdName, osdName); SetControlText(lMenuLanguage, menuLanguage); SetControlText(this, "Device: " + osdName); }
/// <summary> /// Get power state of the given devive /// </summary> /// <param name="device"></param> /// <returns>The power state of the device. Power state is unknown if the query fails</returns> /// <exception cref="CecException">Can't connect to CecBus</exception> public PowerState GetDevicePowerState(CecLogicalAddress device) { PowerState state = PowerState.PowerUnknown; if (IsDeviceReady(device)) { CecPowerStatus cecStatus = connection.GetDevicePowerStatus(device); state = cecStatus switch { CecPowerStatus.On => PowerState.PowerOn, CecPowerStatus.Standby => PowerState.PowerOff, _ => PowerState.PowerUnknown }; } return(state); }
/// <summary> /// /// </summary> public void Scan() { string scanRes = ""; scanRes += "CEC bus information\n"; scanRes += "===================\n"; CecLogicalAddresses addresses = Lib.GetActiveDevices(); for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++) { CecLogicalAddress address = (CecLogicalAddress)iPtr; if (!addresses.IsSet(address)) { continue; } CecVendorId iVendorId = Lib.GetDeviceVendorId(address); bool bActive = Lib.IsActiveDevice(address); ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address); string strAddr = Lib.PhysicalAddressToString(iPhysicalAddress); CecVersion iCecVersion = Lib.GetDeviceCecVersion(address); CecPowerStatus power = Lib.GetDevicePowerStatus(address); string osdName = Lib.GetDeviceOSDName(address); string lang = Lib.GetDeviceMenuLanguage(address); scanRes += "device #" + iPtr + ": " + Lib.ToString(address) + "\n"; scanRes += "address: " + strAddr + "\n"; scanRes += "active source: " + (bActive ? "yes" : "no") + "\n"; scanRes += "vendor: " + Lib.ToString(iVendorId) + "\n"; scanRes += "osd string: " + osdName + "\n"; scanRes += "CEC version: " + Lib.ToString(iCecVersion) + "\n"; scanRes += "power status: " + Lib.ToString(power) + "\n"; if (!string.IsNullOrEmpty(lang)) { scanRes += "language: " + lang + "\n"; } scanRes += "===================" + "\n"; } Trace.Write(scanRes); }
public void Scan() { StringBuilder output = new StringBuilder(); output.AppendLine("CEC bus information"); output.AppendLine("==================="); CecLogicalAddresses addresses = Lib.GetActiveDevices(); for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++) { CecLogicalAddress address = (CecLogicalAddress)iPtr; if (!addresses.IsSet(address)) { continue; } CecVendorId iVendorId = Lib.GetDeviceVendorId(address); bool bActive = Lib.IsActiveDevice(address); ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address); string strAddr = Lib.PhysicalAddressToString(iPhysicalAddress); CecVersion iCecVersion = Lib.GetDeviceCecVersion(address); CecPowerStatus power = Lib.GetDevicePowerStatus(address); string osdName = Lib.GetDeviceOSDName(address); string lang = Lib.GetDeviceMenuLanguage(address); output.AppendLine("device #" + iPtr + ": " + Lib.ToString(address)); output.AppendLine("address: " + strAddr); output.AppendLine("active source: " + (bActive ? "yes" : "no")); output.AppendLine("vendor: " + Lib.ToString(iVendorId)); output.AppendLine("osd string: " + osdName); output.AppendLine("CEC version: " + Lib.ToString(iCecVersion)); output.AppendLine("power status: " + Lib.ToString(power)); if (!string.IsNullOrEmpty(lang)) { output.AppendLine("language: " + lang); } output.AppendLine(""); } Debug.WriteLine(output.ToString()); }
public override void ShowDialog(CecConfigGUI gui, CecLogicalAddress address, ref LibCecSharp lib, bool devicePresent, CecVendorId vendor, bool isActiveSource, ushort physicalAddress, CecVersion version, CecPowerStatus power, string osdName, string menuLanguage) { Dialog.Update(devicePresent, vendor, isActiveSource, physicalAddress, version, power, osdName, menuLanguage); }
public override void ShowDialog(CecLogicalAddress address, ref LibCecSharp lib, bool devicePresent, CecVendorId vendor, bool isActiveSource, ushort physicalAddress, CecVersion version, CecPowerStatus power, string osdName, string menuLanguage) { _dialog.Update(devicePresent, vendor, isActiveSource, physicalAddress, version, power, osdName, menuLanguage); }
public string SendCommand(string command) { if (command == null || command.Length == 0) { return("No command received"); } string[] splitCommand = command.Split(' '); if (splitCommand[0] == "tx" || splitCommand[0] == "txn") { CecCommand bytes = new CecCommand(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber)); } if (command == "txn") { bytes.TransmitTimeout = 0; } Lib.Transmit(bytes); } else if (splitCommand[0] == "default") { Lib.SetActiveSource(CecDeviceType.PlaybackDevice); return("Set default playback device as active"); } else if (splitCommand[0] == "rescan") { Lib.RescanActiveDevices(); return("Rescan active devices"); } else if (splitCommand[0] == "vol") { if (splitCommand[1] == "up") { Lib.VolumeUp(true); return("vol up"); } else if (splitCommand[1] == "down") { Lib.VolumeDown(true); return("vol down"); } else if (splitCommand[1] == "mute") { Lib.MuteAudio(true); return("Vol mute"); } return("Vol sub command not understood"); } else if (splitCommand[0] == "on") { if (splitCommand.Length > 1) { Lib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Signalled ON for device: " + splitCommand[1]); } else { Lib.PowerOnDevices(CecLogicalAddress.Broadcast); return("Signalled broadcast ON"); } } else if (splitCommand[0] == "standby") { if (splitCommand.Length > 1) { Lib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Signalled STANDBY for device: " + splitCommand[1]); } else { Lib.StandbyDevices(CecLogicalAddress.Broadcast); return("Signalled broadcast STANDBY"); } } else if (splitCommand[0] == "setDeviceHDMIPort") { if (splitCommand.Length > 2) { if (splitCommand[1] == "Tv") { Lib.SetHDMIPort(CecLogicalAddress.Tv, byte.Parse(splitCommand[2])); return("Set device " + splitCommand[1] + " to HDMI port " + splitCommand[2]); } if (splitCommand[1] == "AudioSystem") { Lib.SetHDMIPort(CecLogicalAddress.AudioSystem, byte.Parse(splitCommand[2])); return("Set device " + splitCommand[1] + " to HDMI port " + splitCommand[2]); } } return("Incorrect use of setDeviceHDMIPort"); } else if (splitCommand[0] == "poll") { bool bSent = false; if (splitCommand.Length > 1) { bSent = Lib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { bSent = Lib.PollDevice(CecLogicalAddress.Broadcast); } if (bSent) { Console.WriteLine("POLL message sent"); } else { Console.WriteLine("POLL message not sent"); } } else if (splitCommand[0] == "la") { if (splitCommand.Length > 1) { Lib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "pa") { if (splitCommand.Length > 1) { Lib.SetPhysicalAddress(ushort.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "osd") { if (splitCommand.Length > 2) { StringBuilder osdString = new StringBuilder(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { osdString.Append(splitCommand[iPtr]); if (iPtr != splitCommand.Length - 1) { osdString.Append(" "); } } Lib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString()); } } else if (splitCommand[0] == "ping") { return(Lib.PingAdapter().ToString()); } else if (splitCommand[0] == "mon") { bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false; Lib.SwitchMonitoring(enable); } else if (splitCommand[0] == "bl") { Lib.StartBootloader(); } else if (splitCommand[0] == "lang") { if (splitCommand.Length > 1) { string language = Lib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Menu language: " + language); } } else if (splitCommand[0] == "ven") { if (splitCommand.Length > 1) { CecVendorId vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("Vendor ID: " + Lib.ToString(vendor)); } } else if (splitCommand[0] == "ver") { if (splitCommand.Length > 1) { CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("CEC version: " + Lib.ToString(version)); } } else if (splitCommand[0] == "pow") { if (splitCommand.Length > 1) { CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); return("power status: " + Lib.ToString(power)); } } else if (splitCommand[0] == "r") { Console.WriteLine("closing the connection"); Lib.Close(); Console.WriteLine("opening a new connection"); Connect(10000); Console.WriteLine("setting active source"); Lib.SetActiveSource(CecDeviceType.AudioSystem); } else if (splitCommand[0] == "setActiveSource") { if (splitCommand.Length > 1) { if (splitCommand[1] == "AudioSystem") { Lib.SetActiveSource(CecDeviceType.AudioSystem); return("setting active source to audio system"); } if (splitCommand[1] == "PlaybackDevice") { Lib.SetActiveSource(CecDeviceType.PlaybackDevice); return("setting active source to playback device"); } if (splitCommand[1] == "RecordingDevice") { Lib.SetActiveSource(CecDeviceType.RecordingDevice); return("setting active source to Recording device"); } if (splitCommand[1] == "Reserved") { Lib.SetActiveSource(CecDeviceType.Reserved); return("setting active source to Reserved device"); } if (splitCommand[1] == "Tuner") { Lib.SetActiveSource(CecDeviceType.Tuner); return("setting active source to Tuner"); } if (splitCommand[1] == "Tv") { Lib.SetActiveSource(CecDeviceType.Tv); return("setting active source to Tv"); } } return("incorrect use of setActiveSource"); } else if (splitCommand[0] == "scan") { StringBuilder output = new StringBuilder(); output.AppendLine("CEC bus information"); output.AppendLine("==================="); CecLogicalAddresses addresses = Lib.GetActiveDevices(); for (int iPtr = 0; iPtr < addresses.Addresses.Length; iPtr++) { CecLogicalAddress address = (CecLogicalAddress)iPtr; if (!addresses.IsSet(address)) { continue; } CecVendorId iVendorId = Lib.GetDeviceVendorId(address); bool bActive = Lib.IsActiveDevice(address); ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address); string strAddr = Lib.PhysicalAddressToString(iPhysicalAddress); CecVersion iCecVersion = Lib.GetDeviceCecVersion(address); CecPowerStatus power = Lib.GetDevicePowerStatus(address); string osdName = Lib.GetDeviceOSDName(address); string lang = Lib.GetDeviceMenuLanguage(address); output.AppendLine("device #" + iPtr + ": " + Lib.ToString(address)); output.AppendLine("address: " + strAddr); output.AppendLine("active source: " + (bActive ? "yes" : "no")); output.AppendLine("vendor: " + Lib.ToString(iVendorId)); output.AppendLine("osd string: " + osdName); output.AppendLine("CEC version: " + Lib.ToString(iCecVersion)); output.AppendLine("power status: " + Lib.ToString(power)); if (!string.IsNullOrEmpty(lang)) { output.AppendLine("language: " + lang); } output.AppendLine(""); } return(output.ToString()); } return("CEC command not understood"); }
private bool IsOn(CecPowerStatus status) { //Including the transition messes things up. return(status == CecPowerStatus.On);// || status == CecPowerStatus.TransitionStandbyToOn; }
public void MainLoop() { Lib.PowerOnDevices(CecLogicalAddress.Tv); FlushLog(); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); FlushLog(); bool bContinue = true; string command; while (bContinue) { FlushLog(); Console.WriteLine("waiting for input"); command = Console.ReadLine(); if (command.Length == 0) { continue; } string[] splitCommand = command.Split(' '); if (splitCommand[0] == "tx" || splitCommand[0] == "txn") { CecCommand bytes = new CecCommand(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber)); } if (command == "txn") { bytes.TransmitTimeout = 0; } Lib.Transmit(bytes); } else if (splitCommand[0] == "on") { if (splitCommand.Length > 1) { Lib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.PowerOnDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "standby") { if (splitCommand.Length > 1) { Lib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.StandbyDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "poll") { bool bSent = false; if (splitCommand.Length > 1) { bSent = Lib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { bSent = Lib.PollDevice(CecLogicalAddress.Broadcast); } if (bSent) { Console.WriteLine("POLL message sent"); } else { Console.WriteLine("POLL message not sent"); } } else if (splitCommand[0] == "la") { if (splitCommand.Length > 1) { Lib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "pa") { if (splitCommand.Length > 1) { Lib.SetPhysicalAddress(short.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "osd") { if (splitCommand.Length > 2) { StringBuilder osdString = new StringBuilder(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { osdString.Append(splitCommand[iPtr]); if (iPtr != splitCommand.Length - 1) { osdString.Append(" "); } } Lib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString()); } } else if (splitCommand[0] == "ping") { Lib.PingAdapter(); } else if (splitCommand[0] == "mon") { bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false; Lib.SwitchMonitoring(enable); } else if (splitCommand[0] == "bl") { Lib.StartBootloader(); } else if (splitCommand[0] == "lang") { if (splitCommand.Length > 1) { string language = Lib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Menu language: " + language); } } else if (splitCommand[0] == "ven") { if (splitCommand.Length > 1) { CecVendorId vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Vendor ID: " + Lib.ToString(vendor)); } } else if (splitCommand[0] == "ver") { if (splitCommand.Length > 1) { CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("CEC version: " + Lib.ToString(version)); } } else if (splitCommand[0] == "pow") { if (splitCommand.Length > 1) { CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("power status: " + Lib.ToString(power)); } } else if (splitCommand[0] == "r") { Console.WriteLine("closing the connection"); Lib.Close(); FlushLog(); Console.WriteLine("opening a new connection"); Connect(10000); FlushLog(); Console.WriteLine("setting active source"); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); } else if (splitCommand[0] == "scan") { Console.WriteLine("CEC bus information"); Console.WriteLine("==================="); CecLogicalAddresses addresses = Lib.GetActiveDevices(); for (int iPtr = 0; iPtr < addresses.Addresses.Count(); iPtr++) { CecLogicalAddress address = (CecLogicalAddress)iPtr; if (!addresses.IsSet(address)) { continue; } CecVendorId iVendorId = Lib.GetDeviceVendorId(address); bool bActive = Lib.IsActiveDevice(address); ushort iPhysicalAddress = Lib.GetDevicePhysicalAddress(address); string strAddr = string.Format("{0,4:X}", iPhysicalAddress); CecVersion iCecVersion = Lib.GetDeviceCecVersion(address); CecPowerStatus power = Lib.GetDevicePowerStatus(address); string osdName = Lib.GetDeviceOSDName(address); string lang = Lib.GetDeviceMenuLanguage(address); StringBuilder output = new StringBuilder(); output.AppendLine("device #" + iPtr + ": " + Lib.ToString(address)); output.AppendLine("address: " + strAddr); output.AppendLine("active source: " + (bActive ? "yes" : "no")); output.AppendLine("vendor: " + Lib.ToString(iVendorId)); output.AppendLine("osd string: " + osdName); output.AppendLine("CEC version: " + Lib.ToString(iCecVersion)); output.AppendLine("power status: " + Lib.ToString(power)); if (!string.IsNullOrEmpty(lang)) { output.AppendLine("language: " + lang); } Console.WriteLine(output.ToString()); } } else if (splitCommand[0] == "h" || splitCommand[0] == "help") { ShowConsoleHelp(); } else if (splitCommand[0] == "q" || splitCommand[0] == "quit") { bContinue = false; } else if (splitCommand[0] == "log" && splitCommand.Length > 1) { LogLevel = int.Parse(splitCommand[1]); } } }
public void MainLoop() { Lib.PowerOnDevices(CecLogicalAddress.Tv); FlushLog(); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); FlushLog(); bool bContinue = true; string command; while (bContinue) { Console.WriteLine("waiting for input"); command = Console.ReadLine(); if (command.Length == 0) { continue; } string[] splitCommand = command.Split(' '); if (splitCommand[0] == "tx" || splitCommand[0] == "txn") { CecCommand bytes = new CecCommand(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { bytes.PushBack(byte.Parse(splitCommand[iPtr], System.Globalization.NumberStyles.HexNumber)); } if (command == "txn") { bytes.TransmitTimeout = 0; } Lib.Transmit(bytes); } else if (splitCommand[0] == "on") { if (splitCommand.Length > 1) { Lib.PowerOnDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.PowerOnDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "standby") { if (splitCommand.Length > 1) { Lib.StandbyDevices((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { Lib.StandbyDevices(CecLogicalAddress.Broadcast); } } else if (splitCommand[0] == "poll") { bool bSent = false; if (splitCommand.Length > 1) { bSent = Lib.PollDevice((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } else { bSent = Lib.PollDevice(CecLogicalAddress.Broadcast); } if (bSent) { Console.WriteLine("POLL message sent"); } else { Console.WriteLine("POLL message not sent"); } } else if (splitCommand[0] == "la") { if (splitCommand.Length > 1) { Lib.SetLogicalAddress((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "pa") { if (splitCommand.Length > 1) { Lib.SetPhysicalAddress(short.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); } } else if (splitCommand[0] == "osd") { if (splitCommand.Length > 2) { StringBuilder osdString = new StringBuilder(); for (int iPtr = 1; iPtr < splitCommand.Length; iPtr++) { osdString.Append(splitCommand[iPtr]); if (iPtr != splitCommand.Length - 1) { osdString.Append(" "); } } Lib.SetOSDString((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber), CecDisplayControl.DisplayForDefaultTime, osdString.ToString()); } } else if (splitCommand[0] == "ping") { Lib.PingAdapter(); } else if (splitCommand[0] == "mon") { bool enable = splitCommand.Length > 1 ? splitCommand[1] == "1" : false; Lib.SwitchMonitoring(enable); } else if (splitCommand[0] == "bl") { Lib.StartBootloader(); } else if (splitCommand[0] == "lang") { if (splitCommand.Length > 1) { string language = Lib.GetDeviceMenuLanguage((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Menu language: " + language); } } else if (splitCommand[0] == "ven") { if (splitCommand.Length > 1) { ulong vendor = Lib.GetDeviceVendorId((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); Console.WriteLine("Vendor ID: " + vendor); } } else if (splitCommand[0] == "ver") { if (splitCommand.Length > 1) { CecVersion version = Lib.GetDeviceCecVersion((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); switch (version) { case CecVersion.V1_2: Console.WriteLine("CEC version 1.2"); break; case CecVersion.V1_2A: Console.WriteLine("CEC version 1.2a"); break; case CecVersion.V1_3: Console.WriteLine("CEC version 1.3"); break; case CecVersion.V1_3A: Console.WriteLine("CEC version 1.3a"); break; case CecVersion.V1_4: Console.WriteLine("CEC version 1.4"); break; default: Console.WriteLine("unknown CEC version"); break; } } } else if (splitCommand[0] == "pow") { if (splitCommand.Length > 1) { CecPowerStatus power = Lib.GetDevicePowerStatus((CecLogicalAddress)byte.Parse(splitCommand[1], System.Globalization.NumberStyles.HexNumber)); switch (power) { case CecPowerStatus.On: Console.WriteLine("powered on"); break; case CecPowerStatus.InTransitionOnToStandby: Console.WriteLine("on -> standby"); break; case CecPowerStatus.InTransitionStandbyToOn: Console.WriteLine("standby -> on"); break; case CecPowerStatus.Standby: Console.WriteLine("standby"); break; default: Console.WriteLine("unknown power status"); break; } } } else if (splitCommand[0] == "r") { Console.WriteLine("closing the connection"); Lib.Close(); FlushLog(); Console.WriteLine("opening a new connection"); Connect(10000); FlushLog(); Console.WriteLine("setting active source"); Lib.SetActiveSource(CecDeviceType.PlaybackDevice); } else if (splitCommand[0] == "h" || splitCommand[0] == "help") { ShowConsoleHelp(); } else if (splitCommand[0] == "q" || splitCommand[0] == "quit") { bContinue = false; } else if (splitCommand[0] == "log" && splitCommand.Length > 1) { LogLevel = int.Parse(splitCommand[1]); } FlushLog(); } }