public static void Command(this LibCECClient client, params byte[] values) { var cmd = new CecCommand(); foreach (byte value in values) { cmd.PushBack(value); } client.Transmit(cmd); }
public override int ReceiveCommand(CecCommand command) { Trace.WriteLine(string.Format("CEC command '{5}' from {0} to {1} - Ack: {2} Eom: {3} OpcodeSet: {4} Timeout: {6}", iLib.ToString(command.Initiator), iLib.ToString(command.Destination), command.Ack.ToString(), command.Eom.ToString(), command.OpcodeSet.ToString(), iLib.ToString(command.Opcode), command.TransmitTimeout.ToString() )); return(1); }
/// <summary> /// Send command via the command enum <see cref="CecOpcode"/>. /// </summary> /// <param name="client"></param> /// <param name="cmd"></param> public static void Command(this LibCECClient client, CecOpcode cmd) { Console.WriteLine($"Received Command: {cmd}"); CecCommand newCommand = new CecCommand { Initiator = CecLogicalAddress.PlaybackDevice1, Destination = CecLogicalAddress.Tv, Opcode = cmd }; client.Transmit(newCommand); }
public override int ReceiveCommand(CecCommand command) { if (command.Opcode == CecOpcode.Standby && (command.Destination == CecLogicalAddress.Broadcast || command.Destination == _lib.GetLogicalAddresses().Primary)) { if (Settings.StopTvStandby.Value) { var key = new CecKeypress(CecUserControlCode.Stop, 0); foreach (var app in _applications) { app.SendKey(key, false); } Lib.DisableCallbacks(); Application.SetSuspendState(PowerState.Suspend, false, false); } } return(0); }
public void Transmit(CecCommand cmd, bool activateSource = false) { if (cmd.Opcode == CecOpcode.Standby && Lib.GetDevicePowerStatus(CecLogicalAddress.Tv) != CecPowerStatus.On) { return; } if (_settingActiveSource) { return; } if (activateSource) { _settingActiveSource = true; Lib.SetActiveSource(CecDeviceType.PlaybackDevice); /* * Since we dont know when its fully connected as a source, * we have to take a guess on when its done, if we dont * our queued cmd wont trigger. */ Thread.Sleep(CMD_DELAY); _settingActiveSource = false; Transmit(cmd); return; } //First try and transmit command, if that fails try and reconnect the send again. if (!Lib.Transmit(cmd)) { Transmit(cmd, true); return; } //We need some delay if we suceeded with the transmission, //else the tv will spazz out if overloaded with commands. Thread.Sleep(CMD_DELAY); }
public void MainLoop() { bool bContinue = true; string command; while (bContinue) { Console.WriteLine("waiting for input"); command = Console.ReadLine(); if (command != null && 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(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") { 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(); Console.WriteLine("opening a new connection"); Connect(10000); 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.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 = 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) { 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(); } }
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"); }
/// <summary>Dummy RecieveCommand callback</summary> /// <param name="command"></param> /// <returns>Always 1</returns> public override int ReceiveCommand(CecCommand command) => 1;
public int ReceiveCommand(CecCommand command) { return 1; }
public override int ReceiveCommand(CecCommand command) { if (command.Opcode == CecOpcode.Standby && (command.Destination == CecLogicalAddress.Broadcast || command.Destination == _lib.GetLogicalAddresses().Primary)) if (Settings.StopTvStandby.Value) { var key = new CecKeypress(CecUserControlCode.Stop, 0); foreach (var app in _applications) app.SendKey(key, false); Lib.DisableCallbacks(); Application.SetSuspendState(PowerState.Suspend, false, false); } return 0; }
public override int ReceiveCommand(CecCommand command) { if (command.Opcode == CecSharp.CecOpcode.UserControlRelease) { _repeatTimer.Stop(); _keyDown = false; _currentKeycode = 0; _keyCount = 0; } else if (command.Opcode == CecSharp.CecOpcode.UserControlPressed) { _keyDown = true; } // Fix for some play/stop keys else if ((command.Opcode == CecOpcode.Play || command.Opcode == CecOpcode.DeckControl) && command.Initiator == CecLogicalAddress.Tv && command.Parameters.Size == 1) { if (command.Opcode == CecOpcode.Play) { if (command.Parameters.Data[0] == 0x24) { KeyPress((int)CecUserControlCode.Play); } else if (command.Parameters.Data[0] == 0x25) { KeyPress((int)CecUserControlCode.Pause); } else { KeyPress((int)CecUserControlCode.Pause); } } else { KeyPress((int)CecUserControlCode.Stop); } } else if (command.Opcode == CecOpcode.Standby && command.Initiator == CecLogicalAddress.Tv) { WriteLog("TV: Standby."); if (_cecConfig.SendTvPowerOff) { if (_cecConfig.SendTvPowerOffOnlyIfActiveSource && !_lib.IsLibCECActiveSource()) { WriteLog("TVPowerOff button not sent, MediaPortal active source state is: " + _lib.IsLibCECActiveSource().ToString()); } else { WriteLog("TVPowerOff button sent."); KeyPress((int)CecUserControlCode.PowerOffFunction); } } } if (_extensiveLogging) { string opcode = String.Empty; string param = String.Empty; if (command.OpcodeSet) { opcode = command.Opcode.ToString(); } for (short i = 0; i < command.Parameters.Size; i++) { param += String.Format("{0:X}", command.Parameters.Data[i]); } string msg = "Command: " + opcode; if (param.Length > 0) { msg += " Parameters: " + param; } WriteLog(msg); } return(1); }
public override int ReceiveCommand(CecCommand command) { if (command.Opcode == CecSharp.CecOpcode.UserControlRelease) { _repeatTimer.Stop(); _keyDown = false; _currentKeycode = 0; _keyCount = 0; } else if (command.Opcode == CecSharp.CecOpcode.UserControlPressed) { _keyDown = true; } // Fix for some play/stop keys else if ((command.Opcode == CecOpcode.Play || command.Opcode == CecOpcode.DeckControl) && command.Initiator == CecLogicalAddress.Tv && command.Parameters.Size == 1) { if (command.Opcode == CecOpcode.Play) { if (command.Parameters.Data[0] == 0x24) { KeyPress((int)CecUserControlCode.Play); } else if (command.Parameters.Data[0] == 0x25) { KeyPress((int)CecUserControlCode.Pause); } else { KeyPress((int)CecUserControlCode.Pause); } } else { KeyPress((int)CecUserControlCode.Stop); } } else if (command.Opcode == CecOpcode.Standby && command.Initiator == CecLogicalAddress.Tv) { WriteLog("TV: Standby."); if (_cecConfig.SendTvPowerOff) { if (_cecConfig.SendTvPowerOffOnlyIfActiveSource && !_lib.IsLibCECActiveSource()) { WriteLog("TVPowerOff button not sent, MediaPortal active source state is: " + _lib.IsLibCECActiveSource().ToString()); } else { WriteLog("TVPowerOff button sent."); KeyPress((int)CecUserControlCode.PowerOffFunction); } } } if (_extensiveLogging) { string opcode = String.Empty; string param = String.Empty; if (command.OpcodeSet) { opcode = command.Opcode.ToString(); } for (short i = 0; i < command.Parameters.Size; i++) { param += String.Format("{0:X}", command.Parameters.Data[i]); } string msg = "Command: " + opcode; if (param.Length > 0) { msg += " Parameters: " + param; } WriteLog(msg); } return 1; }
/// <summary> /// Handler for commands from the TV - does nothing /// </summary> /// <param name="command"></param> /// <returns></returns> public override int ReceiveCommand(CecCommand command) { return(1); }
public override int ReceiveCommand(CecCommand command) { return Gui.ReceiveCommand(command); }
public override int ReceiveCommand(CecCommand command) { Console.WriteLine("ReceiveCommand triggered, command = " + command.Opcode.ToString()); return(1); }
public override int ReceiveCommand(CecCommand command) { return 0; }
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(); } }