[chronojump] chronopic detect and connect (on contacts) done. Tests pending.
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] chronopic detect and connect (on contacts) done. Tests pending.
- Date: Mon, 6 Apr 2015 10:28:15 +0000 (UTC)
commit b2dec6eb94c301846a9d07e8bcdb382d70474d4d
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Apr 6 12:25:28 2015 +0200
chronopic detect and connect (on contacts) done. Tests pending.
glade/chronojump.glade | 243 +++++++++++++++-----
po/POTFILES.in | 1 +
src/Makefile.am | 2 +-
src/chronopic.cs | 89 +++++++-
...cDialogAutoController.cs => chronopicDetect.cs} | 88 ++++++--
src/constants.cs | 3 +
src/gui/chronojump.cs | 130 +++++++++--
src/gui/chronopic.cs | 144 ++++--------
8 files changed, 500 insertions(+), 200 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 72889a1..77a37f4 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -1860,28 +1860,117 @@
</packing>
</child>
<child>
- <widget class="GtkViewport" id="viewport_chronopics">
+ <widget class="GtkHBox" id="hbox75">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="shadow_type">none</property>
<child>
- <widget class="GtkHBox" id="hbox_chronopics">
- <property name="visible">True</property>
- <property name="app_paintable">True</property>
- <property name="can_focus">True</property>
- <property name="spacing">8</property>
+ <widget class="GtkHBox" id="hbox_chronopic_detecting">
+ <property name="can_focus">False</property>
+ <property name="spacing">4</property>
<child>
- <widget class="GtkHBox" id="hbox91">
+ <widget class="GtkProgressBar"
id="progressbar_chronopic_detecting">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="spacing">4</property>
+ <property name="show_text">True</property>
+ <property name="text" translatable="yes"></property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkButton"
id="button_chronopic_detecting_cancel">
+ <property name="label">gtk-cancel</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </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_chronopic_detecting_info">
+ <property name="label">gtk-info</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkViewport" id="viewport_chronopics">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="shadow_type">none</property>
+ <child>
+ <widget class="GtkHBox" id="hbox_chronopics">
+ <property name="visible">True</property>
+ <property name="app_paintable">True</property>
+ <property name="can_focus">True</property>
+ <property name="spacing">8</property>
<child>
- <widget class="GtkLabel" id="label_chronopics">
+ <widget class="GtkHBox" id="hbox91">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="xpad">5</property>
- <property name="label"
translatable="yes">Chronopics</property>
- <property name="use_markup">True</property>
+ <property name="spacing">4</property>
+ <child>
+ <widget class="GtkLabel" id="label_chronopics">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="xpad">5</property>
+ <property name="label"
translatable="yes">Chronopics</property>
+ <property name="use_markup">True</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_connected_chronopics">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label"
translatable="yes">0</property>
+ <property name="use_markup">True</property>
+ <property name="ellipsize">end</property>
+ <property name="max_width_chars">25</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel"
id="label_chronopics_multitest">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </widget>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -1890,13 +1979,24 @@
</packing>
</child>
<child>
- <widget class="GtkLabel"
id="label_connected_chronopics">
+ <widget class="GtkButton"
id="button_activate_chronopics">
+ <property name="width_request">50</property>
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label"
translatable="yes">0</property>
- <property name="use_markup">True</property>
- <property name="ellipsize">end</property>
- <property name="max_width_chars">25</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="has_tooltip">True</property>
+ <property name="tooltip" translatable="yes">Connect
Chronopics</property>
+ <property name="relief">half</property>
+ <signal name="clicked"
handler="on_chronopic_contacts_clicked" swapped="no"/>
+ <child>
+ <widget class="GtkImage" id="image5">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-connect</property>
+ <property name="icon-size">2</property>
+ </widget>
+ </child>
</widget>
<packing>
<property name="expand">False</property>
@@ -1904,51 +2004,14 @@
<property name="position">1</property>
</packing>
</child>
- <child>
- <widget class="GtkLabel"
id="label_chronopics_multitest">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- </widget>
- <packing>
- <property name="expand">True</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">0</property>
- </packing>
- </child>
- <child>
- <widget class="GtkButton" id="button_activate_chronopics">
- <property name="width_request">50</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="receives_default">True</property>
- <property name="has_tooltip">True</property>
- <property name="tooltip" translatable="yes">Connect
Chronopics</property>
- <property name="relief">half</property>
- <signal name="clicked"
handler="on_chronopic_contacts_clicked" swapped="no"/>
- <child>
- <widget class="GtkImage" id="image5">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="stock">gtk-connect</property>
- <property name="icon-size">2</property>
- </widget>
- </child>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
</child>
</widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
</child>
</widget>
<packing>
@@ -6621,6 +6684,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
@@ -7492,6 +7558,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
<child>
@@ -8615,6 +8684,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="position">2</property>
@@ -9379,6 +9451,9 @@ Second Chronopic to platforms.</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="position">4</property>
@@ -13357,6 +13432,7 @@ on current Chronojump version.</property>
<property name="relief">none</property>
<property name="active">True</property>
<property name="draw_indicator">False</property>
+ <property
name="group">radio_mode_encoder_capture_small</property>
<signal name="toggled"
handler="on_radio_mode_encoder_analyze_small_toggled" swapped="no"/>
<child>
<widget class="GtkHBox" id="hbox135">
@@ -19996,6 +20072,9 @@ by you</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -20668,6 +20747,9 @@ by you</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -21832,6 +21914,9 @@ by you</property>
<placeholder/>
</child>
<child>
+ <placeholder/>
+ </child>
+ <child>
<widget class="GtkButton" id="button_video_url">
<property name="visible">True</property>
<property name="can_focus">True</property>
@@ -22053,6 +22138,9 @@ by you</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="expand">True</property>
@@ -32024,6 +32112,24 @@ options</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -34076,6 +34182,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -34786,6 +34895,9 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -37462,6 +37574,9 @@ show elevation as:</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
<packing>
<property name="left_attach">2</property>
@@ -37798,6 +37913,9 @@ show elevation as:</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
@@ -38149,6 +38267,9 @@ show elevation as:</property>
<child>
<placeholder/>
</child>
+ <child>
+ <placeholder/>
+ </child>
</widget>
</child>
</widget>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e00e7b6..4c52538 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -11,6 +11,7 @@ libcesarplayer/bacon-video-widget-gst-0.10.c
libcesarplayer/video-utils.c
src/chronojump.cs
src/Mini/chronojump_mini.cs
+src/chronopic.cs
src/constants.cs
src/encoder.cs
src/execute/event.cs
diff --git a/src/Makefile.am b/src/Makefile.am
index 46b3a00..e67f453 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -163,7 +163,7 @@ SOURCES = \
serverEvaluator.cs\
server.cs\
chronopic.cs\
- chronopicDialogAutoController.cs\
+ chronopicDetect.cs\
oldCodeNeedToDBConvert/person.cs\
oldCodeNeedToDBConvert/personSession.cs\
oldCodeNeedToDBConvert/sqlite/person.cs\
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 2afb4bf..fdb169d 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -24,6 +24,7 @@ using System.Threading;
using System.Diagnostics; //for detect OS
using System.IO; //for detect OS
+using Mono.Unix;
public class Chronopic {
@@ -529,7 +530,6 @@ public class ChronopicAutoCheck : ChronopicAuto
protected internal override string Communicate()
{
Found = ChronopicAutoDetect.ChronopicType.UNDETECTED;
-
sp.Write("J");
IsChronopicAuto = ( (char) sp.ReadByte() == 'J');
if (IsChronopicAuto)
@@ -715,3 +715,90 @@ public class ChronopicAutoDetect
Detected = "";
}
}
+
+public class ChronopicInit
+{
+ public bool CancelledByUser;
+
+ public ChronopicInit ()
+ {
+ }
+
+ //chronopic init should not touch gtk, for the threads
+ public bool Do (int currentCp, out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS,
string myPort, out string returnString, out bool success)
+ {
+ LogB.Information("starting connection with chronopic");
+
+ CancelledByUser = false;
+ success = true;
+
+ LogB.Information("chronopicInit-1");
+ LogB.Information(string.Format("chronopic port: {0}", myPort));
+ mySp = new SerialPort(myPort);
+ try {
+ mySp.Open();
+ LogB.Information("chronopicInit-2");
+ //-- Create chronopic object, for accessing chronopic
+ myCp = new Chronopic(mySp);
+
+ LogB.Information("chronopicInit-2.1");
+ myCp.Flush();
+
+ //if myCp has been cancelled
+ if(myCp.AbortFlush) {
+ LogB.Information("chronopicInit-2.2 cancelled");
+ success = false;
+ myCp = new Chronopic(); //fake constructor
+ } else {
+ LogB.Information("chronopicInit-3");
+ //on windows, this check make a crash
+ //i think the problem is: as we don't really know the Timeout on Windows
(.NET) and this variable is not defined on chronopic.cs
+ //the Read_platform comes too much soon (when cp is not totally created), and
this makes crash
+
+ //-- Obtener el estado inicial de la plataforma
+
+ bool ok=false;
+ LogB.Information("chronopicInit-4");
+ do {
+ LogB.Information("chronopicInit-5");
+ ok=myCp.Read_platform(out myPS);
+ LogB.Information("chronopicInit-6");
+ } while(! ok && ! CancelledByUser);
+ LogB.Information("chronopicInit-7");
+ if (!ok) {
+ //-- Si hay error terminar
+ LogB.Error(string.Format("Error: {0}", myCp.Error));
+ success = false;
+ }
+ }
+ } catch {
+ LogB.Error("chronopicInit-2.a catched");
+ success = false;
+ myCp = new Chronopic(); //fake constructor
+ }
+
+ bool connected = false;
+ returnString = "";
+ if(success) {
+ if(currentCp == 1)
+ connected = true;
+ returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on
port: {0}"), myPort);
+ }
+ else {
+ returnString = Catalog.GetString("Problems communicating to chronopic.");
+ if(currentCp == 1) {
+ returnString += " " + Catalog.GetString("Changed platform to 'Simulated'");
+ returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB
cable.");
+ }
+
+ //this will raise on_radiobutton_simulated_ativate and
+ //will put cpRunning to false, and simulated to true and cp.Close()
+ if(currentCp == 1) {
+ connected = false;
+ }
+ }
+
+ return connected;
+ }
+
+}
diff --git a/src/chronopicDialogAutoController.cs b/src/chronopicDetect.cs
similarity index 61%
rename from src/chronopicDialogAutoController.cs
rename to src/chronopicDetect.cs
index 99399b0..3350ecf 100644
--- a/src/chronopicDialogAutoController.cs
+++ b/src/chronopicDetect.cs
@@ -19,11 +19,12 @@
*/
-using System.Threading;
using System;
+using System.Threading;
+using System.IO.Ports;
using Gtk;
-public class ChronopicDialogAutoController
+public class ChronopicDetect
{
Thread thread;
@@ -32,13 +33,16 @@ public class ChronopicDialogAutoController
Gtk.Button button_info;
private static bool cancel;
+ private static bool needToChangeProgressbarText;
+
public bool Detecting; //used to block closing chronojump window if true
public string Detected; //readed from chronojump window
+ private ChronopicInit chronopicInit;
+ private bool connectedNormalChronopic;
public Gtk.Button FakeButtonDone;
-
- public ChronopicDialogAutoController (Gtk.ProgressBar progressbar, Gtk.Button button_cancel,
Gtk.Button button_info)
+ public ChronopicDetect (Gtk.ProgressBar progressbar, Gtk.Button button_cancel, Gtk.Button button_info)
{
this.progressbar = progressbar;
this.button_cancel = button_cancel;
@@ -52,20 +56,28 @@ public class ChronopicDialogAutoController
public void Detect(string mode)
{
- if(mode == "ENCODER") {
- LogB.Information("Detecting encoder... ");
+ //set variables
+ cancel = false;
+ Detected = "";
+ Detecting = true;
+ connectedNormalChronopic = false;
- //set variables
- cancel = false;
- Detected = "";
- Detecting = true;
+ progressbar.Text = Constants.ChronopicDetecting;
+ needToChangeProgressbarText = false;
- thread = new Thread(new ThreadStart(detectEncoder));
- GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));
- LogB.ThreadStart();
- thread.Start();
+ if(mode == "ENCODER") {
+ LogB.Information("Detecting encoder... ");
+ thread = new Thread(new ThreadStart(detectEncoder));
+ } else {
+ LogB.Information("Detecting normal Chronopic... ");
+ thread = new Thread(new ThreadStart(detectNormal));
}
+
+ GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));
+
+ LogB.ThreadStart();
+ thread.Start();
}
private void detectEncoder()
@@ -77,6 +89,38 @@ public class ChronopicDialogAutoController
Detected = cad.Detected;
}
+
+ private void detectNormal()
+ {
+ //simulateDriverProblem(); //uncomment to check cancel, info buttons behaviour
+
+ ChronopicAutoDetect cad =
+ new ChronopicAutoDetect(ChronopicAutoDetect.ChronopicType.NORMAL);
+
+ Detected = cad.Detected;
+
+ needToChangeProgressbarText = true;
+
+ connectNormal(Detected);
+ LogB.Debug("detectNormal ended");
+ }
+
+ private static Chronopic cpDoing;
+ private static SerialPort sp;
+ private static Chronopic.Plataforma platformState; //on (in platform), off (jumping), or unknow
+
+ private void connectNormal(string myPort)
+ {
+ LogB.Debug("connectNormal start");
+
+ chronopicInit = new ChronopicInit();
+
+ string message = "";
+ bool success = false;
+ connectedNormalChronopic = chronopicInit.Do(1, out cpDoing, out sp, platformState, myPort,
out message, out success);
+ LogB.Debug("connectNormal end");
+ }
+
private void simulateDriverProblem()
{
@@ -86,7 +130,7 @@ public class ChronopicDialogAutoController
while(crash) {
count ++;
if(count >= 40000) {
- LogB.Debug(" at detectEncoder\n ");
+ LogB.Debug(" at simulateDriverProblem\n ");
count = 0;
}
}
@@ -99,6 +143,8 @@ public class ChronopicDialogAutoController
if(cancel)
thread.Abort();
+
+ LogB.Information("Connected = " + connectedNormalChronopic.ToString());
FakeButtonDone.Click(); //send signal to gui/chronojump.cs to read Detected
Detecting = false;
@@ -109,6 +155,11 @@ public class ChronopicDialogAutoController
progressbar.Pulse();
+ if(needToChangeProgressbarText) {
+ progressbar.Text = Constants.ChronopicNeedTouch;
+ needToChangeProgressbarText = false;
+ }
+
Thread.Sleep (50);
LogB.Debug(thread.ThreadState.ToString());
return true;
@@ -132,8 +183,13 @@ public class ChronopicDialogAutoController
str += "\n\n" + Constants.FindDriverOthers;
new DialogMessage(Constants.MessageTypes.INFO, str);
+ }
+
+ //will be sent to chronopicWin
+ public Chronopic getCP() {
+ return cpDoing;
}
- ~ChronopicDialogAutoController() {}
+ ~ChronopicDetect() {}
}
diff --git a/src/constants.cs b/src/constants.cs
index 4e3b29b..0bc592e 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -490,6 +490,9 @@ public class Constants
public static string FoundUSBSerialPortsString = Catalog.GetString("USB-serial ports found:");
public static string NotFoundUSBSerialPortsString = Catalog.GetString("Not found any USB-serial
ports.") + " " + Catalog.GetString("Is Chronopic connected?");
+ public static string ChronopicDetecting = Catalog.GetString("Detecting ...");
+ public static string ChronopicNeedTouch = Catalog.GetString("Touch device.");
+
public static string FindDriverNeed = Catalog.GetString("Chronopic driver has to be installed.");
public static string FindDriverWindows = Catalog.GetString("If you have problems connecting with
Chronopic, ensure you have the <b>driver</b> installed at 'Windows Start Menu / Chronojump / Install
Chronopic driver'.");
public static string FindDriverOthers = Catalog.GetString("Check Chronojump software website.");
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 4f735c8..df3daa6 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -208,6 +208,10 @@ public partial class ChronoJumpWindow
[Widget] Gtk.Label label_connected_chronopics;
[Widget] Gtk.Label label_chronopics_multitest;
[Widget] Gtk.Image image_simulated_warning;
+ [Widget] Gtk.Box hbox_chronopic_detecting;
+ [Widget] Gtk.ProgressBar progressbar_chronopic_detecting;
+ [Widget] Gtk.Button button_chronopic_detecting_cancel;
+ [Widget] Gtk.Button button_chronopic_detecting_info;
[Widget] Gtk.Box hbox_chronopic_encoder_detecting;
[Widget] Gtk.ProgressBar progressbar_chronopic_encoder_detecting;
[Widget] Gtk.Button button_chronopic_encoder_detecting_cancel;
@@ -2349,7 +2353,7 @@ public partial class ChronoJumpWindow
args.RetVal = true;
//cannot terminate chronojump untile press 'cancel' if autodetect encoder is working
- if(cp_dialog_auto_c != null && cp_dialog_auto_c.Detecting == true)
+ if(cpDetect != null && cpDetect.Detecting == true)
return;
on_quit1_activate (new object(), new EventArgs ());
@@ -2882,46 +2886,58 @@ public partial class ChronoJumpWindow
//it's not visible at startup
session_menuitem.Visible = true;
menuitem_mode.Visible = true;
-
- autoDetectChronopic(m);
- change_multitest_firmware(m);
+ //do not perform autoDetect if we are on contacts and already detected
+ if(chronopicWin.Connected && m != menuitem_modes.POWER)
+ change_multitest_firmware(m);
+ else
+ autoDetectChronopic(m); //will perform change_multitest_firmware at the end (except
on POWER)
+
}
- ChronopicDialogAutoController cp_dialog_auto_c;
+ ChronopicDetect cpDetect;
private void autoDetectChronopic(menuitem_modes m)
{
+ main_menu.Sensitive = false;
+
if(m == menuitem_modes.POWER)
{
- main_menu.Sensitive = false;
hbox_chronopic_encoder_detecting.Visible = true;
viewport_chronopic_encoder.Visible = false;
- cp_dialog_auto_c = new ChronopicDialogAutoController(
+ cpDetect = new ChronopicDetect(
progressbar_chronopic_encoder_detecting,
button_chronopic_encoder_detecting_cancel,
button_chronopic_encoder_detecting_info
);
- cp_dialog_auto_c.Detect("ENCODER");
+ cpDetect.Detect("ENCODER");
- cp_dialog_auto_c.FakeButtonDone.Clicked += new
EventHandler(on_autoDetectChronopic_done);
+ cpDetect.FakeButtonDone.Clicked += new
EventHandler(on_autoDetectChronopic_encoder_done);
}
else {
- LogB.Information("Detecting normal Chronopic... ");
- //cad = new ChronopicAutoDetect(ChronopicAutoDetect.ChronopicType.NORMAL);
- LogB.Warning("Disabled until full chronopic connection is done on 4MHz Chronopics");
+ hbox_chronopic_detecting.Visible = true;
+ viewport_chronopics.Visible = false;
+
+ cpDetect = new ChronopicDetect(
+ progressbar_chronopic_detecting,
+ button_chronopic_detecting_cancel,
+ button_chronopic_detecting_info
+ );
+
+ cpDetect.Detect("NORMAL");
+
+ cpDetect.FakeButtonDone.Clicked += new
EventHandler(on_autoDetectChronopic_normal_done);
}
}
- private void on_autoDetectChronopic_done(object o, EventArgs args)
+ private void on_autoDetectChronopic_encoder_done(object o, EventArgs args)
{
- cp_dialog_auto_c.FakeButtonDone.Clicked -= new EventHandler(on_autoDetectChronopic_done);
+ cpDetect.FakeButtonDone.Clicked -= new EventHandler(on_autoDetectChronopic_encoder_done);
- main_menu.Sensitive = true;
hbox_chronopic_encoder_detecting.Visible = false;
viewport_chronopic_encoder.Visible = true;
-
- string str = cp_dialog_auto_c.Detected;
+
+ string str = cpDetect.Detected;
if(str != null && str != "") {
LogB.Information("Detected at port: " + str);
@@ -2931,6 +2947,48 @@ public partial class ChronoJumpWindow
LogB.Information("Not detected.");
createChronopicWindow(true, Util.GetDefaultPort());
}
+
+ on_autoDetectChronopic_all_done();
+ }
+ private void on_autoDetectChronopic_normal_done(object o, EventArgs args)
+ {
+ cpDetect.FakeButtonDone.Clicked -= new EventHandler(on_autoDetectChronopic_normal_done);
+
+ hbox_chronopic_detecting.Visible = false;
+ viewport_chronopics.Visible = true;
+
+ string str = cpDetect.Detected;
+
+ if(str != null && str != "") {
+ LogB.Information("Detected at port: " + str);
+
+ //set connected stuff for chronopicWin
+ chronopicWin.Connected = true;
+
+ //set cpd for chronopicWin
+ ChronopicPortData cpd = new ChronopicPortData(1, str, true);
+ ArrayList cpdArray = new ArrayList();
+ cpdArray.Add(cpd);
+
+ LogB.Debug("chronopicWin is null? " + (chronopicWin == null).ToString());
+ LogB.Debug("chronopicWin.CP is null? " + (chronopicWin.CP == null).ToString());
+
+ createChronopicWindow(cpDetect.getCP(), cpdArray, true, str);
+
+ LogB.Debug("chronopicWin.CP is null? " + (chronopicWin.CP == null).ToString());
+
+ change_multitest_firmware(getMenuItemMode());
+ }
+ else {
+ LogB.Information("Not detected.");
+ createChronopicWindow(true, Util.GetDefaultPort());
+ }
+
+ on_autoDetectChronopic_all_done();
+ }
+ private void on_autoDetectChronopic_all_done()
+ {
+ main_menu.Sensitive = true;
}
//change debounce time automatically on change menuitem mode (if multitest firmware)
@@ -2941,8 +2999,6 @@ public partial class ChronoJumpWindow
if(! chronopicWin.Connected)
return;
- if(m == menuitem_modes.POWER)
- return;
//http://www.raspberrypi.org/forums/viewtopic.php?f=66&t=88415
//https://bugzilla.xamarin.com/show_bug.cgi?id=15514
@@ -2955,6 +3011,15 @@ public partial class ChronoJumpWindow
}
}
+ LogB.Information("change_multitest_firmware 1");
+
+ LogB.Debug("chronopicWin is null? " + (chronopicWin == null).ToString());
+
+ int cps = chronopicWin.NumConnected();
+ LogB.Debug("cps: " + cps.ToString());
+
+ LogB.Debug("chronopicWin.Connected? " + chronopicWin.Connected.ToString());
+
Chronopic.Plataforma ps;
bool ok = (chronopicWin.CP).Read_platform(out ps);
if(!ok) {
@@ -2965,16 +3030,20 @@ public partial class ChronoJumpWindow
}
+ LogB.Information("change_multitest_firmware 2");
ChronopicAuto ca;
try {
ca = new ChronopicAutoCheck();
string chronopicVersion = ca.Read(chronopicWin.SP);
+ LogB.Debug("version: " + chronopicVersion);
} catch {
LogB.Information("Could not read from Chronopic");
return;
}
+ LogB.Information("change_multitest_firmware 3");
if(ca.IsChronopicAuto) {
+ LogB.Information("change_multitest_firmware 3 a");
try {
int debounceChange = 50;
if(m == menuitem_modes.RUNS)
@@ -4537,21 +4606,31 @@ public partial class ChronoJumpWindow
//encoderPort is usually "" and will be Util.GetDefaultPort
//but, since 1.5.1 when selecting encoder option from main menu,
//then encoderPort will be found and send here
- private void createChronopicWindow(bool recreate, string encoderPort) {
+
+ //normal call
+ private void createChronopicWindow(bool recreate, string encoderPort)
+ {
ArrayList cpd = new ArrayList();
for(int i=1; i<=4;i++) {
ChronopicPortData a = new ChronopicPortData(i,"",false);
cpd.Add(a);
}
-
+ createChronopicWindow(null, cpd, recreate, encoderPort);
+ }
+ //called directly on autodetect (detected cp and cpd is send)
+ private void createChronopicWindow(Chronopic cp, ArrayList cpd, bool recreate, string encoderPort)
+ {
if(encoderPort == "")
encoderPort = Util.GetDefaultPort();
- chronopicWin = ChronopicWindow.Create(cpd, encoderPort, recreate, preferences.volumeOn);
+ chronopicWin = ChronopicWindow.Create(cp, cpd, encoderPort, recreate, preferences.volumeOn);
//chronopicWin.FakeButtonCancelled.Clicked += new EventHandler(on_chronopic_window_cancelled);
- if(notebook_sup.CurrentPage == 0)
- chronopicContactsLabels(0, recreate);
+ if(notebook_sup.CurrentPage == 0) {
+ int cps = chronopicWin.NumConnected();
+ LogB.Debug("cps: " + cps.ToString());
+ chronopicContactsLabels(cps, recreate);
+ }
else //(notebook_sup.CurrentPage == 1)
chronopicEncoderLabels(recreate);
@@ -4597,7 +4676,7 @@ public partial class ChronoJumpWindow
chronopicWin = ChronopicWindow.View(preferences.volumeOn);
}
*/
-
+
private void on_chronopic_window_contacts_connected_or_done (object o, EventArgs args) {
chronopicWin.FakeWindowDone.Clicked -= new
EventHandler(on_chronopic_window_contacts_connected_or_done);
int cps = chronopicWin.NumConnected();
@@ -4627,6 +4706,7 @@ public partial class ChronoJumpWindow
label_connected_chronopics.Text = text;
//label_connected_chronopics.UseMarkup = true;
+ LogB.Debug("cpwin connected: " + chronopicWin.Connected.ToString());
if(colorize)
UtilGtk.ChronopicColors(viewport_chronopics,
label_chronopics, label_connected_chronopics,
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index 1c7c4fd..9db0fbb 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -113,8 +113,8 @@ public class ChronopicWindow
string updateChronopicWinValuesMessage;
//Gtk.Button fakeButtonCancelled;
- [Widget] Gtk.Button fakeConnectionButton; //raised when chronopic detection ended
- [Widget] Gtk.Button fakeWindowDone; //raised when chronopic detection ended
+ [Widget] Gtk.Button fakeConnectionButton; //raised when chronopic connection ended
+ [Widget] Gtk.Button fakeWindowDone; //raised when chronopic connection ended
//[Widget] Gtk.Button fakeWindowReload; //raised when asked to reload
bool isWindows;
@@ -131,7 +131,6 @@ public class ChronopicWindow
bool connected;
bool volumeOn;
int currentCp; //1 to 4
- bool cancelledByUser;
//in order to cancel before close window
static bool connecting;
@@ -156,16 +155,24 @@ public class ChronopicWindow
States loggedState; //log of last state
public enum ChronojumpMode { JUMPORRUN, ENCODER, OTHER };
+
+ private ChronopicInit chronopicInit;
-
- public ChronopicWindow(ArrayList myCpd)
+ public ChronopicWindow(Chronopic cpDetected, ArrayList myCpd)
{
+ LogB.Debug("constructor");
+
Glade.XML gxml;
gxml = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", "chronopic_window",
"chronojump");
gxml.Autoconnect(this);
cpd = myCpd;
+ if(cpDetected != null) {
+ cp = cpDetected;
+ sp = new SerialPort( ((ChronopicPortData) cpd[0]).Port );
+ }
+
UtilGtk.IconWindow(chronopic_window);
if(UtilAll.IsWindows())
@@ -174,6 +181,8 @@ public class ChronopicWindow
isWindows = false;
setDefaultValues();
+
+ chronopicInit = new ChronopicInit();
//Pixbuf pixbuf = new Pixbuf (null, Util.GetImagePath(false) + "chronopic_128.png");
//chronopic_image.Pixbuf = pixbuf;
@@ -195,19 +204,30 @@ public class ChronopicWindow
*/
}
- //recreate is false the first time (on initialization of ChronoJumpWindow at gui/chronojump.cs)
- //after that is true. Usually is used to manage a disconnected chronopic or other ports problems
- //
- //port names come from gui/chronojump.cs to this method (myCpd)
+ /*
+ * recreate is false the first time (on initialization of ChronoJumpWindow at gui/chronojump.cs)
+ * after that is true. Usually is used to manage a disconnected chronopic or other ports problems
+ *
+ * port names come from gui/chronojump.cs to this method (myCpd)
+ */
+ //this is the normal call
static public ChronopicWindow Create (ArrayList myCpd, string myEncoderPort, bool recreate, bool
volumeOn)
{
+ return Create(null, myCpd, myEncoderPort, recreate, volumeOn);
+ }
+ //this is called on AutoDetect
+ static public ChronopicWindow Create (Chronopic cpDetected, ArrayList myCpd, string myEncoderPort,
bool recreate, bool volumeOn)
+ {
+ LogB.Debug("enter create");
if (ChronopicWindowBox != null && recreate) {
ChronopicWindowBox.chronopic_window.Hide();
}
if (ChronopicWindowBox == null || recreate) {
- ChronopicWindowBox = new ChronopicWindow (myCpd);
+ ChronopicWindowBox = new ChronopicWindow (cpDetected, myCpd);
}
+ LogB.Information("create cp is null? " + (ChronopicWindowBox.cp == null).ToString());
+
//don't show until View is called
//ChronopicWindowBox.chronopic_window.Show ();
@@ -224,9 +244,12 @@ public class ChronopicWindow
static public ChronopicWindow View (ChronojumpMode cmode, bool volumeOn)
{
if (ChronopicWindowBox == null) {
- ChronopicWindowBox = new ChronopicWindow (cpd);
+ ChronopicWindowBox = new ChronopicWindow (null, cpd);
}
+ LogB.Information("view cp is null? " + (ChronopicWindowBox.cp == null).ToString());
+
+
ChronopicWindowBox.volumeOn = volumeOn;
if(cmode == ChronojumpMode.JUMPORRUN || cmode == ChronojumpMode.OTHER) {
@@ -300,11 +323,15 @@ public class ChronopicWindow
button_connect_cp4.Sensitive = false;
connected = false;
+ foreach(ChronopicPortData a in cpd)
+ if(a.Connected)
+ connected = true;
+
image_cp1_yes.Hide();
image_cp2_yes.Hide();
image_cp3_yes.Hide();
image_cp4_yes.Hide();
-
+
//encoderPort = "";
//fakeButtonCancelled = new Gtk.Button();
}
@@ -605,80 +632,6 @@ public class ChronopicWindow
new HelpPorts();
}
- //chronopic init should not touch gtk, for the threads
- //private Chronopic chronopicInit (out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma
myPS, string myPort, out string returnString, out bool success)
- private void chronopicInit (out Chronopic myCp, out SerialPort mySp, Chronopic.Plataforma myPS,
string myPort, out string returnString, out bool success)
- {
- LogB.Information ( Catalog.GetString ("starting connection with chronopic") );
-
- success = true;
-
- LogB.Information("chronopicInit-1");
- LogB.Information(string.Format("chronopic port: {0}", myPort));
- mySp = new SerialPort(myPort);
- try {
- mySp.Open();
- LogB.Information("chronopicInit-2");
- //-- Create chronopic object, for accessing chronopic
- myCp = new Chronopic(mySp);
-
- LogB.Information("chronopicInit-2.1");
- myCp.Flush();
-
- //if myCp has been cancelled
- if(myCp.AbortFlush) {
- LogB.Information("chronopicInit-2.2 cancelled");
- success = false;
- myCp = new Chronopic(); //fake constructor
- } else {
- LogB.Information("chronopicInit-3");
- //on windows, this check make a crash
- //i think the problem is: as we don't really know the Timeout on Windows
(.NET) and this variable is not defined on chronopic.cs
- //the Read_platform comes too much soon (when cp is not totally created), and
this makes crash
-
- //-- Obtener el estado inicial de la plataforma
-
- bool ok=false;
- LogB.Information("chronopicInit-4");
- do {
- LogB.Information("chronopicInit-5");
- ok=myCp.Read_platform(out myPS);
- LogB.Information("chronopicInit-6");
- } while(! ok && ! cancelledByUser);
- LogB.Information("chronopicInit-7");
- if (!ok) {
- //-- Si hay error terminar
- LogB.Error(string.Format("Error: {0}", myCp.Error));
- success = false;
- }
- }
- } catch {
- LogB.Error("chronopicInit-2.a catched");
- success = false;
- myCp = new Chronopic(); //fake constructor
- }
-
- returnString = "";
- if(success) {
- if(currentCp == 1)
- connected = true;
- returnString = string.Format(Catalog.GetString("<b>Connected</b> to Chronopic on
port: {0}"), myPort);
- }
- if(! success) {
- returnString = Catalog.GetString("Problems communicating to chronopic.");
- if(currentCp == 1) {
- returnString += " " + Catalog.GetString("Changed platform to 'Simulated'");
- returnString += Catalog.GetString("\n\nWe recommend to remove and connect USB
cable.");
- }
-
- //this will raise on_radiobutton_simulated_ativate and
- //will put cpRunning to false, and simulated to true and cp.Close()
- if(currentCp == 1) {
- connected = false;
- }
- }
- }
-
private void on_check_multichronopic_show_clicked(object o, EventArgs args) {
table_multi_chronopic.Visible = check_multichronopic_show.Active;
}
@@ -783,10 +736,9 @@ public class ChronopicWindow
label_title.UseMarkup = true;
button_cancel.Sensitive = true;
- cancelledByUser = false;
fakeConnectionButton = new Gtk.Button();
- fakeConnectionButton.Clicked += new EventHandler(on_chronopic_detection_ended);
+ fakeConnectionButton.Clicked += new EventHandler(on_chronopic_connection_ended);
connecting = true;
needUpdateChronopicWin = false;
@@ -818,7 +770,7 @@ public class ChronopicWindow
if(currentCp == 1) {
myPort = ((ChronopicPortData) cpd[0]).Port;
cpDoing = cp;
- chronopicInit(out cpDoing, out sp, platformState, myPort, out message, out success);
+ connected = chronopicInit.Do(currentCp, out cpDoing, out sp, platformState, myPort,
out message, out success);
cp = cpDoing;
if(success) {
((ChronopicPortData) cpd[0]).Connected=true;
@@ -850,7 +802,7 @@ public class ChronopicWindow
else if(currentCp == 2) {
myPort = ((ChronopicPortData) cpd[1]).Port;
cpDoing = cp2;
- chronopicInit(out cpDoing, out sp2, platformState2, myPort, out message, out success);
+ connected = chronopicInit.Do(currentCp, out cpDoing, out sp2, platformState2, myPort,
out message, out success);
cp2 = cpDoing;
if(success) {
((ChronopicPortData) cpd[1]).Connected=true;
@@ -878,7 +830,7 @@ public class ChronopicWindow
else if(currentCp == 3) {
myPort = ((ChronopicPortData) cpd[2]).Port;
cpDoing = cp3;
- chronopicInit(out cpDoing, out sp3, platformState3, myPort, out message, out success);
+ connected = chronopicInit.Do(currentCp, out cpDoing, out sp3, platformState3, myPort,
out message, out success);
cp3 = cpDoing;
if(success) {
((ChronopicPortData) cpd[2]).Connected=true;
@@ -902,7 +854,7 @@ public class ChronopicWindow
else if(currentCp == 4) {
myPort = ((ChronopicPortData) cpd[3]).Port;
cpDoing = cp4;
- chronopicInit(out cpDoing, out sp4, platformState4, myPort, out message, out success);
+ connected = chronopicInit.Do(currentCp, out cpDoing, out sp4, platformState4, myPort,
out message, out success);
cp4 = cpDoing;
if(success) {
((ChronopicPortData) cpd[3]).Connected=true;
@@ -936,7 +888,7 @@ public class ChronopicWindow
needUpdateChronopicWin = true;
}
- private void on_chronopic_detection_ended(object o, EventArgs args) {
+ private void on_chronopic_connection_ended(object o, EventArgs args) {
updateChronopicWin(updateChronopicWinValuesState, updateChronopicWinValuesMessage);
}
@@ -948,15 +900,15 @@ public class ChronopicWindow
button_cancel.Sensitive = false;
cpDoing.AbortFlush = true;
- cancelledByUser = true;
+ chronopicInit.CancelledByUser = true;
- //kill the chronopicInit function that is waiting event
+ //kill the chronopicInit.Do function that is waiting event
//thread.Abort();
//http://stackoverflow.com/questions/2853072/thread-does-not-abort-on-application-closing
//LogB.Debug(thread.ThreadState.ToString());
//thread.IsBackground = true;
- //try to solve windows problems when a chronopic detection was cancelled
+ //try to solve windows problems when a chronopic connection was cancelled
//LogB.Debug(thread.ThreadState.ToString());
//thread.Join(1000);
//LogB.Debug(thread.ThreadState.ToString());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]