[chronojump] Initial gui code for forceSensor



commit c159deb34aee96360ed5373f91fbc56e5c41b62e
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Mar 17 18:56:21 2017 +0100

    Initial gui code for forceSensor

 chronojump.csproj      |    1 +
 glade/app1.glade       |  230 +++++++++++++++++++++++++++++++++++++++++++++++-
 src/Makefile.am        |    1 +
 src/eventType.cs       |    2 +-
 src/gui/chronojump.cs  |   27 ++++++
 src/gui/cjCombo.cs     |   34 +++++++
 src/gui/forceSensor.cs |   79 +++++++++++++++++
 7 files changed, 372 insertions(+), 2 deletions(-)
---
diff --git a/chronojump.csproj b/chronojump.csproj
index 698b7bb..1faf122 100644
--- a/chronojump.csproj
+++ b/chronojump.csproj
@@ -1113,6 +1113,7 @@
     <Compile Include="src\encoderCaptureInertialBG.cs" />
     <Compile Include="src\gui\chronojumpIcons.cs" />
     <Compile Include="src\sprint.cs" />
+    <Compile Include="src\gui\forceSensor.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="src\" />
diff --git a/glade/app1.glade b/glade/app1.glade
index 13648f2..101398d 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -2857,6 +2857,53 @@ Carles</property>
                                                 <property name="position">2</property>
                                               </packing>
                                             </child>
+                                            <child>
+                                              <widget class="GtkRadioButton" 
id="radio_mode_force_sensor_small">
+                                                <property name="visible">True</property>
+                                                <property name="can_focus">True</property>
+                                                <property name="receives_default">False</property>
+                                                <property name="relief">none</property>
+                                                <property name="draw_indicator">False</property>
+                                                <property 
name="group">radio_mode_reaction_times_small</property>
+                                                <signal name="toggled" 
handler="on_radio_mode_force_sensor_small_toggled" swapped="no"/>
+                                                <child>
+                                                  <widget class="GtkHBox" id="hbox77">
+                                                    <property name="visible">True</property>
+                                                    <property name="can_focus">False</property>
+                                                    <property name="spacing">10</property>
+                                                    <child>
+                                                      <widget class="GtkImage" 
id="image_mode_force_sensor_small1">
+                                                        <property name="can_focus">False</property>
+                                                        <property name="stock">gtk-missing-image</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">0</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <widget class="GtkLabel" 
id="label_mode_force_sensor_small">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="label" translatable="yes">Force 
sensor</property>
+                                                        <property name="justify">center</property>
+                                                      </widget>
+                                                      <packing>
+                                                        <property name="expand">True</property>
+                                                        <property name="fill">True</property>
+                                                        <property name="position">1</property>
+                                                      </packing>
+                                                    </child>
+                                                  </widget>
+                                                </child>
+                                              </widget>
+                                              <packing>
+                                                <property name="expand">False</property>
+                                                <property name="fill">False</property>
+                                                <property name="position">3</property>
+                                              </packing>
+                                            </child>
                                           </widget>
                                           <packing>
                                             <property name="expand">False</property>
@@ -4084,6 +4131,108 @@ Carles</property>
                                                           </packing>
                                                         </child>
                                                         <child>
+                                                          <widget class="GtkAlignment" id="alignment9">
+                                                            <property name="visible">True</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>
+                                                            <property name="spacing">4</property>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label256">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">Serial port</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="hbox_combo_force_sensor_ports">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkButton" 
id="button_force_sensor_ports_reload">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">True</property>
+                                                            <property name="receives_default">True</property>
+                                                            <property name="has_tooltip">True</property>
+                                                            <signal name="clicked" 
handler="on_button_force_sensor_ports_reload_clicked" swapped="no"/>
+                                                            <child>
+                                                            <widget class="GtkImage" id="image4">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="stock">gtk-refresh</property>
+                                                            <property name="icon-size">1</property>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">True</property>
+                                                            <property name="position">2</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>
+                                                            <property name="position">7</property>
+                                                          </packing>
+                                                        </child>
+                                                        <child>
+                                                          <widget class="GtkLabel" id="label157">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">8</property>
+                                                          </widget>
+                                                          <packing>
+                                                            <property name="position">7</property>
+                                                            <property name="tab_fill">False</property>
+                                                            <property name="type">tab</property>
+                                                          </packing>
+                                                        </child>
+                                                        <child>
                                                           <placeholder/>
                                                         </child>
                                                         <child>
@@ -4093,7 +4242,7 @@ Carles</property>
                                                             <property name="label">sequence</property>
                                                           </widget>
                                                           <packing>
