From: <an...@us...> - 2007-05-04 13:30:35
|
Revision: 372 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=372&view=rev Author: and-81 Date: 2007-05-04 06:30:33 -0700 (Fri, 04 May 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj Added Paths: ----------- trunk/plugins/IgorPlugUSB/Config.Designer.cs trunk/plugins/IgorPlugUSB/Config.cs trunk/plugins/IgorPlugUSB/MappedKeyCode.cs Added: trunk/plugins/IgorPlugUSB/Config.Designer.cs =================================================================== --- trunk/plugins/IgorPlugUSB/Config.Designer.cs (rev 0) +++ trunk/plugins/IgorPlugUSB/Config.Designer.cs 2007-05-04 13:30:33 UTC (rev 372) @@ -0,0 +1,144 @@ +namespace MediaPortal.Plugins +{ + partial class Config + { + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.buttonMapButtons = new System.Windows.Forms.Button(); + this.buttonOK = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.listViewButtons = new System.Windows.Forms.ListView(); + this.columnHeaderButton = new System.Windows.Forms.ColumnHeader(); + this.columnHeaderCode = new System.Windows.Forms.ColumnHeader(); + this.buttonClearAll = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // buttonMapButtons + // + this.buttonMapButtons.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonMapButtons.Location = new System.Drawing.Point(8, 232); + this.buttonMapButtons.Name = "buttonMapButtons"; + this.buttonMapButtons.Size = new System.Drawing.Size(96, 24); + this.buttonMapButtons.TabIndex = 1; + this.buttonMapButtons.Text = "Map Buttons"; + this.buttonMapButtons.UseVisualStyleBackColor = true; + this.buttonMapButtons.Click += new System.EventHandler(this.buttonMapButtons_Click); + // + // buttonOK + // + this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOK.Location = new System.Drawing.Point(240, 232); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(64, 24); + this.buttonOK.TabIndex = 2; + this.buttonOK.Text = "OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.Location = new System.Drawing.Point(312, 232); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(64, 24); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // listViewButtons + // + this.listViewButtons.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.listViewButtons.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.columnHeaderButton, + this.columnHeaderCode}); + this.listViewButtons.FullRowSelect = true; + this.listViewButtons.GridLines = true; + this.listViewButtons.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; + this.listViewButtons.HideSelection = false; + this.listViewButtons.Location = new System.Drawing.Point(8, 8); + this.listViewButtons.Name = "listViewButtons"; + this.listViewButtons.Size = new System.Drawing.Size(368, 216); + this.listViewButtons.TabIndex = 0; + this.listViewButtons.UseCompatibleStateImageBehavior = false; + this.listViewButtons.View = System.Windows.Forms.View.Details; + // + // columnHeaderButton + // + this.columnHeaderButton.Text = "Button"; + this.columnHeaderButton.Width = 134; + // + // columnHeaderCode + // + this.columnHeaderCode.Text = "Code"; + this.columnHeaderCode.Width = 213; + // + // buttonClearAll + // + this.buttonClearAll.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonClearAll.Location = new System.Drawing.Point(112, 232); + this.buttonClearAll.Name = "buttonClearAll"; + this.buttonClearAll.Size = new System.Drawing.Size(72, 24); + this.buttonClearAll.TabIndex = 4; + this.buttonClearAll.Text = "Clear All"; + this.buttonClearAll.UseVisualStyleBackColor = true; + this.buttonClearAll.Click += new System.EventHandler(this.buttonClearAll_Click); + // + // Config + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(388, 266); + this.ControlBox = false; + this.Controls.Add(this.buttonClearAll); + this.Controls.Add(this.listViewButtons); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOK); + this.Controls.Add(this.buttonMapButtons); + this.MinimumSize = new System.Drawing.Size(396, 300); + this.Name = "Config"; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "IgorPlug Plugin Config"; + this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Config_FormClosing); + this.Load += new System.EventHandler(this.Config_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button buttonMapButtons; + private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.ListView listViewButtons; + private System.Windows.Forms.ColumnHeader columnHeaderButton; + private System.Windows.Forms.ColumnHeader columnHeaderCode; + private System.Windows.Forms.Button buttonClearAll; + } +} \ No newline at end of file Added: trunk/plugins/IgorPlugUSB/Config.cs =================================================================== --- trunk/plugins/IgorPlugUSB/Config.cs (rev 0) +++ trunk/plugins/IgorPlugUSB/Config.cs 2007-05-04 13:30:33 UTC (rev 372) @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Threading; +using System.Windows.Forms; +using System.Xml; + +using MediaPortal.Hardware; +using MediaPortal.GUI.Library; +using MediaPortal.InputDevices; + +namespace MediaPortal.Plugins +{ + + public partial class Config : Form + { + + public Config() + { + InitializeComponent(); + } + + private void Config_Load(object sender, EventArgs e) + { + foreach (MappedKeyCode mKC in IgorPlugUSB.KeyCodes) + { + listViewButtons.Items.Add( + new ListViewItem(new string[] { + Enum.GetName(typeof(RemoteButton), mKC.Button), + mKC.KeyCode })); + } + + IgorPlugUSB.ConfigButton = new ConfigButtonPress(ButtonPress); + } + private void Config_FormClosing(object sender, FormClosingEventArgs e) + { + IgorPlugUSB.ConfigButton = null; + } + + private void buttonMapButtons_Click(object sender, EventArgs e) + { + InputMappingForm inputMappingForm = new InputMappingForm(IgorPlugUSB.InputHandler); + inputMappingForm.ShowDialog(); + } + + private void buttonOK_Click(object sender, EventArgs e) + { + IgorPlugUSB.KeyCodes = new List<MappedKeyCode>(); + foreach (ListViewItem item in listViewButtons.Items) + IgorPlugUSB.KeyCodes.Add(new MappedKeyCode(item.SubItems[0].Text, item.SubItems[1].Text)); + + this.DialogResult = DialogResult.OK; + Close(); + } + private void buttonCancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + Close(); + } + + private void buttonClearAll_Click(object sender, EventArgs e) + { + foreach (ListViewItem item in listViewButtons.Items) + item.SubItems[1].Text = ""; + } + + void ButtonPress(string keyCode) + { + if (listViewButtons.SelectedItems.Count == 1) + listViewButtons.SelectedItems[0].SubItems[1].Text = keyCode; + } + + } + +} Modified: trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs =================================================================== --- trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs 2007-05-04 00:46:15 UTC (rev 371) +++ trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs 2007-05-04 13:30:33 UTC (rev 372) @@ -1,26 +1,39 @@ using System; +using System.Collections.Generic; using System.IO; using System.Runtime.InteropServices; using System.Threading; +using System.Windows.Forms; +using System.Xml; using Microsoft.Win32.SafeHandles; +using MediaPortal.Hardware; using MediaPortal.GUI.Library; using MediaPortal.InputDevices; namespace MediaPortal.Plugins { - public class IgorPlugUSB : IPlugin, ISetupForm, IDisposable + delegate void ConfigButtonPress(string keyCode); + + public class IgorPlugUSB : IPlugin, ISetupForm { + #region Constants + + internal const string RemoteFile = "IgorPlugUSBMap.xml"; + internal const string InputHandler = "IgorPlugUSB"; + + #endregion Constants + #region Variables InputHandler _inputHandler; - Thread _readThread; - bool _disposed = false; + internal static ConfigButtonPress ConfigButton = null; + internal static List<MappedKeyCode> KeyCodes = new List<MappedKeyCode>(); #endregion Variables @@ -51,18 +64,6 @@ #endregion Interop - #region Deconstructor - - ~IgorPlugUSB() - { - // call Dispose with false. Since we're in the - // destructor call, the managed resources will be - // disposed of anyways. - Dispose(false); - } - - #endregion - #region IPlugin Members public void Start() @@ -71,10 +72,9 @@ try { - _inputHandler = new InputHandler("IgorPlugUSB"); + _inputHandler = new InputHandler(InputHandler); - ThreadStart readThreadStart = new ThreadStart(ReadThread); - _readThread = new Thread(readThreadStart); + _readThread = new Thread(new ThreadStart(ReadThread)); _readThread.Start(); } catch (Exception ex) @@ -82,7 +82,6 @@ Log.Error("IgorPlugUSB Plugin: {0}", ex.Message); } } - public void Stop() { Log.Info("IgorPlugUSB Plugin: Stop"); @@ -104,8 +103,16 @@ public void ShowPlugin() { - InputMappingForm inputMappingForm = new InputMappingForm("IgorPlugUSB"); - inputMappingForm.ShowDialog(); + LoadRemote(); + + _readThread = new Thread(new ThreadStart(ReadThread)); + _readThread.Start(); + + Config config = new Config(); + if (config.ShowDialog() == DialogResult.OK) + SaveRemote(); + + _readThread.Abort(); } public bool GetHome(out string strButtonText, out string strButtonImage, out string strButtonImageFocus, out string strPictureImage) @@ -116,36 +123,41 @@ #endregion - #region IDisposable Members + #region Implementation - public void Dispose() + void LoadRemote() { - // dispose of the managed and unmanaged resources - Dispose(true); + XmlDocument doc = new XmlDocument(); + doc.Load(RemoteFile); - // tell the GC that the Finalize process no longer needs - // to be run for this object. - GC.SuppressFinalize(this); + XmlNodeList listButtons = doc.DocumentElement.SelectNodes("remotebutton"); + foreach (XmlNode nodeButton in listButtons) + { + KeyCodes.Add(new MappedKeyCode( + nodeButton.Attributes["button"].Value, + nodeButton.Attributes["code"].Value)); + } } + void SaveRemote() + { + XmlTextWriter writer = new XmlTextWriter(RemoteFile, System.Text.Encoding.UTF8); + writer.Formatting = Formatting.Indented; + writer.Indentation = 1; + writer.IndentChar = (char)9; + writer.WriteStartDocument(true); + writer.WriteStartElement("remote"); // <remote> - #endregion - - #region Implementation - - protected virtual void Dispose(bool disposeManagedResources) - { - // process only if mananged and unmanaged resources have - // not been disposed of. - if (!this._disposed) + foreach (MappedKeyCode mKC in KeyCodes) { - if (disposeManagedResources) - { + writer.WriteStartElement("remotebutton"); // <remotebutton> + writer.WriteAttributeString("button", Enum.GetName(typeof(RemoteButton), mKC.Button)); + writer.WriteAttributeString("code", mKC.KeyCode); + writer.WriteEndElement(); // </remotebutton> + } - } - - // dispose unmanaged resources - this._disposed = true; - } + writer.WriteEndElement(); // </remote> + writer.WriteEndDocument(); + writer.Close(); } void ReadThread() @@ -155,7 +167,8 @@ byte[] deviceBuffer = new byte[256]; int codeLength; int returnCode; - int keyCode; + string keyCode; + int translatedKeyCode; int lastCode = -1; DateTime lastCodeTime = DateTime.Now; @@ -189,16 +202,37 @@ if (codeLength == 0) continue; - keyCode = (int)deviceBuffer[3]; - timeSpan = DateTime.Now - lastCodeTime; + keyCode = String.Empty; + for (int i = 0; i < codeLength; i++) + keyCode += deviceBuffer[i].ToString("X2"); - if (keyCode != lastCode || timeSpan.Milliseconds > 250) + if (ConfigButton != null) { - lastCode = keyCode; - lastCodeTime = DateTime.Now; - _inputHandler.MapAction(keyCode); + ConfigButton(keyCode); + continue; } - + + foreach (MappedKeyCode mKC in KeyCodes) + { + if (mKC.KeyCode == keyCode) + { + translatedKeyCode = (int)mKC.Button; + timeSpan = DateTime.Now - lastCodeTime; + + if (translatedKeyCode != lastCode || timeSpan.Milliseconds > 250) + { + lastCode = translatedKeyCode; + lastCodeTime = DateTime.Now; + + Log.Info("IgorPlugUSB Plugin: Key mapped \"{0}\"", keyCode); + _inputHandler.MapAction(translatedKeyCode); + } + + break; + } + } + + Log.Info("IgorPlugUSB Plugin: Key not mapped \"{0}\"", keyCode); } } catch (ThreadAbortException) Modified: trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj =================================================================== --- trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj 2007-05-04 00:46:15 UTC (rev 371) +++ trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj 2007-05-04 13:30:33 UTC (rev 372) @@ -46,7 +46,14 @@ --> <ItemGroup> <Compile Include="AssemblyInfo.cs" /> + <Compile Include="Config.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="Config.Designer.cs"> + <DependentUpon>Config.cs</DependentUpon> + </Compile> <Compile Include="IgorPlugUSB.cs" /> + <Compile Include="MappedKeyCode.cs" /> </ItemGroup> <ItemGroup> <Reference Include="Core, Version=1.0.2581.1884, Culture=neutral, processorArchitecture=MSIL"> @@ -61,6 +68,7 @@ </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> <Reference Include="Utils, Version=1.0.2581.1867, Culture=neutral, processorArchitecture=MSIL"> @@ -77,4 +85,10 @@ <CopyToOutputDirectory>Always</CopyToOutputDirectory> </Content> </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="Config.resx"> + <SubType>Designer</SubType> + <DependentUpon>Config.cs</DependentUpon> + </EmbeddedResource> + </ItemGroup> </Project> \ No newline at end of file Added: trunk/plugins/IgorPlugUSB/MappedKeyCode.cs =================================================================== --- trunk/plugins/IgorPlugUSB/MappedKeyCode.cs (rev 0) +++ trunk/plugins/IgorPlugUSB/MappedKeyCode.cs 2007-05-04 13:30:33 UTC (rev 372) @@ -0,0 +1,56 @@ +using System; + +using MediaPortal.Hardware; + +namespace MediaPortal.Plugins +{ + + [CLSCompliant(false)] + public class MappedKeyCode + { + + #region Variables + + public RemoteButton _button; + public string _keyCode; + + #endregion Variables + + #region Properties + + public RemoteButton Button + { + get { return _button; } + set { _button = value; } + } + public string KeyCode + { + get { return _keyCode; } + set { _keyCode = value; } + } + + #endregion Properties + + #region Constructors + + public MappedKeyCode() + : this(RemoteButton.None, String.Empty) + { + } + + public MappedKeyCode(string button, string keyCode) + : this((RemoteButton)Enum.Parse(typeof(RemoteButton), button), keyCode) + { + } + + public MappedKeyCode(RemoteButton button, string keyCode) + { + _button = button; + _keyCode = keyCode; + } + + #endregion Constructors + + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2007-05-04 13:55:12
|
Revision: 374 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=374&view=rev Author: and-81 Date: 2007-05-04 06:55:10 -0700 (Fri, 04 May 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IgorPlugUSB/Config.cs trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs Modified: trunk/plugins/IgorPlugUSB/Config.cs =================================================================== --- trunk/plugins/IgorPlugUSB/Config.cs 2007-05-04 13:31:38 UTC (rev 373) +++ trunk/plugins/IgorPlugUSB/Config.cs 2007-05-04 13:55:10 UTC (rev 374) @@ -25,6 +25,8 @@ private void Config_Load(object sender, EventArgs e) { + listViewButtons.Items.Clear(); + foreach (MappedKeyCode mKC in IgorPlugUSB.KeyCodes) { listViewButtons.Items.Add( @@ -48,7 +50,7 @@ private void buttonOK_Click(object sender, EventArgs e) { - IgorPlugUSB.KeyCodes = new List<MappedKeyCode>(); + IgorPlugUSB.KeyCodes.Clear(); foreach (ListViewItem item in listViewButtons.Items) IgorPlugUSB.KeyCodes.Add(new MappedKeyCode(item.SubItems[0].Text, item.SubItems[1].Text)); Modified: trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs =================================================================== --- trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs 2007-05-04 13:31:38 UTC (rev 373) +++ trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs 2007-05-04 13:55:10 UTC (rev 374) @@ -72,6 +72,8 @@ try { + LoadRemote(); + _inputHandler = new InputHandler(InputHandler); _readThread = new Thread(new ThreadStart(ReadThread)); @@ -127,6 +129,8 @@ void LoadRemote() { + KeyCodes.Clear(); + XmlDocument doc = new XmlDocument(); doc.Load(RemoteFile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <an...@us...> - 2007-05-11 04:37:47
|
Revision: 395 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=395&view=rev Author: and-81 Date: 2007-05-10 21:37:46 -0700 (Thu, 10 May 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj Modified: trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs =================================================================== --- trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs 2007-05-10 05:51:39 UTC (rev 394) +++ trunk/plugins/IgorPlugUSB/IgorPlugUSB.cs 2007-05-11 04:37:46 UTC (rev 395) @@ -22,8 +22,8 @@ #region Constants - internal const string RemoteFile = "IgorPlugUSBMap.xml"; - internal const string InputHandler = "IgorPlugUSB"; + internal const string RemoteFile = "IgorPlugUSBMap.xml"; + internal const string InputHandler = "IgorPlugUSB"; #endregion Constants Modified: trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj =================================================================== --- trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj 2007-05-10 05:51:39 UTC (rev 394) +++ trunk/plugins/IgorPlugUSB/IgorPlugUSB.csproj 2007-05-11 04:37:46 UTC (rev 395) @@ -56,14 +56,14 @@ <Compile Include="MappedKeyCode.cs" /> </ItemGroup> <ItemGroup> - <Reference Include="Core, Version=1.0.2581.1884, Culture=neutral, processorArchitecture=MSIL"> + <Reference Include="Core, Version=1.0.2546.32606, Culture=neutral, processorArchitecture=x86"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\MediaPortal\Core\bin\Release\Core.dll</HintPath> + <HintPath>..\..\MediaPortal 0.2.2.0\Core.DLL</HintPath> <Private>False</Private> </Reference> - <Reference Include="RemotePlugins, Version=1.0.2581.1913, Culture=neutral, processorArchitecture=MSIL"> + <Reference Include="RemotePlugins, Version=1.0.2546.32615, Culture=neutral, processorArchitecture=x86"> <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\MediaPortal\RemotePlugins\bin\Release\RemotePlugins.dll</HintPath> + <HintPath>..\..\MediaPortal 0.2.2.0\RemotePlugins.DLL</HintPath> <Private>False</Private> </Reference> <Reference Include="System" /> @@ -71,11 +71,6 @@ <Reference Include="System.Drawing" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> - <Reference Include="Utils, Version=1.0.2581.1867, Culture=neutral, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\MediaPortal\Utils\bin\Release\Utils.dll</HintPath> - <Private>False</Private> - </Reference> </ItemGroup> <PropertyGroup> <PostBuildEvent>copy "*.*" "\MediaPortal Development\Plugin Releases\IgorPlugUSB\"</PostBuildEvent> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |