[chronojump] Force sensor webcam capture done!
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Force sensor webcam capture done!
- Date: Tue, 10 Sep 2019 11:47:39 +0000 (UTC)
commit 8609b9486c2dc9a2335a12ab8d6f9e21451d712b
Author: Xavier de Blas <xaviblas gmail com>
Date: Tue Sep 10 13:47:29 2019 +0200
Force sensor webcam capture done!
src/constants.cs | 2 +-
src/execute/event.cs | 2 --
src/forceSensor.cs | 10 ++++++++--
src/gui/chronojump.cs | 23 +++++++++++++++++------
src/gui/chronopic.cs | 2 +-
src/gui/forceSensor.cs | 42 +++++++++++++++++++++++++++++++-----------
src/gui/webcam.cs | 18 ++++++++++++------
src/sqlite/forceSensor.cs | 9 ++++++++-
8 files changed, 78 insertions(+), 30 deletions(-)
---
diff --git a/src/constants.cs b/src/constants.cs
index 06b0187d..dd168922 100644
--- a/src/constants.cs
+++ b/src/constants.cs
@@ -112,7 +112,7 @@ public class Constants
public const string SubtractionBetweenTests = "Subtraction between tests";
//tests types (dont' use character '-' will be used multimedia file names)
- public enum TestTypes { JUMP, JUMP_RJ, RUN, RUN_I, RT, PULSE, MULTICHRONOPIC, ENCODER }
+ public enum TestTypes { JUMP, JUMP_RJ, RUN, RUN_I, FORCESENSOR, RT, PULSE, MULTICHRONOPIC, ENCODER }
public static string JumpSimpleName = "Jump simple";
public static string JumpReactiveName = "Jump reactive";
public static string RunSimpleName = "Run simple";
diff --git a/src/execute/event.cs b/src/execute/event.cs
index cf988008..55b95da2 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -66,8 +66,6 @@ public class EventExecute
protected string feedbackMessage;
protected bool needShowFeedbackMessage;
- public bool WebcamStarted;
-
//instances with the info to create
public PrepareEventGraphJumpSimple PrepareEventGraphJumpSimpleObject;
public PrepareEventGraphJumpReactive PrepareEventGraphJumpReactiveObject;
diff --git a/src/forceSensor.cs b/src/forceSensor.cs
index 46dab2c3..2a182dc8 100644
--- a/src/forceSensor.cs
+++ b/src/forceSensor.cs
@@ -67,9 +67,9 @@ public class ForceSensor
this.exerciseName = exerciseName;
}
- public void InsertSQL(bool dbconOpened)
+ public int InsertSQL(bool dbconOpened)
{
- SqliteForceSensor.Insert(dbconOpened, toSQLInsertString());
+ return SqliteForceSensor.Insert(dbconOpened, toSQLInsertString());
}
private string toSQLInsertString()
@@ -145,6 +145,7 @@ public class ForceSensor
public int UniqueID
{
get { return uniqueID; }
+ set { uniqueID = value; }
}
public int ExerciseID
{
@@ -166,6 +167,11 @@ public class ForceSensor
get { return comments; }
set { comments = value; }
}
+ public string VideoURL
+ {
+ get { return videoURL; }
+ set { videoURL = value; }
+ }
public string ExerciseName
{
get { return exerciseName; }
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index ae32c7b2..e0907dfe 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -3501,7 +3501,7 @@ public partial class ChronoJumpWindow
hbox_capture_phases_time.Visible = (m != Constants.Menuitem_modes.FORCESENSOR && m !=
Constants.Menuitem_modes.RUNSENCODER);
if(! configChronojump.Compujump)
- showWebcamCaptureContactsControls (m != Constants.Menuitem_modes.FORCESENSOR && m !=
Constants.Menuitem_modes.RUNSENCODER);
+ showWebcamCaptureContactsControls (m != Constants.Menuitem_modes.RUNSENCODER);
force_sensor_menuitem.Visible = (m == Constants.Menuitem_modes.FORCESENSOR);
@@ -3901,7 +3901,7 @@ public partial class ChronoJumpWindow
on_force_sensor_activate(canCaptureC);
*/
- on_buttons_force_sensor_clicked(button_execute_test, new EventArgs ());
+ on_button_execute_test_acceptedPre_start_camera(false);
return;
}
if(current_menuitem_mode == Constants.Menuitem_modes.RUNSENCODER)
@@ -3960,25 +3960,36 @@ public partial class ChronoJumpWindow
return;
}
- on_button_execute_test_acceptedPre();
+ on_button_execute_test_acceptedPre_start_camera(true);
}
UtilGtk.DeviceColors(viewport_chronopics, true);
}
// camera stuff if needed
- private void on_button_execute_test_acceptedPre()
+ // true is chronopic
+ // false is arduino like force sensor
+ private void on_button_execute_test_acceptedPre_start_camera(bool chronopic)
{
button_video_play_this_test_sensitive (WebcamManage.GuiContactsEncoder.CONTACTS, false);
webcamManage = new WebcamManage();
if(! webcamStart (WebcamManage.GuiContactsEncoder.CONTACTS, 1))
{
- on_button_execute_test_accepted();
+ if(chronopic)
+ on_button_execute_test_accepted();
+ else
+ on_buttons_force_sensor_clicked(button_execute_test, new EventArgs ());
+
return;
}
bool waitUntilRecording = true;
if(! waitUntilRecording)
- on_button_execute_test_accepted();
+ {
+ if(chronopic)
+ on_button_execute_test_accepted();
+ else
+ on_buttons_force_sensor_clicked(button_execute_test, new EventArgs ());
+ }
}
void on_button_execute_test_accepted ()
diff --git a/src/gui/chronopic.cs b/src/gui/chronopic.cs
index 19871ade..45c91248 100644
--- a/src/gui/chronopic.cs
+++ b/src/gui/chronopic.cs
@@ -88,7 +88,7 @@ public partial class ChronoJumpWindow
return;
} else {
button_activate_chronopics.Show();
- on_button_execute_test_acceptedPre();
+ on_button_execute_test_acceptedPre_start_camera(true);
return;
}
}
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 2b506653..dbc09fe3 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -112,6 +112,9 @@ public partial class ChronoJumpWindow
private ForceSensor currentForceSensor;
private ForceSensorExercise currentForceSensorExercise;
+ DateTime forceSensorTimeStartCapture;
+
+ //non GTK on this method
/*
* arduinoCaptureStatus:
@@ -402,6 +405,8 @@ public partial class ChronoJumpWindow
button_execute_test.Sensitive = sensitive;
button_force_sensor_analyze_load.Sensitive = sensitive;
+ vbox_contacts_camera.Sensitive = sensitive;
+
//other gui buttons
main_menu.Sensitive = sensitive;
hbox_contacts_sup_capture_analyze_two_buttons.Sensitive = sensitive;
@@ -740,7 +745,6 @@ public partial class ChronoJumpWindow
false, getExerciseIDFromAnyCombo(combo_force_sensor_exercise,
forceSensorComboExercisesString, false), false)[0];
}
- //non GTK on this method
private void forceSensorCaptureDo()
{
lastChangedTime = 0;
@@ -767,7 +771,7 @@ public partial class ChronoJumpWindow
forceCaptureStartMark = true;
forceSensorTimeStart = DateTime.Now; //to have an active count of capture time
- DateTime forceSensorTimeStartCapture = forceSensorTimeStart; //to have same DateTime on
filename and on sql datetime
+ forceSensorTimeStartCapture = forceSensorTimeStart; //to have same DateTime on filename and
on sql datetime
capturingForce = arduinoCaptureStatus.CAPTURING;
string captureComment = getCaptureComment(); //includes "_" if it's no empty
@@ -897,15 +901,6 @@ public partial class ChronoJumpWindow
((IDisposable)writer).Dispose();
capturingForce = arduinoCaptureStatus.STOP;
- currentForceSensor = new ForceSensor(-1, currentPerson.UniqueID, currentSession.UniqueID,
- currentForceSensorExercise.UniqueID, getForceSensorCaptureOptions(),
- ForceSensor.AngleUndefined, getLaterality(false),
- Util.GetLastPartOfPath(fileName), //filename
- Util.MakeURLrelative(Util.GetForceSensorSessionDir(currentSession.UniqueID)),
//url
- UtilDate.ToFile(forceSensorTimeStartCapture), captureComment, "", //dateTime,
comment, videoURL
- currentForceSensorExercise.Name);
- currentForceSensor.InsertSQL(false);
-
if(forceProcessCancel || forceProcessError)
Util.FileDelete(fileName);
else {
@@ -940,6 +935,28 @@ LogB.Information(" re C ");
else
{
event_execute_label_message.Text = "Saved.";
+
+ currentForceSensor = new ForceSensor(-1, currentPerson.UniqueID,
currentSession.UniqueID,
+ currentForceSensorExercise.UniqueID,
getForceSensorCaptureOptions(),
+ ForceSensor.AngleUndefined, getLaterality(false),
+ Util.GetLastPartOfPath(lastForceSensorFile + ".csv"),
//filename
+
Util.MakeURLrelative(Util.GetForceSensorSessionDir(currentSession.UniqueID)), //url
+ UtilDate.ToFile(forceSensorTimeStartCapture),
getCaptureComment(), "", //dateTime, comment, videoURL
+ currentForceSensorExercise.Name);
+
+ currentForceSensor.UniqueID = currentForceSensor.InsertSQL(false);
+
+ //stop camera
+ if(webcamEnd (Constants.TestTypes.FORCESENSOR,
currentForceSensor.UniqueID))
+ {
+ //add the videoURL to SQL
+ currentForceSensor.VideoURL =
Util.GetVideoFileName(currentSession.UniqueID,
+ Constants.TestTypes.FORCESENSOR,
+ currentForceSensor.UniqueID);
+ SqliteForceSensor.Update(false, currentForceSensor);
+ label_video_feedback.Text = "";
+ }
+
Thread.Sleep (250); //Wait a bit to ensure is copied
fscPoints.InitRealWidthHeight();
@@ -963,6 +980,9 @@ LogB.Information(" re C ");
}
} else if(forceProcessCancel || forceProcessError)
{
+ //stop the camera (and do not save)
+ webcamEnd (Constants.TestTypes.FORCESENSOR, -1);
+
if(forceProcessCancel)
event_execute_label_message.Text = "Cancelled.";
else
diff --git a/src/gui/webcam.cs b/src/gui/webcam.cs
index 67eea509..01734af9 100644
--- a/src/gui/webcam.cs
+++ b/src/gui/webcam.cs
@@ -201,7 +201,10 @@ public partial class ChronoJumpWindow
label_video_feedback_text (WebcamManage.GuiContactsEncoder.CONTACTS,
Catalog.GetString("Recording ..."));
}
- on_button_execute_test_accepted ();
+ if(current_menuitem_mode == Constants.Menuitem_modes.FORCESENSOR)
+ on_buttons_force_sensor_clicked(button_execute_test, new EventArgs ());
+ else
+ on_button_execute_test_accepted ();
LogB.ThreadEnded();
return false;
@@ -303,11 +306,12 @@ public partial class ChronoJumpWindow
//can pass a -1 uniqueID if test is cancelled
- private void webcamEnd (Constants.TestTypes testType, int uniqueID)
+ //returns false if not ended (maybe because did not started)
+ private bool webcamEnd (Constants.TestTypes testType, int uniqueID)
{
- //on contacts tests, we have WebcamStarted. No need to stop camera because it is not recording
+ //on contacts tests, we have ReallyStarted. No need to stop camera because it is not recording
if(testType != Constants.TestTypes.ENCODER && ! webcamManage.ReallyStarted)
- return;
+ return false;
WebcamManage.GuiContactsEncoder guiContactsEncoder = WebcamManage.GuiContactsEncoder.CONTACTS;
if(testType == Constants.TestTypes.ENCODER)
@@ -321,14 +325,14 @@ public partial class ChronoJumpWindow
}
if(! preferences.videoOn || webcamManage == null)
- return;
+ return false;
Webcam.Result result = webcamManage.RecordEnd (1);
if(! result.success)
{
new DialogMessage(Constants.MessageTypes.WARNING, result.error);
- return;
+ return false;
}
webcamEndParams = new WebcamEndParams(1, currentSession.UniqueID, testType, uniqueID,
guiContactsEncoder);
@@ -356,6 +360,8 @@ public partial class ChronoJumpWindow
GLib.Timeout.Add(50, new GLib.TimeoutHandler(webcamEndDo));
}
}
+
+ return true; //really ended
}
private bool webcamEndDo()
diff --git a/src/sqlite/forceSensor.cs b/src/sqlite/forceSensor.cs
index 91dedb3b..64bf91f3 100644
--- a/src/sqlite/forceSensor.cs
+++ b/src/sqlite/forceSensor.cs
@@ -60,7 +60,7 @@ class SqliteForceSensor : Sqlite
dbcmd.ExecuteNonQuery();
}
- public static void Insert (bool dbconOpened, string insertString)
+ public static int Insert (bool dbconOpened, string insertString)
{
if(! dbconOpened)
Sqlite.Open();
@@ -71,8 +71,14 @@ class SqliteForceSensor : Sqlite
LogB.SQL(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery(); //TODO uncomment this again
+ string myString = @"select last_insert_rowid()";
+ dbcmd.CommandText = myString;
+ int myLast = Convert.ToInt32(dbcmd.ExecuteScalar()); // Need to type-cast since
`ExecuteScalar` returns an object.
+
if(! dbconOpened)
Sqlite.Close();
+
+ return myLast;
}
public static void Update (bool dbconOpened, ForceSensor fs)
@@ -85,6 +91,7 @@ class SqliteForceSensor : Sqlite
", captureOption = \"" + fs.CaptureOption.ToString() +
"\", laterality = \"" + fs.Laterality +
"\", comments = \"" + fs.Comments +
+ "\", videoURL = \"" + Util.MakeURLrelative(fs.VideoURL) +
"\" WHERE uniqueID = " + fs.UniqueID;
LogB.SQL(dbcmd.CommandText.ToString());
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]