From: <an...@us...> - 2007-12-12 06:23:24
|
Revision: 1147 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1147&view=rev Author: and-81 Date: 2007-12-11 22:23:22 -0800 (Tue, 11 Dec 2007) Log Message: ----------- Added Paths: ----------- trunk/plugins/IR Server Suite/Util Apps/IR File Tool/ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.Designer.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.resx trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IR File Tool.csproj trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IrCode.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IrDecoder.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/MceDetectionData.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/Program.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/Pronto.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/Properties/ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/Properties/AssemblyInfo.cs trunk/plugins/IR Server Suite/Util Apps/IR File Tool/RemoteDetectionData.cs trunk/plugins/IR Server Suite/Util Apps/SageSetup/ trunk/plugins/IR Server Suite/Util Apps/SageSetup/FormMain.Designer.cs trunk/plugins/IR Server Suite/Util Apps/SageSetup/FormMain.cs trunk/plugins/IR Server Suite/Util Apps/SageSetup/FormMain.resx trunk/plugins/IR Server Suite/Util Apps/SageSetup/Program.cs trunk/plugins/IR Server Suite/Util Apps/SageSetup/Properties/ trunk/plugins/IR Server Suite/Util Apps/SageSetup/Properties/AssemblyInfo.cs trunk/plugins/IR Server Suite/Util Apps/SageSetup/Sage Setup.csproj trunk/plugins/IR Server Suite/Util Apps/SageSetup/SageSetup.exe.manifest Removed Paths: ------------- trunk/plugins/IR Server Suite/Applications/IR File Tool/ trunk/plugins/IR Server Suite/Applications/SageSetup/ Added: trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.Designer.cs =================================================================== --- trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.Designer.cs (rev 0) +++ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.Designer.cs 2007-12-12 06:23:22 UTC (rev 1147) @@ -0,0 +1,237 @@ +namespace IrFileTool +{ + partial class FormMain + { + /// <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.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.buttonSetCarrier = new System.Windows.Forms.Button(); + this.checkBoxStoreBinary = new System.Windows.Forms.CheckBox(); + this.buttonAttemptDecode = new System.Windows.Forms.Button(); + this.textBoxCarrier = new System.Windows.Forms.TextBox(); + 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; + // + // 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); + // + // 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; + // + // 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(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; + } +} + Added: trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.cs =================================================================== --- trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.cs (rev 0) +++ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.cs 2007-12-12 06:23:22 UTC (rev 1147) @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +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() + { + if (String.IsNullOrEmpty(_fileName)) + this.Text = "IR File Tool"; + else + this.Text = "IR File Tool - " + _fileName; + + 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(); + _fileName = "New File.IR"; + + 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); + } + + _fileName = openFileDialog.FileName; + + 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); + + if (textBoxCarrier.Text.Equals("Unknown", StringComparison.OrdinalIgnoreCase)) + { + switch (codeType) + { + case IrProtocol.RC5: textBoxCarrier.Text = "36000"; break; + case IrProtocol.RC5X: textBoxCarrier.Text = "36000"; break; + case IrProtocol.NEC: textBoxCarrier.Text = "38000"; break; + + default: + return; + } + + _code.Carrier = int.Parse(textBoxCarrier.Text); + + RefreshForm(); + } + } + 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(); + } + + } + +} Added: trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.resx =================================================================== --- trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.resx (rev 0) +++ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/FormMain.resx 2007-12-12 06:23:22 UTC (rev 1147) @@ -0,0 +1,132 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <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 Added: trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IR File Tool.csproj =================================================================== --- trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IR File Tool.csproj (rev 0) +++ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IR File Tool.csproj 2007-12-12 06:23:22 UTC (rev 1147) @@ -0,0 +1,92 @@ +<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>{B5E711A2-E6D0-4BEA-B66B-7A8B0BCA6A4D}</ProjectGuid> + <OutputType>WinExe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>IRFileTool</RootNamespace> + <AssemblyName>IR File Tool</AssemblyName> + <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent> + <StartupObject>IrFileTool.Program</StartupObject> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + <UseVSHostingProcess>false</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> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> + <DebugSymbols>true</DebugSymbols> + <OutputPath>bin\x86\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <DebugType>full</DebugType> + <PlatformTarget>x86</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> + <OutputPath>bin\x86\Release\</OutputPath> + <DefineConstants> + </DefineConstants> + <Optimize>true</Optimize> + <DebugType>pdbonly</DebugType> + <PlatformTarget>x86</PlatformTarget> + <ErrorReport>prompt</ErrorReport> + <UseVSHostingProcess>false</UseVSHostingProcess> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Data" /> + <Reference Include="System.Deployment" /> + <Reference Include="System.Drawing" /> + <Reference Include="System.Windows.Forms" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="FormMain.cs"> + <SubType>Form</SubType> + </Compile> + <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"> + <SubType>Designer</SubType> + <DependentUpon>FormMain.cs</DependentUpon> + </EmbeddedResource> + </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> + --> +</Project> \ No newline at end of file Added: trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IrCode.cs =================================================================== --- trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IrCode.cs (rev 0) +++ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IrCode.cs 2007-12-12 06:23:22 UTC (rev 1147) @@ -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/Util Apps/IR File Tool/IrDecoder.cs =================================================================== --- trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IrDecoder.cs (rev 0) +++ trunk/plugins/IR Server Suite/Util Apps/IR File Tool/IrDecoder.cs 2007-12-12 06:23:22 UTC (rev 1147) @@ -0,0 +1,2074 @@ +using System; +using System.Collections.Generic; +#if TRACE +using System.Diagnostics; +#endif +using System.Text; + +namespace IrFileTool +{ + + #region Enumerations + + /// <summary> + /// Protocol of IR Code. + /// </summary> + enum IrProtocol + { + /// <summary> + /// No protocol. + /// </summary> + None, + + /// <summary> + /// Daewoo protocol. 38kHz carrier. + /// </summary> + Daewoo, + /// <summary> + /// ITT protocol (unsupported). + /// </summary> + ITT, + /// <summary> + /// JVC protocol. 38kHz carrier. + /// </summary> + JVC, + /// <summary> + /// Matsushita protocol. 56.8kHz carrier. + /// </summary> + Matsushita, + /// <summary> + /// Mitsubishi protocol. 40kHz carrier. + /// </summary> + Mitsubishi, + /// <summary> + /// NEC protocol. 38kHz carrier. + /// </summary> + NEC, + /// <summary> + /// Nokia NRC17 protocol. 38kHz carrier. + /// </summary> + NRC17, + /// <summary> + /// Panasonic protocol. 38kHz carrier. + /// </summary> + Panasonic, + /// <summary> + /// Philips RC5 protocol. 36kHz carrier. + /// </summary> + RC5, + /// <summary> + /// Philips RC5X protocol. 36kHz carrier. + /// </summary> + RC5X, + /// <summary> + /// Philips RC6 protocol (Mode 0). 36kHz carrier. + /// </summary> + RC6, + /// <summary> + /// Philips RC6 protocol (Mode 6A). 36kHz carrier. + /// </summary> + RC6A, + /// <summary> + /// Microsoft's protocol variation of Philips RC6. 36kHz carrier. + /// </summary> + RC6_MCE, + /// <summary> + /// Foxtel's protocol variation of Philips RC6. 36kHz carrier. + /// </summary> + RC6_Foxtel, + /// <summary> + /// RCA protocol. 56kHz carrier. + /// </summary> + RCA, + /// <summary> + /// Philips RC-MM protocol. This protocol cannot be reliably (if at all) decoded by the MCE device. 36kHz carrier. + /// </summary> + RCMM, + /// <summary> + /// RECS-80 protocol. 38kHz carrier. + /// </summary> + RECS80, + /// <summary> + /// Sharp protocol (unsupported). 38kHz carrier + /// </summary> + Sharp, + /// <summary> + /// Sony SIRC protocol. 40kHz carrier. + /// </summary> + SIRC, + /// <summary> + /// Toshiba protocol. 38kHz carrier. + /// </summary> + Toshiba, + /// <summary> + /// X-Sat protocol (unsupported). 38kHz carrier. + /// </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 PrefixRC6Foxtel = 0x000FCA93; + + 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(String.Format("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 HeaderS... [truncated message content] |