From d0e29cda579aa32bb958bbdf3cb6983d0d481d7e Mon Sep 17 00:00:00 2001 From: Jens True Date: Mon, 5 Jul 2021 19:54:27 +0200 Subject: [PATCH] Disable configuration menu not yet working. Queue sound signals (Currently grace period is same as on period --- Tidstagning/MainUI.Designer.cs | 33 ++++++++++---------- Tidstagning/Relay.cs | 55 +++++++++++++++++++++++++++------- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/Tidstagning/MainUI.Designer.cs b/Tidstagning/MainUI.Designer.cs index 16706ca..d3adb85 100644 --- a/Tidstagning/MainUI.Designer.cs +++ b/Tidstagning/MainUI.Designer.cs @@ -41,9 +41,7 @@ this.txtHeader = new System.Windows.Forms.TextBox(); this.grid = new System.Windows.Forms.DataGridView(); this.Complete = new System.Windows.Forms.DataGridViewButtonColumn(); - this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.DNF = new System.Windows.Forms.DataGridViewButtonColumn(); - this.entryBindingSource = new System.Windows.Forms.BindingSource(this.components); this.txtLog = new System.Windows.Forms.TableLayoutPanel(); this.lblClock = new System.Windows.Forms.Label(); this.flowLayoutPanelConfiguration = new System.Windows.Forms.FlowLayoutPanel(); @@ -53,12 +51,14 @@ this.label2 = new System.Windows.Forms.Label(); this.buttonConfig = new System.Windows.Forms.Button(); this.Clock = new System.Windows.Forms.Timer(this.components); + this.nameDataGridViewTextBoxColumn = new System.Windows.Forms.DataGridViewTextBoxColumn(); + this.entryBindingSource = new System.Windows.Forms.BindingSource(this.components); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.entryBindingSource)).BeginInit(); this.txtLog.SuspendLayout(); this.flowLayoutPanelConfiguration.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericSignalLength)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.entryBindingSource)).BeginInit(); this.SuspendLayout(); // // btnTest @@ -118,7 +118,7 @@ this.textStartProcedure.Name = "textStartProcedure"; this.textStartProcedure.ReadOnly = true; this.textStartProcedure.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this.textStartProcedure.Size = new System.Drawing.Size(258, 311); + this.textStartProcedure.Size = new System.Drawing.Size(258, 321); this.textStartProcedure.TabIndex = 10; this.textStartProcedure.WordWrap = false; // @@ -208,13 +208,6 @@ this.Complete.ReadOnly = true; this.Complete.Text = "Mål"; // - // nameDataGridViewTextBoxColumn - // - this.nameDataGridViewTextBoxColumn.DataPropertyName = "SailNumber"; - this.nameDataGridViewTextBoxColumn.HeaderText = "Sejlnummer"; - this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn"; - this.nameDataGridViewTextBoxColumn.ReadOnly = true; - // // DNF // this.DNF.HeaderText = "DNF"; @@ -223,10 +216,6 @@ this.DNF.Text = "Udgået"; this.DNF.UseColumnTextForButtonValue = true; // - // entryBindingSource - // - this.entryBindingSource.DataSource = typeof(Tidstagning.Entry); - // // txtLog // this.txtLog.ColumnCount = 3; @@ -344,6 +333,7 @@ this.buttonConfig.TabIndex = 29; this.buttonConfig.Text = "Konfiguration"; this.buttonConfig.UseVisualStyleBackColor = true; + this.buttonConfig.Visible = false; this.buttonConfig.Click += new System.EventHandler(this.buttonConfig_Click); // // Clock @@ -351,6 +341,17 @@ this.Clock.Enabled = true; this.Clock.Tick += new System.EventHandler(this.Clock_Tick); // + // nameDataGridViewTextBoxColumn + // + this.nameDataGridViewTextBoxColumn.DataPropertyName = "SailNumber"; + this.nameDataGridViewTextBoxColumn.HeaderText = "Sejlnummer"; + this.nameDataGridViewTextBoxColumn.Name = "nameDataGridViewTextBoxColumn"; + this.nameDataGridViewTextBoxColumn.ReadOnly = true; + // + // entryBindingSource + // + this.entryBindingSource.DataSource = typeof(Tidstagning.Entry); + // // MainUI // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -368,12 +369,12 @@ this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.entryBindingSource)).EndInit(); this.txtLog.ResumeLayout(false); this.txtLog.PerformLayout(); this.flowLayoutPanelConfiguration.ResumeLayout(false); this.flowLayoutPanelConfiguration.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericSignalLength)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.entryBindingSource)).EndInit(); this.ResumeLayout(false); } diff --git a/Tidstagning/Relay.cs b/Tidstagning/Relay.cs index d75ef28..0972fd2 100644 --- a/Tidstagning/Relay.cs +++ b/Tidstagning/Relay.cs @@ -9,7 +9,14 @@ namespace Tidstagning { SerialPort com; Timer cooldownTimer; - Queue signals = new Queue(); + + struct SignalSpec + { + public uint duration; + public bool output_on; + }; + Queue signals = new Queue(); + bool processing_queue = false; public Relay(string ComPort = null) { com = new SerialPort(); @@ -45,19 +52,47 @@ namespace Tidstagning public void Sound(uint time) { Debug.WriteLine("Requesting horn for: " + time.ToString() + "ms"); - signals.Enqueue(time); - On(); - if (signals.Count == 1) + SignalSpec on_signal; + on_signal.duration = time; + on_signal.output_on = true; + + signals.Enqueue(on_signal); + + SignalSpec gracePeriod; + gracePeriod.duration = time; + gracePeriod.output_on = false; + signals.Enqueue(gracePeriod); + if (processing_queue == false) { - cooldownTimer = new System.Threading.Timer(x => + Run(); + } + } + + private void Run() + { + if (signals.Count == 0) { - Off(); - signals.Dequeue(); - }, null, signals.Peek(), Timeout.Infinite); + processing_queue = false; } else - { - cooldownTimer.Change(signals.Peek(), Timeout.Infinite); + { + processing_queue = true; + SignalSpec signal = signals.Peek(); + + if(signal.output_on) + { + On(); + } + else + { + Off(); + } + + cooldownTimer = new System.Threading.Timer(x => + { + signals.Dequeue(); + Run(); + }, null, signal.duration, Timeout.Infinite); } }