Exemplo n.º 1
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (_availableInputs.Contains(input))
            {
                switch (input)
                {
                case DisplayDeviceInput.HDMI1:
                    _requestedInputValue = "HDMI";
                    break;

                case DisplayDeviceInput.DVI:
                    _requestedInputValue = "D-RGB";
                    break;

                case DisplayDeviceInput.VGA:
                    _requestedInputValue = "A-RGB2";
                    break;

                case DisplayDeviceInput.HDBaseT:
                    _requestedInputValue = "HDBT";
                    break;
                }

                _socket.Send(string.Format("INPUT={0}", _requestedInputValue));
                _socket.Send("GET=INPUT");
            }
            else
            {
                CloudLog.Error("{0} does not have the option of input: {1}", this, input);
            }
        }
Exemplo n.º 2
0
        public string InputCommandForInput(DisplayDeviceInput input)
        {
            switch (input)
            {
            case DisplayDeviceInput.HDMI1:
            case DisplayDeviceInput.HDMI2:
            case DisplayDeviceInput.HDMI3:
            case DisplayDeviceInput.HDMI4:
                return("HDMI");

            case DisplayDeviceInput.VGA:
                return("A-RGB");

            case DisplayDeviceInput.DVI:
                return("D-RGB");

            case DisplayDeviceInput.YUV:
                return("COMP");

            case DisplayDeviceInput.Composite:
                return("VIDEO");

            default: return("");
            }
        }
Exemplo n.º 3
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (_availableInputs.Contains(input))
            {
                _requestedInput = input;

                switch (input)
                {
                case DisplayDeviceInput.HDMI1:
                    Send('x', 'b', 0x90);
                    break;

                case DisplayDeviceInput.HDMI2:
                    Send('x', 'b', 0x91);
                    break;

                case DisplayDeviceInput.HDMI3:
                    Send('x', 'b', 0x92);
                    break;

                case DisplayDeviceInput.HDMI4:
                    Send('x', 'b', 0x93);
                    break;
                }
            }
            else
            {
                CloudLog.Error("{0} does not have the option of input: {1}", this, input);
            }
        }
Exemplo n.º 4
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (AvailableInputs.All(i => i != input))
            {
                throw new Exception("Invalid Input");
            }

            ResetPolling();

            switch (input)
            {
            case DisplayDeviceInput.BuiltIn:
                Send("Source=0");
                break;

            case DisplayDeviceInput.DisplayPort:
                Send("Source=1");
                break;

            case DisplayDeviceInput.HDMI1:
                Send("Source=2");
                break;

            case DisplayDeviceInput.VGA:
                Send("Source=3");
                break;

            case DisplayDeviceInput.Wireless:
                Send("Source=4");
                break;
            }
        }
Exemplo n.º 5
0
        public string InputCommandForInput(DisplayDeviceInput input)
        {
            switch (input)
            {
            case DisplayDeviceInput.HDMI1:
                return("hdmi1");

            case DisplayDeviceInput.HDMI2:
                return("hdmi2");

            case DisplayDeviceInput.HDMI3:
                return("hdmi3/pc");

            case DisplayDeviceInput.DisplayPort:
                return("displayport");

            case DisplayDeviceInput.VGA:
                return("vga1");

            case DisplayDeviceInput.DVI:
                return("dvi");

            case DisplayDeviceInput.Composite:
                return("video");

            default: return("");
            }
        }
