From: <an...@us...> - 2008-02-10 13:09:21
|
Revision: 1357 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1357&view=rev Author: and-81 Date: 2008-02-10 05:09:14 -0800 (Sun, 10 Feb 2008) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/Properties/AssemblyInfo.cs Added Paths: ----------- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HCW Receiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HcwReceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/IrRemoteWrapper.cs trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/ReceiverWindow.cs Removed Paths: ------------- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HCW Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HcwTransceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/irremote.cs Copied: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver (from rev 1349, trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver) Added: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HCW Receiver.csproj =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HCW Receiver.csproj (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HCW Receiver.csproj 2008-02-10 13:09:14 UTC (rev 1357) @@ -0,0 +1,99 @@ +<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProductVersion>8.0.50727</ProductVersion> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{EE8F2C22-8BD3-4832-85F0-E6F67ED3AADB}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>HcwTransceiver</RootNamespace> + <AssemblyName>HCW Transceiver</AssemblyName> + <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>false</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>TRACE;DEBUG</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + <UseVSHostingProcess>false</UseVSHostingProcess> + <DocumentationFile>bin\Debug\HCW Transceiver.XML</DocumentationFile> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <DebugType>none</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants> + </DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + <UseVSHostingProcess>false</UseVSHostingProcess> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> + <OutputPath>bin\x86\Debug\</OutputPath> + <DefineConstants>DEBUG</DefineConstants> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + <DebugType>full</DebugType> + <PlatformTarget>x86</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> + <OutputPath>bin\x86\Release\</OutputPath> + <Optimize>true</Optimize> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + <DebugType> + </DebugType> + <PlatformTarget>x86</PlatformTarget> + <UseVSHostingProcess>false</UseVSHostingProcess> + <ErrorReport>prompt</ErrorReport> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Configure.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="Configure.Designer.cs"> + <DependentUpon>Configure.cs</DependentUpon> + </Compile> + <Compile Include="HcwReceiver.cs" /> + <Compile Include="IrRemoteWrapper.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="ReceiverWindow.cs" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Configure.resx"> + <DependentUpon>Configure.cs</DependentUpon> + <SubType>Designer</SubType> + </EmbeddedResource> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\IR Server Plugin Interface\IR Server Plugin Interface.csproj"> + <Project>{D8B3D28F-62CE-4CA7-86CE-B7EAD614A94C}</Project> + <Name>IR Server Plugin Interface</Name> + <Private>False</Private> + </ProjectReference> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> + <PropertyGroup> + <PostBuildEvent> + </PostBuildEvent> + </PropertyGroup> +</Project> \ No newline at end of file Deleted: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HCW Transceiver.csproj =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HCW Transceiver.csproj 2008-02-08 23:50:57 UTC (rev 1349) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HCW Transceiver.csproj 2008-02-10 13:09:14 UTC (rev 1357) @@ -1,98 +0,0 @@ -<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProductVersion>8.0.50727</ProductVersion> - <SchemaVersion>2.0</SchemaVersion> - <ProjectGuid>{EE8F2C22-8BD3-4832-85F0-E6F67ED3AADB}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>HcwTransceiver</RootNamespace> - <AssemblyName>HCW Transceiver</AssemblyName> - <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>false</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>TRACE;DEBUG</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <UseVSHostingProcess>false</UseVSHostingProcess> - <DocumentationFile>bin\Debug\HCW Transceiver.XML</DocumentationFile> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>none</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants> - </DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <UseVSHostingProcess>false</UseVSHostingProcess> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> - <OutputPath>bin\x86\Debug\</OutputPath> - <DefineConstants>DEBUG</DefineConstants> - <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <DebugType>full</DebugType> - <PlatformTarget>x86</PlatformTarget> - <ErrorReport>prompt</ErrorReport> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> - <OutputPath>bin\x86\Release\</OutputPath> - <Optimize>true</Optimize> - <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <DebugType> - </DebugType> - <PlatformTarget>x86</PlatformTarget> - <UseVSHostingProcess>false</UseVSHostingProcess> - <ErrorReport>prompt</ErrorReport> - </PropertyGroup> - <ItemGroup> - <Reference Include="System" /> - <Reference Include="System.Data" /> - <Reference Include="System.Drawing" /> - <Reference Include="System.Windows.Forms" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Configure.cs"> - <SubType>Form</SubType> - </Compile> - <Compile Include="Configure.Designer.cs"> - <DependentUpon>Configure.cs</DependentUpon> - </Compile> - <Compile Include="HcwTransceiver.cs" /> - <Compile Include="irremote.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <ItemGroup> - <EmbeddedResource Include="Configure.resx"> - <DependentUpon>Configure.cs</DependentUpon> - <SubType>Designer</SubType> - </EmbeddedResource> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\IR Server Plugin Interface\IR Server Plugin Interface.csproj"> - <Project>{D8B3D28F-62CE-4CA7-86CE-B7EAD614A94C}</Project> - <Name>IR Server Plugin Interface</Name> - <Private>False</Private> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> - <PropertyGroup> - <PostBuildEvent> - </PostBuildEvent> - </PropertyGroup> -</Project> \ No newline at end of file Added: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HcwReceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HcwReceiver.cs (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HcwReceiver.cs 2008-02-10 13:09:14 UTC (rev 1357) @@ -0,0 +1,226 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; +using System.Windows.Forms; +using System.Xml; + +using Microsoft.Win32.SafeHandles; + +using IRServerPluginInterface; + +namespace HcwTransceiver +{ + + /// <summary> + /// IR Server plugin supporting Hauppauge devices. + /// </summary> + [CLSCompliant(false)] + public class HcwReceiver : IRServerPluginBase, IRemoteReceiver, IConfigure + { + + #region Delegates + + //Sets up callback so that other forms can catch a key press + delegate void HCWEvent(int keypress); + //event HCWEvent HCWKeyPressed; + + #endregion Delegates + + #region Constants + + static readonly string ConfigurationFile = + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + + "\\IR Server Suite\\IR Server\\HCW Transceiver.xml"; + + #endregion Constants + + #region Variables + + int _repeatDelay; + bool _stopIrExe; + bool _startIrExe; + + IrRemoteWrapper _irRemoteWrapper = null; + RemoteHandler _remoteButtonHandler = null; + + int _lastCode = 0; + DateTime _lastCodeTime = DateTime.Now; + + #endregion Variables + + #region Implementation + + /// <summary> + /// Name of the IR Server plugin. + /// </summary> + /// <value>The name.</value> + public override string Name { get { return "HCW Receiver"; } } + /// <summary> + /// IR Server plugin version. + /// </summary> + /// <value>The version.</value> + public override string Version { get { return "1.0.4.2"; } } + /// <summary> + /// The IR Server plugin's author. + /// </summary> + /// <value>The author.</value> + public override string Author { get { return "and-81, original MediaPortal code by mPod"; } } + /// <summary> + /// A description of the IR Server plugin. + /// </summary> + /// <value>The description.</value> + public override string Description { get { return "Support for Hauppauge devices"; } } + + /// <summary> + /// Start the IR Server plugin. + /// </summary> + public override void Start() + { + LoadSettings(); + + _irRemoteWrapper = new IrRemoteWrapper(); + _irRemoteWrapper.ButtonCallback = new ButtonReceived(ButtonCallback); + + if (_stopIrExe) + _irRemoteWrapper.StopIrExe(); + + _irRemoteWrapper.Start(); + } + /// <summary> + /// Suspend the IR Server plugin when computer enters standby. + /// </summary> + public override void Suspend() + { + //_irRemoteWrapper.Stop(); + } + /// <summary> + /// Resume the IR Server plugin when the computer returns from standby. + /// </summary> + public override void Resume() + { + //_irRemoteWrapper.Start(); + } + /// <summary> + /// Stop the IR Server plugin. + /// </summary> + public override void Stop() + { + _irRemoteWrapper.Stop(); + + if (_startIrExe) + _irRemoteWrapper.StartIrExe(); + } + + + /// <summary> + /// Configure the IR Server plugin. + /// </summary> + /// <param name="owner">The owner window to use for creating modal dialogs.</param> + public void Configure(IWin32Window owner) + { + LoadSettings(); + + Configure config = new Configure(); + + config.RepeatDelay = _repeatDelay; + + if (config.ShowDialog(owner) == DialogResult.OK) + { + _repeatDelay = config.RepeatDelay; + + SaveSettings(); + } + } + + + /// <summary> + /// Callback for remote button presses. + /// </summary> + /// <value>The remote callback.</value> + public RemoteHandler RemoteCallback + { + get { return _remoteButtonHandler; } + set { _remoteButtonHandler = value; } + } + + + void ButtonCallback(int button) + { + DateTime now = DateTime.Now; + TimeSpan timeSpan = now - _lastCodeTime; + + if (_lastCode != button || timeSpan.Milliseconds >= _repeatDelay) + { + if (_remoteButtonHandler != null) + _remoteButtonHandler(button.ToString()); + + _lastCodeTime = now; + } + + _lastCode = button; + } + + + void LoadSettings() + { + try + { + XmlDocument doc = new XmlDocument(); + doc.Load(ConfigurationFile); + + _repeatDelay = int.Parse(doc.DocumentElement.Attributes["RepeatDelay"].Value); + _stopIrExe = bool.Parse(doc.DocumentElement.Attributes["StopIrExe"].Value); + _startIrExe = bool.Parse(doc.DocumentElement.Attributes["StartIrExe"].Value); + } +#if TRACE + catch (Exception ex) + { + Trace.WriteLine(ex.ToString()); +#else + catch + { +#endif + _repeatDelay = 500; + _stopIrExe = true; + _startIrExe = true; + } + } + void SaveSettings() + { + try + { + XmlTextWriter writer = new XmlTextWriter(ConfigurationFile, Encoding.UTF8); + writer.Formatting = Formatting.Indented; + writer.Indentation = 1; + writer.IndentChar = (char)9; + writer.WriteStartDocument(true); + writer.WriteStartElement("settings"); // <settings> + + writer.WriteAttributeString("RepeatDelay", _repeatDelay.ToString()); + writer.WriteAttributeString("StopIrExe", _stopIrExe.ToString()); + writer.WriteAttributeString("StartIrExe", _startIrExe.ToString()); + + writer.WriteEndElement(); // </settings> + writer.WriteEndDocument(); + writer.Close(); + } +#if TRACE + catch (Exception ex) + { + Trace.WriteLine(ex.ToString()); + } +#else + catch + { + } +#endif + } + + #endregion Implementation + + } + +} Deleted: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HcwTransceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HcwTransceiver.cs 2008-02-08 23:50:57 UTC (rev 1349) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/HcwTransceiver.cs 2008-02-10 13:09:14 UTC (rev 1357) @@ -1,191 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using System.Windows.Forms; -using System.Xml; - -using Microsoft.Win32.SafeHandles; - -using IRServerPluginInterface; - -namespace HcwTransceiver -{ - - /// <summary> - /// IR Server plugin supporting Hauppauge devices. - /// </summary> - [CLSCompliant(false)] - public class HcwTransceiver : IRServerPluginBase, IRemoteReceiver, IConfigure - { - - #region Delegates - - //Sets up callback so that other forms can catch a key press - delegate void HCWEvent(int keypress); - //event HCWEvent HCWKeyPressed; - - #endregion Delegates - - #region Constants - - static readonly string ConfigurationFile = - Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + - "\\IR Server Suite\\IR Server\\HCW Transceiver.xml"; - - #endregion Constants - - #region Variables - - RemoteHandler _remoteButtonHandler = null; - - - int _repeatDelay; - - string _lastCode = String.Empty; - DateTime _lastCodeTime = DateTime.Now; - - #endregion Variables - - #region Implementation - - /// <summary> - /// Name of the IR Server plugin. - /// </summary> - /// <value>The name.</value> - public override string Name { get { return "HCW Receiver"; } } - /// <summary> - /// IR Server plugin version. - /// </summary> - /// <value>The version.</value> - public override string Version { get { return "1.0.4.2"; } } - /// <summary> - /// The IR Server plugin's author. - /// </summary> - /// <value>The author.</value> - public override string Author { get { return "and-81, original MediaPortal code by mPod"; } } - /// <summary> - /// A description of the IR Server plugin. - /// </summary> - /// <value>The description.</value> - public override string Description { get { return "Support for Hauppauge devices"; } } - - /// <summary> - /// Start the IR Server plugin. - /// </summary> - public override void Start() - { - LoadSettings(); - - - } - /// <summary> - /// Suspend the IR Server plugin when computer enters standby. - /// </summary> - public override void Suspend() - { - Stop(); - } - /// <summary> - /// Resume the IR Server plugin when the computer returns from standby. - /// </summary> - public override void Resume() - { - Start(); - } - /// <summary> - /// Stop the IR Server plugin. - /// </summary> - public override void Stop() - { - - } - - - /// <summary> - /// Configure the IR Server plugin. - /// </summary> - /// <param name="owner">The owner window to use for creating modal dialogs.</param> - public void Configure(IWin32Window owner) - { - LoadSettings(); - - Configure config = new Configure(); - - config.RepeatDelay = _repeatDelay; - - if (config.ShowDialog(owner) == DialogResult.OK) - { - _repeatDelay = config.RepeatDelay; - - SaveSettings(); - } - } - - - /// <summary> - /// Callback for remote button presses. - /// </summary> - /// <value>The remote callback.</value> - public RemoteHandler RemoteCallback - { - get { return _remoteButtonHandler; } - set { _remoteButtonHandler = value; } - } - - - void LoadSettings() - { - try - { - XmlDocument doc = new XmlDocument(); - doc.Load(ConfigurationFile); - - _repeatDelay = int.Parse(doc.DocumentElement.Attributes["RepeatDelay"].Value); - } -#if TRACE - catch (Exception ex) - { - Trace.WriteLine(ex.ToString()); -#else - catch - { -#endif - _repeatDelay = 500; - } - } - void SaveSettings() - { - try - { - XmlTextWriter writer = new XmlTextWriter(ConfigurationFile, Encoding.UTF8); - writer.Formatting = Formatting.Indented; - writer.Indentation = 1; - writer.IndentChar = (char)9; - writer.WriteStartDocument(true); - writer.WriteStartElement("settings"); // <settings> - - writer.WriteAttributeString("RepeatDelay", _repeatDelay.ToString()); - - writer.WriteEndElement(); // </settings> - writer.WriteEndDocument(); - writer.Close(); - } -#if TRACE - catch (Exception ex) - { - Trace.WriteLine(ex.ToString()); - } -#else - catch - { - } -#endif - } - - #endregion Implementation - - } - -} Added: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/IrRemoteWrapper.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/IrRemoteWrapper.cs (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/IrRemoteWrapper.cs 2008-02-10 13:09:14 UTC (rev 1357) @@ -0,0 +1,234 @@ +using System; +using System.Diagnostics; +using System.IO; +using System.Runtime.InteropServices; +using System.Threading; +using System.Windows.Forms; + +using Microsoft.Win32; + +namespace HcwTransceiver +{ + + /// <summary> + /// Callback for remote button press events. + /// </summary> + public delegate void ButtonReceived(int buttonCode); + + /// <summary> + /// Wrapper class for irremote.dll + /// </summary> + public class IrRemoteWrapper + { + + #region Interop + + /// <summary> + /// The SetDllDirectory function adds a directory to the search path used to locate DLLs for the application. + /// http://msdn.microsoft.com/library/en-us/dllproc/base/setdlldirectory.asp + /// </summary> + /// <param name="PathName">Pointer to a null-terminated string that specifies the directory to be added to the search path.</param> + /// <returns></returns> + [DllImport("kernel32.dll")] + static extern bool SetDllDirectory( + string PathName); + + /// <summary> + /// Registers window handle with Hauppauge IR driver + /// </summary> + /// <param name="WindowHandle"></param> + /// <param name="Msg"></param> + /// <param name="Verbose"></param> + /// <param name="IRPort"></param> + /// <returns></returns> + [DllImport("irremote.dll")] + static extern bool IR_Open( + IntPtr WindowHandle, + uint Msg, + bool Verbose, + ushort IRPort); + + /// <summary> + /// Gets the received key code (new version, works for PVR-150 as well) + /// </summary> + /// <param name="RepeatCount"></param> + /// <param name="RemoteCode"></param> + /// <param name="KeyCode"></param> + /// <returns></returns> + [DllImport("irremote.dll")] + static extern bool IR_GetSystemKeyCode( + out int RepeatCount, + out int RemoteCode, + out int KeyCode); + + /// <summary> + /// Unregisters window handle from Hauppauge IR driver + /// </summary> + /// <param name="WindowHandle"></param> + /// <param name="Msg"></param> + /// <returns></returns> + [DllImport("irremote.dll")] + static extern bool IR_Close( + IntPtr WindowHandle, + uint Msg); + + #endregion Interop + + #region Constants + + /// <summary> + /// Current Version. + /// </summary> + public const string CurrentVersion = "2.49.23332"; + + const int HCWPVR2 = 0x001E; // 45-Button Remote + const int HCWPVR = 0x001F; // 34-Button Remote + const int HCWCLASSIC = 0x0000; // 21-Button Remote + + const int WM_TIMER = 0x0113; + + #endregion Constants + + #region Variables + + ButtonReceived _buttonReceived; + + ReceiverWindow _window; + + #endregion Variables + + #region Properties + + /// <summary> + /// Gets or sets the button callback. + /// </summary> + /// <value>The button callback.</value> + public ButtonReceived ButtonCallback + { + get { return _buttonReceived; } + set { _buttonReceived = value; } + } + + #endregion Properties + + #region Constructor + + /// <summary> + /// Initializes a new instance of the <see cref="IrRemoteWrapper"/> class. + /// </summary> + public IrRemoteWrapper() + { + _window = new ReceiverWindow(); + _window.ProcMsg = new ProcessMessage(WndProc); + } + + #endregion Constructor + + #region Public Methods + + /// <summary> + /// Starts this instance. + /// </summary> + public void Start() + { + if (!IR_Open(_window.Handle, 0, false, 0)) + throw new ApplicationException("Failed to open IR device"); + } + + /// <summary> + /// Stops this instance. + /// </summary> + public void Stop() + { + if (!IR_Close(_window.Handle, 0)) + throw new ApplicationException("Failed to close IR device"); + } + + /// <summary> + /// Starts the ir.exe. + /// </summary> + public void StartIrExe() + { + if (Process.GetProcessesByName("Ir").Length == 0) + Process.Start(GetHCWPath() + "Ir.exe", "/QUIET"); + } + + /// <summary> + /// Stops the ir.exe. + /// </summary> + public void StopIrExe() + { + Process.Start(GetHCWPath() + "Ir.exe", "/QUIT"); + Thread.Sleep(500); + + if (Process.GetProcessesByName("Ir").Length != 0) + foreach (Process proc in Process.GetProcessesByName("Ir")) + proc.Kill(); + } + + #endregion Public Methods + + static bool IRSetDllDirectory(string PathName) + { + return SetDllDirectory(PathName); + } + + static string GetHCWPath() + { + string dllPath = null; + + using (RegistryKey rkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Hauppauge WinTV Infrared Remote")) + { + if (rkey != null) + { + dllPath = rkey.GetValue("UninstallString").ToString(); + if (dllPath.IndexOf("UNir32") > 0) + dllPath = dllPath.Substring(0, dllPath.IndexOf("UNir32")); + else if (dllPath.IndexOf("UNIR32") > 0) + dllPath = dllPath.Substring(0, dllPath.IndexOf("UNIR32")); + } + } + + return dllPath; + } + + static string GetDllPath() + { + string dllPath = GetHCWPath(); + if (!File.Exists(dllPath + "irremote.DLL")) + dllPath = null; + + return dllPath; + } + + void WndProc(ref Message m) + { + if (m.Msg != WM_TIMER) + return; + + int repeatCount = 0; + int remoteCode = 0; + int keyCode = 0; + if (!IR_GetSystemKeyCode(out repeatCount, out remoteCode, out keyCode)) + return; + + int buttonCode = keyCode; + switch (remoteCode) + { + case HCWCLASSIC: buttonCode = keyCode; break; + case HCWPVR: buttonCode = keyCode + 1000; break; + case HCWPVR2: buttonCode = keyCode + 2000; break; +#if TRACE + default: + Trace.WriteLine("IrRemoteWrapper - Unknown Remote Code: " + remoteCode); + break; +#endif + } + + if (_buttonReceived != null) + _buttonReceived(buttonCode); + } + + } + +} Modified: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/Properties/AssemblyInfo.cs 2008-02-08 23:50:57 UTC (rev 1349) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/Properties/AssemblyInfo.cs 2008-02-10 13:09:14 UTC (rev 1357) @@ -6,11 +6,11 @@ // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. -[assembly: AssemblyTitle("HCW Transceiver")] -[assembly: AssemblyDescription("IR Server plugin to support the HCW transceiver")] +[assembly: AssemblyTitle("HCW Receiver")] +[assembly: AssemblyDescription("IR Server plugin to support the HCW Receiver")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("HcwTransceiver")] +[assembly: AssemblyProduct("HcwReceiver")] [assembly: AssemblyCopyright("Aaron Dinnage")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] Added: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/ReceiverWindow.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/ReceiverWindow.cs (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/ReceiverWindow.cs 2008-02-10 13:09:14 UTC (rev 1357) @@ -0,0 +1,72 @@ +using System; +using System.Windows.Forms; + +namespace HcwTransceiver +{ + + #region Delegates + + /// <summary> + /// Windows message processing delegate. + /// </summary> + /// <param name="m">Windows message.</param> + delegate void ProcessMessage(ref Message m); + + #endregion Delegates + + /// <summary> + /// Use this class to receive windows messages. + /// </summary> + class ReceiverWindow : NativeWindow + { + + #region Variables + + ProcessMessage _processMessage; + + #endregion Variables + + #region Properties + + /// <summary> + /// Gets or Sets the Windows Message processing delegate. + /// </summary> + public ProcessMessage ProcMsg + { + get { return _processMessage; } + set { _processMessage = value; } + } + + #endregion Properties + + #region Constructor + + /// <summary> + /// Create a Windows Message receiving window object. + /// </summary> + public ReceiverWindow() + { + CreateParams createParams = new CreateParams(); + createParams.ExStyle = 0x80; + createParams.Style = unchecked((int)0x80000000); + + base.CreateHandle(createParams); + } + + #endregion Constructor + + #region Implementation + + protected override void WndProc(ref Message m) + { + if (_processMessage != null) + _processMessage(ref m); + + base.WndProc(ref m); + } + + #endregion Implementation + + } + +} Deleted: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/irremote.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/irremote.cs 2008-02-08 23:50:57 UTC (rev 1349) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Receiver/irremote.cs 2008-02-10 13:09:14 UTC (rev 1357) @@ -1,196 +0,0 @@ -#region Copyright (C) 2005-2007 Team MediaPortal - -/* - * Copyright (C) 2005-2007 Team MediaPortal - * http://www.team-mediaportal.com - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU Make; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - */ - -#endregion - -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32; -//using MediaPortal.GUI.Library; -using System.IO; - -namespace HcwTransceiver -{ - - /// <summary> - /// Wrapper class for irremote.dll - /// </summary> - [CLSCompliant(false)] - public static class irremote - { - #region DLL-Imports - - /// <summary> - /// The SetDllDirectory function adds a directory to the search path used to locate DLLs for the application. - /// http://msdn.microsoft.com/library/en-us/dllproc/base/setdlldirectory.asp - /// </summary> - /// <param name="PathName">Pointer to a null-terminated string that specifies the directory to be added to the search path.</param> - /// <returns></returns> - [DllImport("kernel32.dll")] - static extern bool SetDllDirectory( - string PathName); - - /// <summary> - /// Registers window handle with Hauppauge IR driver - /// </summary> - /// <param name="WindowHandle"></param> - /// <param name="Msg"></param> - /// <param name="Verbose"></param> - /// <param name="IRPort"></param> - /// <returns></returns> - [DllImport("irremote.dll")] - static extern bool IR_Open( - int WindowHandle, - uint Msg, - bool Verbose, - ushort IRPort); - - /// <summary> - /// Gets the received key code (new version, works for PVR-150 as well) - /// </summary> - /// <param name="RepeatCount"></param> - /// <param name="RemoteCode"></param> - /// <param name="KeyCode"></param> - /// <returns></returns> - [DllImport("irremote.dll")] - static extern bool IR_GetSystemKeyCode( - out int RepeatCount, - out int RemoteCode, - out int KeyCode); - - /// <summary> - /// Unregisters window handle from Hauppauge IR driver - /// </summary> - /// <param name="WindowHandle"></param> - /// <param name="Msg"></param> - /// <returns></returns> - [DllImport("irremote.dll")] - static extern bool IR_Close( - int WindowHandle, - uint Msg); - - #endregion - - - /// <summary> - /// Current Version. - /// </summary> - public static string CurrentVersion = "2.49.23332"; - - /// <summary> - /// Close the device. - /// </summary> - /// <param name="WindowHandle">The window handle.</param> - /// <param name="Msg">The MSG.</param> - /// <returns><c>true</c> if successful; otherwise <c>false</c>.</returns> - public static bool IRClose(IntPtr WindowHandle, uint Msg) - { - return IR_Close((int)WindowHandle, Msg); - } - - /// <summary> - /// Get system key code. - /// </summary> - /// <param name="RepeatCount">The repeat count.</param> - /// <param name="RemoteCode">The remote code.</param> - /// <param name="KeyCode">The key code.</param> - /// <returns><c>true</c> if successful; otherwise <c>false</c>.</returns> - public static bool IRGetSystemKeyCode(out int RepeatCount, out int RemoteCode, out int KeyCode) - { - RepeatCount = 0; - RemoteCode = 0; - KeyCode = 0; - bool result = false; - try - { - result = IR_GetSystemKeyCode(out RepeatCount, out RemoteCode, out KeyCode); - } - catch (AccessViolationException) - { - } - catch (Exception ex) - { - Console.WriteLine("HCW: Exception while querying remote: {0}", ex.Message); - } - return result; - } - - /// <summary> - /// Opens the device. - /// </summary> - /// <param name="WindowHandle">The window handle.</param> - /// <param name="Msg">The MSG.</param> - /// <param name="Verbose">if set to <c>true</c> [verbose].</param> - /// <param name="IRPort">The IR port.</param> - /// <returns><c>true</c> if successful; otherwise <c>false</c>.</returns> - public static bool IROpen(IntPtr WindowHandle, uint Msg, bool Verbose, ushort IRPort) - { - return IR_Open((int)WindowHandle, Msg, Verbose, IRPort); - } - - /// <summary> - /// Set DLL directory. - /// </summary> - /// <param name="PathName">Name of the path.</param> - /// <returns><c>true</c> if successful; otherwise <c>false</c>.</returns> - public static bool IRSetDllDirectory(string PathName) - { - return SetDllDirectory(PathName); - } - - /// <summary> - /// Get the Hauppauge IR components installation path from the windows registry. - /// </summary> - /// <returns>Installation path of the Hauppauge IR components</returns> - public static string GetHCWPath() - { - string dllPath = null; - using (RegistryKey rkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Hauppauge WinTV Infrared Remote")) - { - if (rkey != null) - { - dllPath = rkey.GetValue("UninstallString").ToString(); - if (dllPath.IndexOf("UNir32") > 0) - dllPath = dllPath.Substring(0, dllPath.IndexOf("UNir32")); - else if (dllPath.IndexOf("UNIR32") > 0) - dllPath = dllPath.Substring(0, dllPath.IndexOf("UNIR32")); - } - } - return dllPath; - } - - /// <summary> - /// Returns the path of the DLL component - /// </summary> - /// <returns>DLL path</returns> - public static string GetDllPath() - { - string dllPath = GetHCWPath(); - if (!File.Exists(dllPath + "irremote.DLL")) - { - dllPath = null; - } - return dllPath; - } - } -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |