Ejemplo n.º 1
0
   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);
   }
Ejemplo n.º 2
0
        public List <string> GetActiveDevices()
        {
            _lib.RescanActiveDevices();

            List <string> devices = new List <string>();

            CecLogicalAddresses addresses = _lib.GetActiveDevices();

            for (int i = 0; i < addresses.Addresses.Length; i++)
            {
                CecLogicalAddress address = (CecLogicalAddress)i;
                if (!addresses.IsSet(address))
                {
                    continue;
                }

                string device = String.Empty;

                device += _lib.ToString(_lib.GetDeviceVendorId(address)) + ',';
                device += _lib.GetDeviceOSDName(address) + ',';
                device += _lib.ToString(_lib.GetDevicePowerStatus(address)) + ',';
                device += _lib.IsActiveDevice(address).ToString() + ',';
                device += _lib.GetDevicePhysicalAddress(address).ToString();

                devices.Add(device);
            }

            return(devices);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Switch power state of the given device to the requested power state
        /// </summary>
        /// <param name="device"></param>
        /// <param name="requestedPowerState"></param>
        /// <returns cref="PowerState">New PowerSate. Power state is unknown if the switch fails</returns>
        /// <exception cref="CecException">Can't connect to CecBus</exception>
        public PowerState SwitchDevicePowerState(CecLogicalAddress device, PowerState requestedPowerState)
        {
            PowerState state = PowerState.PowerUnknown;

            switch (requestedPowerState)
            {
            case PowerState.PowerOff:
                if (IsDeviceReady(device) && connection.StandbyDevices(device))
                {
                    state = PowerState.PowerOff;
                }
                break;

            case PowerState.PowerOn:
                // Close and reopen the connection as we lose it when we go to sleep
                connection.Close();
                if (!connection.Open(controller.ComPort, timeout))
                {
                    throw new CecException(Resources.ErrorNoCecControllerConnection);
                }
                // Register active source of the connection
                connection.SetActiveSource(CecDeviceType.PlaybackDevice);

                if (IsDeviceReady(device) && connection.PowerOnDevices(device))
                {
                    state = PowerState.PowerOn;
                }
                break;

            default:
                break;
            }

            return(state);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Send "Power ON" -signal to device.
        /// </summary>
        public bool WakeDevice(CecLogicalAddress device)
        {
            bool res = _lib.PowerOnDevices(device);

            WriteLog("Wake " + device.ToString() + " ... " + (res ? "Done." : "Failed."));

            return(res);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Send "Stand by" -signal to device.
        /// </summary>
        public bool StandByDevice(CecLogicalAddress device)
        {
            bool res = _lib.StandbyDevices(device);

            WriteLog("Put " + device.ToString() + " to standby mode ... " + (res ? "Done." : "Failed."));

            return(res);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the name of a port. Does not work.
        /// </summary>
        /// <param name="address"></param>
        /// <returns></returns>
        public String GetName(CecLogicalAddress address)
        {
            //throw new InvalidOperationException("This does not work");
            String result = null;
            StringRetrieverCallback callback = n => result = n;

            CecManager_GetName(ptr, callback, address);
            return(result);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Activate the source at the given logical address. 
        /// </summary>
        /// <param name="address">The logical address of the device to activate</param>
        public void ActivateSource(CecLogicalAddress address)
        {
            if (SuppressUpdates || _activeProcess != null) return;

              _controller.SetControlsEnabled(false);
              _activeProcess = new SendActivateSource(_controller.Lib, address);
              _activeProcess.EventHandler += ProcessEventHandler;
              (new Thread(_activeProcess.Run)).Start();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Fetch device information and show an information dialog for the device at the given logical address
        /// </summary>
        /// <param name="address">The logical address of the device to get the info for</param>
        public void ShowDeviceInfo(CecLogicalAddress address)
        {
            if (SuppressUpdates || _activeProcess != null)
            {
                return;
            }

            _controller.SetControlsEnabled(false);
            _activeProcess = new ShowDeviceInfo(_controller, _controller.Lib, address);
            _activeProcess.EventHandler += ProcessEventHandler;
            (new Thread(_activeProcess.Run)).Start();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Activate the source at the given logical address.
        /// </summary>
        /// <param name="address">The logical address of the device to activate</param>
        public void SetStreamPath(CecLogicalAddress address)
        {
            if (SuppressUpdates || _activeProcess != null)
            {
                return;
            }

            _controller.SetControlsEnabled(false);
            _activeProcess = new SendActivateSource(_controller.Lib, address);
            _activeProcess.EventHandler += ProcessEventHandler;
            (new Thread(_activeProcess.Run)).Start();
        }
Ejemplo n.º 11
0
   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);
   }
Ejemplo n.º 12
0
 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);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Change the device to which the adapter is connected and/or the HDMI port number
        /// </summary>
        /// <param name="address">The new device to which the adapter is connected</param>
        /// <param name="portnumber">The new HDMI port number</param>
        public void SetConnectedDevice(CecLogicalAddress address, int portnumber)
        {
            if (SuppressUpdates || _activeProcess != null)
            {
                return;
            }

            _controller.SetControlsEnabled(false);
            _activeProcess = new UpdateConnectedDevice(_controller.Lib, address, portnumber);
            _activeProcess.EventHandler += ProcessEventHandler;
            (new Thread(_activeProcess.Run)).Start();
        }
Ejemplo n.º 14
0
        public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
        {
            WriteLog("HDMI-device: " + logicalAddress.ToString() + " was " + (activated ? "activated." : "deactivated."));

            if (activated)
            { // MediaPortal becomes active source
                KeyPress(310);
            }
            else
            { // MediaPortal was deactivated
                KeyPress(311);
            }
        }
Ejemplo n.º 15
0
        public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
        {
            if (!activated)
            {
                return;
            }

            foreach (var app in _applications)
            {
                if (app.AutoStartApplication.Value)
                {
                    app.Start(false);
                }
            }
        }
Ejemplo n.º 16
0
        private CecLogicalAddress GetTargetDevice()
        {
            if (cbCommandDestination.InvokeRequired)
            {
                GetTargetDeviceCallback d      = GetTargetDevice;
                CecLogicalAddress       retval = CecLogicalAddress.Unknown;
                try
                {
                    retval = (CecLogicalAddress)Invoke(d, new object[] { });
                }
                catch (Exception) { }
                return(retval);
            }

            return(CECSettingLogicalAddresses.GetLogicalAddressFromString(cbCommandDestination.Text));
        }
Ejemplo n.º 17
0
        /// <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);
        }
Ejemplo n.º 18
0
        public void SetVendorName(CecLogicalAddress address, CecVendorId vendorId, string vendorName)
        {
            VendorNames[(int)address] = vendorName;

            if (address == CecLogicalAddress.Tv && vendorId == CecVendorId.Panasonic)
            {
                DeviceType.AllowedTypeMask = new CecDeviceTypeList {
                    Types = new[] { CecDeviceType.PlaybackDevice }
                };
            }

            foreach (var setting in _settings)
            {
                if (setting.Value.SettingType == CECSettingType.LogicalAddress)
                {
                    setting.Value.AsSettingLogicalAddress.ResetItems(true);
                }
            }
        }
Ejemplo n.º 19
0
        /// <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);
        }
Ejemplo n.º 20
0
        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());
        }