Exemplo n.º 6
0
        public byte InputCommandForInput(DisplayDeviceInput input)
        {
            switch (input)
            {
            case DisplayDeviceInput.HDMI1:
                return(0x09);

            case DisplayDeviceInput.HDMI2:
                return(0x0a);

            case DisplayDeviceInput.HDMI3:
                return(0x0b);

            case DisplayDeviceInput.HDMI4:
                return(0x0c);

            case DisplayDeviceInput.DisplayPort:
                return(0x0d);

            case DisplayDeviceInput.BuiltIn:
                return(0x0e);

            case DisplayDeviceInput.VGA:
                return(0x00);

            default:
                return(0xff);
            }
        }
        byte GetInputCommandForInput(DisplayDeviceInput input)
        {
            switch (input)
            {
            case DisplayDeviceInput.HDMI1: return(0x21);

            case DisplayDeviceInput.HDMI2: return(0x23);

            case DisplayDeviceInput.HDMI3: return(0x31);

            case DisplayDeviceInput.VGA: return(0x14);

            case DisplayDeviceInput.DVI: return(0x18);

            case DisplayDeviceInput.Composite: return(0x0c);

            case DisplayDeviceInput.YUV: return(0x08);

            case DisplayDeviceInput.DisplayPort: return(0x25);

            case DisplayDeviceInput.MagicInfo: return(0x60);

            case DisplayDeviceInput.TV: return(0x40);

            case DisplayDeviceInput.RGBHV: return(0x1e);
            }
            throw new IndexOutOfRangeException("Input not supported on this device");
        }
Exemplo n.º 8
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (!Power)
            {
                Power = true;
            }

            switch (input)
            {
            case DisplayDeviceInput.HDMI1:
            case DisplayDeviceInput.HDMI2:
            case DisplayDeviceInput.HDMI3:
                SendInputCommand(input.ToString().ToLower());
                break;

            case DisplayDeviceInput.DVI:
                SendInputCommand("dp1");
                break;

            case DisplayDeviceInput.VGA:
                SendInputCommand("vga1");
                break;

            case DisplayDeviceInput.BuiltIn:
                SendInputCommand("ops1");
                break;

            case DisplayDeviceInput.BuiltIn2:
                SendInputCommand("ops1cc");
                break;

            default:
                throw new ArgumentOutOfRangeException("input", "Not a supported value");
            }
        }
Exemplo n.º 9
0
 public override void SetInput(DisplayDeviceInput input)
 {
     _requestedInput = InputCommandForInput(input);
     if (_requestedInput == 0xff)
     {
         return;
     }
     _socket.Send(1, MessageType.Write, new byte[] { 0x4d, 0x49, 0x4e, _requestedInput });
 }
Exemplo n.º 10
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (!Power)
            {
                Power = true;
            }

            _currentInput = input;
            SendInputCommand(_currentInput);
        }
Exemplo n.º 11
0
 protected virtual void RouteSourceDisplayDeviceInput(DisplayDeviceInput input)
 {
     try
     {
         _displayDevice.SetInput(input);
     }
     catch (Exception e)
     {
         CloudLog.Exception(e, "Error setting display device input");
     }
 }
Exemplo n.º 12
0
        public override void SetInput(DisplayDeviceInput input)
        {
            if (_availableInputs.Contains(input))
            {
                switch (input)
                {
                case DisplayDeviceInput.HDMI1:
                    _requestedInputValue = 3;
                    break;

                case DisplayDeviceInput.HDMI2:
                    _requestedInputValue = 4;
                    break;

                case DisplayDeviceInput.DVI:
                    _requestedInputValue = 5;
                    break;

                case DisplayDeviceInput.VGA:
                    _requestedInputValue = 1;
                    break;

                case DisplayDeviceInput.SDI:
                    _requestedInputValue = 7;
                    break;

                case DisplayDeviceInput.HDBaseT:
                    _requestedInputValue = 8;
                    break;
                }

                if (_requestedInputValue > 0)
                {
                    Send(string.Format("SIN {0}", _requestedInputValue));
                }
            }
            else
            {
                CloudLog.Error("{0} does not have the option of input: {1}", this, input);
            }
        }
Exemplo n.º 13
0
        byte GetInputCommandForInput(DisplayDeviceInput input)
        {
            switch (input)
            {
            case DisplayDeviceInput.DisplayPort: return(0x0f);

            case DisplayDeviceInput.DisplayPort2: return(0x10);

            case DisplayDeviceInput.HDMI1: return(0x11);

            case DisplayDeviceInput.HDMI2: return(0x12);

            case DisplayDeviceInput.HDMI3: return(0x82);

            case DisplayDeviceInput.HDMI4: return(0x83);

            case DisplayDeviceInput.DVI: return(0x03);

            case DisplayDeviceInput.DVI2: return(0x04);

            case DisplayDeviceInput.VGA: return(0x01);
            }
            throw new IndexOutOfRangeException("Input not supported on this device");
        }
