[chronojump] Added thread to force sensor
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Added thread to force sensor
- Date: Thu, 30 Mar 2017 17:04:49 +0000 (UTC)
commit 7c377e0e9146897101cfae486ef233f69a653794
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Mar 30 19:04:28 2017 +0200
Added thread to force sensor
glade/app1.glade | 25 -------------------
src/gui/chronojump.cs | 19 +++++++++++++-
src/gui/forceSensor.cs | 61 +++++++++++++++++++++++++++++++++++++++++------
3 files changed, 70 insertions(+), 35 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index aa4dc92..c508aa9 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -4027,24 +4027,6 @@ Carles</property>
<property name="can_focus">False</property>
<property name="top_padding">8</property>
<child>
- <widget class="GtkHBox" id="hbox78">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="spacing">20</property>
- <child>
- <widget class="GtkLabel" id="label255">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="xalign">0</property>
- <property name="label">Force sensor</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
<widget class="GtkHBox" id="hbox152">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -4098,13 +4080,6 @@ Carles</property>
</packing>
</child>
</widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
</child>
</widget>
<packing>
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 8958561..97e432c 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -3389,6 +3389,13 @@ public partial class ChronoJumpWindow
{
event_execute_ButtonCancel.Clicked -= new EventHandler(on_cancel_clicked);
+ if(forceThread.IsAlive)
+ {
+ LogB.Information("cancel clicked on force");
+ forceProcessCancel = true;
+ return;
+ }
+
LogB.Information("cancel clicked one");
//this will mark the test as cancelled
@@ -3418,6 +3425,13 @@ public partial class ChronoJumpWindow
//to avoid doble finish or cancel while finishing
hideButtons();
+ if(forceThread.IsAlive)
+ {
+ LogB.Information("finish clicked on force");
+ forceProcessFinish = true;
+ return;
+ }
+
LogB.Information("finish clicked one");
event_execute_ButtonFinish.Clicked -= new EventHandler(on_finish_clicked);
@@ -3468,13 +3482,14 @@ public partial class ChronoJumpWindow
void on_button_execute_test_clicked (object o, EventArgs args)
{
- if(radio_menuitem_mode_other.Active && radio_mode_force_sensor_small.Active) {
+ if(radio_menuitem_mode_other.Active && radio_mode_force_sensor_small.Active)
+ {
LogB.Debug("radio_mode_force_sensor");
/*
* force sensor is not FTDI
on_force_sensor_activate(canCaptureC);
*/
- force_sensor_capture();
+ forceSensorCapture();
return;
}
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 55eb65e..5315165 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -20,6 +20,7 @@
using System;
using System.IO.Ports;
+using System.Threading;
using Gtk;
using Glade;
using System.Text; //StringBuilder
@@ -32,6 +33,10 @@ public partial class ChronoJumpWindow
CjComboForceSensorPorts comboForceSensorPorts;
+ Thread forceThread;
+ static bool forceProcessFinish;
+ static bool forceProcessCancel;
+
private void on_button_force_sensor_ports_reload_clicked(object o, EventArgs args)
{
createComboForceSensorPorts(false);
@@ -55,25 +60,65 @@ public partial class ChronoJumpWindow
}
combo_force_sensor_ports.Sensitive = true;
}
-
- private void force_sensor_capture()
+
+ string forceSensorPortName;
+ private void forceSensorCapture()
{
- string portName = UtilGtk.ComboGetActive(combo_force_sensor_ports);
- if(portName == null || portName == "")
+ forceSensorPortName = UtilGtk.ComboGetActive(combo_force_sensor_ports);
+ if(forceSensorPortName == null || forceSensorPortName == "")
+ {
+ new DialogMessage(Constants.MessageTypes.WARNING, "Please, select port");
return;
+ }
- SerialPort port = new SerialPort(portName, 115200);
+ forceProcessFinish = false;
+ forceProcessCancel = false;
+
+ event_execute_ButtonFinish.Clicked -= new EventHandler(on_finish_clicked);
+ event_execute_ButtonFinish.Clicked += new EventHandler(on_finish_clicked);
+
+ event_execute_ButtonCancel.Clicked -= new EventHandler(on_cancel_clicked);
+ event_execute_ButtonCancel.Clicked += new EventHandler(on_cancel_clicked);
+
+ forceThread = new Thread(new ThreadStart(forceSensorCaptureDo));
+ GLib.Idle.Add (new GLib.IdleHandler (pulseGTKForceSensor));
+ }
+
+ //non GTK on this method
+ private void forceSensorCaptureDo()
+ {
+ SerialPort port = new SerialPort(forceSensorPortName, 115200);
port.Open();
- int count = 0;
string str;
- while(count < 1000)
+ while(! forceProcessFinish && ! forceProcessCancel)
{
str = port.ReadLine();
LogB.Information("Readed: " + str);
label_force_sensor_value.Text = str;
- count ++;
}
+
+ port.Close();
+ }
+
+ private bool pulseGTKForceSensor ()
+ {
+ if(! forceThread.IsAlive || forceProcessFinish || forceProcessCancel)
+ {
+ LogB.ThreadEnding();
+ //finishPulsebar(...);
+ LogB.ThreadEnded();
+ return false;
+ }
+ /*
+ updatePulsebar(...); //activity on pulsebar
+ update graph or vscale
+ */
+
+ Thread.Sleep (50);
+ LogB.Information(" ForceSensor:"+ forceThread.ThreadState.ToString());
+ return true;
}
+
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]