Ejemplo n.º 1
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.º 2
0
        private string DevicesToString(CecLogicalAddresses list)
        {
            if (list.Primary == CecLogicalAddress.Unknown)
            {
                return(string.Empty);
            }

            string deviceList = "";

            foreach (CecLogicalAddress a in list.Addresses)
            {
                if (a != CecLogicalAddress.Unknown && a != CecLogicalAddress.Unregistered)
                {
                    deviceList += a.ToString() + ',';
                }
            }

            if (deviceList.Length == 0)
            {
                return(string.Empty);
            }
            else
            {
                return(deviceList.Remove(deviceList.Length - 1));
            }
        }
Ejemplo n.º 3
0
 static bool HasAdvancedDeviceIdSet(CecLogicalAddresses addresses)
 {
     foreach (var val in addresses.Addresses)
     {
         if (val != CecLogicalAddress.Tv && val != CecLogicalAddress.AudioSystem)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        public void SetDefaults()
        {
            HdmiPort   = 1;
            DeviceType = CecDeviceType.RecordingDevice;

            OsdName = "MediaPortal";

            FastScrolling            = false;
            FastScrollingRepeatDelay = 2;
            FastScrollingRepeatRate  = 40;

            RequireDelayBetweenKeys = false;
            DelayBetweenKeys        = 300;

            DisableScreensaver = false;
            ExtensiveLogging   = false;

            WakeDevicesOnStart    = true;
            ActivateSourceOnStart = true;
            OnStartWakeDevices    = new CecLogicalAddresses();
            OnStartWakeDevices.Set(CecLogicalAddress.Tv);
            OnStartWakeDevices.Set(CecLogicalAddress.AudioSystem);

            StandbyDevicesOnExit   = false;
            InactivateSourceOnExit = false;
            OnExitStandbyDevices   = new CecLogicalAddresses();
            OnExitStandbyDevices.Set(CecLogicalAddress.Tv);
            OnExitStandbyDevices.Set(CecLogicalAddress.AudioSystem);

            WakeDevicesOnResume      = true;
            ActivateSourceOnResume   = true;
            RequireUserInputOnResume = true;
            OnResumeWakeDevices      = new CecLogicalAddresses();
            OnResumeWakeDevices.Set(CecLogicalAddress.Tv);
            OnResumeWakeDevices.Set(CecLogicalAddress.AudioSystem);

            StandbyDevicesOnSleep   = true;
            InactivateSourceOnSleep = false;
            OnSleepStandbyDevices   = new CecLogicalAddresses();
            OnSleepStandbyDevices.Set(CecLogicalAddress.Tv);
            OnSleepStandbyDevices.Set(CecLogicalAddress.AudioSystem);

            ClientVersion = LibCECConfiguration.CurrentVersion;
            ConnectedTo   = CecLogicalAddress.Tv;

            SendTvPowerOff = false;
            SendTvPowerOffOnlyIfActiveSource = true;
            RequireActiveSourceWhenSleep     = true;

            ControlVolume        = false;
            ForcePhysicalAddress = false;
            PhysicalAddress      = "1000";
        }
Ejemplo n.º 5
0
    private static int SerialiseLogicalAddresses(CecLogicalAddresses addresses)
    {
      var retVal = 0;
      for (int addr = (int)CecLogicalAddress.Tv; addr <= (int)CecLogicalAddress.Broadcast; addr++)
      {
        if (addresses.IsSet((CecLogicalAddress)addr))
        {
          retVal += (int)Math.Pow(2, addr);
        }
      }

      return retVal;
    }
Ejemplo n.º 6
0
        private static int SerialiseLogicalAddresses(CecLogicalAddresses addresses)
        {
            var retVal = 0;

            for (int addr = (int)CecLogicalAddress.Tv; addr <= (int)CecLogicalAddress.Broadcast; addr++)
            {
                if (addresses.IsSet((CecLogicalAddress)addr))
                {
                    retVal += (int)Math.Pow(2, addr);
                }
            }

            return(retVal);
        }
Ejemplo n.º 7
0
    private static CecLogicalAddresses DeserialiseLogicalAddresses(int addresses)
    {
      CecLogicalAddresses retVal = new CecLogicalAddresses();
      if (addresses == 0)
        return retVal;

      for (int addr = (int)CecLogicalAddress.Tv; addr <= (int)CecLogicalAddress.Broadcast; addr++)
      {
        int val = (int)Math.Pow(2, addr);
        if ((addresses & val) == val)
          retVal.Set((CecLogicalAddress)addr);
      }

      return retVal;
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Send "Stand by" -signal to multiple devices.
        /// </summary>
        public bool StandByDevice(CecLogicalAddresses device)
        {
            bool ret = true;

            foreach (CecLogicalAddress a in device.Addresses)
            {
                if (a != CecLogicalAddress.Unknown)
                {
                    if (!StandByDevice(a))
                    {
                        ret = false;
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 9
0
        private static CecLogicalAddresses DeserialiseLogicalAddresses(int addresses)
        {
            CecLogicalAddresses retVal = new CecLogicalAddresses();

            if (addresses == 0)
            {
                return(retVal);
            }

            for (int addr = (int)CecLogicalAddress.Tv; addr <= (int)CecLogicalAddress.Broadcast; addr++)
            {
                int val = (int)Math.Pow(2, addr);
                if ((addresses & val) == val)
                {
                    retVal.Set((CecLogicalAddress)addr);
                }
            }

            return(retVal);
        }
Ejemplo n.º 10
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.º 11
0
        private CecLogicalAddresses ParseDevices(string devices)
        {
            CecLogicalAddresses list = new CecLogicalAddresses();

            if (devices.Length == 0)
            {
                return(list);
            }

            string[] devicelist = devices.Split(',');

            foreach (string d in devicelist)
            {
                if (d != "Unknown" && d != "Unregistered")
                {
                    list.Set((CecSharp.CecLogicalAddress)Enum.Parse(typeof(CecLogicalAddress), d));
                }
            }

            return(list);
        }
Ejemplo n.º 12
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.º 13
0
        private void ShowSelectDevices(CecLogicalAddresses list)
        {
            SelectDevices sel = new SelectDevices();

            sel.StartPosition = FormStartPosition.CenterParent;

            foreach (PropertyInfo property in sel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
            {
                if (property.CanWrite && property.PropertyType.Equals(typeof(System.Boolean)))
                {
                    property.SetValue(sel, false, null);
                    if (list.IsSet((CecLogicalAddress)Enum.Parse(typeof(CecLogicalAddress), property.Name, true)))
                    {
                        property.SetValue(sel, true, null);
                    }
                }
            }

            if (sel.ShowDialog(this) == DialogResult.OK)
            {
                list.Clear();

                foreach (PropertyInfo property in sel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
                {
                    if (property.CanRead && property.PropertyType.Equals(typeof(System.Boolean)))
                    {
                        if ((bool)property.GetValue(sel, null))
                        {
                            list.Set((CecLogicalAddress)Enum.Parse(typeof(CecLogicalAddress), property.Name, true));
                        }
                    }
                }

                sel = null;
            }
        }
Ejemplo n.º 14
0
    private CecLogicalAddresses ParseDevices(string devices)
    {
      CecLogicalAddresses list = new CecLogicalAddresses();

      if (devices.Length == 0)
      {
        return list;
      }

      string[] devicelist = devices.Split(',');
      
      foreach (string d in devicelist)
      {
        if (d != "Unknown" && d != "Unregistered")
        {
          list.Set((CecSharp.CecLogicalAddress)Enum.Parse(typeof(CecLogicalAddress), d));
        }
      }

      return list;
    }
Ejemplo n.º 15
0
    private void ShowSelectDevices(CecLogicalAddresses list)
    {

      SelectDevices sel = new SelectDevices();
      sel.StartPosition = FormStartPosition.CenterParent;

      foreach (PropertyInfo property in sel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
      {
        if (property.CanWrite && property.PropertyType.Equals(typeof(System.Boolean)))
        {
          property.SetValue(sel, false, null);
          if (list.IsSet((CecLogicalAddress)Enum.Parse(typeof(CecLogicalAddress), property.Name, true)))
          {
            property.SetValue(sel, true, null);
          }
        }
      }

      if (sel.ShowDialog(this) == DialogResult.OK)
      {
        list.Clear();

        foreach (PropertyInfo property in sel.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly))
        {
          if (property.CanRead && property.PropertyType.Equals(typeof(System.Boolean)))
          {
            if ((bool)property.GetValue(sel, null))
            {
              list.Set((CecLogicalAddress)Enum.Parse(typeof(CecLogicalAddress), property.Name, true));
            }
          }
        }

        sel = null;
      }
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Event handler for processing updates for a background thread
    /// </summary>
    /// <param name="src">The source that sent the event</param>
    /// <param name="updateEvent">The type of event</param>
    private void ProcessEventHandler(object src, UpdateEvent updateEvent)
    {
      switch (updateEvent.Type)
      {
        case UpdateEventType.StatusText:
          _controller.SetStatusText(updateEvent.StringValue);
          break;
        case UpdateEventType.ProgressBar:
          _controller.SetProgressBar(updateEvent.IntValue, true);
          break;
        case UpdateEventType.PhysicalAddress:
          _controller.Settings.PhysicalAddress.Value = (ushort)updateEvent.IntValue;
          break;
        case UpdateEventType.TVVendorId:
          _controller.Settings.SetVendorName(CecLogicalAddress.Tv, (CecVendorId)updateEvent.IntValue, _controller.Lib.ToString((CecVendorId)updateEvent.IntValue));
          break;
        case UpdateEventType.BaseDevice:
          _controller.Settings.ConnectedDevice.Value = (CecLogicalAddress)updateEvent.IntValue;
          break;
        case UpdateEventType.HDMIPort:
          _controller.Settings.HDMIPort.Value = (byte)updateEvent.IntValue;
          break;
        case UpdateEventType.HasAVRDevice:
          CecLogicalAddresses allowedMask = new CecLogicalAddresses();
          allowedMask.Set(CecLogicalAddress.Tv);
          if (updateEvent.BoolValue)
            allowedMask.Set(CecLogicalAddress.AudioSystem);
          _controller.Settings.ConnectedDevice.AllowedAddressMask = allowedMask;
          break;
        case UpdateEventType.AVRVendorId:
          _controller.Settings.SetVendorName(CecLogicalAddress.AudioSystem, (CecVendorId)updateEvent.IntValue, _controller.Lib.ToString((CecVendorId)updateEvent.IntValue));
          break;
        case UpdateEventType.Configuration:
          SuppressUpdates = true;
          _controller.ConfigurationChanged(updateEvent.ConfigValue);
          SuppressUpdates = false;
          break;
        case UpdateEventType.PollDevices:
          _controller.CheckActiveDevices();
          break;
        case UpdateEventType.ProcessCompleted:
          if (!(_activeProcess is GetCurrentPhysicalAddress) && !SuppressUpdates)
          {
            _activeProcess = new GetCurrentPhysicalAddress(_controller.Lib);
            _activeProcess.EventHandler += ProcessEventHandler;
            (new Thread(_activeProcess.Run)).Start();
          }
          else
          {
            _activeProcess = null;
          }

          if (_updatingInfoPanel != null)
          {
            _updatingInfoPanel.SetControlEnabled(_updatingInfoPanel.bUpdate, true);
            _updatingInfoPanel = null;
          }

          _controller.SetControlsEnabled(true);
          _controller.SetProgressBar(100, false);

          if (_controller.Settings.StartHidden.Value)
          {
            _controller.SetShowInTaskbar(false);
            //SetToolStripMenuText(tsMenuShowHide, Resources.show);
            _controller.Hide(true);
          }

          break;
        case UpdateEventType.ExitApplication:
          SuppressUpdates = true;
          _activeProcess = null;
          Application.Exit();
          break;
        case UpdateEventType.Connected:
          _controller.SetControlsEnabled(true);
          break;
      }
    }
Ejemplo n.º 17
0
 static bool HasAdvancedDeviceIdSet(CecLogicalAddresses addresses)
 {
     foreach (var val in addresses.Addresses)
     if (val != CecLogicalAddress.Tv && val != CecLogicalAddress.AudioSystem)
       return true;
       return false;
 }
Ejemplo n.º 18
0
    /// <summary>
    /// Send "Stand by" -signal to multiple devices.
    /// </summary>
    public bool StandByDevice(CecLogicalAddresses device)
    {
      bool ret = true;

      foreach (CecLogicalAddress a in device.Addresses)
      {
        if (a != CecLogicalAddress.Unknown)
        {
          if (!StandByDevice(a))
          {
            ret = false;
          }
        }
      }

      return ret;
    }
Ejemplo n.º 19
0
 public CECSettingLogicalAddresses(string keyName, string friendlyName, CecLogicalAddresses defaultValue, SettingChangedHandler changedHandler) :
     base(CECSettingType.LogicalAddresses, keyName, friendlyName, SerialiseLogicalAddresses(defaultValue), changedHandler)
 {
 }
Ejemplo n.º 20
0
 public CECSettingLogicalAddresses(string keyName, string friendlyName, CecLogicalAddresses defaultValue, SettingChangedHandler changedHandler)
     : base(CECSettingType.LogicalAddresses, keyName, friendlyName, SerialiseLogicalAddresses(defaultValue), changedHandler)
 {
 }
Ejemplo n.º 21
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.º 22
0
    public void SetDefaults()
    {
      HdmiPort = 1;
      DeviceType = CecDeviceType.RecordingDevice;

      OsdName = "MediaPortal";

      FastScrolling = false;
      FastScrollingRepeatDelay = 2;
      FastScrollingRepeatRate = 40;

      RequireDelayBetweenKeys = false;
      DelayBetweenKeys = 300;

      DisableScreensaver = false;
      ExtensiveLogging = false;

      WakeDevicesOnStart = true;
      ActivateSourceOnStart = true;
      OnStartWakeDevices = new CecLogicalAddresses();
      OnStartWakeDevices.Set(CecLogicalAddress.Tv);
      OnStartWakeDevices.Set(CecLogicalAddress.AudioSystem);

      StandbyDevicesOnExit = false;
      InactivateSourceOnExit = false;
      OnExitStandbyDevices = new CecLogicalAddresses();
      OnExitStandbyDevices.Set(CecLogicalAddress.Tv);
      OnExitStandbyDevices.Set(CecLogicalAddress.AudioSystem);

      WakeDevicesOnResume = true;
      ActivateSourceOnResume = true;
      RequireUserInputOnResume = true;
      OnResumeWakeDevices = new CecLogicalAddresses();
      OnResumeWakeDevices.Set(CecLogicalAddress.Tv);
      OnResumeWakeDevices.Set(CecLogicalAddress.AudioSystem);

      StandbyDevicesOnSleep = true;
      InactivateSourceOnSleep = false;
      OnSleepStandbyDevices = new CecLogicalAddresses();
      OnSleepStandbyDevices.Set(CecLogicalAddress.Tv);
      OnSleepStandbyDevices.Set(CecLogicalAddress.AudioSystem);

      ClientVersion = LibCECConfiguration.CurrentVersion;
      ConnectedTo = CecLogicalAddress.Tv;

      SendTvPowerOff = false;
      SendTvPowerOffOnlyIfActiveSource = true;
      RequireActiveSourceWhenSleep = true;

      ControlVolume = false;
      ForcePhysicalAddress = false;
      PhysicalAddress = "1000";

    }
Ejemplo n.º 23
0
    private string DevicesToString(CecLogicalAddresses list)
    {
      if (list.Primary == CecLogicalAddress.Unknown)
      {
        return string.Empty;
      }

      string deviceList = "";

      foreach (CecLogicalAddress a in list.Addresses)
      {
        if (a != CecLogicalAddress.Unknown && a != CecLogicalAddress.Unregistered)
        {
          deviceList += a.ToString() + ',';
        }
      }

      if (deviceList.Length == 0)
      {
        return string.Empty;
      }
      else
      {
        return deviceList.Remove(deviceList.Length - 1);
      }

    }
Ejemplo n.º 24
0
        /// <summary>
        /// Event handler for processing updates for a background thread
        /// </summary>
        /// <param name="src">The source that sent the event</param>
        /// <param name="updateEvent">The type of event</param>
        private void ProcessEventHandler(object src, UpdateEvent updateEvent)
        {
            switch (updateEvent.Type)
            {
            case UpdateEventType.StatusText:
                _controller.SetStatusText(updateEvent.StringValue);
                break;

            case UpdateEventType.ProgressBar:
                _controller.SetProgressBar(updateEvent.IntValue, true);
                break;

            case UpdateEventType.PhysicalAddress:
                _controller.Settings.PhysicalAddress.Value = (ushort)updateEvent.IntValue;
                break;

            case UpdateEventType.TVVendorId:
                _controller.Settings.SetVendorName(CecLogicalAddress.Tv, (CecVendorId)updateEvent.IntValue, _controller.Lib.ToString((CecVendorId)updateEvent.IntValue));
                break;

            case UpdateEventType.BaseDevice:
                _controller.Settings.ConnectedDevice.Value = (CecLogicalAddress)updateEvent.IntValue;
                break;

            case UpdateEventType.HDMIPort:
                _controller.Settings.HDMIPort.Value = (byte)updateEvent.IntValue;
                break;

            case UpdateEventType.HasAVRDevice:
                CecLogicalAddresses allowedMask = new CecLogicalAddresses();
                allowedMask.Set(CecLogicalAddress.Tv);
                if (updateEvent.BoolValue)
                {
                    allowedMask.Set(CecLogicalAddress.AudioSystem);
                }
                _controller.Settings.ConnectedDevice.AllowedAddressMask = allowedMask;
                break;

            case UpdateEventType.AVRVendorId:
                _controller.Settings.SetVendorName(CecLogicalAddress.AudioSystem, (CecVendorId)updateEvent.IntValue, _controller.Lib.ToString((CecVendorId)updateEvent.IntValue));
                break;

            case UpdateEventType.Configuration:
                SuppressUpdates = true;
                _controller.ConfigurationChanged(updateEvent.ConfigValue);
                SuppressUpdates = false;
                break;

            case UpdateEventType.PollDevices:
                _controller.CheckActiveDevices();
                break;

            case UpdateEventType.ProcessCompleted:
                if (!(_activeProcess is GetCurrentPhysicalAddress) && !SuppressUpdates)
                {
                    _activeProcess = new GetCurrentPhysicalAddress(_controller.Lib);
                    _activeProcess.EventHandler += ProcessEventHandler;
                    (new Thread(_activeProcess.Run)).Start();
                }
                else
                {
                    _activeProcess = null;
                }

                if (_updatingInfoPanel != null)
                {
                    _updatingInfoPanel.SetControlEnabled(_updatingInfoPanel.bUpdate, true);
                    _updatingInfoPanel = null;
                }

                _controller.SetControlsEnabled(true);
                _controller.SetProgressBar(100, false);

                if (_controller.Settings.StartHidden.Value)
                {
                    _controller.SetShowInTaskbar(false);
                    //SetToolStripMenuText(tsMenuShowHide, Resources.show);
                    _controller.Hide(true);
                }

                break;

            case UpdateEventType.ExitApplication:
                SuppressUpdates = true;
                _activeProcess  = null;
                Application.Exit();
                break;

            case UpdateEventType.Connected:
                _controller.SetControlsEnabled(true);
                break;
            }
        }
Ejemplo n.º 25
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]);
                }
            }
        }