[chronojump] EncoderRhythm much improved. Working for c and ecS now.
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] EncoderRhythm much improved. Working for c and ecS now.
- Date: Fri, 26 Jan 2018 16:34:10 +0000 (UTC)
commit b283812f2c994f7ea9d436675a18a4d16f8aaf7a
Author: Xavier de Blas <xaviblas gmail com>
Date: Fri Jan 26 17:33:06 2018 +0100
EncoderRhythm much improved. Working for c and ecS now.
src/encoderCapture.cs | 40 ++++++++++++++++++++++++++++++++++++++--
src/encoderRhythm.cs | 46 ++++++++++++++++++++++++++++++++++------------
src/gui/encoder.cs | 32 +++++++++++++++++++++-----------
3 files changed, 93 insertions(+), 25 deletions(-)
---
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index bd67e8e..8645722 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -22,6 +22,7 @@ using System;
using System.IO;
using System.IO.Ports;
using System.Collections.Generic; //List<T>
+using Gtk;
public abstract class EncoderCapture
{
@@ -39,6 +40,12 @@ public abstract class EncoderCapture
public int EncoderCapturePointsCaptured;
public int EncoderCapturePointsPainted;
+ //encoderRhythm stuff
+ private bool useRhythm;
+ public int RhythmNRep; //used to know rest between clusters
+ public bool RhythmEcconUp;
+ private Gtk.Button fakeButtonRhythm;
+
// ---- protected stuff ----
protected int widthG;
protected int heightG;
@@ -111,7 +118,9 @@ public abstract class EncoderCapture
//if cont (continuous mode), then will not end when too much time passed before start
- public void InitGlobal (int widthG, int heightG, int time, int timeEnd, bool cont, string eccon,
string port, bool capturingInertialBG, bool showOnlyBars, bool simulated)
+ public void InitGlobal (int widthG, int heightG, int time, int timeEnd,
+ bool cont, string eccon, string port, bool capturingInertialBG, bool showOnlyBars,
+ bool simulated, bool useRhythm)
{
this.widthG = widthG;
this.heightG = heightG;
@@ -120,6 +129,10 @@ public abstract class EncoderCapture
this.capturingInertialBG = capturingInertialBG;
this.showOnlyBars = showOnlyBars;
this.simulated = simulated;
+ this.useRhythm = useRhythm;
+
+ if(useRhythm)
+ fakeButtonRhythm = new Gtk.Button();
//---- a) open port -----
if(simulated)
@@ -146,6 +159,9 @@ public abstract class EncoderCapture
recordingTime = time * 1000;
recordedTimeCont = 1; //not 0 to not have divide by zero problems
+ RhythmNRep = 0;
+ RhythmEcconUp = true;
+
encoderReaded = new List<int>();
encoderReadedInertialDisc = new List<int>();
@@ -539,7 +555,9 @@ public abstract class EncoderCapture
*/
- if( shouldSendCurve() )
+ //store in a boolean to not call shouldSendCurve() two times
because it changes some variables
+ bool shouldSendCurveBool = shouldSendCurve();
+ if(shouldSendCurveBool)
{
//if compujump, wakeup screen if it's off
//do it on the first repetition because it will not
be sleeping on the rest of repetitions
@@ -559,6 +577,19 @@ public abstract class EncoderCapture
lastDirectionStoredIsUp = ecc.up;
}
+
+ /*
+ * manage encoderRhythm stuff
+ * also on "c" send info if we ended ecc phase
+ */
+ if( useRhythm && (shouldSendCurveBool || (eccon == "c" && !
ecc.up)) )
+ {
+ LogB.Information("SSC: " + ecc.up.ToString());
+ if( (eccon == "c" && ecc.up) || (eccon != "c" && !
ecc.up))
+ RhythmNRep ++;
+ RhythmEcconUp = ecc.up;
+ fakeButtonRhythm.Click();
+ }
}
//on inertial is different
@@ -848,6 +879,11 @@ public abstract class EncoderCapture
public void Finish() {
finish = true;
}
+
+ public Button FakeButtonRhythm
+ {
+ get { return fakeButtonRhythm; }
+ }
}
diff --git a/src/encoderRhythm.cs b/src/encoderRhythm.cs
index e493e9b..587b1c6 100644
--- a/src/encoderRhythm.cs
+++ b/src/encoderRhythm.cs
@@ -37,8 +37,8 @@ public class EncoderRhythm
Active = false;
//default values
- EccSeconds = 0.5;
- ConSeconds = 0.5;
+ EccSeconds = 1;
+ ConSeconds = 1;
RestRepsSeconds = 0;
RepsCluster = 1; //1 is default, minimum value and means "no use clusters"
@@ -95,11 +95,15 @@ public class EncoderRhythmExecute
private DateTime lastRepetitionDT;
private EncoderRhythm encoderRhythm;
private int nreps;
+ private bool lastIsUp;
private bool restClusterTimeEndedFlag;
private double fractionRepetition;
private double fractionRest;
+ //true is for con or ecc-con (gravitatory, always end on "con"), false is for con-ecc (inertial)
+ private bool eccon_ec = true;
+
//constructor
public EncoderRhythmExecute(EncoderRhythm encoderRhythm)
@@ -128,11 +132,13 @@ public class EncoderRhythmExecute
return (nreps % encoderRhythm.RepsCluster == 0);
}
- public void SetLastRepetitionDT()
+ public void ChangePhase(int nrep, bool up)
{
lastRepetitionDT = DateTime.Now;
- nreps ++;
restClusterTimeEndedFlag = false;
+
+ nreps = nrep;
+ lastIsUp = up;
}
private bool checkIfRestingBetweenClusters(double totalSeconds)
@@ -140,7 +146,12 @@ public class EncoderRhythmExecute
if(restClusterTimeEndedFlag)
return false;
- if(nreps > 0 && nreps % encoderRhythm.RepsCluster == 0)
+ /*
+ * We are resting when we done more than 0 repetitions, AND
+ * mod of repetitions by RepsCluster == 0 AND
+ * if repetition ends on c, whe have done c (or if it ends on e, we have done e)
+ */
+ if(nreps > 0 && nreps % encoderRhythm.RepsCluster == 0 && lastIsUp == eccon_ec)
{
if(totalSeconds < encoderRhythm.RestClustersSeconds)
return true;
@@ -169,7 +180,6 @@ public class EncoderRhythmExecute
calculateRepetitionFraction(totalSeconds);
}
- //reptition has an initial rest phase
private void calculateRepetitionFraction(double totalSeconds)
{
//first repetition in cluster will not have rest
@@ -177,7 +187,12 @@ public class EncoderRhythmExecute
if(encoderRhythm.UseClusters() && firstInCluster())
restRepsSeconds = 0;
- if(totalSeconds < restRepsSeconds)
+ /*
+ * if ( (we ended concentric and it's ecc-con ||
+ * we ended excentric and it's con-ecc) && totalSeconds < restRepsSeconds)
+ * then there's a rest between repetitions
+ */
+ if(lastIsUp == eccon_ec && totalSeconds < restRepsSeconds)
{
TextRepetition = "";
TextRest = "Resting " +
@@ -187,18 +202,25 @@ public class EncoderRhythmExecute
fractionRest = totalSeconds / restRepsSeconds;
return;
}
- else if((totalSeconds - restRepsSeconds) < encoderRhythm.EccSeconds)
+
+ /*
+ * if we ended con and repetition ends at con, then substract restRepsSeconds to totalSeconds
to calculate fraction
+ * als when we done ecc and repetition ends at ecc
+ */
+ if(restRepsSeconds > 0 && lastIsUp == eccon_ec)
+ totalSeconds -= restRepsSeconds;
+
+ if(lastIsUp)
{
TextRepetition = "Excentric";
TextRest = "";
- fractionRepetition = 1 - ((totalSeconds - restRepsSeconds) /
encoderRhythm.EccSeconds);
+ fractionRepetition = 1 - ((totalSeconds) / encoderRhythm.EccSeconds);
fractionRest = 0;
return;
- }
- else {
+ } else {
TextRepetition = "Concentric";
TextRest = "";
- fractionRepetition = (totalSeconds - (restRepsSeconds + encoderRhythm.EccSeconds)) /
encoderRhythm.ConSeconds;
+ fractionRepetition = (totalSeconds) / encoderRhythm.ConSeconds;
fractionRest = 0;
return;
}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 3baf1ce..8839cac 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -5288,7 +5288,8 @@ public partial class ChronoJumpWindow
portName,
(encoderConfigurationCurrent.has_inertia &&
eCaptureInertialBG != null),
configChronojump.EncoderCaptureShowOnlyBars,
- currentSession.Name == Constants.SessionSimulatedName &&
testsActive
+ currentSession.Name == Constants.SessionSimulatedName &&
testsActive,
+ (encoderRhythm.Active && !
encoderConfigurationCurrent.has_inertia) //rhythm only on gravitory now
);
if(encoderConfigurationCurrent.has_inertia && eCaptureInertialBG != null)
@@ -5312,10 +5313,16 @@ public partial class ChronoJumpWindow
{
reallyCutByTriggers = preferences.encoderCaptureCutByTriggers;
notebook_encoder_signal_comment_rhythm_and_triggers.Page = 2;
- } else if(encoderRhythm.Active)
+ } else if(encoderRhythm.Active && ! encoderConfigurationCurrent.has_inertia)
//rhythm only on gravitory now
{
notebook_encoder_signal_comment_rhythm_and_triggers.Page = 1;
image_encoder_rhythm_rest.Visible = encoderRhythm.UseRest();
+
+ if(encoderRhythm.Active)
+ {
+ eCapture.FakeButtonRhythm.Clicked -= new
EventHandler(on_encoder_rhythm_changed);
+ eCapture.FakeButtonRhythm.Clicked += new
EventHandler(on_encoder_rhythm_changed);
+ }
}
encoderRProcCapture.CutByTriggers = reallyCutByTriggers;
@@ -5336,7 +5343,8 @@ public partial class ChronoJumpWindow
chronopicRegister.ConnectedOfType(ChronopicRegisterPort.Types.ENCODER).Port,
false,
false,
- false
+ false,
+ false //encoderRhythm.Active
);
encoderRProcCapture.CutByTriggers = Preferences.TriggerTypes.NO_TRIGGERS;
//do not cutByTriggers on inertial, yet.
@@ -5795,11 +5803,6 @@ public partial class ChronoJumpWindow
if(needToRefreshTreeviewCapture)
{
- //TODO: is better to do this before when the curves was sent,
- //not when needToRefreshTreeviewCapture (because this is too later because
it's returning from R)
- encoderRhythmExecute.SetLastRepetitionDT();
- image_encoder_rhythm_alert.Visible = false;
-
//LogB.Error("HERE YES");
//LogB.Error(encoderCaptureStringR);
@@ -6030,7 +6033,8 @@ public partial class ChronoJumpWindow
{
encoder_pulsebar_rhythm_eccon.Fraction = 0;
label_encoder_rhythm_rest.Text = "";
- encoder_pulsebar_rhythm_eccon.Text = "Waiting 1st rep.";
+ image_encoder_rhythm_rest.Visible = false;
+ encoder_pulsebar_rhythm_eccon.Text = "Waiting 1st phase";
return;
}
@@ -6038,9 +6042,15 @@ public partial class ChronoJumpWindow
encoder_pulsebar_rhythm_eccon.Fraction = encoderRhythmExecute.FractionRepetition;
encoder_pulsebar_rhythm_eccon.Text = encoderRhythmExecute.TextRepetition;
label_encoder_rhythm_rest.Text = encoderRhythmExecute.TextRest;
+ image_encoder_rhythm_rest.Visible = encoderRhythmExecute.TextRest != "";
- if(encoderRhythmExecute.FractionRepetition >= 1)
- image_encoder_rhythm_alert.Visible = true;
+ //TODO: this warning should appear also if value is 0, end of ecc phase
+ //image_encoder_rhythm_alert.Visible = (encoderRhythmExecute.FractionRepetition >= 1);
+ }
+ //no GTK here (just in case)
+ private void on_encoder_rhythm_changed(object o, EventArgs args)
+ {
+ encoderRhythmExecute.ChangePhase(eCapture.RhythmNRep, eCapture.RhythmEcconUp);
}
// -------------- drawingarea_encoder_analyze_instant
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]