Ejemplo n.º 21
0
 public async Task SetStandby(CecLogicalAddress address)
 {
     await readLock.Run(() => cecManager.SetStandby(address));
 }
Ejemplo n.º 22
0
    /// <summary>
    /// Send "Stand by" -signal to device.
    /// </summary>
    public bool StandByDevice(CecLogicalAddress device)
    {
      bool res = _lib.StandbyDevices(device);

      WriteLog("Put " + device.ToString() + " to standby mode ... " + (res ? "Done." : "Failed."));

      return res;
    }
Ejemplo n.º 23
0
 public string GetPowerStatus(CecLogicalAddress device)
 {
   return _lib.GetDevicePowerStatus(device).ToString();
 }
Ejemplo n.º 24
0
 public string GetVendor(CecLogicalAddress device)
 {
   return _lib.GetDeviceVendorId(device).ToString();
 }
Ejemplo n.º 25
0
 public void ShowDeviceInfo(CecLogicalAddress address)
 {
     if (!SuppressUpdates && ActiveProcess == null)
       {
     SetControlsEnabled(false);
     ActiveProcess = new ShowDeviceInfo(this, ref Lib, address);
     ActiveProcess.EventHandler += ProcessEventHandler;
     (new Thread(ActiveProcess.Run)).Start();
       }
 }
