diff --git a/data/EFMR/emulator.profile.json b/data/EFMR/emulator.profile.json index d4dfe5bd..3f30c06c 100644 --- a/data/EFMR/emulator.profile.json +++ b/data/EFMR/emulator.profile.json @@ -3,7 +3,7 @@ [ { "pin":1, - "state":"high" + "voltage":"high" } ] } diff --git a/src/SharpTools/SharpTerminal/EmulatorManager.cs b/src/SharpTools/SharpTerminal/EmulatorManager.cs new file mode 100644 index 00000000..82bb2a16 --- /dev/null +++ b/src/SharpTools/SharpTerminal/EmulatorManager.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Windows.Forms; + +namespace SharpTerminal +{ + class Emulator + { + + } + + internal static class EmulatorManager + { + static readonly Dictionary g_mapEmulators = []; + + public static void StartEmulator(string deviceName) + { + if (string.IsNullOrWhiteSpace(deviceName)) + { + throw new ArgumentException(nameof(deviceName)); + } + + if (g_mapEmulators.ContainsKey(deviceName)) + { + //nothing to do + return; + } + + var emulator = new Emulator(); + g_mapEmulators[deviceName] = emulator; + } + } + + internal class EmulatorManagerProxy: IControlProvider + { + Control IControlProvider.CreateControl(IConsole console) + { + return new Forms.EmulatorDashboardUserControl(); + } + } +} diff --git a/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.Designer.cs b/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.Designer.cs new file mode 100644 index 00000000..e197b1d3 --- /dev/null +++ b/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.Designer.cs @@ -0,0 +1,90 @@ +namespace SharpTerminal.Forms +{ + partial class EmulatorDashboardUserControl + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.Windows.Forms.Label m_lbTitle; + System.Windows.Forms.GroupBox groupBox1; + listView1 = new System.Windows.Forms.ListView(); + m_lbTitle = new System.Windows.Forms.Label(); + groupBox1 = new System.Windows.Forms.GroupBox(); + groupBox1.SuspendLayout(); + SuspendLayout(); + // + // m_lbTitle + // + m_lbTitle.AutoSize = true; + m_lbTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 0); + m_lbTitle.Location = new System.Drawing.Point(4, 0); + m_lbTitle.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + m_lbTitle.Name = "m_lbTitle"; + m_lbTitle.Size = new System.Drawing.Size(103, 24); + m_lbTitle.TabIndex = 2; + m_lbTitle.Text = "Emulators"; + // + // groupBox1 + // + groupBox1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + groupBox1.Controls.Add(listView1); + groupBox1.Location = new System.Drawing.Point(4, 27); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new System.Drawing.Size(466, 437); + groupBox1.TabIndex = 4; + groupBox1.TabStop = false; + groupBox1.Text = "Running"; + // + // listView1 + // + listView1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + listView1.FullRowSelect = true; + listView1.GridLines = true; + listView1.Location = new System.Drawing.Point(6, 22); + listView1.Name = "listView1"; + listView1.Size = new System.Drawing.Size(454, 409); + listView1.TabIndex = 3; + listView1.UseCompatibleStateImageBehavior = false; + listView1.View = System.Windows.Forms.View.Details; + // + // EmulatorDashboardUserControl + // + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + Controls.Add(groupBox1); + Controls.Add(m_lbTitle); + Name = "EmulatorDashboardUserControl"; + Size = new System.Drawing.Size(473, 467); + groupBox1.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private System.Windows.Forms.ListView listView1; + } +} diff --git a/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.cs b/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.cs new file mode 100644 index 00000000..b141bd64 --- /dev/null +++ b/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SharpTerminal.Forms +{ + public partial class EmulatorDashboardUserControl : UserControl + { + public EmulatorDashboardUserControl() + { + InitializeComponent(); + } + } +} diff --git a/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.resx b/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.resx new file mode 100644 index 00000000..f9300e77 --- /dev/null +++ b/src/SharpTools/SharpTerminal/Forms/EmulatorDashboardUserControl.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + False + + + False + + \ No newline at end of file diff --git a/src/SharpTools/SharpTerminal/Forms/ObjectsTreeViewUserControl.cs b/src/SharpTools/SharpTerminal/Forms/ObjectsTreeViewUserControl.cs index fa8c6028..79389446 100644 --- a/src/SharpTools/SharpTerminal/Forms/ObjectsTreeViewUserControl.cs +++ b/src/SharpTools/SharpTerminal/Forms/ObjectsTreeViewUserControl.cs @@ -207,6 +207,7 @@ private async void mRequestManager_ConnectionStateChanged(RequestManager sender, var emulatorNode = mTreeView.Nodes.Add("Emulator"); emulatorNode.Name = "Emulator"; + emulatorNode.Tag = new EmulatorManagerProxy(); if(mPreviousSelectedObject != null) { @@ -336,10 +337,10 @@ private void mTreeView_AfterSelect(object sender, TreeViewEventArgs e) control.Dispose(); } - if (e.Node.Tag is not RemoteObject remoteObject) + if (e.Node.Tag is not IControlProvider controlProvider) return; - var newControl = remoteObject.CreateControl(mConsole); + var newControl = controlProvider.CreateControl(mConsole); MainDisplayPanel.Controls.Add(newControl); newControl.Dock = DockStyle.Fill; diff --git a/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.Designer.cs b/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.Designer.cs index 0e37ccfb..09d052db 100644 --- a/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.Designer.cs +++ b/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.Designer.cs @@ -45,6 +45,8 @@ private void InitializeComponent() m_lbTitle = new System.Windows.Forms.Label(); m_btnRename = new System.Windows.Forms.Button(); m_btnClear = new System.Windows.Forms.Button(); + m_btnEmulate = new System.Windows.Forms.Button(); + m_btnBlock = new System.Windows.Forms.Button(); groupBox1 = new System.Windows.Forms.GroupBox(); groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)m_gridMain).BeginInit(); @@ -152,10 +154,35 @@ private void InitializeComponent() m_btnClear.UseVisualStyleBackColor = true; m_btnClear.Click += m_btnClear_Click; // + // m_btnEmulate + // + m_btnEmulate.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; + m_btnEmulate.Enabled = false; + m_btnEmulate.Location = new System.Drawing.Point(192, 323); + m_btnEmulate.Name = "m_btnEmulate"; + m_btnEmulate.Size = new System.Drawing.Size(75, 23); + m_btnEmulate.TabIndex = 5; + m_btnEmulate.Text = "Emulate"; + m_btnEmulate.UseVisualStyleBackColor = true; + m_btnEmulate.Click += m_btnEmulate_Click; + // + // m_btnBlock + // + m_btnBlock.Anchor = System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left; + m_btnBlock.Enabled = false; + m_btnBlock.Location = new System.Drawing.Point(273, 323); + m_btnBlock.Name = "m_btnBlock"; + m_btnBlock.Size = new System.Drawing.Size(75, 23); + m_btnBlock.TabIndex = 6; + m_btnBlock.Text = "Block"; + m_btnBlock.UseVisualStyleBackColor = true; + // // RemoteDeviceUserControl // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + Controls.Add(m_btnBlock); + Controls.Add(m_btnEmulate); Controls.Add(m_btnClear); Controls.Add(m_btnRename); Controls.Add(groupBox1); @@ -180,5 +207,7 @@ private void InitializeComponent() private System.Windows.Forms.DataGridViewTextBoxColumn Column5; private System.Windows.Forms.Button m_btnRename; private System.Windows.Forms.Button m_btnClear; + private System.Windows.Forms.Button m_btnEmulate; + private System.Windows.Forms.Button m_btnBlock; } } diff --git a/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.cs b/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.cs index 3c196ec3..83bf7b88 100644 --- a/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.cs +++ b/src/SharpTools/SharpTerminal/Forms/RemoteDeviceUserControl.cs @@ -36,6 +36,11 @@ public RemoteDeviceUserControl(IConsole console, RemoteDevice remoteDevice, Remo m_btnRename.Enabled = !mRemoteDevice.Registered; + this.RefreshButtonsState(); + + mRemoteDevice.StateChanged += RemoteDevice_StateChanged; + remoteDevice.PropertyChanged += RemoteDevice_PropertyChanged; + this.UpdateLabel(); if (pins == null) @@ -59,8 +64,17 @@ public RemoteDeviceUserControl(IConsole console, RemoteDevice remoteDevice, Remo row.DefaultCellStyle.BackColor = Color.Red; } } + } - remoteDevice.PropertyChanged += RemoteDevice_PropertyChanged; + private void RefreshButtonsState() + { + m_btnBlock.Enabled = mRemoteDevice.ConnectionStatus == RemoteDevice.Status.ONLINE; + m_btnEmulate.Enabled = mRemoteDevice.ConnectionStatus == RemoteDevice.Status.OFFLINE; + } + + private void RemoteDevice_StateChanged(RemoteObject sender, EventArgs args) + { + this.RefreshButtonsState(); } private void UpdateLabel() @@ -102,7 +116,7 @@ private async void m_btnRename_Click(object sender, EventArgs e) private async void m_btnClear_Click(object sender, EventArgs e) { - if(MessageBox.Show("Are you sure? This cannot be undone!!", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) + if (MessageBox.Show("Are you sure? This cannot be undone!!", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes) return; try @@ -113,8 +127,13 @@ private async void m_btnClear_Click(object sender, EventArgs e) } catch (Exception ex) { - MessageBox.Show("Error: " + ex.Message, "Error during operation", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Error: " + ex.Message, "Operation failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void m_btnEmulate_Click(object sender, EventArgs e) + { + EmulatorManager.StartEmulator(mRemoteDevice.Name); + } } } diff --git a/src/SharpTools/SharpTerminal/Forms/RemoteLocationUserControl.Designer.cs b/src/SharpTools/SharpTerminal/Forms/RemoteLocationUserControl.Designer.cs index ed8625b2..145464e3 100644 --- a/src/SharpTools/SharpTerminal/Forms/RemoteLocationUserControl.Designer.cs +++ b/src/SharpTools/SharpTerminal/Forms/RemoteLocationUserControl.Designer.cs @@ -40,6 +40,22 @@ private void InitializeComponent() columnHeader4 = new System.Windows.Forms.ColumnHeader(); SuspendLayout(); // + // columnHeader1 + // + columnHeader1.Text = "Address"; + // + // columnHeader2 + // + columnHeader2.Text = "Type"; + // + // columnHeader3 + // + columnHeader3.Text = "Name"; + // + // columnHeader4 + // + columnHeader4.Text = "Device"; + // // m_lbTitle // m_lbTitle.AutoSize = true; @@ -65,22 +81,6 @@ private void InitializeComponent() m_lvItems.UseCompatibleStateImageBehavior = false; m_lvItems.View = System.Windows.Forms.View.Details; // - // columnHeader1 - // - columnHeader1.Text = "Address"; - // - // columnHeader2 - // - columnHeader2.Text = "Type"; - // - // columnHeader3 - // - columnHeader3.Text = "Name"; - // - // columnHeader4 - // - columnHeader4.Text = "Device"; - // // RemoteLocationUserControl // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); diff --git a/src/SharpTools/SharpTerminal/IControlProvider.cs b/src/SharpTools/SharpTerminal/IControlProvider.cs new file mode 100644 index 00000000..47bde462 --- /dev/null +++ b/src/SharpTools/SharpTerminal/IControlProvider.cs @@ -0,0 +1,9 @@ +using System.Windows.Forms; + +namespace SharpTerminal +{ + internal interface IControlProvider + { + public Control CreateControl(IConsole console); + } +} diff --git a/src/SharpTools/SharpTerminal/RemoteObject.cs b/src/SharpTools/SharpTerminal/RemoteObject.cs index 996f216d..8f220547 100644 --- a/src/SharpTools/SharpTerminal/RemoteObject.cs +++ b/src/SharpTools/SharpTerminal/RemoteObject.cs @@ -11,7 +11,6 @@ using System; using System.Collections.Generic; using System.ComponentModel; -using System.IO; using System.Json; using System.Linq; using System.Runtime.Versioning; @@ -42,7 +41,7 @@ public interface IRemoteObjectAction } [SupportedOSPlatform("windows")] - public class RemoteObject: NotifyPropertyBase + public class RemoteObject: NotifyPropertyBase, IControlProvider { [Category("Object")] public string Name { get; } diff --git a/src/SharpTools/SharpTerminal/SharpTerminal.csproj.user b/src/SharpTools/SharpTerminal/SharpTerminal.csproj.user index 69f201a2..8d9101ef 100644 --- a/src/SharpTools/SharpTerminal/SharpTerminal.csproj.user +++ b/src/SharpTools/SharpTerminal/SharpTerminal.csproj.user @@ -11,6 +11,9 @@ UserControl + + UserControl + Form diff --git a/todo.txt b/todo.txt index 654eee31..344a904b 100644 --- a/todo.txt +++ b/todo.txt @@ -3,7 +3,7 @@ DCCLite - Better emulator: - Make sharpConsole able to start emulator as is - - Make sharpconsole start emulator using a existing device name + - Make sharpconsole start emulator using a existing device name (auto generate eprom?) - Show it on SharpConsole and remote connect to it. - Allow pin states to be set: - Set voltage level: LOW or HIGH