Exemplo n.º 14
0
        private void SocketOnReceivedData(string data)
        {
            if (data.StartsWith("g:"))
            {
                var response = data.Substring(2, data.Length - 2);
#if DEBUG
                //CrestronConsole.PrintLine("{0} received: {1}", this, response);
#endif
                if (!response.Contains("="))
                {
                    return;
                }

                var command = response.Split('=')[0];
                var value   = response.Split('=')[1];

                switch (command)
                {
                case "POWER":
                {
                    switch (value)
                    {
                    case "OFF":
                        SetPowerFeedback(DevicePowerStatus.PowerOff);
                        break;

                    case "ON":
                        SetPowerFeedback(DevicePowerStatus.PowerOn);
                        break;

                    case "ON2OFF":
                        SetPowerFeedback(DevicePowerStatus.PowerCooling);
                        break;

                    case "OFF2ON":
                        SetPowerFeedback(DevicePowerStatus.PowerWarming);
                        break;
                    }
                }
                break;

                case "INPUT":
                {
                    _currentInput = GetInputForInputValue(value);
                    if (_requestedInputValue.Length > 0 && _requestedInputValue != value)
                    {
                        _socket.Send(string.Format("INPUT={0}", _requestedInputValue));
                    }
                    else if (_requestedInputValue.Length > 0)
                    {
                        _requestedInputValue = string.Empty;
                    }
                }
                break;

                case "LAMPCOUNTER":
                {
                    if (value.StartsWith("\"[") && value.EndsWith("]\""))
                    {
                        var bar = value.Substring(2, value.Length - 4);

                        var count = 0;
                        foreach (var c in bar)
                        {
                            if (c != '_')
                            {
                                count++;
                            }
                            else
                            {
                                break;
                            }
                        }

                        DisplayUsage =
                            (ushort)Tools.ScaleRange(count, 0, bar.Length, ushort.MinValue, ushort.MaxValue);
                    }
                }
                break;
                }
            }
            else if (data.StartsWith("e:"))
            {
                CloudLog.Error("{0} recieved Error: {1}", this, data.Substring(2, data.Length - 2));
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Set the input on the display
 /// </summary>
 /// <param name="input"></param>
 public abstract void SetInput(DisplayDeviceInput input);
Exemplo n.º 16
0
        private void SocketOnReceivedData(byte[] bytes)
        {
#if DEBUG
            CrestronConsole.Print("{0} received: ", GetType());
            Tools.PrintBytes(bytes, 0, bytes.Length, true);
#endif

            if (bytes[3] == 0x50 && bytes[4] == 0x4f && bytes[5] == 0x57)
            {
#if DEBUG
                CrestronConsole.PrintLine("Power = {0}", Convert.ToBoolean(bytes[6]));
#endif
                SetPowerFeedback(Convert.ToBoolean(bytes[6]) ? DevicePowerStatus.PowerOn : DevicePowerStatus.PowerOff);
            }

            else if (bytes[3] == 0x4d && bytes[4] == 0x49 && bytes[5] == 0x4e)
            {
#if DEBUG
                CrestronConsole.PrintLine("Actual input = {0}, requested input = {1}", bytes[6], _requestedInput);
#endif

                switch (bytes[6])
                {
                case 0x09:
                    _currentInput = DisplayDeviceInput.HDMI1;
                    break;

                case 0x0a:
                    _currentInput = DisplayDeviceInput.HDMI2;
                    break;

                case 0x0b:
                    _currentInput = DisplayDeviceInput.HDMI3;
                    break;

                case 0x0c:
                    _currentInput = DisplayDeviceInput.HDMI4;
                    break;

                case 0x0d:
                    _currentInput = DisplayDeviceInput.DisplayPort;
                    break;

                case 0x0e:
                    _currentInput = DisplayDeviceInput.BuiltIn;
                    break;

                case 0x00:
                    _currentInput = DisplayDeviceInput.VGA;
                    break;

                default:
                    _currentInput = DisplayDeviceInput.Unknown;
                    break;
                }

                if (_requestedInput != 0xff && _requestedInput != bytes[6])
                {
                    _socket.Send(1, MessageType.Write, new byte[] { 0x4d, 0x49, 0x4e, _requestedInput });
                }
                else if (_requestedInput != 0xff && _requestedInput == bytes[6])
                {
                    _requestedInput = 0xff;
                }
            }

            else if (bytes[3] == 0x56 && bytes[4] == 0x4f && bytes[5] == 0x4c)
            {
                var v = Convert.ToUInt32(bytes[6]);
                //if (_volume.Equals(v)) return;
                //_volume = v;
                //OnVolumeChanged(this, new VolumeChangeEventArgs(VolumeLevelChangeEventType.LevelChanged));
            }
        }
Exemplo n.º 17
0
        private object ReceiveBufferProcess(object userspecific)
        {
            var bytes     = new Byte[1000];
            var byteIndex = 0;

            while (true)
            {
                try
                {
                    var b = _rxQueue.Dequeue();

                    if (_programStopping)
                    {
                        return(null);
                    }
                    if (b == 10)
                    {
                        //ignore
                    }
                    else if (b == 13)
                    {
                        var copiedBytes = new byte[byteIndex];
                        Array.Copy(bytes, copiedBytes, byteIndex);
#if DEBUG
                        CrestronConsole.Print("Surface Hub Processed Response: ");
                        Tools.PrintBytes(copiedBytes, 0, copiedBytes.Length, true);
#endif
                        try
                        {
                            var match = Regex.Match(Encoding.ASCII.GetString(copiedBytes, 0, copiedBytes.Length),
                                                    @"^\w+=\d+$");
                            if (match.Success)
                            {
                                var paramName = match.Groups[1].Value;
                                if (string.IsNullOrEmpty(paramName))
                                {
                                    var value = 0;
                                    try
                                    {
                                        value = int.Parse(match.Groups[2].Value);
                                    }
                                    catch
                                    {
                                        Debug.WriteWarn(
                                            string.Format("{0}, Error parsing value \"{1}\" for key paramName\"{2}\"",
                                                          GetType().Name, match.Groups[2].Value, paramName));
                                    }

                                    switch (paramName)
                                    {
                                    case "power":
                                        switch (value)
                                        {
                                        case 1:
                                            SetPowerFeedback(DevicePowerStatus.PowerWarming);
                                            break;

                                        case 5:
                                            SetPowerFeedback(DevicePowerStatus.PowerOn);
                                            break;

                                        default:
                                            SetPowerFeedback(DevicePowerStatus.PowerOff);
                                            break;
                                        }
                                        break;

                                    case "source":
                                        switch (value)
                                        {
                                        case 0:
                                            _currentInput = DisplayDeviceInput.BuiltIn;
                                            break;

                                        case 1:
                                            _currentInput = DisplayDeviceInput.DisplayPort;
                                            break;

                                        case 2:
                                            _currentInput = DisplayDeviceInput.HDMI1;
                                            break;

                                        case 3:
                                            _currentInput = DisplayDeviceInput.VGA;
                                            break;

                                        case 4:
                                            _currentInput = DisplayDeviceInput.Wireless;
                                            break;
                                        }
                                        break;
                                    }
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            CloudLog.Exception(e);
                        }

                        byteIndex = 0;
                    }
                    else
                    {
                        bytes[byteIndex] = b;
                        byteIndex++;
                    }
                }
                catch (Exception e)
                {
                    if (e.Message != "ThreadAbortException")
                    {
#if DEBUG
                        CrestronConsole.Print("Error in Surface Hub Rx Handler: ");
                        Tools.PrintBytes(bytes, 0, byteIndex);
#endif
                        CloudLog.Exception(string.Format("{0} - Exception in rx thread", GetType().Name), e);
                    }
                }

                CrestronEnvironment.AllowOtherAppsToRun();
                Thread.Sleep(0);
            }
        }
Exemplo n.º 18
0
 public override void SetInput(DisplayDeviceInput input)
 {
 }
Exemplo n.º 19
0
        private object CheckStatusThread(object userSpecific)
        {
            CloudLog.Info("{0} Started status checking thread", GetType().Name);

            while (!_programStopping)
            {
                try
                {
                    if (_inputStatusNotChecked)
                    {
                        _checkWait.Wait(5000);
                    }
                    else
                    {
                        _checkWait.Wait(60000);
                    }

                    _threadRunning = true;

                    CrestronEnvironment.AllowOtherAppsToRun();
                    Thread.Sleep(0);

                    if (_programStopping)
                    {
                        return(null);
                    }

                    #region Get System Info

                    var response =
                        SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/system", "getSystemInformation", "1.0")
                        .Await();
                    if (response.Type != SonyBraviaResponseType.Success)
                    {
                        if (response.ConnectionFailed)
                        {
                            DeviceCommunicating = false;
                            _connectionOk       = false;
                        }
                        continue;
                    }

                    try
                    {
                        var info = response.Data.First() as JObject;
                        _serialNumber = info["serial"].Value <string>();
                        _model        = info["model"].Value <string>();
                        _macAddress   = info["macAddr"].Value <string>();
                        _versionInfo  = info["generation"].Value <string>();
                    }
                    catch (Exception e)
                    {
                        CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                           response.RequestMethod);
                    }

                    #endregion

                    #region Get Power Status

                    var previousPowerWasNotOn = PowerStatus != DevicePowerStatus.PowerOn;

                    response =
                        SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/system", "getPowerStatus", "1.0")
                        .Await();
                    if (response.Type != SonyBraviaResponseType.Success)
                    {
                        if (response.ConnectionFailed)
                        {
                            DeviceCommunicating = false;
                            _connectionOk       = false;
                        }
                        continue;
                    }

                    try
                    {
                        var info = response.Data.First() as JObject;

                        switch (info["status"].Value <string>())
                        {
                        case "standby":
                            SetPowerFeedback(DevicePowerStatus.PowerOff);
                            break;

                        case "active":
                            SetPowerFeedback(DevicePowerStatus.PowerOn);
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                           response.RequestMethod);
                        continue;
                    }

                    #endregion

                    DeviceCommunicating = true;

                    if (PowerStatus == DevicePowerStatus.PowerOn)
                    {
                        #region Get Input Status

                        response =
                            SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/avContent",
                                                         "getPlayingContentInfo", "1.0").Await();
                        if (response.Type != SonyBraviaResponseType.Success)
                        {
                            CloudLog.Warn("Error trying to get input status from Sony Display, will try again in 5 seconds");
                            _inputStatusNotChecked = true;
                            continue;
                        }

                        try
                        {
                            var info = response.Data.First() as JObject;

                            var uri = info["uri"].Value <string>();

                            if (_availableSources != null && _availableSources.Any(s => s != null && s.Uri == uri))
                            {
                                _currentInput = _availableSources.First(s => s.Uri == uri).InputType;

                                if (_requestedInput != DisplayDeviceInput.Unknown && _currentInput != _requestedInput)
                                {
                                    SetInput(_requestedInput,
                                             previousPowerWasNotOn ? TimeSpan.FromSeconds(2) : TimeSpan.Zero);
                                }
                                else if (_requestedInput == _currentInput)
                                {
                                    _requestedInput = DisplayDeviceInput.Unknown;
                                }
                            }
                            else
                            {
                                _currentInput = DisplayDeviceInput.Unknown;
                            }

                            _inputStatusNotChecked = false;
                        }
                        catch (Exception e)
                        {
                            CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                               response.RequestMethod);
                        }

                        #endregion

                        #region Get Volume Level

                        response =
                            SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/audio", "getVolumeInformation",
                                                         "1.0").Await();
                        if (response.Type != SonyBraviaResponseType.Success)
                        {
                            continue;
                        }

                        try
                        {
                            foreach (var token in response.Data.First())
                            {
                                var info = token as JObject;

                                var type =
                                    (TargetVolumeDeviceType)
                                    Enum.Parse(typeof(TargetVolumeDeviceType), info["target"].Value <string>(), true);

                                var currentLevel = info["volume"].Value <int>();
                                var minLevel     = info["minVolume"].Value <int>();
                                var maxLevel     = info["maxVolume"].Value <int>();
                                var mute         = info["mute"].Value <bool>();

                                var control =
                                    _volumeControls.Cast <SonyBraviaVolumeControl>()
                                    .FirstOrDefault(c => c.TargetType == type);

                                if (control == null)
                                {
                                    continue;
                                }

                                control.VolumeMin     = minLevel;
                                control.VolumeMax     = maxLevel;
                                control.InternalLevel = currentLevel;
                                control.InternalMute  = mute;
                            }
                        }
                        catch (Exception e)
                        {
                            CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                               response.RequestMethod);
                        }

                        #endregion
                    }

                    if (_connectionOk)
                    {
                        continue;
                    }

                    CloudLog.Info("{0} at {1} will now get status. Either failed previously or first connect",
                                  GetType().Name, DeviceAddressString);

                    #region Get Input and Source Schemes

                    var schemes = new List <string>();

                    response =
                        SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/avContent", "getSchemeList", "1.0")
                        .Await();
                    if (response.Type != SonyBraviaResponseType.Success)
                    {
                        CloudLog.Error("{0} could not get SchemeList, {1}", GetType().Name, response.Type);
                        continue;
                    }

                    try
                    {
                        var info = response.Data.First() as JArray;

                        schemes.AddRange(info.Select(token => token as JObject).Select(o => o["scheme"].Value <string>()));

                        if (schemes.Count == 0)
                        {
                            CloudLog.Warn("Received empty array for {0} getSchemeList, moving to generate defaults",
                                          GetType().Name);
                            goto ErrorGettingInputs;
                        }
                    }
                    catch (Exception e)
                    {
                        CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                           response.RequestMethod);
                        continue;
                    }

                    var sources = new Dictionary <string, List <string> >();

                    foreach (var scheme in schemes)
                    {
                        response =
                            SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/avContent", "getSourceList", "1.0",
                                                         new JObject
                        {
                            { "scheme", scheme }
                        }).Await();

                        if (response.Type != SonyBraviaResponseType.Success)
                        {
                            CloudLog.Warn("{0} could not get SourceList for scheme \"{1}\", {2}",
                                          GetType().Name, scheme, response.Type);
                            continue;
                        }

                        try
                        {
                            var info = response.Data.First() as JArray;

                            var list = new List <string>();
                            sources[scheme] = list;
                            list.AddRange(info.Select(token => token as JObject)
                                          .Select(o => o["source"].Value <string>()));
                        }
                        catch (Exception e)
                        {
                            CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                               response.RequestMethod);
                        }
                    }

                    var newContentList = new List <SonyContentSource>();

                    foreach (
                        var source in
                        sources.Where(k => k.Key != "fav").Select(k => k.Value).SelectMany(scheme => scheme))
                    {
                        response =
                            SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/avContent", "getContentList",
                                                         "1.0", new JObject
                        {
                            { "source", source }
                        }).Await();

                        if (response.Type != SonyBraviaResponseType.Success)
                        {
                            CloudLog.Warn("{0} could not get ConntentList for source \"{1}\", {2}",
                                          GetType().Name, source, response.Type);
                            continue;
                        }

                        try
                        {
                            var info = response.Data.First() as JArray;

                            foreach (var token in info)
                            {
                                try
                                {
                                    var input = new SonyContentSource(token as JObject);
                                    newContentList.Add(input);
                                    Debug.WriteInfo("Sony content source", input.ToString());
                                }
                                catch (Exception e)
                                {
                                    CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                                       response.RequestMethod);
                                }
                            }

                            goto FoundInputs;
                        }
                        catch (Exception e)
                        {
                            CloudLog.Exception(e, "Error in request: \"{0}\", {1}", response.RequestUri,
                                               response.RequestMethod);
                        }
                    }

