[chronojump] encoder auto -> cont (50%). Also on capture only max num of initial zeros is 1000
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] encoder auto -> cont (50%). Also on capture only max num of initial zeros is 1000
- Date: Mon, 11 Jul 2016 18:15:07 +0000 (UTC)
commit fe5b3e737ede109b9576302a833c9e417d976cec
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Jul 11 20:10:03 2016 +0200
encoder auto -> cont (50%). Also on capture only max num of initial zeros is 1000
glade/chronojump.glade | 6 +-
src/encoderCapture.cs | 129 ++++++++++++++++++++++++++++++++++--------------
src/gui/encoder.cs | 16 +++++--
3 files changed, 107 insertions(+), 44 deletions(-)
---
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 1044a8b..54d56e5 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -14056,8 +14056,8 @@ low ressistance</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
- <widget class="GtkCheckButton"
id="checkbutton_encoder_auto">
- <property name="label">Auto</property>
+ <widget class="GtkCheckButton"
id="checkbutton_encoder_cont">
+ <property name="label">Cont</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property
name="receives_default">False</property>
@@ -15607,7 +15607,7 @@ low ressistance</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property
name="receives_default">False</property>
- <property name="tooltip"
translatable="yes">Groupal / current set</property>
+ <property name="tooltip"
translatable="yes">Groupal / current session</property>
<property name="active">True</property>
<property name="draw_indicator">False</property>
<property
name="group">radio_encoder_analyze_individual_current_set</property>
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index 0b8c830..e8b1c7c 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -21,6 +21,7 @@
using System;
using System.IO;
using System.IO.Ports;
+using System.Collections.Generic; //List<T>
public abstract class EncoderCapture
{
@@ -32,23 +33,24 @@ public abstract class EncoderCapture
public int Countdown;
//stored to be realtime displayed
- public Gdk.Point [] EncoderCapturePoints;
- public Gdk.Point [] EncoderCapturePointsInertialDisc;
+ public List<Gdk.Point> EncoderCapturePoints;
+ public List<Gdk.Point> EncoderCapturePointsInertialDisc;
public int EncoderCapturePointsCaptured;
public int EncoderCapturePointsPainted;
// ---- protected stuff ----
protected int widthG;
protected int heightG;
- protected bool auto;
+ protected bool cont;
protected string eccon;
protected double realHeightG;
- protected int recordingTime;
+ protected int recordingTime; //on !cont, capture time is defined previously
+ protected int recordedTimeCont; //on cont, capture time is not defined, and this value has the actual
recorded time
protected int byteReaded;
- protected static int [] encoderReaded; //data coming from encoder and converted
- protected static int [] encoderReadedInertialDisc; //data coming from encoder and converted
+ protected static List<int> encoderReaded; //data coming from encoder and converted
+ protected static List<int> encoderReadedInertialDisc; //data coming from encoder and converted
/*
* sum: sum ob byteReaded, it's the vertical position
@@ -117,12 +119,12 @@ public abstract class EncoderCapture
return true;
}
- //if auto (automatic mode), then will not end when too much time passed before start
- public void InitGlobal (int widthG, int heightG, int time, int timeEnd, bool auto, string eccon,
string port)
+ //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)
{
this.widthG = widthG;
this.heightG = heightG;
- this.auto = auto;
+ this.cont = cont;
this.eccon = eccon;
//---- a) open port -----
@@ -143,10 +145,12 @@ public abstract class EncoderCapture
msCount = 0; //used for visual feedback of remaining time
recordingTime = time * 1000;
- encoderReaded = new int[recordingTime];
- encoderReadedInertialDisc = new int[recordingTime];
- EncoderCapturePoints = new Gdk.Point[recordingTime];
- EncoderCapturePointsInertialDisc = new Gdk.Point[recordingTime];
+ recordedTimeCont = 1; //not 0 to not have divide by zero problems
+
+ encoderReaded = new List<int>();
+ encoderReadedInertialDisc = new List<int>();
+ EncoderCapturePoints = new List<Gdk.Point>();
+ EncoderCapturePointsInertialDisc = new List<Gdk.Point>();
EncoderCapturePointsCaptured = 0;
EncoderCapturePointsPainted = 0; //-1 means delete screen
sum = 0;
@@ -179,7 +183,7 @@ public abstract class EncoderCapture
previousEnd = 0;
lastNonZero = 0;
- //this will be used to stop encoder automatically
+ //this will be used to stop encoder automatically (on !cont mode)
consecutiveZeros = -1;
consecutiveZerosMax = timeEnd * 1000;
@@ -222,6 +226,9 @@ public abstract class EncoderCapture
i = i+1;
if(i >= 0)
{
+ if(cont)
+ recordedTimeCont ++;
+
if(inertialCaptureDirectionInverted)
byteReaded *= -1;
@@ -240,7 +247,7 @@ public abstract class EncoderCapture
//when a curve has not been found and then there are 2*n seconds of inactivity
if(
(Ecca.curvesAccepted > 0 && consecutiveZeros >=
consecutiveZerosMax) ||
- (! auto && Ecca.curvesAccepted == 0 && consecutiveZeros >=
(2* consecutiveZerosMax)) )
+ (! cont && Ecca.curvesAccepted == 0 && consecutiveZeros >=
(2* consecutiveZerosMax)) )
{
finish = true;
LogB.Information("SHOULD FINISH");
@@ -248,13 +255,13 @@ public abstract class EncoderCapture
sumInertialDisc += byteReaded;
- encoderReadedInertialDisc[i] = byteReaded;
+ encoderReadedInertialDisc.Add(byteReaded);
if(inertialChangedConToEcc())
byteReaded *= -1;
sum += byteReaded;
- encoderReaded[i] = byteReaded;
+ encoderReaded.Add(byteReaded);
assignEncoderCapturePoints();
@@ -341,7 +348,7 @@ public abstract class EncoderCapture
//since 1.5.0 secundary thread is capturing and sending data to R
process
//while main thread is reading data coming from R and updating GUI
- LogB.Debug("curve stuff" + ecc.startFrame + ":" + ecc.endFrame + ":"
+ encoderReaded.Length);
+ LogB.Debug("curve stuff" + ecc.startFrame + ":" + ecc.endFrame + ":"
+ encoderReaded.Count);
if(ecc.endFrame - ecc.startFrame > 0 )
{
double [] curve = new double[ecc.endFrame - ecc.startFrame];
@@ -417,7 +424,7 @@ public abstract class EncoderCapture
}
}
- } while (i < (recordingTime -1) && ! cancel && ! finish);
+ } while ( (cont || i < (recordingTime -1)) && ! cancel && ! finish);
LogB.Debug("runEncoderCaptureCsharp main bucle end");
@@ -474,10 +481,14 @@ public abstract class EncoderCapture
//on inertial also assigns to EncoderCapturePointsInertialDisc
protected virtual void assignEncoderCapturePoints()
{
- EncoderCapturePoints[i] = new Gdk.Point(
- Convert.ToInt32(widthG * i / recordingTime),
+ int xWidth = recordingTime;
+ if(cont)
+ xWidth = recordedTimeCont;
+
+ EncoderCapturePoints.Add(new Gdk.Point(
+ Convert.ToInt32(widthG * i / xWidth),
Convert.ToInt32( (heightG/2) - ( sum * heightG / realHeightG) )
- );
+ ));
}
//on inertial also uses to EncoderCapturePointsInertialDisc
@@ -489,11 +500,15 @@ public abstract class EncoderCapture
{
realHeightG *= 2;
+ int xWidth = recordingTime;
+ if(cont)
+ xWidth = recordedTimeCont;
+
double sum2=0;
for(int j=0; j <= i; j ++) {
sum2 += encoderReaded[j];
EncoderCapturePoints[j] = new Gdk.Point(
- Convert.ToInt32(widthG * j / recordingTime),
+ Convert.ToInt32(widthG * j / xWidth),
Convert.ToInt32( (heightG/2) - ( sum2 * heightG /
realHeightG) )
);
}
@@ -537,14 +552,39 @@ public abstract class EncoderCapture
directionCompleted = directionNow;
}
+ protected List<int> trimInitialZeros(List<int> l)
+ {
+ int count = 0; //position of the first non-zero value
+
+ //1. find when there's the first non-zero
+ foreach(int k in l) {
+ if(k != 0)
+ break;
+
+ count ++;
+ }
+
+ //number of allowed milliseconds with zero values at start (will be cut by reduceCurveBySpeed)
+ int allowedZeroMSAtStart = 1000;
+
+ if(count > allowedZeroMSAtStart)
+ {
+ l.RemoveRange(0, count-allowedZeroMSAtStart);
+ } // else: not enough zeros at start, don't need to trim
+
+ return l;
+ }
+
//on inertial recordes encoderReadedInertialDisc
protected virtual void saveToFile(string file)
{
TextWriter writer = File.CreateText(file);
+ encoderReaded = trimInitialZeros(encoderReaded);
+
string sep = "";
- for(int j=0; j < i ; j ++) {
- writer.Write(sep + encoderReaded[j]); //store the raw file (before
encoderConfigurationConversions)
+ foreach(int k in encoderReaded) {
+ writer.Write(sep + k); //store the raw file (before encoderConfigurationConversions)
sep = ", ";
}
@@ -632,6 +672,11 @@ public class EncoderCaptureInertial : EncoderCapture
directionLastMSecond *= -1;
sum *= -1;
sumInertialDisc *= -1;
+
+ int xWidth = recordingTime;
+ if(cont)
+ xWidth = recordedTimeCont;
+
for(int j=0; j <= i; j ++) {
encoderReaded[j] *= -1;
encoderReadedInertialDisc[j] *= -1;
@@ -640,12 +685,12 @@ public class EncoderCaptureInertial : EncoderCapture
for(int j=0; j <= i; j ++) {
sum2 += encoderReaded[j];
EncoderCapturePoints[j] = new Gdk.Point(
- Convert.ToInt32(widthG * j / recordingTime),
+ Convert.ToInt32(widthG * j / xWidth),
Convert.ToInt32( (heightG/2) - ( sum2 * heightG /
realHeightG) )
);
//same for InertialDisc. Read comment 2 on the top of this method
EncoderCapturePointsInertialDisc[j] = new Gdk.Point(
- Convert.ToInt32(widthG * j / recordingTime),
+ Convert.ToInt32(widthG * j / xWidth),
Convert.ToInt32( (heightG/2) - ( sum2 * heightG /
realHeightG) )
);
}
@@ -668,14 +713,18 @@ public class EncoderCaptureInertial : EncoderCapture
protected override void assignEncoderCapturePoints()
{
- EncoderCapturePoints[i] = new Gdk.Point(
- Convert.ToInt32(widthG * i / recordingTime),
+ int xWidth = recordingTime;
+ if(cont)
+ xWidth = recordedTimeCont;
+
+ EncoderCapturePoints.Add(new Gdk.Point(
+ Convert.ToInt32(widthG * i / xWidth),
Convert.ToInt32( (heightG/2) - ( sum * heightG / realHeightG) )
- );
- EncoderCapturePointsInertialDisc[i] = new Gdk.Point(
- Convert.ToInt32(widthG * i / recordingTime),
+ ));
+ EncoderCapturePointsInertialDisc.Add(new Gdk.Point(
+ Convert.ToInt32(widthG * i / xWidth),
Convert.ToInt32( (heightG/2) - ( sumInertialDisc * heightG / realHeightG) )
- );
+ ));
}
protected override void encoderCapturePointsAdaptativeDisplay()
@@ -688,17 +737,21 @@ public class EncoderCaptureInertial : EncoderCapture
EncoderCapturePointsInertialDisc[i].Y < 0 ) {
realHeightG *= 2;
+ int xWidth = recordingTime;
+ if(cont)
+ xWidth = recordedTimeCont;
+
double sum2 = 0;
double sum2InertialDisc = 0;
for(int j=0; j <= i; j ++) {
sum2 += encoderReaded[j];
sum2InertialDisc += encoderReadedInertialDisc[j];
EncoderCapturePoints[j] = new Gdk.Point(
- Convert.ToInt32(widthG * j / recordingTime),
+ Convert.ToInt32(widthG * j / xWidth),
Convert.ToInt32( (heightG/2) - ( sum2 * heightG /
realHeightG) )
);
EncoderCapturePointsInertialDisc[j] = new Gdk.Point(
- Convert.ToInt32(widthG * j / recordingTime),
+ Convert.ToInt32(widthG * j / xWidth),
Convert.ToInt32( (heightG/2) - ( sum2InertialDisc * heightG /
realHeightG) )
);
}
@@ -723,9 +776,11 @@ public class EncoderCaptureInertial : EncoderCapture
{
TextWriter writer = File.CreateText(file);
+ encoderReadedInertialDisc = trimInitialZeros(encoderReadedInertialDisc);
+
string sep = "";
- for(int j=0; j < i ; j ++) {
- writer.Write(sep + encoderReadedInertialDisc[j]); //store the raw file (before
encoderConfigurationConversions)
+ foreach(int k in encoderReadedInertialDisc) {
+ writer.Write(sep + k); //store the raw file (before encoderConfigurationConversions)
sep = ", ";
}
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 95aab9a..303c96e 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -78,7 +78,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.MenuItem menuitem_export_encoder_signal;
[Widget] Gtk.Label label_encoder_curve_action;
[Widget] Gtk.Button button_encoder_delete_signal;
- [Widget] Gtk.CheckButton checkbutton_encoder_auto;
+ [Widget] Gtk.CheckButton checkbutton_encoder_cont;
[Widget] Gtk.VPaned vpaned_encoder_main;
[Widget] Gtk.VPaned vpaned_encoder_capture_video_and_set_graph;
@@ -2033,12 +2033,16 @@ public partial class ChronoJumpWindow
else
eCapture = new EncoderCaptureGravitatory();
+ int recordingTime = (int) encoderCaptureOptionsWin.spin_encoder_capture_time.Value;
+ if(checkbutton_encoder_cont.Active)
+ recordingTime = 0;
+
eCapture.InitGlobal(
encoder_capture_signal_drawingarea.Allocation.Width,
encoder_capture_signal_drawingarea.Allocation.Height,
- (int) encoderCaptureOptionsWin.spin_encoder_capture_time.Value,
+ recordingTime,
(int) encoderCaptureOptionsWin.spin_encoder_capture_inactivity_end_time.Value,
- checkbutton_encoder_auto.Active,
+ checkbutton_encoder_cont.Active,
findEccon(true),
chronopicWin.GetEncoderPort()
);
@@ -3871,6 +3875,10 @@ public partial class ChronoJumpWindow
if(eCapture.EncoderCapturePoints == null)
return;
+ //continuous mode not show the capture line
+ if(checkbutton_encoder_cont.Active)
+ return;
+
bool refreshAreaOnly = false;
//mark meaning screen should be erased
@@ -5443,7 +5451,7 @@ public partial class ChronoJumpWindow
encoderShowCaptureDoingButtons(false);
- if(action == encoderActions.CURVES_AC && checkbutton_encoder_auto.Active)
+ if(action == encoderActions.CURVES_AC && checkbutton_encoder_cont.Active)
on_button_encoder_capture_clicked (new object (), new EventArgs ());
} else { //ANALYZE
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]