Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Philips TV 2013s #1

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added Auto3D-Philips/2013 - discrete IR Codes.xlsx
Binary file not shown.
Binary file added Auto3D-Philips/2014 - discrete IR Codes.xlsx
Binary file not shown.
12 changes: 11 additions & 1 deletion Auto3D-Philips/Auto3D-Philips.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
<Reference Include="Dialogs">
<HintPath>..\Externals\Dialogs.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\Externals\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand All @@ -76,7 +80,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DiVine.cs" />
<Compile Include="Connection\DiVine.cs" />
<Compile Include="Connection\DiVineAdapter.cs" />
<Compile Include="Connection\IPhilipsTVAdapter.cs" />
<Compile Include="Connection\JointSpaceBaseAdapter.cs" />
<Compile Include="Connection\JointSpaceV5Adapter.cs" />
<Compile Include="Connection\JointSpaceV1Adapter.cs" />
<Compile Include="Connection\ProtocolClasses.cs" />
<Compile Include="PhilipsRemoteKeypad.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down
10 changes: 8 additions & 2 deletions Auto3D-Philips/DiVine.cs → Auto3D-Philips/Connection/DiVine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,15 @@ private static bool Ping(String ipAddress)
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;

PingReply reply = pingSender.Send(ipAddress, timeout, buffer, options);
try
{
PingReply reply = pingSender.Send(ipAddress, timeout, buffer, options);

return reply.Status == IPStatus.Success;
}
catch (Exception) { }

return reply.Status == IPStatus.Success;
return false;
}

public static bool Init(String ipAddress)
Expand Down
66 changes: 66 additions & 0 deletions Auto3D-Philips/Connection/DiVineAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Net;
using System.Collections.Generic;

namespace MediaPortal.ProcessPlugins.Auto3D.Devices
{
public class DiVineAdapter : IPhilipsTVAdapter
{
private static readonly Dictionary<string, DiVine.RC6Codes> _keys = new Dictionary<string, DiVine.RC6Codes>
{
{ "Home", DiVine.RC6Codes.rc6S0MenuOn },
{ "Adjust", DiVine.RC6Codes.rc6S0AmbLightMode },
{ "Back", DiVine.RC6Codes.rc6S0PreviousProgram },
{ "Options", DiVine.RC6Codes.rc6S0Options },
{ "OK", DiVine.RC6Codes.rc6S0Acknowledge },
{ "CursorLeft", DiVine.RC6Codes.rc6S0StepLeft },
{ "CursorRight", DiVine.RC6Codes.rc6S0StepRight },
{ "CursorUp", DiVine.RC6Codes.rc6S0StepUp },
{ "CursorDown", DiVine.RC6Codes.rc6S0StepDown },
{ "3D", DiVine.RC6Codes.rc6S0Display3D },
{ "Delay", DiVine.RC6Codes.rc6S0 },
{ "Off", DiVine.RC6Codes.rc6S0SystemStandby },
};

public bool SendCommand(string command)
{
DiVine.RC6Codes key;
if (_keys.TryGetValue(command, out key))
{
DiVine.SendKeyEx(key);
return true;
}

return false;
}

public SystemBase Connect(string host)
{
IPAddress address;
if (IPAddress.TryParse(host, out address) && !address.Equals(IPAddress.Any) && !address.Equals(IPAddress.Broadcast))
{
DiVine.Init(host);
}

return new DiVineSystem
{
country = string.Empty,
name = "DiVine TV"
};
}

public void Disconnect()
{
if (DiVine.IsConnected)
DiVine.Exit();
}


public bool IsConnected
{
get
{
return DiVine.IsConnected;
}
}
}
}
13 changes: 13 additions & 0 deletions Auto3D-Philips/Connection/IPhilipsTVAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace MediaPortal.ProcessPlugins.Auto3D.Devices
{
public interface IPhilipsTVAdapter
{
bool SendCommand(string command);

SystemBase Connect(string host);

void Disconnect();

bool IsConnected { get; }
}
}
146 changes: 146 additions & 0 deletions Auto3D-Philips/Connection/JointSpaceBaseAdapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using MediaPortal.GUI.Library;
using Newtonsoft.Json;