-                                                            <property name="position">7</property>
+                                                            <property name="position">8</property>
                                                             <property name="tab_fill">False</property>
                                                             <property name="type">tab</property>
                                                           </packing>
@@ -6528,6 +6677,36 @@ after time</property>
                                                             <property name="type">tab</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkAlignment" id="alignment26">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="top_padding">8</property>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label261">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="xalign">0</property>
+                                                            <property name="label">Force sensor</property>
+                                                            </widget>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="position">7</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label260">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">page 8</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="position">7</property>
+                                                            <property name="tab_fill">False</property>
+                                                            <property name="type">tab</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">True</property>
@@ -10688,6 +10867,52 @@ after time</property>
                                                             <property name="type">tab</property>
                                                             </packing>
                                                             </child>
+                                                            <child>
+                                                            <widget class="GtkVBox" id="vbox79">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="border_width">20</property>
+                                                            <property name="spacing">10</property>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label262">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</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="GtkLabel" 
id="label_force_sensor_value">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="expand">False</property>
+                                                            <property name="fill">False</property>
+                                                            <property name="position">1</property>
+                                                            </packing>
+                                                            </child>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="position">7</property>
+                                                            </packing>
+                                                            </child>
+                                                            <child>
+                                                            <widget class="GtkLabel" id="label263">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="label">Force sensors</property>
+                                                            </widget>
+                                                            <packing>
+                                                            <property name="position">7</property>
+                                                            <property name="tab_fill">False</property>
+                                                            <property name="type">tab</property>
+                                                            </packing>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="position">1</property>
@@ -19436,6 +19661,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/Makefile.am b/src/Makefile.am
index 1190e51..80c1b69 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,6 +21,7 @@ SOURCES = \
        gui/eventGraphConfigure.cs\
        gui/event.cs\
        gui/executeAuto.cs\
+       gui/forceSensor.cs\
        gui/guiTests.cs\
        gui/jump.cs\
        gui/jumpsProfile.cs\
diff --git a/src/eventType.cs b/src/eventType.cs
index 03491e8..84e7553 100644
--- a/src/eventType.cs
+++ b/src/eventType.cs
@@ -23,7 +23,7 @@ using System;
 public class EventType 
 {
        public enum Types {
-               JUMP, RUN, PULSE, REACTIONTIME, MULTICHRONOPIC
+               JUMP, RUN, PULSE, REACTIONTIME, MULTICHRONOPIC, FORCESENSOR
        }
 
        protected Types type; //jump, run, reactionTime, pulse
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index e628084..4692343 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -92,6 +92,8 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.RadioButton radio_mode_reaction_times_small;
        [Widget] Gtk.RadioButton radio_mode_pulses_small;
        [Widget] Gtk.RadioButton radio_mode_multi_chronopic_small;
+       [Widget] Gtk.RadioButton radio_mode_force_sensor_small;
+
        [Widget] Gtk.RadioButton radio_mode_encoder_capture_small;
        [Widget] Gtk.RadioButton radio_mode_encoder_analyze_small;
        [Widget] Gtk.Image image_mode_jumps_small;
@@ -492,6 +494,8 @@ public partial class ChronoJumpWindow
                                myType = currentPulseType;
                        else //if(radio_mode_multi_chronopic_small.Active)
                                myType = currentMultiChronopicType;
+                       //else //if(radio_mode_force_sensor_small.Active)
+                       //      myType = currentForceType;
                }
                        
                if(myType.Name == "DJa" && extra_window_jumps_check_dj_fall_calculate.Active)
@@ -790,6 +794,16 @@ public partial class ChronoJumpWindow
                        hbox_results_legend.Visible = false;
                }
        }
+
+       public void on_radio_mode_force_sensor_small_toggled (object obj, EventArgs args) {
+               if(radio_mode_force_sensor_small.Active)
+               {
+                       vbox_last_test_buttons.Sensitive = false;
+                       notebooks_change(7);
+                       //on_extra_window_force_sensor_test_changed(obj, args);
+                       hbox_results_legend.Visible = false;
+               }
+       }
        
        public void on_radio_mode_encoder_capture_small_toggled (object obj, EventArgs args) {
                if(radio_mode_encoder_capture_small.Active) 
@@ -3442,6 +3456,16 @@ public partial class ChronoJumpWindow
 
        void on_button_execute_test_clicked (object o, EventArgs args) 
        {
+               if(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();
+                       return;
+               }
+
                // stop capturing inertial on the background if we start capturing a contacts test
                if(encoderThreadBG != null && encoderThreadBG.IsAlive)
                {
@@ -4900,6 +4924,9 @@ LogB.Debug("X");
                                                                currentMultiChronopic.Cp4InStr, 
                                                                currentMultiChronopic.Cp4OutStr);
                                        break;
+                               case EventType.Types.FORCESENSOR:
+                                       LogB.Information("Cannot update of force sensor");
+                                       break;
                        }
                }
                catch {
diff --git a/src/gui/cjCombo.cs b/src/gui/cjCombo.cs
index f9dea58..bfee6d6 100644
--- a/src/gui/cjCombo.cs
+++ b/src/gui/cjCombo.cs
@@ -52,6 +52,19 @@ public class CjCombo
                UtilGtk.ComboUpdate(combo, namesToCombo, "");
                combo.Active = 0;
        }
