From: <an...@us...> - 2007-08-22 15:01:36
|
Revision: 856 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=856&view=rev Author: and-81 Date: 2007-08-22 08:01:30 -0700 (Wed, 22 Aug 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/Properties/AssemblyInfo.cs Added Paths: ----------- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HCW Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HcwTransceiver.cs Removed Paths: ------------- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/USB-UIRT Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/UirtTransceiver.cs Copied: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver (from rev 853, trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver) Added: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HCW Transceiver.csproj =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HCW Transceiver.csproj (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HCW Transceiver.csproj 2007-08-22 15:01:30 UTC (rev 856) @@ -0,0 +1,95 @@ +<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>DEBUG</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + <UseVSHostingProcess>true</UseVSHostingProcess> + </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="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>copy "$(TargetFileName)" "\MediaPortal Development\Plugin Releases\IR Server Suite\IR Server Plugins\"</PostBuildEvent> + </PropertyGroup> +</Project> \ No newline at end of file Added: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HcwTransceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HcwTransceiver.cs (rev 0) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/HcwTransceiver.cs 2007-08-22 15:01:30 UTC (rev 856) @@ -0,0 +1,438 @@ +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 +{ + + [CLSCompliant(false)] + public class HcwTransceiver : + IRServerPlugin, IConfigure, ITransmitIR, ILearnIR, IRemoteReceiver, IDisposable + { + + #region Interop + + [StructLayout(LayoutKind.Sequential)] + struct UUINFO + { + public int fwVersion; + public int protVersion; + public char fwDateDay; + public char fwDateMonth; + public char fwDateYear; + } + + //Not used + //[StructLayout(LayoutKind.Sequential)] + //internal struct UUGPIO + //{ + // public byte[] irCode; + // public byte action; + // public byte duration; + //} + + [DllImport("uuirtdrv.dll")] + static extern IntPtr UUIRTOpen(); + + [DllImport("uuirtdrv.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool UUIRTClose( + IntPtr hHandle); + + //[DllImport("uuirtdrv.dll")] + //[return: MarshalAs(UnmanagedType.Bool)] + //internal static extern bool UUIRTGetDrvInfo(ref int puDrvVersion); + + //[DllImport("uuirtdrv.dll")] + //[return: MarshalAs(UnmanagedType.Bool)] + //internal static extern bool UUIRTGetUUIRTInfo( + // IntPtr hHandle, + // ref UUINFO puuInfo); + + //[DllImport("uuirtdrv.dll")] + //[return: MarshalAs(UnmanagedType.Bool)] + //internal static extern bool UUIRTGetUUIRTConfig( + // IntPtr hHandle, + // ref uint puConfig); + + //[DllImport("uuirtdrv.dll")] + //[return: MarshalAs(UnmanagedType.Bool)] + //internal static extern bool UUIRTSetUUIRTConfig( + // IntPtr hHandle, + // uint uConfig); + + [DllImport("uuirtdrv.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool UUIRTTransmitIR( + IntPtr hHandle, + string IRCode, + int codeFormat, + int repeatCount, + int inactivityWaitTime, + IntPtr hEvent, + int res1, + int res2); + + [DllImport("uuirtdrv.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool UUIRTLearnIR( + IntPtr hHandle, + int codeFormat, + [MarshalAs(UnmanagedType.LPStr)] StringBuilder ircode, + IRLearnCallbackDelegate progressProc, + int userData, + ref int pAbort, + int param1, + [MarshalAs(UnmanagedType.AsAny)] Object o, + [MarshalAs(UnmanagedType.AsAny)] Object oo); + + [DllImport("uuirtdrv.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool UUIRTSetReceiveCallback( + IntPtr hHandle, + UUIRTReceiveCallbackDelegate receiveProc, + int none); + + //[DllImport("uuirtdrv.dll")] + //static extern bool UUIRTSetUUIRTGPIOCfg(IntPtr hHandle, int index, ref UUGPIO GpioSt); + + //[DllImport("uuirtdrv.dll")] + //static extern bool UUIRTGetUUIRTGPIOCfg(IntPtr hHandle, ref int numSlots, ref uint dwPortPins, + // ref UUGPIO GpioSt); + + #endregion + + #region Delegates + + delegate void UUIRTReceiveCallbackDelegate(string irCode, IntPtr userData); + delegate void IRLearnCallbackDelegate(uint progress, uint sigQuality, ulong carrierFreq, IntPtr userData); + + #endregion Delegates + + #region Constants + + static readonly string ConfigurationFile = + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + + "\\IR Server Suite\\IR Server\\USB-UIRT Transceiver.xml"; + + const int UUIRTDRV_IRFMT_UUIRT = 0x0000; + const int UUIRTDRV_IRFMT_PRONTO = 0x0010; + const int UUIRTDRV_IRFMT_LEARN_FORCERAW = 0x0100; + const int UUIRTDRV_IRFMT_LEARN_FORCESTRUC = 0x0200; + const int UUIRTDRV_IRFMT_LEARN_FORCEFREQ = 0x0400; + const int UUIRTDRV_IRFMT_LEARN_FREQDETECT = 0x0800; + + static readonly string[] Ports = new string[] { "Default", "Port 1", "Port 2", "Port 3" }; + + const int AbortLearn = -1; + const int AllowLearn = 0; + + #endregion Constants + + #region Variables + + RemoteHandler _remoteButtonHandler = null; + + string _blastPort = Ports[0]; + + int _repeatDelay; + int _blastRepeats; + int _learnTimeout; + + //ulong _learnCarrierFreq; + + string _lastCode = String.Empty; + DateTime _lastCodeTime = DateTime.Now; + + // ------- + + int _abortLearn = AllowLearn; + bool _learnTimedOut; + UUIRTReceiveCallbackDelegate _receiveCallback = null; + bool _isUsbUirtLoaded = false; + IntPtr _usbUirtHandle = IntPtr.Zero; + bool _disposed = false; + + #endregion Variables + + #region Deconstructor + + ~HcwTransceiver() + { + Dispose(false); + } + + #endregion Deconstructor + + #region IDisposable Members + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposeManagedResources) + { + if (!_disposed) + { + _disposed = true; + + if (disposeManagedResources) + { + // Dispose any managed resources. + } + + if (_isUsbUirtLoaded && _usbUirtHandle != new IntPtr(-1) && _usbUirtHandle != IntPtr.Zero) + { + UUIRTClose(_usbUirtHandle); + _usbUirtHandle = IntPtr.Zero; + _isUsbUirtLoaded = false; + } + } + } + + #endregion IDisposable Members + + #region Implementation + + public override string Name { get { return "USB-UIRT"; } } + public override string Version { get { return "1.0.3.3"; } } + public override string Author { get { return "and-81"; } } + public override string Description { get { return "Support for the USB-UIRT transceiver"; } } + + public override bool Start() + { + LoadSettings(); + + _usbUirtHandle = UUIRTOpen(); + + if (_usbUirtHandle != new IntPtr(-1)) + { + _isUsbUirtLoaded = true; + + // Setup callack to receive IR messages + _receiveCallback = new UUIRTReceiveCallbackDelegate(UUIRTReceiveCallback); + UUIRTSetReceiveCallback(_usbUirtHandle, _receiveCallback, 0); + } + + return _isUsbUirtLoaded; + } + public override void Suspend() + { + Stop(); + } + public override void Resume() + { + Start(); + } + public override void Stop() + { + UUIRTClose(_usbUirtHandle); + + _usbUirtHandle = IntPtr.Zero; + _isUsbUirtLoaded = false; + } + + public void Configure() + { + LoadSettings(); + + Configure config = new Configure(); + + config.RepeatDelay = _repeatDelay; + config.BlastRepeats = _blastRepeats; + config.LearnTimeout = _learnTimeout; + + if (config.ShowDialog() == DialogResult.OK) + { + _repeatDelay = config.RepeatDelay; + _blastRepeats = config.BlastRepeats; + _learnTimeout = config.LearnTimeout; + + SaveSettings(); + } + } + + public RemoteHandler RemoteCallback + { + get { return _remoteButtonHandler; } + set { _remoteButtonHandler = value; } + } + + public string[] AvailablePorts { get { return Ports; } } + + public bool Transmit(string port, byte[] data) + { + bool result = false; + + string irCode = Encoding.ASCII.GetString(data); + + // Set blaster port ... + if (port.Equals(Ports[1], StringComparison.InvariantCultureIgnoreCase)) + irCode = "Z1" + irCode; + else if (port.Equals(Ports[2], StringComparison.InvariantCultureIgnoreCase)) + irCode = "Z2" + irCode; + else if (port.Equals(Ports[3], StringComparison.InvariantCultureIgnoreCase)) + irCode = "Z3" + irCode; + + result = UUIRTTransmitIR( + _usbUirtHandle, // Handle to USB-UIRT + irCode, // IR Code + UUIRTDRV_IRFMT_PRONTO, // Code Format + _blastRepeats, // Repeat Count + 0, // Inactivity Wait Time + IntPtr.Zero, // hEvent + 0, // reserved1 + 0 // reserved2 + ); + + return result; + } + public LearnStatus Learn(out byte[] data) + { + bool result = false; + + data = null; + + StringBuilder irCode = new StringBuilder("1", 2048); + _abortLearn = AllowLearn; + _learnTimedOut = false; + + //_learnCarrierFreq = 0; + + Timer timer = new Timer(); + timer.Interval = _learnTimeout; + timer.Tick += new EventHandler(timer_Tick); + timer.Enabled = true; + timer.Start(); + + //IRLearnCallbackDelegate learnCallback = new IRLearnCallbackDelegate(UUIRTLearnCallback); + + result = UirtTransceiver.UUIRTLearnIR( + _usbUirtHandle, // Handle to USB-UIRT + UirtTransceiver.UUIRTDRV_IRFMT_PRONTO | UirtTransceiver.UUIRTDRV_IRFMT_LEARN_FREQDETECT, // | UirtTransceiver.UUIRTDRV_IRFMT_LEARN_FORCERAW + irCode, // Where to put the IR Code + null, // Learn status callback + 0, // User data + ref _abortLearn, // Abort flag? + 0, + null, + null); + + timer.Stop(); + + //MessageBox.Show(_learnCarrierFreq.ToString()); + + if (_learnTimedOut) + { + return LearnStatus.Timeout; + } + else if (result) + { + data = Encoding.ASCII.GetBytes(irCode.ToString()); + + return LearnStatus.Success; + } + else + { + return LearnStatus.Failure; + } + } + + void LoadSettings() + { + try + { + XmlDocument doc = new XmlDocument(); + doc.Load(ConfigurationFile); + + _repeatDelay = int.Parse(doc.DocumentElement.Attributes["RepeatDelay"].Value); + _blastRepeats = int.Parse(doc.DocumentElement.Attributes["BlastRepeats"].Value); + _learnTimeout = int.Parse(doc.DocumentElement.Attributes["LearnTimeout"].Value); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + + _repeatDelay = 500; + _blastRepeats = 4; + _learnTimeout = 10000; + } + } + void SaveSettings() + { + try + { + XmlTextWriter writer = new XmlTextWriter(ConfigurationFile, System.Text.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("BlastRepeats", _blastRepeats.ToString()); + writer.WriteAttributeString("LearnTimeout", _learnTimeout.ToString()); + + writer.WriteEndElement(); // </settings> + writer.WriteEndDocument(); + writer.Close(); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + } + + void UUIRTReceiveCallback(string keyCode, IntPtr userData) + { + if (_remoteButtonHandler == null) + return; + + TimeSpan timeSpan = DateTime.Now - _lastCodeTime; + + if (keyCode == _lastCode) // Repeated button + { + if (timeSpan.Milliseconds > _repeatDelay) + { + _remoteButtonHandler(keyCode); + _lastCodeTime = DateTime.Now; + } + } + else + { + _remoteButtonHandler(keyCode); + _lastCodeTime = DateTime.Now; + } + + _lastCode = keyCode; + } + /* + void UUIRTLearnCallback(uint progress, uint sigQuality, ulong carrierFreq, IntPtr userData) + { + _learnCarrierFreq = carrierFreq; + //MessageBox.Show(_learnCarrierFreq.ToString()); + } + */ + void timer_Tick(object sender, EventArgs e) + { + _abortLearn = AbortLearn; + _learnTimedOut = true; + + ((Timer)sender).Stop(); + } + + #endregion Implementation + + } + +} Modified: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/Properties/AssemblyInfo.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/Properties/AssemblyInfo.cs 2007-08-22 05:26:54 UTC (rev 853) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/Properties/AssemblyInfo.cs 2007-08-22 15:01:30 UTC (rev 856) @@ -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("USB-UIRT Transceiver")] -[assembly: AssemblyDescription("IR Server plugin to support the USB-UIRT transceiver")] +[assembly: AssemblyTitle("HCW Transceiver")] +[assembly: AssemblyDescription("IR Server plugin to support the HCW transceiver")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("UirtTransceiver")] +[assembly: AssemblyProduct("HcwTransceiver")] [assembly: AssemblyCopyright("Aaron Dinnage")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] Deleted: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/USB-UIRT Transceiver.csproj =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/USB-UIRT Transceiver.csproj 2007-08-22 05:26:54 UTC (rev 853) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/USB-UIRT Transceiver.csproj 2007-08-22 15:01:30 UTC (rev 856) @@ -1,95 +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>{99B5CA78-3E0B-477F-A7D3-EE1B65E85DE4}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>UirtTransceiver</RootNamespace> - <AssemblyName>USB-UIRT 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>DEBUG</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - <TreatWarningsAsErrors>true</TreatWarningsAsErrors> - <UseVSHostingProcess>true</UseVSHostingProcess> - </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="UirtTransceiver.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>copy "$(TargetFileName)" "\MediaPortal Development\Plugin Releases\IR Server Suite\IR Server Plugins\"</PostBuildEvent> - </PropertyGroup> -</Project> \ No newline at end of file Deleted: trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/UirtTransceiver.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/UirtTransceiver.cs 2007-08-22 05:26:54 UTC (rev 853) +++ trunk/plugins/IR Server Suite/IR Server Plugins/HCW Transceiver/UirtTransceiver.cs 2007-08-22 15:01:30 UTC (rev 856) @@ -1,465 +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 UirtTransceiver -{ - - [CLSCompliant(false)] - public class UirtTransceiver : IIRServerPlugin, IDisposable - { - - #region Interop - - [StructLayout(LayoutKind.Sequential)] - struct UUINFO - { - public int fwVersion; - public int protVersion; - public char fwDateDay; - public char fwDateMonth; - public char fwDateYear; - } - - //Not used - //[StructLayout(LayoutKind.Sequential)] - //internal struct UUGPIO - //{ - // public byte[] irCode; - // public byte action; - // public byte duration; - //} - - [DllImport("uuirtdrv.dll")] - static extern IntPtr UUIRTOpen(); - - [DllImport("uuirtdrv.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool UUIRTClose( - IntPtr hHandle); - - //[DllImport("uuirtdrv.dll")] - //[return: MarshalAs(UnmanagedType.Bool)] - //internal static extern bool UUIRTGetDrvInfo(ref int puDrvVersion); - - //[DllImport("uuirtdrv.dll")] - //[return: MarshalAs(UnmanagedType.Bool)] - //internal static extern bool UUIRTGetUUIRTInfo( - // IntPtr hHandle, - // ref UUINFO puuInfo); - - //[DllImport("uuirtdrv.dll")] - //[return: MarshalAs(UnmanagedType.Bool)] - //internal static extern bool UUIRTGetUUIRTConfig( - // IntPtr hHandle, - // ref uint puConfig); - - //[DllImport("uuirtdrv.dll")] - //[return: MarshalAs(UnmanagedType.Bool)] - //internal static extern bool UUIRTSetUUIRTConfig( - // IntPtr hHandle, - // uint uConfig); - - [DllImport("uuirtdrv.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool UUIRTTransmitIR( - IntPtr hHandle, - string IRCode, - int codeFormat, - int repeatCount, - int inactivityWaitTime, - IntPtr hEvent, - int res1, - int res2); - - [DllImport("uuirtdrv.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool UUIRTLearnIR( - IntPtr hHandle, - int codeFormat, - [MarshalAs(UnmanagedType.LPStr)] StringBuilder ircode, - IRLearnCallbackDelegate progressProc, - int userData, - ref int pAbort, - int param1, - [MarshalAs(UnmanagedType.AsAny)] Object o, - [MarshalAs(UnmanagedType.AsAny)] Object oo); - - [DllImport("uuirtdrv.dll")] - [return: MarshalAs(UnmanagedType.Bool)] - static extern bool UUIRTSetReceiveCallback( - IntPtr hHandle, - UUIRTReceiveCallbackDelegate receiveProc, - int none); - - //[DllImport("uuirtdrv.dll")] - //static extern bool UUIRTSetUUIRTGPIOCfg(IntPtr hHandle, int index, ref UUGPIO GpioSt); - - //[DllImport("uuirtdrv.dll")] - //static extern bool UUIRTGetUUIRTGPIOCfg(IntPtr hHandle, ref int numSlots, ref uint dwPortPins, - // ref UUGPIO GpioSt); - - #endregion - - #region Delegates - - delegate void UUIRTReceiveCallbackDelegate(string irCode, IntPtr userData); - delegate void IRLearnCallbackDelegate(uint progress, uint sigQuality, ulong carrierFreq, IntPtr userData); - - #endregion Delegates - - #region Constants - - static readonly string ConfigurationFile = - Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + - "\\IR Server Suite\\IR Server\\USB-UIRT Transceiver.xml"; - - const int UUIRTDRV_IRFMT_UUIRT = 0x0000; - const int UUIRTDRV_IRFMT_PRONTO = 0x0010; - const int UUIRTDRV_IRFMT_LEARN_FORCERAW = 0x0100; - const int UUIRTDRV_IRFMT_LEARN_FORCESTRUC = 0x0200; - const int UUIRTDRV_IRFMT_LEARN_FORCEFREQ = 0x0400; - const int UUIRTDRV_IRFMT_LEARN_FREQDETECT = 0x0800; - - static readonly string[] Ports = new string[] { "Default", "Port 1", "Port 2", "Port 3" }; - - const int AbortLearn = -1; - const int AllowLearn = 0; - - #endregion Constants - - #region Variables - - RemoteHandler _remoteButtonHandler = null; - - string _blastPort = Ports[0]; - - int _repeatDelay; - int _blastRepeats; - int _learnTimeout; - - //ulong _learnCarrierFreq; - - string _lastCode = String.Empty; - DateTime _lastCodeTime = DateTime.Now; - - // ------- - - int _abortLearn = AllowLearn; - bool _learnTimedOut; - UUIRTReceiveCallbackDelegate _receiveCallback = null; - bool _isUsbUirtLoaded = false; - IntPtr _usbUirtHandle = IntPtr.Zero; - bool _disposed = false; - - #endregion Variables - - #region Deconstructor - - ~UirtTransceiver() - { - Dispose(false); - } - - #endregion Deconstructor - - #region IDisposable Members - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposeManagedResources) - { - if (!_disposed) - { - _disposed = true; - - if (disposeManagedResources) - { - // Dispose any managed resources. - } - - if (_isUsbUirtLoaded && _usbUirtHandle != new IntPtr(-1) && _usbUirtHandle != IntPtr.Zero) - { - UUIRTClose(_usbUirtHandle); - _usbUirtHandle = IntPtr.Zero; - _isUsbUirtLoaded = false; - } - } - } - - #endregion - - #region IIRServerPlugin Members - - public string Name { get { return "USB-UIRT"; } } - public string Version { get { return "1.0.3.3"; } } - public string Author { get { return "and-81"; } } - public string Description { get { return "Support for the USB-UIRT transceiver"; } } - public bool CanReceive { get { return true; } } - public bool CanTransmit { get { return true; } } - public bool CanLearn { get { return true; } } - public bool CanConfigure { get { return true; } } - - public RemoteHandler RemoteCallback - { - get { return _remoteButtonHandler; } - set { _remoteButtonHandler = value; } - } - - public KeyboardHandler KeyboardCallback { get { return null; } set { } } - - public MouseHandler MouseCallback { get { return null; } set { } } - - public string[] AvailablePorts { get { return Ports; } } - - public void Configure() - { - LoadSettings(); - - Configure config = new Configure(); - - config.RepeatDelay = _repeatDelay; - config.BlastRepeats = _blastRepeats; - config.LearnTimeout = _learnTimeout; - - if (config.ShowDialog() == DialogResult.OK) - { - _repeatDelay = config.RepeatDelay; - _blastRepeats = config.BlastRepeats; - _learnTimeout = config.LearnTimeout; - - SaveSettings(); - } - } - public bool Start() - { - LoadSettings(); - - _usbUirtHandle = UUIRTOpen(); - - if (_usbUirtHandle != new IntPtr(-1)) - { - _isUsbUirtLoaded = true; - - // Setup callack to receive IR messages - _receiveCallback = new UUIRTReceiveCallbackDelegate(UUIRTReceiveCallback); - UUIRTSetReceiveCallback(_usbUirtHandle, _receiveCallback, 0); - } - - return _isUsbUirtLoaded; - } - public void Suspend() { } - public void Resume() { } - public void Stop() - { - UUIRTClose(_usbUirtHandle); - - _usbUirtHandle = IntPtr.Zero; - _isUsbUirtLoaded = false; - } - - public bool Transmit(string file) - { - bool result = false; - - try - { - StreamReader streamReader = new StreamReader(file); - string irCode = streamReader.ReadToEnd(); - streamReader.Close(); - - // Set blaster port ... - if (_blastPort == Ports[1]) - irCode = "Z1" + irCode; - else if (_blastPort == Ports[2]) - irCode = "Z2" + irCode; - else if (_blastPort == Ports[3]) - irCode = "Z3" + irCode; - - result = UUIRTTransmitIR( - _usbUirtHandle, // Handle to USB-UIRT - irCode, // IR Code - UUIRTDRV_IRFMT_PRONTO, // Code Format - _blastRepeats, // Repeat Count - 0, // Inactivity Wait Time - IntPtr.Zero, // hEvent - 0, // reserved1 - 0 // reserved2 - ); - } - catch - { - result = false; - } - - return result; - } - public LearnStatus Learn(out byte[] data) - { - bool result = false; - - data = null; - - StringBuilder irCode = new StringBuilder("1", 2048); - _abortLearn = AllowLearn; - _learnTimedOut = false; - - //_learnCarrierFreq = 0; - - Timer timer = new Timer(); - timer.Interval = _learnTimeout; - timer.Tick += new EventHandler(timer_Tick); - timer.Enabled = true; - timer.Start(); - - //IRLearnCallbackDelegate learnCallback = new IRLearnCallbackDelegate(UUIRTLearnCallback); - - result = UirtTransceiver.UUIRTLearnIR( - _usbUirtHandle, // Handle to USB-UIRT - UirtTransceiver.UUIRTDRV_IRFMT_PRONTO | UirtTransceiver.UUIRTDRV_IRFMT_LEARN_FREQDETECT, // | UirtTransceiver.UUIRTDRV_IRFMT_LEARN_FORCERAW - irCode, // Where to put the IR Code - null, // Learn status callback - 0, // User data - ref _abortLearn, // Abort flag? - 0, - null, - null); - - timer.Stop(); - - //MessageBox.Show(_learnCarrierFreq.ToString()); - - if (_learnTimedOut) - { - return LearnStatus.Timeout; - } - else if (result) - { - data = Encoding.ASCII.GetBytes(irCode.ToString()); - - return LearnStatus.Success; - } - else - { - return LearnStatus.Failure; - } - } - - public bool SetPort(string port) - { - foreach (string availablePort in Ports) - { - if (port == availablePort) - { - _blastPort = availablePort; - return true; - } - } - - return false; - } - - #endregion IIRServerPlugin Members - - #region Implementation - - void LoadSettings() - { - try - { - XmlDocument doc = new XmlDocument(); - doc.Load(ConfigurationFile); - - _repeatDelay = int.Parse(doc.DocumentElement.Attributes["RepeatDelay"].Value); - _blastRepeats = int.Parse(doc.DocumentElement.Attributes["BlastRepeats"].Value); - _learnTimeout = int.Parse(doc.DocumentElement.Attributes["LearnTimeout"].Value); - } - catch (Exception ex) - { - Console.WriteLine(ex.ToString()); - - _repeatDelay = 500; - _blastRepeats = 4; - _learnTimeout = 10000; - } - } - void SaveSettings() - { - try - { - XmlTextWriter writer = new XmlTextWriter(ConfigurationFile, System.Text.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("BlastRepeats", _blastRepeats.ToString()); - writer.WriteAttributeString("LearnTimeout", _learnTimeout.ToString()); - - writer.WriteEndElement(); // </settings> - writer.WriteEndDocument(); - writer.Close(); - } - catch (Exception ex) - { - Console.WriteLine(ex.ToString()); - } - } - - void UUIRTReceiveCallback(string keyCode, IntPtr userData) - { - if (_remoteButtonHandler == null) - return; - - TimeSpan timeSpan = DateTime.Now - _lastCodeTime; - - if (keyCode == _lastCode) // Repeated button - { - if (timeSpan.Milliseconds > _repeatDelay) - { - _remoteButtonHandler(keyCode); - _lastCodeTime = DateTime.Now; - } - } - else - { - _remoteButtonHandler(keyCode); - _lastCodeTime = DateTime.Now; - } - - _lastCode = keyCode; - } - /* - void UUIRTLearnCallback(uint progress, uint sigQuality, ulong carrierFreq, IntPtr userData) - { - _learnCarrierFreq = carrierFreq; - //MessageBox.Show(_learnCarrierFreq.ToString()); - } - */ - void timer_Tick(object sender, EventArgs e) - { - _abortLearn = AbortLearn; - _learnTimedOut = true; - - ((Timer)sender).Stop(); - } - - #endregion Implementation - - } - -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |