[chronojump] Feature: detects if Chronopic is disconnected (only simple jumps yet)



commit 3af9a96223253a4029b41306b9fd85b7fd9bd2f5
Author: Xavier de Blas <xaviblas master gnome org>
Date:   Wed Jun 2 00:21:24 2010 +0800

    Feature: detects if Chronopic is disconnected (only simple jumps yet)

 src/chronopic.cs      |   14 ++++++++++++++
 src/execute/event.cs  |   15 ++++++++++++++-
 src/execute/jump.cs   |   31 ++++++++++++++++++++++++++++---
 src/gui/chronojump.cs |   20 +++++++++++++-------
 src/gui/chronopic.cs  |    9 ++++-----
 5 files changed, 73 insertions(+), 16 deletions(-)
---
diff --git a/src/chronopic.cs b/src/chronopic.cs
index f53a004..aba3113 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -154,6 +154,20 @@ public class Chronopic {
 		int n;
 		int count;
 		bool status;
+			
+Console.Write("o1");
+		if (sp.IsOpen) {
+			sp.Close();
+			try {
+				sp.Open();
+			} catch {
+				status=false;
+				plataforma = Plataforma.UNKNOW;
+				this.error=ErrorType.Timeout;
+				return status;
+			}
+		}
+Console.Write("o2");
 
 //Console.Write("h");
 		//-- Enviar la trama por el puerto serie
diff --git a/src/execute/event.cs b/src/execute/event.cs
index 5d053a4..0d79821 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -120,6 +120,9 @@ public class EventExecute
 	protected bool finish;
 	protected bool totallyFinished;
 	
+	//if chronopic is disconnected by user, port changes, ...
+	protected bool chronopicDisconnected;
+	
 	// multi Chronopic stuff
 	protected int chronopics; 
 	protected bool totallyFinishedMulti1;
@@ -164,6 +167,9 @@ public class EventExecute
 	{
 		Chronopic.Plataforma myPlatformState  = Chronopic.Plataforma.UNKNOW; //on (in platform), off (jumping), or unknow
 		bool ok = false;
+		int timeWait = 50; //wait 50ms between calls to Read_platform
+		int timeLimit = 1000;
+		int count = 0; 
 
 		do {
 			try {
@@ -171,7 +177,9 @@ public class EventExecute
 			} catch {
 				Log.WriteLine("Manage called after finishing constructor, do later");
 			}
-		} while (! ok);
+			Thread.Sleep(timeWait); //wait 50ms
+			count += timeWait;
+		} while (! ok && count < timeLimit);
 
 		return myPlatformState;
 	}
@@ -505,6 +513,11 @@ public class EventExecute
 		set { totallyFinished = value; }
 	}
 
+	public bool ChronopicDisconnected
+	{
+		get { return chronopicDisconnected; }
+	}
+
 	public Event EventDone {
 		get { return eventDone; }
 	}
diff --git a/src/execute/jump.cs b/src/execute/jump.cs
index 1a9a540..c5f9cb1 100644
--- a/src/execute/jump.cs
+++ b/src/execute/jump.cs
@@ -125,6 +125,9 @@ public class JumpExecute : EventExecute
 			//prepare jump for being cancelled if desired
 			cancel = false;
 			totallyCancelled = false;
+	
+			//boolean to know if chronopic has been disconnected	
+			chronopicDisconnected = false;
 
 			//in simulated mode, make the jump start just when we arrive to waitEvent at the first time
 			//mark now that we have leaved platform:
@@ -137,7 +140,7 @@ public class JumpExecute : EventExecute
 			GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));
 			thread.Start(); 
 		} 
-		else {
+		else if (platformState==Chronopic.Plataforma.OFF) {
 			ConfirmWindow confirmWin;		
 			confirmWin = ConfirmWindow.Show( 
 					Catalog.GetString("You are OUT, come inside and press the 'accept' button"), "", "");
@@ -147,9 +150,19 @@ public class JumpExecute : EventExecute
 			//we call again this function
 			confirmWin.Button_accept.Clicked += new EventHandler(callAgainManage);
 			
-			//if confirmWin.Button_cancel is pressed retuen
+			//if confirmWin.Button_cancel is pressed return
 			confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
 		}
+		else { //UNKNOW (Chronopic disconnected, port changed, ...)
+			chronopicDisconnected = true;
+			ErrorWindow errorWin;		
+			errorWin = ErrorWindow.Show( 
+					Catalog.GetString("Chronopic seems disconnected. Reconnect again on Chronopic Window."));
+
+			Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);
+
+			errorWin.Button_accept.Clicked += new EventHandler(cancel_event_before_start);
+		}
 	}
 
 	public override void ManageFall()
@@ -173,6 +186,8 @@ public class JumpExecute : EventExecute
 			cancel = false;
 			totallyCancelled = false;
 
+			//boolean to know if chronopic has been disconnected	
+			chronopicDisconnected = false;
 
 
 			//in simulated mode, make the jump start just when we arrive to waitEvent at the first time
@@ -185,7 +200,7 @@ public class JumpExecute : EventExecute
 			GLib.Idle.Add (new GLib.IdleHandler (PulseGTK));
 			thread.Start(); 
 		} 
-		else {
+		else if (platformState==Chronopic.Plataforma.OFF) {
 			ConfirmWindow confirmWin;		
 			confirmWin = ConfirmWindow.Show( 
 					Catalog.GetString("You are IN, please leave the platform, and press the 'accept' button"), "", "");
@@ -197,6 +212,16 @@ public class JumpExecute : EventExecute
 			//if confirmWin.Button_cancel is pressed return
 			confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
 		}
+		else { //UNKNOW (Chronopic disconnected, port changed, ...)
+			chronopicDisconnected = true;
+			ErrorWindow errorWin;		
+			errorWin = ErrorWindow.Show( 
+					Catalog.GetString("Chronopic seems disconnected. Reconnect again on Chronopic Window."));
+
+			Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);
+
+			errorWin.Button_accept.Clicked += new EventHandler(cancel_event_before_start);
+		}
 	}
 	
 	//for calling it again after a confirmWindow says that you have to be in or out the platform
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 16454e9..906ffe0 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -466,13 +466,7 @@ public class ChronoJumpWindow
 		
 		repetitiveConditionsWin = RepetitiveConditionsWindow.Create();
 
-		ArrayList cpd = new ArrayList();
-		for(int i=1; i<=4;i++) {
-			ChronopicPortData a = new ChronopicPortData(i,"",false);
-			cpd.Add(a);
-		}
-		chronopicWin = ChronopicWindow.Create(cpd);
-
+		createChronopicWindow(false);
 
 		//We have no session, mark some widgets as ".Sensitive = false"
 		sensitiveGuiNoSession();
@@ -504,6 +498,15 @@ public class ChronoJumpWindow
 	}
 */
 
+	private void createChronopicWindow(bool recreate) {
+		ArrayList cpd = new ArrayList();
+		for(int i=1; i<=4;i++) {
+			ChronopicPortData a = new ChronopicPortData(i,"",false);
+			cpd.Add(a);
+		}
+		chronopicWin = ChronopicWindow.Create(cpd, recreate);
+	}
+
 
 	private void putNonStandardIcons() {
 		Pixbuf pixbuf;
@@ -2910,6 +2913,9 @@ Console.WriteLine("X");
 		
 			//unhide buttons for delete last jump
 			sensitiveGuiYesEvent();
+		} else if( currentEventExecute.ChronopicDisconnected ) {
+			Log.WriteLine("DISCONNECTED gui/cj");
+			createChronopicWindow(true);
 		}
 		
 		//unhide buttons that allow jumping
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index f0e005b..3cb62ef 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -128,7 +128,7 @@ public class ChronopicWindow
 		gxml = Glade.XML.FromAssembly (Util.GetGladePath() + "chronojump.glade", "chronopic_window", null);
 		gxml.Autoconnect(this);
 
-		cpd=myCpd;
+		cpd = myCpd;
 			
 		UtilGtk.IconWindow(chronopic_window);
 
@@ -152,12 +152,11 @@ public class ChronopicWindow
 		*/
 	}
 	
-	static public ChronopicWindow Create (ArrayList myCpd)
+	//recreate is used when a Chronopic was disconnected
+	static public ChronopicWindow Create (ArrayList myCpd, bool recreate)
 	{
-		if (ChronopicWindowBox == null) {
+		if (ChronopicWindowBox == null || recreate) {
 			ChronopicWindowBox = new ChronopicWindow (myCpd);
-
-		//put an icon to window
 		}
 		
 		//don't show until View is called



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