From: <an...@us...> - 2007-11-28 15:06:32
|
Revision: 1097 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1097&view=rev Author: and-81 Date: 2007-11-28 07:06:23 -0800 (Wed, 28 Nov 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.Designer.cs trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.cs trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.resx trunk/plugins/IR Server Suite/Applications/IR File Tool/IR File Tool.csproj trunk/plugins/IR Server Suite/Applications/IR File Tool/Properties/AssemblyInfo.cs trunk/plugins/IR Server Suite/Applications/IR Server/IR Server.csproj trunk/plugins/IR Server Suite/Applications/SageSetup/Sage Setup.csproj trunk/plugins/IR Server Suite/Applications/Translator/Translator.csproj trunk/plugins/IR Server Suite/Applications/Tray Launcher/Tray Launcher.csproj trunk/plugins/IR Server Suite/Applications/Virtual Remote/Virtual Remote.csproj trunk/plugins/IR Server Suite/Applications/Virtual Remote Skin Editor/Virtual Remote Skin Editor.csproj trunk/plugins/IR Server Suite/IR Server Plugins/Custom HID Receiver/Custom HID Receiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/FusionRemote Receiver/FusionREMOTE Receiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/IRMan Receiver/IRMan Receiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/IRTrans Transceiver/IRTrans Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/IgorPlug Receiver/IgorPlug Receiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Microsoft MCE Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/Serial IR Blaster/Serial IR Blaster.csproj trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/USB-UIRT Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/WinLirc Transceiver/WinLirc Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/Windows Message Receiver/Windows Message Receiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/X10 Transceiver/X10 Transceiver.csproj trunk/plugins/IR Server Suite/IR Server Plugins/XBCDRC Receiver/XBCDRC Receiver.csproj trunk/plugins/IR Server Suite/IR Server Suite.sln trunk/plugins/IR Server Suite/Input Service/Input Service/Input Service.csproj trunk/plugins/IR Server Suite/Input Service/Input Service Configuration/Configuration.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Blast Zone Plugin/MP Blast Zone Plugin.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/MP Control Plugin/MP Control Plugin.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/TV2 Blaster Plugin/TV2 Blaster Plugin.csproj trunk/plugins/IR Server Suite/MediaPortal Plugins/TV3 Blaster Plugin/TV3 Blaster Plugin.csproj trunk/plugins/MCEReplacement/MCEReplacement.csproj Added Paths: ----------- trunk/plugins/IR Server Suite/Applications/IR File Tool/IrCode.cs trunk/plugins/IR Server Suite/Applications/IR File Tool/IrDecoder.cs trunk/plugins/IR Server Suite/Applications/IR File Tool/MceDetectionData.cs trunk/plugins/IR Server Suite/Applications/IR File Tool/Pronto.cs trunk/plugins/IR Server Suite/Applications/IR File Tool/RemoteDetectionData.cs Modified: trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj 2007-11-27 21:02:33 UTC (rev 1096) +++ trunk/plugins/IR Server Suite/Applications/Debug Client/Debug Client.csproj 2007-11-28 15:06:23 UTC (rev 1097) @@ -98,6 +98,7 @@ </Target> --> <PropertyGroup> - <PostBuildEvent>copy "*.*" "\MediaPortal Development\Plugin Releases\IR Server Suite\$(ProjectName)\"</PostBuildEvent> + <PostBuildEvent> + </PostBuildEvent> </PropertyGroup> </Project> \ No newline at end of file Modified: trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj 2007-11-27 21:02:33 UTC (rev 1096) +++ trunk/plugins/IR Server Suite/Applications/IR Blast/IR Blast.csproj 2007-11-28 15:06:23 UTC (rev 1097) @@ -83,6 +83,7 @@ </Target> --> <PropertyGroup> - <PostBuildEvent>copy "*.*" "\MediaPortal Development\Plugin Releases\IR Server Suite\$(ProjectName)\"</PostBuildEvent> + <PostBuildEvent> + </PostBuildEvent> </PropertyGroup> </Project> \ No newline at end of file Modified: trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj 2007-11-27 21:02:33 UTC (rev 1096) +++ trunk/plugins/IR Server Suite/Applications/IR Blast (No Window)/IR Blast (No Window).csproj 2007-11-28 15:06:23 UTC (rev 1097) @@ -84,6 +84,7 @@ </Target> --> <PropertyGroup> - <PostBuildEvent>copy "$(TargetFileName)" "\MediaPortal Development\Plugin Releases\IR Server Suite\IR Blast\"</PostBuildEvent> + <PostBuildEvent> + </PostBuildEvent> </PropertyGroup> </Project> \ No newline at end of file Modified: trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.Designer.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.Designer.cs 2007-11-27 21:02:33 UTC (rev 1096) +++ trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.Designer.cs 2007-11-28 15:06:23 UTC (rev 1097) @@ -28,20 +28,210 @@ /// </summary> private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); + this.menuStrip = new System.Windows.Forms.MenuStrip(); + this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.newToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveasToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.quitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.textBoxPronto = new System.Windows.Forms.TextBox(); + this.labelCarrier = new System.Windows.Forms.Label(); + this.toolTips = new System.Windows.Forms.ToolTip(this.components); + this.textBoxCarrier = new System.Windows.Forms.TextBox(); + this.buttonSetCarrier = new System.Windows.Forms.Button(); + this.checkBoxStoreBinary = new System.Windows.Forms.CheckBox(); + this.buttonAttemptDecode = new System.Windows.Forms.Button(); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); + this.menuStrip.SuspendLayout(); this.SuspendLayout(); // + // menuStrip + // + this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fileToolStripMenuItem}); + this.menuStrip.Location = new System.Drawing.Point(0, 0); + this.menuStrip.Name = "menuStrip"; + this.menuStrip.Size = new System.Drawing.Size(497, 24); + this.menuStrip.TabIndex = 0; + this.menuStrip.Text = "menuStrip"; + // + // fileToolStripMenuItem + // + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.newToolStripMenuItem, + this.openToolStripMenuItem, + this.saveToolStripMenuItem, + this.saveasToolStripMenuItem, + this.toolStripSeparator1, + this.quitToolStripMenuItem}); + this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; + this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20); + this.fileToolStripMenuItem.Text = "&File"; + // + // newToolStripMenuItem + // + this.newToolStripMenuItem.Name = "newToolStripMenuItem"; + this.newToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.newToolStripMenuItem.Text = "&New"; + this.newToolStripMenuItem.Click += new System.EventHandler(this.newToolStripMenuItem_Click); + // + // openToolStripMenuItem + // + this.openToolStripMenuItem.Name = "openToolStripMenuItem"; + this.openToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.openToolStripMenuItem.Text = "&Open ..."; + this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); + // + // saveToolStripMenuItem + // + this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + this.saveToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.saveToolStripMenuItem.Text = "&Save"; + this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click); + // + // saveasToolStripMenuItem + // + this.saveasToolStripMenuItem.Name = "saveasToolStripMenuItem"; + this.saveasToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.saveasToolStripMenuItem.Text = "Save &as ..."; + this.saveasToolStripMenuItem.Click += new System.EventHandler(this.saveasToolStripMenuItem_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(135, 6); + // + // quitToolStripMenuItem + // + this.quitToolStripMenuItem.Name = "quitToolStripMenuItem"; + this.quitToolStripMenuItem.Size = new System.Drawing.Size(138, 22); + this.quitToolStripMenuItem.Text = "&Quit"; + this.quitToolStripMenuItem.Click += new System.EventHandler(this.quitToolStripMenuItem_Click); + // + // textBoxPronto + // + this.textBoxPronto.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.textBoxPronto.Font = new System.Drawing.Font("Courier New", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.textBoxPronto.Location = new System.Drawing.Point(8, 32); + this.textBoxPronto.Multiline = true; + this.textBoxPronto.Name = "textBoxPronto"; + this.textBoxPronto.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.textBoxPronto.Size = new System.Drawing.Size(481, 136); + this.textBoxPronto.TabIndex = 1; + // + // labelCarrier + // + this.labelCarrier.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.labelCarrier.Location = new System.Drawing.Point(8, 176); + this.labelCarrier.Name = "labelCarrier"; + this.labelCarrier.Size = new System.Drawing.Size(56, 20); + this.labelCarrier.TabIndex = 2; + this.labelCarrier.Text = "Carrier:"; + this.labelCarrier.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // textBoxCarrier + // + this.textBoxCarrier.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.textBoxCarrier.Location = new System.Drawing.Point(64, 176); + this.textBoxCarrier.Name = "textBoxCarrier"; + this.textBoxCarrier.Size = new System.Drawing.Size(64, 20); + this.textBoxCarrier.TabIndex = 3; + // + // buttonSetCarrier + // + this.buttonSetCarrier.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonSetCarrier.Location = new System.Drawing.Point(136, 176); + this.buttonSetCarrier.Name = "buttonSetCarrier"; + this.buttonSetCarrier.Size = new System.Drawing.Size(32, 20); + this.buttonSetCarrier.TabIndex = 4; + this.buttonSetCarrier.Text = "Set"; + this.toolTips.SetToolTip(this.buttonSetCarrier, "Change the carrier frequency"); + this.buttonSetCarrier.UseVisualStyleBackColor = true; + this.buttonSetCarrier.Click += new System.EventHandler(this.buttonSetCarrier_Click); + // + // checkBoxStoreBinary + // + this.checkBoxStoreBinary.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxStoreBinary.Location = new System.Drawing.Point(328, 176); + this.checkBoxStoreBinary.Name = "checkBoxStoreBinary"; + this.checkBoxStoreBinary.Size = new System.Drawing.Size(160, 24); + this.checkBoxStoreBinary.TabIndex = 6; + this.checkBoxStoreBinary.Text = "Store mceir.dll compatible"; + this.toolTips.SetToolTip(this.checkBoxStoreBinary, "Store this IR Code in an MceIr.dll compatible form"); + this.checkBoxStoreBinary.UseVisualStyleBackColor = true; + // + // buttonAttemptDecode + // + this.buttonAttemptDecode.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.buttonAttemptDecode.Location = new System.Drawing.Point(192, 176); + this.buttonAttemptDecode.Name = "buttonAttemptDecode"; + this.buttonAttemptDecode.Size = new System.Drawing.Size(112, 24); + this.buttonAttemptDecode.TabIndex = 5; + this.buttonAttemptDecode.Text = "Attempt decode"; + this.toolTips.SetToolTip(this.buttonAttemptDecode, "Try to decode the IR signal into a recognised format"); + this.buttonAttemptDecode.UseVisualStyleBackColor = true; + this.buttonAttemptDecode.Click += new System.EventHandler(this.buttonAttemptDecode_Click); + // + // openFileDialog + // + this.openFileDialog.DefaultExt = "IR"; + this.openFileDialog.Filter = "IR Files|*.IR"; + this.openFileDialog.Title = "Open an IR file ..."; + // + // saveFileDialog + // + this.saveFileDialog.DefaultExt = "IR"; + this.saveFileDialog.Filter = "IR Files|*.IR"; + this.saveFileDialog.Title = "Save an IR file ..."; + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(284, 264); + this.ClientSize = new System.Drawing.Size(497, 209); + this.Controls.Add(this.buttonAttemptDecode); + this.Controls.Add(this.checkBoxStoreBinary); + this.Controls.Add(this.buttonSetCarrier); + this.Controls.Add(this.textBoxCarrier); + this.Controls.Add(this.labelCarrier); + this.Controls.Add(this.textBoxPronto); + this.Controls.Add(this.menuStrip); + this.MainMenuStrip = this.menuStrip; + this.MinimumSize = new System.Drawing.Size(505, 236); this.Name = "FormMain"; this.Text = "IR File Tool"; + this.menuStrip.ResumeLayout(false); + this.menuStrip.PerformLayout(); this.ResumeLayout(false); + this.PerformLayout(); } #endregion + + private System.Windows.Forms.MenuStrip menuStrip; + private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem newToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveasToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; + private System.Windows.Forms.ToolStripMenuItem quitToolStripMenuItem; + private System.Windows.Forms.TextBox textBoxPronto; + private System.Windows.Forms.Label labelCarrier; + private System.Windows.Forms.ToolTip toolTips; + private System.Windows.Forms.TextBox textBoxCarrier; + private System.Windows.Forms.Button buttonSetCarrier; + private System.Windows.Forms.CheckBox checkBoxStoreBinary; + private System.Windows.Forms.Button buttonAttemptDecode; + private System.Windows.Forms.OpenFileDialog openFileDialog; + private System.Windows.Forms.SaveFileDialog saveFileDialog; } } Modified: trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.cs 2007-11-27 21:02:33 UTC (rev 1096) +++ trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.cs 2007-11-28 15:06:23 UTC (rev 1097) @@ -3,16 +3,192 @@ using System.ComponentModel; using System.Data; using System.Drawing; +using System.IO; using System.Text; using System.Windows.Forms; namespace IrFileTool { + public partial class FormMain : Form { + + string _fileName = String.Empty; + + IrCode _code = new IrCode(); + + public FormMain() { InitializeComponent(); } + + void RefreshForm() + { + textBoxPronto.Text = Encoding.ASCII.GetString(_code.ToByteArray(true)); + + switch (_code.Carrier) + { + case IrCode.CarrierFrequencyDCMode: + textBoxCarrier.Text = "DC Mode"; + break; + + case IrCode.CarrierFrequencyUnknown: + textBoxCarrier.Text = "Unknown"; + break; + + default: + textBoxCarrier.Text = _code.Carrier.ToString(); + break; + } + } + + void Save() + { + if (!checkBoxStoreBinary.Checked) + { + Pronto.WriteProntoFile(_fileName, Pronto.ConvertIrCodeToProntoRaw(_code)); + } + else + { + using (FileStream file = File.OpenWrite(_fileName)) + { + byte[] fileBytes = DataPacket(_code); + + file.Write(fileBytes, 0, fileBytes.Length); + } + } + } + + + private void newToolStripMenuItem_Click(object sender, EventArgs e) + { + _code = new IrCode(); + + RefreshForm(); + } + + private void openToolStripMenuItem_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog(this) != DialogResult.OK) + return; + + using (FileStream file = File.OpenRead(openFileDialog.FileName)) + { + if (file.Length == 0) + { + MessageBox.Show(this, "The selected file is empty", "Empty file", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + byte[] fileData = new byte[file.Length]; + + file.Read(fileData, 0, (int)file.Length); + + _code = IrCode.FromByteArray(fileData); + } + + RefreshForm(); + } + + private void saveToolStripMenuItem_Click(object sender, EventArgs e) + { + Save(); + } + + private void saveasToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog(this) != DialogResult.OK) + return; + + _fileName = saveFileDialog.FileName; + + Save(); + } + + private void quitToolStripMenuItem_Click(object sender, EventArgs e) + { + this.Close(); + } + + private void buttonAttemptDecode_Click(object sender, EventArgs e) + { + IrDecoder.DecodeIR(_code.TimingData, new RemoteCallback(RemoteEvent), new KeyboardCallback(KeyboardEvent), new MouseCallback(MouseEvent)); + } + + static byte[] DataPacket(IrCode code) + { + if (code.TimingData.Length == 0) + return null; + + // Construct data bytes into "packet" ... + List<byte> packet = new List<byte>(); + + for (int index = 0; index < code.TimingData.Length; index++) + { + double time = (double)code.TimingData[index]; + + byte duration = (byte)Math.Abs(Math.Round(time / 50)); + bool pulse = (time > 0); + + while (duration > 0x7F) + { + packet.Add((byte)(pulse ? 0xFF : 0x7F)); + + duration -= 0x7F; + } + + packet.Add((byte)(pulse ? 0x80 | duration : duration)); + } + + // Insert byte count markers into packet data bytes ... + int subpackets = (int)Math.Ceiling(packet.Count / (double)4); + + byte[] output = new byte[packet.Count + subpackets + 1]; + + int outputPos = 0; + + for (int packetPos = 0; packetPos < packet.Count; ) + { + byte copyCount = (byte)(packet.Count - packetPos < 4 ? packet.Count - packetPos : 0x04); + + output[outputPos++] = (byte)(0x80 | copyCount); + + for (int index = 0; index < copyCount; index++) + output[outputPos++] = packet[packetPos++]; + } + + output[outputPos] = 0x80; + + return output; + } + + void RemoteEvent(IrProtocol codeType, uint keyCode, bool firstPress) + { + MessageBox.Show(this, String.Format("Remote: {0}, {1}", Enum.GetName(typeof(IrProtocol), codeType), keyCode), "Decode IR", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + void KeyboardEvent(uint keyCode, uint modifiers) + { + MessageBox.Show(this, String.Format("Keyboard: {0}, {1}", keyCode, modifiers), "Decode IR", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + void MouseEvent(int deltaX, int deltaY, bool right, bool left) + { + MessageBox.Show(this, String.Format("Mouse: DX {0}, DY {1}, Right: {2}, Left: {3}", deltaX, deltaY, right, left), "Decode IR", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + + private void buttonSetCarrier_Click(object sender, EventArgs e) + { + if (textBoxCarrier.Text == "Unknown") + return; + + if (textBoxCarrier.Text == "DC Mode") + _code.Carrier = IrCode.CarrierFrequencyDCMode; + + _code.Carrier = int.Parse(textBoxCarrier.Text); + + RefreshForm(); + } + } -} \ No newline at end of file + +} Modified: trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.resx =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.resx 2007-11-27 21:02:33 UTC (rev 1096) +++ trunk/plugins/IR Server Suite/Applications/IR File Tool/FormMain.resx 2007-11-28 15:06:23 UTC (rev 1097) @@ -117,4 +117,16 @@ <resheader name="writer"> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> + <metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>17, 17</value> + </metadata> + <metadata name="toolTips.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>119, 17</value> + </metadata> + <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>209, 17</value> + </metadata> + <metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> + <value>333, 17</value> + </metadata> </root> \ No newline at end of file Modified: trunk/plugins/IR Server Suite/Applications/IR File Tool/IR File Tool.csproj =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR File Tool/IR File Tool.csproj 2007-11-27 21:02:33 UTC (rev 1096) +++ trunk/plugins/IR Server Suite/Applications/IR File Tool/IR File Tool.csproj 2007-11-28 15:06:23 UTC (rev 1097) @@ -10,8 +10,7 @@ <RootNamespace>IRFileTool</RootNamespace> <AssemblyName>IR File Tool</AssemblyName> <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> - <StartupObject> - </StartupObject> + <StartupObject>IrFileTool.Program</StartupObject> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <DebugSymbols>true</DebugSymbols> @@ -21,14 +20,17 @@ <DefineConstants>DEBUG;TRACE</DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> + <DebugType>none</DebugType> <Optimize>true</Optimize> <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> + <DefineConstants> + </DefineConstants> <ErrorReport>prompt</ErrorReport> <WarningLevel>4</WarningLevel> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> <DebugSymbols>true</DebugSymbols> @@ -64,8 +66,13 @@ <Compile Include="FormMain.Designer.cs"> <DependentUpon>FormMain.cs</DependentUpon> </Compile> + <Compile Include="IrCode.cs" /> + <Compile Include="IrDecoder.cs" /> + <Compile Include="MceDetectionData.cs" /> <Compile Include="Program.cs" /> + <Compile Include="Pronto.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="RemoteDetectionData.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="FormMain.resx"> Added: trunk/plugins/IR Server Suite/Applications/IR File Tool/IrCode.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR File Tool/IrCode.cs (rev 0) +++ trunk/plugins/IR Server Suite/Applications/IR File Tool/IrCode.cs 2007-11-28 15:06:23 UTC (rev 1097) @@ -0,0 +1,287 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; + +// Remember: Pulse is Positive, Space is Negative. + +namespace IrFileTool +{ + + /// <summary> + /// Encapsulates an MCE compatible IR Code. + /// </summary> + class IrCode + { + + #region Constants + + /// <summary> + /// The carrier frequency for this code is Unknown. + /// </summary> + public const int CarrierFrequencyUnknown = -1; + /// <summary> + /// This code does not use a carrier wave. + /// </summary> + public const int CarrierFrequencyDCMode = 0; + /// <summary> + /// Default carrier frequency, 36kHz (the carrier frequency for RC5, RC6 and RC-MM). + /// </summary> + public const int CarrierFrequencyDefault = 36000; + + /// <summary> + /// How long the longest IR Code space should be (microseconds). + /// </summary> + const int LongestSpace = -100000; + + #endregion Constants + + #region Member Variables + + int _carrier; + int[] _timingData; + + #endregion Member Variables + + #region Properties + + /// <summary> + /// Gets or Sets the IR carrier frequency. + /// </summary> + public int Carrier + { + get { return _carrier; } + set { _carrier = value; } + } + + /// <summary> + /// Gets or Sets the IR timing data. + /// </summary> + public int[] TimingData + { + get { return _timingData; } + set { _timingData = value; } + } + + #endregion Properties + + #region Constructors + + public IrCode() : this(CarrierFrequencyUnknown, new int[] { }) { } + public IrCode(int carrier) : this(carrier, new int[] { }) { } + public IrCode(int[] timingData) : this(CarrierFrequencyUnknown, timingData) { } + public IrCode(int carrier, int[] timingData) + { + _carrier = carrier; + _timingData = timingData; + } + + #endregion Constructors + + #region Methods + + /// <summary> + /// Locates the gap between button presses and reduces the data down to just the first press. + /// </summary> + /// <returns>true if successful, otherwise false.</returns> + public bool FinalizeData() + { + if (_timingData.Length == 0) + return false; + + List<int> newData = new List<int>(); + + foreach (int time in _timingData) + { + if (time <= LongestSpace) + { + newData.Add(LongestSpace); + break; + } + else + { + newData.Add(time); + } + } + + _timingData = newData.ToArray(); + return true; + } + + /// <summary> + /// Add timing data to this IR Code. + /// </summary> + /// <param name="timingData">Addition timing data.</param> + public void AddTimingData(int[] timingData) + { + List<int> newTimingData = new List<int>(); + + int index = 0; + + if (_timingData.Length > 1) + { + for (index = 0; index < _timingData.Length - 1; index++) + newTimingData.Add(_timingData[index]); + } + else if (_timingData.Length == 0) + { + _timingData = new int[timingData.Length]; + timingData.CopyTo(_timingData, 0); + return; + } + + if (timingData.Length == 0 || index >= _timingData.Length) + return; + + if (Math.Sign(timingData[0]) == Math.Sign(_timingData[index])) + { + newTimingData.Add(_timingData[index] + timingData[0]); + + for (index = 1; index < timingData.Length; index++) + newTimingData.Add(timingData[index]); + } + else + { + newTimingData.Add(_timingData[index]); + newTimingData.AddRange(timingData); + } + + _timingData = newTimingData.ToArray(); + } + + /// <summary> + /// Creates a byte array representation of this IR Code. + /// </summary> + /// <param name="asPronto">Set this parameter true to convert the IR Code into Pronto format.</param> + /// <returns>Byte array representation.</returns> + public byte[] ToByteArray(bool asPronto) + { + StringBuilder output = new StringBuilder(); + + if (asPronto) + { + ushort[] prontoData = Pronto.ConvertIrCodeToProntoRaw(this); + + for (int index = 0; index < prontoData.Length; index++) + { + output.Append(prontoData[index].ToString("X4")); + if (index != prontoData.Length - 1) + output.Append(' '); + } + } + else // Native format (only benefit is a slightly more accurate Carrier Frequency) + { + output.Append("MCE,"); + output.AppendFormat("{0},", _carrier); + + for (int index = 0; index < _timingData.Length; index++) + { + output.Append(_timingData[index]); + if (index != _timingData.Length - 1) + output.Append(','); + } + } + + return Encoding.ASCII.GetBytes(output.ToString()); + } + + #endregion Methods + + #region Static Methods + + /// <summary> + /// Creates an IrCode object from old IR file bytes. + /// </summary> + /// <param name="data">IR file bytes.</param> + /// <returns>New IrCode object.</returns> + static IrCode FromOldData(byte[] data) + { + List<int> timingData = new List<int>(); + + int len = 0; + + for (int index = 0; index < data.Length; index++) + { + byte curByte = data[index]; + + if ((curByte & 0x80) != 0) + len += (int)(curByte & 0x7F); + else + len -= (int)curByte; + + if ((curByte & 0x7F) != 0x7F) + { + timingData.Add(len * 50); + len = 0; + } + } + + if (len != 0) + timingData.Add(len * 50); + + return new IrCode(timingData.ToArray()); + } + + /// <summary> + /// Create an IrCode object from Native file bytes. + /// </summary> + /// <param name="data">IR file bytes.</param> + /// <returns>New IrCode object.</returns> + static IrCode FromNativeData(string data) + { + if (String.IsNullOrEmpty(data)) + throw new ArgumentNullException("data"); + + string[] elements = data.Split(new char[] { ',' }); + + if (elements.Length < 3) + throw new ApplicationException("Invalid native IR file data"); + + IrCode newCode = new IrCode(); + newCode.Carrier = int.Parse(elements[1]); + + int[] timingData = new int[elements.Length - 2]; + for (int index = 2; index < elements.Length; index++) + timingData[index - 2] = int.Parse(elements[index]); + + newCode.TimingData = timingData; + + return newCode; + } + + /// <summary> + /// Create a new IrCode object from byte array data. + /// </summary> + /// <param name="data">Byte array to create from.</param> + /// <returns>New IrCode object.</returns> + public static IrCode FromByteArray(byte[] data) + { + if (data[4] == ' ') + { + string code = Encoding.ASCII.GetString(data); + + string[] stringData = code.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + ushort[] prontoData = new ushort[stringData.Length]; + for (int i = 0; i < stringData.Length; i++) + prontoData[i] = ushort.Parse(stringData[i], System.Globalization.NumberStyles.HexNumber); + + return Pronto.ConvertProntoDataToIrCode(prontoData); + } + else if (data[0] == 'M' && data[1] == 'C' && data[2] == 'E') + { + string code = Encoding.ASCII.GetString(data); + + return FromNativeData(code); + } + else + { + return FromOldData(data); + } + } + + #endregion Static Methods + + } + +} Added: trunk/plugins/IR Server Suite/Applications/IR File Tool/IrDecoder.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR File Tool/IrDecoder.cs (rev 0) +++ trunk/plugins/IR Server Suite/Applications/IR File Tool/IrDecoder.cs 2007-11-28 15:06:23 UTC (rev 1097) @@ -0,0 +1,2070 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Text; + +namespace IrFileTool +{ + + #region Enumerations + + /// <summary> + /// Protocol of IR Code. + /// </summary> + enum IrProtocol + { + /// <summary> + /// No protocol. + /// </summary> + None, + + /// <summary> + /// Daewoo protocol. + /// </summary> + Daewoo, + /// <summary> + /// ITT protocol (unsupported). + /// </summary> + ITT, + /// <summary> + /// JVC protocol. + /// </summary> + JVC, + /// <summary> + /// Matsushita protocol. + /// </summary> + Matsushita, + /// <summary> + /// Mitsubishi protocol. + /// </summary> + Mitsubishi, + /// <summary> + /// NEC protocol. + /// </summary> + NEC, + /// <summary> + /// Nokia NRC17 protocol. + /// </summary> + NRC17, + /// <summary> + /// Panasonic protocol. + /// </summary> + Panasonic, + /// <summary> + /// Philips RC5 protocol. + /// </summary> + RC5, + /// <summary> + /// Philips RC5X protocol. + /// </summary> + RC5X, + /// <summary> + /// Philips RC6 protocol (Mode 0). + /// </summary> + RC6, + /// <summary> + /// Philips RC6 protocol (Mode 6A). + /// </summary> + RC6A, + /// <summary> + /// Microsoft's protocol variation of Philips RC6. + /// </summary> + RC6_MCE, + /// <summary> + /// RCA protocol. + /// </summary> + RCA, + /// <summary> + /// Philips RC-MM protocol. This protocol cannot be reliably (if at all) decoded by the MCE device. + /// </summary> + RCMM, + /// <summary> + /// RECS-80 protocol. + /// </summary> + RECS80, + /// <summary> + /// Sharp protocol (unsupported). + /// </summary> + Sharp, + /// <summary> + /// Sony SIRC protocol. + /// </summary> + SIRC, + /// <summary> + /// Toshiba protocol. + /// </summary> + Toshiba, + /// <summary> + /// X-Sat protocol (unsupported). + /// </summary> + XSAT, + + /// <summary> + /// Unknown protocol. + /// </summary> + Unknown, + } + + #endregion Enumerations + + #region Delegates + + delegate void RemoteCallback(IrProtocol codeType, uint keyCode, bool firstPress); + delegate void KeyboardCallback(uint keyCode, uint modifiers); + delegate void MouseCallback(int deltaX, int deltaY, bool rightButton, bool leftButton); + + #endregion Delegates + + /// <summary> + /// Used for decoding received IR Codes. + /// </summary> + static class IrDecoder + { + + #region Constants + + const ushort ToggleBitMce = 0x8000; + const ushort ToggleMaskMce = 0x7FFF; + const ushort CustomerMce = 0x800F; + + const ushort ToggleBitRC5 = 0x0800; + const ushort ToggleMaskRC5 = 0xF7FF; + + const uint ToggleBitRC5X = 0x00020000; + const ushort ToggleMaskRC5X = 0xFFFF; + + const uint RC6HeaderMask = 0xFFFFFFF0; + + const uint PrefixRC6 = 0x000FC950; + const uint PrefixRC6A = 0x000FCA90; + + const uint MceMouse = 1; + const uint MceKeyboard = 4; + + #endregion Constants + + #region Detection Data + + static RemoteDetectionData Daewoo_Data = new RemoteDetectionData(); + static RemoteDetectionData JVC_Data = new RemoteDetectionData(); + static RemoteDetectionData Matsushita_Data = new RemoteDetectionData(); + static RemoteDetectionData Mitsubishi_Data = new RemoteDetectionData(); + static RemoteDetectionData NEC_Data = new RemoteDetectionData(); + static RemoteDetectionData NRC17_Data = new RemoteDetectionData(); + static RemoteDetectionData Panasonic_Data = new RemoteDetectionData(); + static RemoteDetectionData RC5_Data = new RemoteDetectionData(); + static RemoteDetectionData RC6_Data = new RemoteDetectionData(); + static RemoteDetectionData RCA_Data = new RemoteDetectionData(); + static RemoteDetectionData RECS80_Data = new RemoteDetectionData(); + static RemoteDetectionData SIRC_Data = new RemoteDetectionData(); + static RemoteDetectionData Toshiba_Data = new RemoteDetectionData(); + + static MceDetectionData MCE_Data = new MceDetectionData(); + + #endregion Detection Data + + #region Methods + + /// <summary> + /// Decode timing data to discover IR Protocol and packet payload. + /// </summary> + /// <param name="timingData">Input timing data.</param> + /// <param name="remoteCallback">Method to call when Remote button decoded.</param> + /// <param name="keyboardCallback">Method to call when Keyboard event decoded.</param> + /// <param name="mouseCallback">Method to call when Mouse event decoded.</param> + public static void DecodeIR(int[] timingData, RemoteCallback remoteCallback, KeyboardCallback keyboardCallback, MouseCallback mouseCallback) + { + if (timingData == null) + return; + + try + { + DetectDaewoo(timingData, remoteCallback); + //DetectITT(timingData, remoteCallback); + DetectJVC(timingData, remoteCallback); + DetectMatsushita(timingData, remoteCallback); + DetectMitsubishi(timingData, remoteCallback); + DetectNEC(timingData, remoteCallback); + DetectNRC17(timingData, remoteCallback); + DetectPanasonic(timingData, remoteCallback); + DetectRC5(timingData, remoteCallback); + DetectRC6(timingData, remoteCallback); + DetectRCA(timingData, remoteCallback); + //DetectRCMM(timingData, remoteCallback); + DetectRECS80(timingData, remoteCallback); + //DetectSharp(timingData, remoteCallback); + DetectSIRC(timingData, remoteCallback); + DetectToshiba(timingData, remoteCallback); + //DetectXSAT(timingData, remoteCallback); + + DetectMCE(timingData, keyboardCallback, mouseCallback); + //DetectIMon(timingData, keyboardCallback, mouseCallback); + } +#if TRACE + catch (Exception ex) + { + Trace.WriteLine(ex.ToString()); +#else + catch + { +#endif + Daewoo_Data = new RemoteDetectionData(); + JVC_Data = new RemoteDetectionData(); + Matsushita_Data = new RemoteDetectionData(); + Mitsubishi_Data = new RemoteDetectionData(); + NEC_Data = new RemoteDetectionData(); + NRC17_Data = new RemoteDetectionData(); + Panasonic_Data = new RemoteDetectionData(); + RC5_Data = new RemoteDetectionData(); + RC6_Data = new RemoteDetectionData(); + RCA_Data = new RemoteDetectionData(); + RECS80_Data = new RemoteDetectionData(); + SIRC_Data = new RemoteDetectionData(); + Toshiba_Data = new RemoteDetectionData(); + + MCE_Data = new MceDetectionData(); + } + } + + static void DetectDaewoo(int[] timingData, RemoteCallback remoteCallback) + { + for (int i = 0; i < timingData.Length; i++) + { + int duration = Math.Abs(timingData[i]); + bool pulse = (timingData[i] > 0); + bool ignored = true; + + //Trace.WriteLine("Daewoo - {0}: {1}", Enum.GetName(typeof(RemoteDetectionState), Daewoo_Data.State), timingData[i]); + + switch (Daewoo_Data.State) + { + + #region HeaderPulse + case RemoteDetectionState.HeaderPulse: + if (pulse && IsBetween(duration, 7800, 8200)) + { + Daewoo_Data.State = RemoteDetectionState.HeaderSpace; + ignored = false; + } + break; + #endregion HeaderPulse + + #region HeaderSpace + case RemoteDetectionState.HeaderSpace: + if (!pulse && IsBetween(duration, 3800 , 4200)) + { + Daewoo_Data.State = RemoteDetectionState.Data; + Daewoo_Data.HalfBit = 0; + Daewoo_Data.Bit = 0; + Daewoo_Data.Code = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 10000 , 40000)) // For Repeats + { + Daewoo_Data.State = RemoteDetectionState.Data; + Daewoo_Data.HalfBit = 0; + Daewoo_Data.Bit = 0; + Daewoo_Data.Code = 0; + ignored = false; + } + break; + #endregion HeaderSpace + + #region Data + case RemoteDetectionState.Data: + if (pulse && IsBetween(duration, 350, 750)) + { + Daewoo_Data.HalfBit = 1; + ignored = false; + } + else if (!pulse && IsBetween(duration, 250, 650) && Daewoo_Data.HalfBit == 1) + { + Daewoo_Data.Code <<= 1; + Daewoo_Data.Bit++; + Daewoo_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 1250, 1650) && Daewoo_Data.HalfBit == 1) + { + Daewoo_Data.Code <<= 1; + Daewoo_Data.Code |= 1; + Daewoo_Data.Bit++; + Daewoo_Data.HalfBit = 0; + ignored = false; + } + else + { + //Trace.WriteLine("Daewoo Error"); + } + + if (Daewoo_Data.Bit == 16) + { + remoteCallback(IrProtocol.Daewoo, Daewoo_Data.Code, false); + Daewoo_Data.State = RemoteDetectionState.Leading; + } + break; + #endregion Data + + #region Leading + case RemoteDetectionState.Leading: + if (pulse && IsBetween(duration, 350, 750)) + { + Daewoo_Data.State = RemoteDetectionState.HeaderSpace; + ignored = false; + } + break; + #endregion Leading + + } + + if (ignored && (Daewoo_Data.State != RemoteDetectionState.HeaderPulse)) + Daewoo_Data.State = RemoteDetectionState.HeaderPulse; + } + } + static void DetectJVC(int[] timingData, RemoteCallback remoteCallback) + { + for (int i = 0; i < timingData.Length; i++) + { + int duration = Math.Abs(timingData[i]); + bool pulse = (timingData[i] > 0); + bool ignored = true; + + //Trace.WriteLine("JVC - {0}: {1}", Enum.GetName(typeof(RemoteDetectionState), JVC_Data.State), timingData[i]); + + switch (JVC_Data.State) + { + + #region HeaderPulse + case RemoteDetectionState.HeaderPulse: + if (pulse && IsBetween(duration, 8300, 8500)) + { + JVC_Data.State = RemoteDetectionState.HeaderSpace; + ignored = false; + } + break; + #endregion HeaderPulse + + #region HeaderSpace + case RemoteDetectionState.HeaderSpace: + if (!pulse && IsBetween(duration, 4100, 4300)) + { + JVC_Data.Toggle = 0; + + JVC_Data.State = RemoteDetectionState.Data; + JVC_Data.HalfBit = 0; + JVC_Data.Bit = 0; + JVC_Data.Code = 0; + ignored = false; + } + break; + #endregion HeaderSpace + + #region Data + case RemoteDetectionState.Data: + if (pulse && IsBetween(duration, 450, 650)) + { + JVC_Data.HalfBit = 1; + ignored = false; + } + else if (!pulse && IsBetween(duration, 450, 650) && JVC_Data.HalfBit == 1) + { + JVC_Data.Code <<= 1; + JVC_Data.Bit++; + JVC_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 1450, 1700) && JVC_Data.HalfBit == 1) + { + JVC_Data.Code <<= 1; + JVC_Data.Code |= 1; + JVC_Data.Bit++; + JVC_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && duration >= 10000) + { + if (JVC_Data.Bit == 16) + { + bool first = false; + if (JVC_Data.Code != JVC_Data.Toggle) + first = true; + + remoteCallback(IrProtocol.JVC, JVC_Data.Code, first); + ignored = false; + + JVC_Data.Toggle = (int)JVC_Data.Code; + + if (duration > 25000) + JVC_Data.State = RemoteDetectionState.HeaderPulse; + else + JVC_Data.State = RemoteDetectionState.Data; + + JVC_Data.HalfBit = 0; + JVC_Data.Bit = 0; + JVC_Data.Code = 0; + } + else if (JVC_Data.Bit == 32) + { + remoteCallback(IrProtocol.Unknown, JVC_Data.Code, false); + } + else + { + //Trace.WriteLine("JVC Error"); + } + + } + else + { + //Trace.WriteLine("JVC Error"); + } + + break; + #endregion Data + + } + + if (ignored && (JVC_Data.State != RemoteDetectionState.HeaderPulse)) + JVC_Data.State = RemoteDetectionState.HeaderPulse; + } + } + static void DetectMatsushita(int[] timingData, RemoteCallback remoteCallback) + { + for (int i = 0; i < timingData.Length; i++) + { + int duration = Math.Abs(timingData[i]); + bool pulse = (timingData[i] > 0); + bool ignored = true; + + //Trace.WriteLine("Matsushita - {0}: {1}", Enum.GetName(typeof(RemoteDetectionState), Matsushita_Data.State), timingData[i]); + + switch (Matsushita_Data.State) + { + + #region HeaderPulse + case RemoteDetectionState.HeaderPulse: + if (pulse && IsBetween(duration, 3300, 3700)) + { + Matsushita_Data.State = RemoteDetectionState.HeaderSpace; + ignored = false; + } + //else + //Trace.WriteLine("HeaderPulse fall through"); + + break; + #endregion HeaderPulse + + #region HeaderSpace + case RemoteDetectionState.HeaderSpace: + if (!pulse && IsBetween(duration, 3300, 3700)) + { + Matsushita_Data.State = RemoteDetectionState.Data; + Matsushita_Data.HalfBit = 0; + Matsushita_Data.Bit = 0; + Matsushita_Data.Code = 0; + ignored = false; + } + //else + //Trace.WriteLine("HeaderSpace fell through"); + + break; + #endregion HeaderSpace + + #region Data + case RemoteDetectionState.Data: + if (pulse && IsBetween(duration, 650, 1050)) + { + Matsushita_Data.HalfBit = 1; + ignored = false; + } + else if (!pulse && IsBetween(duration, 650, 1050) && Matsushita_Data.HalfBit == 1) + { + Matsushita_Data.Code <<= 1; + Matsushita_Data.Bit++; + Matsushita_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 2450, 2850) && Matsushita_Data.HalfBit == 1) + { + Matsushita_Data.Code <<= 1; + Matsushita_Data.Code |= 1; + Matsushita_Data.Bit++; + Matsushita_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && duration >= 20000 && Matsushita_Data.HalfBit == 1) + { + if (Matsushita_Data.Bit != 22) + break; + + uint code = Matsushita_Data.Code >> 12; + remoteCallback(IrProtocol.Matsushita, code, false); + Matsushita_Data.State = RemoteDetectionState.HeaderPulse; + Matsushita_Data.HalfBit = 0; + ignored = false; + } + else + { + //Trace.WriteLine("Matsushita Error"); + } + + break; + #endregion Data + + } + + if (ignored && (Matsushita_Data.State != RemoteDetectionState.HeaderPulse)) + { + //Trace.WriteLine("ignored"); + Matsushita_Data.State = RemoteDetectionState.HeaderPulse; + } + } + } + static void DetectMitsubishi(int[] timingData, RemoteCallback remoteCallback) + { + for (int i = 0; i < timingData.Length; i++) + { + int duration = Math.Abs(timingData[i]); + bool pulse = (timingData[i] > 0); + bool ignored = true; + + //Trace.WriteLine("Mitsubishi - {0}: {1}", Enum.GetName(typeof(RemoteDetectionState), Mitsubishi_Data.State), timingData[i]); + + switch (Mitsubishi_Data.State) + { + + #region HeaderPulse + case RemoteDetectionState.HeaderPulse: + if (pulse && IsBetween(duration, 7800, 8200)) + { + Mitsubishi_Data.State = RemoteDetectionState.HeaderSpace; + ignored = false; + } + + break; + #endregion HeaderPulse + + #region HeaderSpace + case RemoteDetectionState.HeaderSpace: + if (!pulse && IsBetween(duration, 3800, 4200)) + { + Mitsubishi_Data.State = RemoteDetectionState.Data; + Mitsubishi_Data.HalfBit = 0; + Mitsubishi_Data.Bit = 0; + Mitsubishi_Data.Code = 0; + ignored = false; + } + + break; + #endregion HeaderSpace + + #region Data + case RemoteDetectionState.Data: + if (pulse && IsBetween(duration, 350, 650)) + { + Mitsubishi_Data.HalfBit = 1; + ignored = false; + } + else if (!pulse && IsBetween(duration, 350, 650) && Mitsubishi_Data.HalfBit == 1) + { + Mitsubishi_Data.Code <<= 1; + Mitsubishi_Data.Bit++; + Mitsubishi_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 1300, 1700) && Mitsubishi_Data.HalfBit == 1) + { + Mitsubishi_Data.Code <<= 1; + Mitsubishi_Data.Code |= 1; + Mitsubishi_Data.Bit++; + Mitsubishi_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 3800, 4200) && Mitsubishi_Data.HalfBit == 1 && Mitsubishi_Data.Bit == 8) + { + Mitsubishi_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && duration >= 20000 && Mitsubishi_Data.HalfBit == 1 && Mitsubishi_Data.Bit == 16) + { + remoteCallback(IrProtocol.Mitsubishi, Mitsubishi_Data.Code, false); + Mitsubishi_Data.State = RemoteDetectionState.HeaderPulse; + Mitsubishi_Data.HalfBit = 0; + ignored = false; + } + + break; + #endregion Data + + } + + if (ignored && (Mitsubishi_Data.State != RemoteDetectionState.HeaderPulse)) + { + //Trace.WriteLine("ignored"); + Mitsubishi_Data.State = RemoteDetectionState.HeaderPulse; + } + } + } + static void DetectNEC(int[] timingData, RemoteCallback remoteCallback) + { + for (int i = 0; i < timingData.Length; i++) + { + int duration = Math.Abs(timingData[i]); + bool pulse = (timingData[i] > 0); + bool ignored = true; + + //Trace.WriteLine("NEC - {0}: {1}", Enum.GetName(typeof(RemoteDetectionState), NEC_Data.State), timingData[i]); + + switch (NEC_Data.State) + { + + #region HeaderPulse + case RemoteDetectionState.HeaderPulse: + if (pulse && IsBetween(duration, 8800, 9200)) + { + NEC_Data.State = RemoteDetectionState.HeaderSpace; + ignored = false; + } + + break; + #endregion HeaderPulse + + #region HeaderSpace + case RemoteDetectionState.HeaderSpace: + if (!pulse && IsBetween(duration, 4300, 4700)) + { + NEC_Data.State = RemoteDetectionState.Data; + NEC_Data.HalfBit = 0; + NEC_Data.Bit = 0; + NEC_Data.Code = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 2050, 2450)) // For Repeats + { + //Trace.Write("Repeat"); + + if (NEC_Data.Code != 0) + { + uint address = (NEC_Data.Code >> 24) & 0xFF; + uint command = (NEC_Data.Code >> 8) & 0xFF; + + uint code = (address << 8) + command; + + //Trace.WriteLine(" Code: {0}", code); + + remoteCallback(IrProtocol.NEC, code, false); + + NEC_Data.State = RemoteDetectionState.Leading; + ignored = false; + } + } + + break; + #endregion HeaderSpace + + #region Data + case RemoteDetectionState.Data: + if (pulse && IsBetween(duration, 350, 750)) + { + NEC_Data.HalfBit = 1; + ignored = false; + } + else if (!pulse && IsBetween(duration, 350, 650) && NEC_Data.HalfBit == 1) + { + NEC_Data.Code <<= 1; + NEC_Data.Bit++; + NEC_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && IsBetween(duration, 1200, 2800) && NEC_Data.HalfBit == 1) + { + NEC_Data.Code <<= 1; + NEC_Data.Code |= 1; + NEC_Data.Bit++; + NEC_Data.HalfBit = 0; + ignored = false; + } + else if (!pulse && duration >= 12000) + { + if (NEC_Data.Bit != 32) + { + if (NEC_Data.Code != 0) + { + //Trace.WriteLine("Invalid NEC: {0}bit, {1:X}", NEC_Data.Bit, NEC_Data.Code); + remoteCallback(IrProtocol.Unknown, NEC_Data.Code, false); + } + break; + } + + uint address = (NEC_Data.Code >> 24) & 0xFF; + uint notAddress = (NEC_Data.Code >> 16) & 0xFF; + + uint command = (NEC_Data.Code >> 8) & 0xFF; + uint notCommand = NEC_Data.Code & 0xFF; + + if ((address + notAddress == 0xFF) && (command + notCommand == 0xFF)) + { + uint code = (address << 8) + command; + remoteCallback(IrProtocol.NEC, code, true); + NEC_Data.State = RemoteDetectionState.HeaderPulse; + ignored = false; + } + else + { + //Trace.WriteLine("Invalid NEC: {0:X}", NEC_Data.Code); + remoteCallback(IrProtocol.Unknown, NEC_Data.Code, false); + } + } + + break; + #endregion Data + + #region Leading + case RemoteDetectionState.Leading: + if (pulse && IsBetween(duration, 400, 800)) + { + ignored = false; + } + else if (!pulse && duration > 10000) + { + ignored = false; + NEC_Data.State = RemoteDetectionState.HeaderPulse; + } + + break; + #endregion Leading + + } + + if (ignored && (NEC_Data.State != RemoteDetectionState.HeaderPulse)) + NEC_Data.State = RemoteDetectionState.HeaderPulse; + } + } + static void DetectNRC17(int[] timingData, RemoteCallback remoteCallback) + { + for (int i = 0; i < timingData.Length; i++) + { + int duration = Math.Abs(timingData[i]); + bool pulse = (timingData[i] > 0); + bool ignored = true; + + //Trace.WriteLine("NRC17 - {0}: {1}", Enum.GetName(typeof(RemoteDetectionState), NRC17_Data.State), timingData[i]); + + switch (NRC17_Data.State) + { + + #region HeaderPulse + case RemoteDetectionState.HeaderPulse: + + if (pulse && IsBetween(duration, 400, 650)) + { + NRC17_Data.State = RemoteDetectionState.HeaderSpace; + ignored = false; + } + break; + #endregion HeaderPulse + + #region HeaderSpace + case RemoteDetectionState.HeaderSpace: + + if (!pulse && + (IsBetween(duration, 2350, 2600) || // Normal battery + IsBetween(duration, 3350, 3600))) // Low battery + { + NRC17_Data.State = RemoteDetectionState.Data; + NRC17_Data.HalfBit = 0; + NRC17_Data.Bit = 17; + NRC17_Data.Header = 0; + NRC17_Data.Code = 0; + ignored = false; + } + break; + #endregion HeaderSpace + + #region Data + case RemoteDetectionState.Data: + if (NRC17_Data.HalfBit == 0) + { + if (pulse && IsBetween(duration, 300, 700)) + { + // Logic 1 + NRC17_Data.HalfBit = 1; + NRC17_Data.Code |= (uint)(1 << NRC17_Data.Bit--); + ignored = false; + } + else if (!pulse && IsBetween(duration, 300, 700)) + { + // Logic 0 + NRC17_Data.HalfBit = 1; + NRC17_Data.Bit--; + ignored = false; + } + } + else + { + if (!pulse && IsBetween(duration, 300, 700)) + { + NRC17_Data.HalfBit = 0; + ... [truncated message content] |