Ejemplo n.º 26
0
 public void SendImageViewOn(CecLogicalAddress address)
 {
     if (!SuppressUpdates && ActiveProcess == null)
       {
     SetControlsEnabled(false);
     ActiveProcess = new SendImageViewOn(ref Lib, address);
     ActiveProcess.EventHandler += ProcessEventHandler;
     (new Thread(ActiveProcess.Run)).Start();
       }
 }
Ejemplo n.º 27
0
    /// <summary>
    /// Change the device to which the adapter is connected and/or the HDMI port number
    /// </summary>
    /// <param name="address">The new device to which the adapter is connected</param>
    /// <param name="portnumber">The new HDMI port number</param>
    public void SetConnectedDevice(CecLogicalAddress address, int portnumber)
    {
      if (SuppressUpdates || _activeProcess != null) return;

      _controller.SetControlsEnabled(false);
      _activeProcess = new UpdateConnectedDevice(_controller.Lib, address, portnumber);
      _activeProcess.EventHandler += ProcessEventHandler;
      (new Thread(_activeProcess.Run)).Start();
    }
Ejemplo n.º 28
0
 public SendStandby(ref LibCecSharp lib, CecLogicalAddress address)
 {
     Lib = lib;
       Address = address;
 }
Ejemplo n.º 29
0
 public UpdateConnectedDevice(ref LibCecSharp lib, CecLogicalAddress address, int portNumber)
 {
     Lib = lib;
       Address = address;
       PortNumber = portNumber;
 }
Ejemplo n.º 30
0
 public async Task SetHdmiPort(CecLogicalAddress device, byte port)
 {
     await readLock.Run(() => cecManager.SetHdmiPort(device, port));
 }
Ejemplo n.º 31
0
 public async Task <CecVendorId> GetVendor(CecLogicalAddress address)
 {
     return(await readLock.Run(() => cecManager.GetVendor(address)));
 }
Ejemplo n.º 32
0
 public UpdateConnectedDevice(LibCecSharp lib, CecLogicalAddress address, int portNumber)
 {
   _lib = lib;
   _address = address;
   _portNumber = portNumber;
 }
Ejemplo n.º 33
0
    public void SetVendorName(CecLogicalAddress address, CecVendorId vendorId, string vendorName)
    {
      VendorNames[(int)address] = vendorName;

      if (address == CecLogicalAddress.Tv && vendorId == CecVendorId.Panasonic)
      {
        DeviceType.AllowedTypeMask = new CecDeviceTypeList {Types = new[] {CecDeviceType.PlaybackDevice}};
      }

      foreach (var setting in _settings)
      {
        if (setting.Value.SettingType == CECSettingType.LogicalAddress)
          setting.Value.AsSettingLogicalAddress.ResetItems(true);
      }
    }
Ejemplo n.º 34
0
 public SendImageViewOn(ref LibCecSharp lib, CecLogicalAddress address)
 {
     Lib = lib;
       Address = address;
 }
Ejemplo n.º 35
0
 public CECSettingLogicalAddress(string keyName, string friendlyName, CecLogicalAddress defaultValue, SettingChangedHandler changedHandler) :
   base(CECSettingType.LogicalAddress, keyName, friendlyName, (int)defaultValue, changedHandler, OnFormat)
 {
   LowerLimit = (int) CecLogicalAddress.Tv;
   UpperLimit = (int) CecLogicalAddress.Broadcast;
 }
Ejemplo n.º 36
0
 public string GetOsdName(CecLogicalAddress device)
 {
   return _lib.GetDeviceOSDName(device).ToString();
 }
Ejemplo n.º 37
0
 public async Task <bool> SendKeypress(CecLogicalAddress iDestination, CecControlCode key, bool bWait)
 {
     return(await readLock.Run(() => cecManager.SendKeypress(iDestination, key, bWait)));
 }