ErrorGettingInputs:
                    CloudLog.Warn("Error getting input schemes for {0}, Generating default HDMI inputs", GetType().Name);
                    _availableSources = new List <SonyContentSource>()
                    {
                        new SonyContentSource("extInput:hdmi?port=1", "HDMI 1", 0),
                        new SonyContentSource("extInput:hdmi?port=2", "HDMI 2", 1),
                        new SonyContentSource("extInput:hdmi?port=3", "HDMI 3", 2),
                        new SonyContentSource("extInput:hdmi?port=4", "HDMI 4", 3)
                    };
                    goto InputsDone;

FoundInputs:
                    _availableSources = newContentList;

InputsDone:
                    Debug.WriteSuccess("Available inputs");
                    foreach (var source in _availableSources)
                    {
                        Debug.WriteNormal(source.ToString());
                    }

                    #endregion

                    _connectionOk = true;
                }
                catch (Exception e)
                {
                    CloudLog.Error("Error in {0}, message = {1}", Thread.CurrentThread.Name, e.Message);
                }
            }

            return(null);
        }
Exemplo n.º 20
0
        public void SetInput(DisplayDeviceInput input, TimeSpan delay)
        {
            _requestedInput = input;

            CloudLog.Debug("{0}.SetInput({1})", GetType().Name, _requestedInput);

            if (RequestedPower != Power)
            {
                CloudLog.Debug("{0}.SetInput({1}) ... Waiting for power", GetType().Name, _requestedInput);
                return;
            }

            if (_inputSetThread != null && _inputSetThread.ThreadState == Thread.eThreadStates.ThreadRunning)
            {
                return;
            }

            _inputSetThread = new Thread(specific =>
            {
                try
                {
                    CloudLog.Debug("{0}._inputSetThread Started", GetType().Name);

                    var delayWait = (int)((TimeSpan)specific).TotalMilliseconds;

                    CloudLog.Debug("{0}._inputSetThread waiting for {1}ms", GetType().Name, delayWait);

                    Thread.Sleep(delayWait);

                    if (_availableSources == null || _availableSources.Count == 0)
                    {
                        CloudLog.Warn("{0}.SetInput - _availableSources is null or empty", GetType().Name);
                        _connectionOk = false;
                    }

                    if (!_connectionOk)
                    {
                        CloudLog.Warn(
                            "{0} not initialized properly at time of trying to set input. Alerting poll thread and waiting",
                            GetType().Name);
                        _checkWait.Set();
                        Thread.Sleep(2000);
                    }

                    if (PowerStatus == DevicePowerStatus.PowerWarming)
                    {
                        CloudLog.Debug("{0}.SetInput - device is warming up, waiting...", GetType().Name);
                        Thread.Sleep(2000);
                    }

                    CloudLog.Debug("{0}._inputSetThread finding the Uri for \"{1}\"", GetType().Name, _requestedInput);

                    var availableSource = _availableSources.FirstOrDefault(s => s.InputType == _requestedInput);
                    if (availableSource == null)
                    {
                        CloudLog.Error(
                            "Cannot set display to {0} as it's not in the list of available sources. Init error?", _requestedInput);
                        _connectionOk = false;
                        return(null);
                    }

                    var uri = availableSource.Uri;

                    var response =
                        SonyBraviaHttpClient.Request(_deviceAddress, _psk, "/sony/avContent", "setPlayContent", "1.0",
                                                     new JObject
                    {
                        { "uri", uri }
                    }).Await();

                    if (response.Type == SonyBraviaResponseType.Success)
                    {
                        _currentInput = _requestedInput;
                    }
                    else if (response.Type == SonyBraviaResponseType.Failed)
                    {
                        CloudLog.Error("Could not set display input, Response = {0}, {1}", response.Type,
                                       response.Exception.Message);
                    }
                    else
                    {
                        CloudLog.Error("Could not set display input, Response = {0}", response.Type);
                    }
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e, "Error setting input for display, {0}", e.Message);
                }

                _checkWait.Set();

                return(null);
            }, delay);
        }