namespace MediaPortal.ProcessPlugins.Auto3D.Devices
{
public abstract class JointSpaceBaseAdapter : IPhilipsTVAdapter
{
private const string ContentType = "application/json; charset=UTF-8";

protected string Host { get; set; }

public virtual bool SendCommand(string command)
{
return PostRequest(KeyUri, new JointSpaceKey { key = command });
}

public virtual SystemBase Connect(string host)
{
Host = host;
return null;
}

public virtual void Disconnect()
{
Host = string.Empty;
}

public virtual bool IsConnected
{
get
{
if (!string.IsNullOrEmpty(Host))
{
return !string.IsNullOrEmpty(GetRequest(SystemUri, string.Empty));
}

return false;
}
}

protected abstract string SystemUri { get; }
protected abstract string KeyUri { get; }

protected bool PostRequest(string url, JointSpaceKey key)
{
try
{
Log.Debug("Auto3D: PostRequest to URL = \"" + url + "\"");

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.Timeout = 3000;
request.ContentType = ContentType;
request.Method = "POST";

var jsonString = JsonConvert.SerializeObject(key, Formatting.Indented);
Log.Debug("Auto3D: JSON-String = \"" + jsonString + "\"");

using (var streamWriter = new StreamWriter(request.GetRequestStream(), Encoding.UTF8))
{
streamWriter.Write(jsonString);
streamWriter.Flush();
streamWriter.Close();
}

Application.DoEvents();
Thread.Sleep(50);

using (var httpResponse = (HttpWebResponse)request.GetResponse())
{
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
Log.Debug(result);
}
}

Application.DoEvents();
}
catch (Exception ex)
{
Log.Info("Auto3D: PostRequest: " + ex.Message);
Auto3DHelpers.ShowAuto3DMessage("Command to TV could not be sent: " + ex.Message, false, 0);
return false;
}

return true;
}

protected string GetRequest(string url, string jsonString)
{
string result = string.Empty;
try
{
Log.Debug("Auto3D: GetRequest to URL = \"" + url + "\"");

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.Timeout = 3000;
request.ContentType = ContentType;
request.Accept = ContentType;
request.Method = "GET";

if (!string.IsNullOrEmpty(jsonString))
{
Log.Debug("Auto3D: JSON-String = \"" + jsonString + "\"");

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
streamWriter.Write(jsonString);
streamWriter.Flush();
streamWriter.Close();
}
}

Application.DoEvents();
Thread.Sleep(50);

using (var httpResponse = (HttpWebResponse)request.GetResponse())
{
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
result = streamReader.ReadToEnd();
Log.Debug(result);
}
}

Application.DoEvents();
}
catch (Exception ex)
{
Log.Info("Auto3D: GetRequest: " + ex.Message);
Auto3DHelpers.ShowAuto3DMessage("Request to TV could not be sent: " + ex.Message, false, 0);
result = string.Empty;
}

return result;
}
}
}
56 changes: 56 additions & 0 deletions Auto3D-Philips/Connection/JointSpaceV1Adapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace MediaPortal.ProcessPlugins.Auto3D.Devices
{
public class JointSpaceV1Adapter : JointSpaceBaseAdapter
{
private static readonly Dictionary<string, string> _keys = new Dictionary<string, string>
{
{ "Home", "Home" },
{ "Adjust", "Adjust" },
{ "Back", "Back" },
{ "Options", "Options" },
{ "OK", "Confirm" },
{ "CursorLeft", "CursorLeft" },
{ "CursorRight", "CursorRight" },
{ "CursorUp", "CursorUp" },
{ "CursorDown", "CursorDown" },
{ "3D", "3dDepth" },
{ "Delay", string.Empty },
{ "Off", "Standby" },
};

public override bool SendCommand(string command)
{
string key;
if (_keys.TryGetValue(command, out key))
{
return base.SendCommand(key);
}

return false;
}

public override SystemBase Connect(string host)
{
base.Connect(host);
return JsonConvert.DeserializeObject<JointSpaceV1System>(GetRequest(SystemUri, string.Empty));
}

protected override string SystemUri
{
get
{
return string.Format(@"http://{0}:1925/1/system", Host);
}
}
protected override string KeyUri
{
get
{
return string.Format(@"http://{0}:1925/1/input/key", Host);
}
}
}
}
57 changes: 57 additions & 0 deletions Auto3D-Philips/Connection/JointSpaceV5Adapter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace MediaPortal.ProcessPlugins.Auto3D.Devices
{
public class JointSpaceV5Adapter : JointSpaceBaseAdapter
{
private static readonly Dictionary<string, string> _keys = new Dictionary<string, string>
{
{ "Home", "Home" },
{ "Adjust", "Adjust" },
{ "Back", "Back" },
{ "Options", "Options" },
{ "OK", "Confirm" },
{ "CursorLeft", "CursorLeft" },
{ "CursorRight", "CursorRight" },
{ "CursorUp", "CursorUp" },
{ "CursorDown", "CursorDown" },
{ "3D", "3dFormat" },
{ "Delay", string.Empty },
{ "Off", "Standby" },
};

public override bool SendCommand(string command)
{
string key;
if (_keys.TryGetValue(command, out key))
{
return base.SendCommand(key);
}

return false;
}

public override SystemBase Connect(string host)
{
base.Connect(host);
return JsonConvert.DeserializeObject<JointSpaceV5System>(GetRequest(SystemUri, string.Empty));
}

protected override string SystemUri
{
get
{
return string.Format(@"http://{0}:1925/5/system", Host);
}
}

protected override string KeyUri
{
get
{
return string.Format(@"http://{0}:1925/5/input/key", Host);
}
}
}
}