Ejemplo n.º 38
0
    /// <summary>
    /// Send "Power ON" -signal to device.
    /// </summary>
    public bool WakeDevice(CecLogicalAddress device)
    {
      bool res = _lib.PowerOnDevices(device);

      WriteLog("Wake " + device.ToString() + " ... " + (res ? "Done." : "Failed.")); 

      return res;
    }
Ejemplo n.º 39
0
 public ShowDeviceInfo(CecConfigGUI gui, ref LibCecSharp lib, CecLogicalAddress address)
 {
     Gui     = gui;
     Lib     = lib;
     Address = address;
 }
Ejemplo n.º 40
0
 public SendActivateSource(ref LibCecSharp lib, CecLogicalAddress address)
 {
     Lib = lib;
       Address = address;
 }
Ejemplo n.º 41
0
        public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
        {
            if (!activated)
            return;

              foreach (var app in _applications)
              {
            if (app.AutoStartApplication.Value)
              app.Start(false);
              }
        }
Ejemplo n.º 42
0
 public void SetConnectedDevice(CecLogicalAddress address, int portnumber)
 {
     if (!SuppressUpdates && ActiveProcess == null)
       {
     SetControlsEnabled(false);
     ActiveProcess = new UpdateConnectedDevice(ref Lib, address, portnumber);
     ActiveProcess.EventHandler += ProcessEventHandler;
     (new Thread(ActiveProcess.Run)).Start();
       }
 }
Ejemplo n.º 43
0
 public ShowDeviceInfo(CECController controller, LibCecSharp lib, CecLogicalAddress address)
 {
     _controller = controller;
       _lib = lib;
       _address = address;
 }
Ejemplo n.º 44
0
 public ShowDeviceInfo(CecConfigGUI gui, ref LibCecSharp lib, CecLogicalAddress address)
 {
     Gui = gui;
       Lib = lib;
       Address = address;
 }
Ejemplo n.º 45
0
 public SendImageViewOn(LibCecSharp lib, CecLogicalAddress address)
 {
     _lib = lib;
       _address = address;
 }
Ejemplo n.º 46
0
 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);
 }
Ejemplo n.º 47
0
 public SendStandby(LibCecSharp lib, CecLogicalAddress address)
 {
     _lib = lib;
       _address = address;
 }
Ejemplo n.º 48
0
 public ShowDeviceInfo(CECController controller, LibCecSharp lib, CecLogicalAddress address)
 {
     _controller = controller;
     _lib        = lib;
     _address    = address;
 }
Ejemplo n.º 49
0
 public SendImageViewOn(ref LibCecSharp lib, CecLogicalAddress address)
 {
     Lib     = lib;
     Address = address;
 }
Ejemplo n.º 50
0
 public SendImageViewOn(LibCecSharp lib, CecLogicalAddress address)
 {
     _lib     = lib;
     _address = address;
 }
Ejemplo n.º 51
0
        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");
        }
Ejemplo n.º 52
0
 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);
 }
Ejemplo n.º 53
0
 public SendActivateSource(LibCecSharp lib, CecLogicalAddress address)
 {
     _lib     = lib;
     _address = address;
 }
Ejemplo n.º 54
0
        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]);
                }
            }
        }
Ejemplo n.º 55
0
 public SendActivateSource(LibCecSharp lib, CecLogicalAddress address)
 {
   _lib = lib;
   _address = address;
 }
Ejemplo n.º 56
0
 public async Task <bool> SendKeyRelease(CecLogicalAddress iDestination, bool bWait)
 {
     return(await readLock.Run(() => cecManager.SendKeyRelease(iDestination, bWait)));
 }
Ejemplo n.º 57
0
    public override void SourceActivated(CecLogicalAddress logicalAddress, bool activated)
    {
      WriteLog("HDMI-device: " + logicalAddress.ToString() + " was " + (activated ? "activated." : "deactivated."));

      if (activated)
      { // MediaPortal becomes active source
        KeyPress(310);
      }
      else
      { // MediaPortal was deactivated
        KeyPress(311);
      }
    }