Exemplo n.º 21
0
 public override void SetInput(DisplayDeviceInput input)
 {
     SetInput(input, TimeSpan.Zero);
 }
Exemplo n.º 22
0
        private void OnReceivedData(byte[] data)
        {
            DeviceCommunicating = true;
            string rx    = Encoding.ASCII.GetString(data, 0, data.Length);
            var    match = Regex.Match(rx, @"(\w) (\w{2}) OK(\w{2})");

            if (!match.Success)
            {
                return;
            }
            var commandType = match.Groups[1].Value;
            var id          = uint.Parse(match.Groups[2].Value);

            if (id != _displayId)
            {
                return;
            }
            var value = uint.Parse(match.Groups[3].Value, NumberStyles.HexNumber);

            //Debug.WriteSuccess("LG Response", "Command \"{0}\" = {1}", commandType, value.ToString("X2"));

            switch (commandType)
            {
            // Power Response
            case "a":
                if (PowerStatus == DevicePowerStatus.PowerOff && value == 0x01)
                {
                    PowerStatus = DevicePowerStatus.PowerWarming;
                }
                else if (PowerStatus == DevicePowerStatus.PowerWarming && value == 0x01)
                {
                    PowerStatus = DevicePowerStatus.PowerOn;
                }
                else if (PowerStatus == DevicePowerStatus.PowerOn && value == 0x00)
                {
                    PowerStatus = DevicePowerStatus.PowerCooling;
                }
                else if (PowerStatus == DevicePowerStatus.PowerCooling && value == 0x00)
                {
                    PowerStatus = DevicePowerStatus.PowerOff;
                }
                break;

            // Input Response
            case "b":
                switch (value)
                {
                case 0x90:
                    _currentInput = DisplayDeviceInput.HDMI1;
                    break;

                case 0x91:
                    _currentInput = DisplayDeviceInput.HDMI2;
                    break;

                case 0x92:
                    _currentInput = DisplayDeviceInput.HDMI3;
                    break;

                case 0x93:
                    _currentInput = DisplayDeviceInput.HDMI4;
                    break;
                }

                if (_requestedInput != DisplayDeviceInput.Unknown && _requestedInput != _currentInput)
                {
                    SetInput(_requestedInput);
                }
                else
                {
                    _requestedInput = DisplayDeviceInput.Unknown;
                }
                break;

            // Mute Response
            case "e":
                _audioLevel.UpdateFromFeedback(value == 0x00);
                break;

            // Volume Response
            case "f":
                var scaledLevel = Tools.ScaleRange(value, 0x00, 0x64, ushort.MinValue, ushort.MaxValue);
                _audioLevel.UpdateFromFeedback((ushort)scaledLevel);
                break;
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Create a source which is local to a display only
 /// </summary>
 /// <param name="display">The display used</param>
 /// <param name="displayDeviceInput">Input used to connect to the display</param>
 /// <param name="type">The type of source</param>
 /// <param name="device">The device driver for the source</param>
 protected SourceBase(DisplayBase display, DisplayDeviceInput displayDeviceInput, SourceType type, ISourceDevice device)
     : this(display.System, type, device)
 {
     AssignedDisplay    = display;
     DisplayDeviceInput = displayDeviceInput;
 }
Exemplo n.º 24
0
 public override void SetInput(DisplayDeviceInput input)
 {
     SendInputCommand(GetInputCommandForInput(input));
 }
Exemplo n.º 25
0
 protected abstract void SendInputCommand(DisplayDeviceInput input);