/// <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); }
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 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()); }
/// <summary> /// Is the TV screen on? /// </summary> /// <returns></returns> public bool TvScreenIsOn() { return(CecLib.GetDevicePowerStatus(CecLogicalAddress.Tv) == CecPowerStatus.On); }
public string GetPowerStatus(CecLogicalAddress device) { return(_lib.GetDevicePowerStatus(device).ToString()); }