+       //used when strings are not translatable, like port names
+       public void FillNoTranslate()
+       {
+               select();
+
+               string [] namesToCombo = new String [l_types.Count];
+               int i =0;
+               foreach(string type in l_types)
+                       namesToCombo[i++] = type;
+
+               UtilGtk.ComboUpdate(combo, namesToCombo, "");
+               combo.Active = 0;
+       }
        
        protected void package() 
        {
@@ -190,3 +203,24 @@ public class CjComboSelectRunsI : CjCombo
                l_types = (List<object>) SqliteRunIntervalType.SelectRunIntervalTypesNew("", false); 
//without allrunsname, not only name
        }
 }
+
+public class CjComboForceSensorPorts : CjCombo
+{
+       public CjComboForceSensorPorts(Gtk.ComboBox combo_force_sensor_ports, Gtk.HBox 
hbox_combo_force_sensor_ports)
+       {
+               this.combo = combo_force_sensor_ports;
+               this.hbox = hbox_combo_force_sensor_ports;
+
+               create();
+               FillNoTranslate();
+               package();
+       }
+
+       protected override void select()
+       {
+               l_types = new List<object>();
+               string [] strArray = ChronopicPorts.GetPorts();
+               foreach(string str in strArray)
+                       l_types.Add(str);
+       }
+}
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
new file mode 100644
index 0000000..55eb65e
--- /dev/null
+++ b/src/gui/forceSensor.cs
@@ -0,0 +1,79 @@
+/*
+ * This file is part of ChronoJump
+ *
+ * ChronoJump is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 2 of the License, or   
+ *    (at your option) any later version.
+ *    
+ * ChronoJump is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
+ *    GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * Copyright (C) 2017   Xavier de Blas <xaviblas gmail com> 
+ */
+
+using System;
+using System.IO.Ports;
+using Gtk;
+using Glade;
+using System.Text; //StringBuilder
+
+public partial class ChronoJumpWindow 
+{
+       [Widget] Gtk.HBox hbox_combo_force_sensor_ports;
+       [Widget] Gtk.ComboBox combo_force_sensor_ports;
+       [Widget] Gtk.Label label_force_sensor_value;
+       
+       CjComboForceSensorPorts comboForceSensorPorts;
+
+       private void on_button_force_sensor_ports_reload_clicked(object o, EventArgs args)
+       {
+               createComboForceSensorPorts(false);
+       }
+
+       private void createComboForceSensorPorts(bool create) 
+       {
+               if(comboForceSensorPorts == null)
+                       create = true;
+
+               if(create)
+               {
+                       //LogB.Information("CREATE");
+                       comboForceSensorPorts = new CjComboForceSensorPorts(combo_force_sensor_ports, 
hbox_combo_force_sensor_ports);
+                       combo_force_sensor_ports = comboForceSensorPorts.Combo;
+                       //combo_force_sensor_ports.Changed += new EventHandler 
(on_combo_force_sensor_ports_changed);
+               } else {
+                       //LogB.Information("NO CREATE");
+                       comboForceSensorPorts.FillNoTranslate();
+                       combo_force_sensor_ports = comboForceSensorPorts.Combo;
+               }
+               combo_force_sensor_ports.Sensitive = true;
+       }
+       
+       private void force_sensor_capture()
+       {
+               string portName = UtilGtk.ComboGetActive(combo_force_sensor_ports);
+               if(portName == null || portName == "")
+                       return;
+
+               SerialPort port = new SerialPort(portName, 115200);
+               port.Open();
+
+               int count = 0;
+               string str;
+               while(count < 1000)
+               {
+                       str = port.ReadLine();
+                       LogB.Information("Readed: " + str);
+                       label_force_sensor_value.Text = str;
+                       count ++;
+               }
+       }
+}
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]