Пример #1
0
        private bool InternalSendCommand(String command)
        {
            if (UDAPnP.Protocol == UDAPnP.LGProtocol.LG2011 ||
                UDAPnP.Protocol == UDAPnP.LGProtocol.LG2012x)
            {
                if (!UDAPnP.HandleKeyInput(command))
                {
                    // if for some reason connection was lost, try to reconnect

                    if (!ConnectAndPair())
                    {
                        Auto3DHelpers.ShowAuto3DMessage("Connection to LG TV failed!", false, 0);
                        Log.Error("Auto3D: Connection to LG TV failed!");

                        return(false);
                    }

                    // second try to send the command

                    if (!UDAPnP.HandleKeyInput(command))
                    {
                        Log.Error("Auto3D: HandleKeyInput failed for command: " + command);
                        return(false);
                    }
                }
            }
            else // WebOS
            {
                WebOS.SendSpecialKey(command);
            }

            return(true);
        }
Пример #2
0
        internal bool ConnectAndPair()
        {
            if (UDAPnP.Protocol == UDAPnP.LGProtocol.LG2011 ||
                UDAPnP.Protocol == UDAPnP.LGProtocol.LG2012x)
            {
                // LG UPnP stack is sometimes very slow in answering,
                // so wait up to 5 seconds before giving up pairing.

                int loops = 0;

                while (IPAddress == null || IPAddress.Length == 0)
                {
                    Thread.Sleep(5);

                    if (loops++ > 100)
                    {
                        Log.Error("Auto3D: LG service not connected withing additional 10 seconds!");
                        return(false);
                    }
                }

                if (UDAPnP.UpdateServiceInformation(IPAddress))
                {
                    Log.Info("Auto3D: UpdateServiceInfo OK");

                    if (PairingKey.Length > 0)
                    {
                        if (UDAPnP.RequestPairing(PairingKey))
                        {
                            Log.Info("Auto3D: Pairing LG client with key {0} succeeded", PairingKey);
                        }
                        else
                        {
                            Log.Error("Auto3D: Pairing LG client with key {0} failed!", PairingKey);
                            return(false);
                        }
                    }
                }
                else
                {
                    Log.Error("Auto3D: UpdateServiceInfo failed!");
                    return(false);
                }
            }
            else // WebOS
            {
                WebOS.Register(IPAddress, PairingKey);
            }

            return(true);
        }
Пример #3
0
        private void buttonShowKey_Click(object sender, EventArgs e)
        {
            if (UDAPnP.Protocol == UDAPnP.LGProtocol.LG2011 ||
                UDAPnP.Protocol == UDAPnP.LGProtocol.LG2012x)
            {
                if (!UDAPnP.Connected)
                {
                    if (!UDAPnP.UpdateServiceInformation(_device.IPAddress))
                    {
                        MessageBox.Show("Connection to LG TV failed!");
                        return;
                    }
                }

                UDAPnP.RequestPairingKey();
            }
            else // WebOS
            {
                textBoxPairingKey.Text = WebOS.Pair(_device.IPAddress);
                SaveSettings();
            }
        }
Пример #4
0
        public override bool SendCommand(RemoteCommand rc)
        {
            switch (rc.Command)
            {
            case "Home":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("67"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("21"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("HOME"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "Back":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("40"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("412"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("BACK"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "OK":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("68"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("20"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("ENTER"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "CursorLeft":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("7"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("14"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("LEFT"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "CursorRight":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("6"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("15"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("RIGHT"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "CursorUp":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("64"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("12"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("UP"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "CursorDown":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("65"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("13"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("DOWN"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "Mode3D":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("220"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("400"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("3D_MODE"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "Exit":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("91"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("412"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (!InternalSendCommand("EXIT"))
                    {
                        return(false);
                    }
                    break;
                }
                break;

            case "Off":

                switch (UDAPnP.Protocol)
                {
                case UDAPnP.LGProtocol.LG2011:

                    if (!InternalSendCommand("8"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.LG2012x:

                    if (!InternalSendCommand("1"))
                    {
                        return(false);
                    }
                    break;

                case UDAPnP.LGProtocol.WebOS:

                    if (Auto3DHelpers.Ping(IPAddress))
                    {
                        WebOS.TurnOff();
                    }
                    break;
                }
                break;

            case "Delay":

                // do nothing here
                break;

            default:

                Log.Info("Auto3D: Unknown command - " + rc.Command);
                break;
            }

            return(true);
        }
Пример #5
0
 public override void ServiceRemoved(UPnPService service)
 {
     Log.Info("Auto3D: LG service removed");
     WebOS.Close();
     base.ServiceRemoved(service);
 }