[chronojump] Fixed 700380: Inverted encoder reading
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] Fixed 700380: Inverted encoder reading
- Date: Thu, 6 Jun 2013 12:00:29 +0000 (UTC)
commit 91a742567316a965ef3e2812e022055f0110cc35
Author: Xavier de Blas <xaviblas gmail com>
Date: Thu Jun 6 13:58:54 2013 +0200
Fixed 700380: Inverted encoder reading
encoder/pyserial_pyper.py | 7 ++++++-
encoder/pyserial_pyper_windows.py | 9 +++++++--
glade/chronojump.glade | 2 +-
src/encoder.cs | 8 +++++---
src/gui/encoder.cs | 33 +++++++++++++++++++++++++++++----
src/sqlite/encoder.cs | 6 ++++--
src/util.cs | 33 ++++++++++++++++++++++++++++++++-
7 files changed, 84 insertions(+), 14 deletions(-)
---
diff --git a/encoder/pyserial_pyper.py b/encoder/pyserial_pyper.py
index 74f5159..acfdda6 100644
--- a/encoder/pyserial_pyper.py
+++ b/encoder/pyserial_pyper.py
@@ -64,7 +64,8 @@ powerLowerCondition = int(sys.argv[18])
peakPowerHigherCondition = int(sys.argv[19])
peakPowerLowerCondition = int(sys.argv[20])
mainVariable = sys.argv[21]
-w_serial_port = sys.argv[22]
+inverted = sys.argv[22]
+w_serial_port = sys.argv[23]
delete_initial_time = 20 #delete first records because there's encoder bug
#w_baudrate = 9600 # Setting the baudrate of Chronopic(9600)
@@ -526,6 +527,10 @@ if __name__ == '__main__':
# conver HEX to INT value
signedChar_data = unpack('b' * len(byte_data), byte_data)[0]
+
+ # invert sign if inverted is selected
+ if inverted == 1:
+ signedChard_data *= -1
temp.append(signedChar_data)
if(i>0):
diff --git a/encoder/pyserial_pyper_windows.py b/encoder/pyserial_pyper_windows.py
index 958aa78..80ef761 100644
--- a/encoder/pyserial_pyper_windows.py
+++ b/encoder/pyserial_pyper_windows.py
@@ -66,8 +66,9 @@ powerLowerCondition = int(sys.argv[18])
peakPowerHigherCondition = int(sys.argv[19])
peakPowerLowerCondition = int(sys.argv[20])
mainVariable = sys.argv[21]
-w_serial_port = sys.argv[22]
-r_path = sys.argv[23]
+inverted = sys.argv[22]
+w_serial_port = sys.argv[23]
+r_path = sys.argv[24]
delete_initial_time = 20 #delete first records because there's encoder bug
#w_baudrate = 9600 # Setting the baudrate of Chronopic(9600)
@@ -537,6 +538,10 @@ if __name__ == '__main__':
# conver HEX to INT value
signedChar_data = unpack('b' * len(byte_data), byte_data)[0]
+
+ # invert sign if inverted is selected
+ if inverted == 1:
+ signedChard_data *= -1
temp.append(signedChar_data)
if(i>0):
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index 6d6cb96..6069077 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -12314,7 +12314,7 @@ on current Chronojump version.</property>
<property name="spacing">6</property>
<property name="homogeneous">True</property>
<child>
- <widget class="GtkCheckButton"
id="checkbutton_encoder_inverted">
+ <widget class="GtkCheckButton"
id="check_encoder_inverted">
<property name="label"
translatable="yes">Inverted</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
diff --git a/src/encoder.cs b/src/encoder.cs
index 80f6bf0..5f22c50 100644
--- a/src/encoder.cs
+++ b/src/encoder.cs
@@ -51,6 +51,7 @@ public class EncoderParams
private int peakPowerLowerCondition;
private string mainVariable;
private string decimalSeparator; //used in export data from R to csv
+ private bool inverted;
public EncoderParams()
{
@@ -64,7 +65,7 @@ public class EncoderParams
double maxSpeedHigherCondition, double maxSpeedLowerCondition,
int powerHigherCondition, int powerLowerCondition,
int peakPowerHigherCondition, int peakPowerLowerCondition,
- string mainVariable)
+ string mainVariable, bool inverted)
{
this.time = time;
this.minHeight = minHeight;
@@ -85,6 +86,7 @@ public class EncoderParams
this.peakPowerHigherCondition = peakPowerHigherCondition;
this.peakPowerLowerCondition = peakPowerLowerCondition;
this.mainVariable = mainVariable;
+ this.inverted = inverted;
}
public string ToString1 ()
@@ -102,7 +104,7 @@ public class EncoderParams
" " + Util.ConvertToPoint(maxSpeedLowerCondition.ToString()) +
" " + powerHigherCondition.ToString() + " " + powerLowerCondition.ToString() +
" " + peakPowerHigherCondition.ToString() + " " +
peakPowerLowerCondition.ToString() +
- " " + mainVariable;
+ " " + mainVariable + " " + Util.BoolToInt(inverted).ToString();
}
//to graph.R
@@ -259,7 +261,7 @@ public class EncoderSQL
public string description;
public string future1; //active or inactive curves
public string future2; //URL of video of signals
- public string future3;
+ public string future3; //inverted
public string exerciseName;
public string ecconLong;
diff --git a/src/gui/encoder.cs b/src/gui/encoder.cs
index 9ebe9b7..e42078f 100644
--- a/src/gui/encoder.cs
+++ b/src/gui/encoder.cs
@@ -36,6 +36,7 @@ public partial class ChronoJumpWindow
[Widget] Gtk.Button button_encoder_capture;
[Widget] Gtk.RadioButton radiobutton_encoder_capture_safe;
[Widget] Gtk.RadioButton radiobutton_encoder_capture_external;
+ [Widget] Gtk.CheckButton check_encoder_inverted;
[Widget] Gtk.Button button_encoder_bells;
[Widget] Gtk.Button button_encoder_capture_cancel;
[Widget] Gtk.Button button_encoder_capture_finish;
@@ -139,6 +140,8 @@ public partial class ChronoJumpWindow
double encoderSmoothEccCon;
double encoderSmoothCon;
+ bool lastRecalculateWasInverted;
+
//CAPTURE is the capture from csharp (not from external python)
//difference between CALCULECURVES and RECALCULATE_OR_LOAD is: CALCULECURVES does a autosave at end
enum encoderModes { CAPTURE, CALCULECURVES, RECALCULATE_OR_LOAD, ANALYZE }
@@ -246,13 +249,16 @@ public partial class ChronoJumpWindow
maxSpeedHigherCondition, maxSpeedLowerCondition,
powerHigherCondition, powerLowerCondition,
peakPowerHigherCondition, peakPowerLowerCondition,
- repetitiveConditionsWin.EncoderMainVariable
+ repetitiveConditionsWin.EncoderMainVariable,
+ check_encoder_inverted.Active
);
EncoderStruct es = new EncoderStruct(
"", //no data input
"", //no graph ouptut
Util.GetEncoderDataTempFileName(), "", ep);
+
+ lastRecalculateWasInverted = check_encoder_inverted.Active;
if (radiobutton_encoder_capture_external.Active) {
encoderStartVideoRecord();
@@ -305,8 +311,16 @@ public partial class ChronoJumpWindow
void on_button_encoder_recalculate_clicked (object o, EventArgs args)
{
- if (File.Exists(Util.GetEncoderDataTempFileName()))
+ if (File.Exists(Util.GetEncoderDataTempFileName())) {
+ //change sign on signal file if check_encoder_inverted changed
+
+ if(lastRecalculateWasInverted != check_encoder_inverted.Active) {
+ Util.ChangeSign(Util.GetEncoderDataTempFileName());
+ lastRecalculateWasInverted = check_encoder_inverted.Active;
+ }
+
encoderThreadStart(encoderModes.RECALCULATE_OR_LOAD);
+ }
else
encoder_pulsebar_capture.Text = Catalog.GetString("Missing data.");
}
@@ -850,6 +864,8 @@ public partial class ChronoJumpWindow
encoderTimeStamp = es.GetDate(false);
encoderSignalUniqueID = es.uniqueID;
button_video_play_this_test_encoder.Sensitive = (es.future2 != "");
+ check_encoder_inverted.Active = (es.future3 == "1");
+ lastRecalculateWasInverted = check_encoder_inverted.Active;
}
}
@@ -1259,8 +1275,11 @@ public partial class ChronoJumpWindow
}
string myID = "-1";
- if(mode == "signal")
+ string future3 = ""; //unused on curve
+ if(mode == "signal") {
myID = encoderSignalUniqueID;
+ future3 = Util.BoolToInt(check_encoder_inverted.Active).ToString();
+ }
EncoderSQL eSQL = new EncoderSQL(
myID,
@@ -1278,7 +1297,8 @@ public partial class ChronoJumpWindow
(int) spin_encoder_capture_min_height.Value,
-1, //Since 1.3.7 smooth is not stored in curves
desc,
- "","","",
+ "","",
+ future3,
Util.FindOnArray(':', 2, 1, UtilGtk.ComboGetActive(combo_encoder_exercise),
encoderExercisesTranslationAndBodyPWeight) //exerciseName
(english)
);
@@ -1437,6 +1457,11 @@ public partial class ChronoJumpWindow
byteReaded = sp.ReadByte();
if(byteReaded > 128)
byteReaded = byteReaded - 256;
+
+ //invert sign if inverted is selected
+ if(check_encoder_inverted.Active)
+ byteReaded *= -1;
+
i=i+1;
if(i >= 0) {
sum += byteReaded;
diff --git a/src/sqlite/encoder.cs b/src/sqlite/encoder.cs
index 0e032f5..a7ed594 100644
--- a/src/sqlite/encoder.cs
+++ b/src/sqlite/encoder.cs
@@ -56,7 +56,7 @@ class SqliteEncoder : Sqlite
"description TEXT, " +
"future1 TEXT, " + //works as status: "active", "inactive"
"future2 TEXT, " + //URL of video of signals
- "future3 TEXT )";
+ "future3 TEXT )"; //Inverted (encoder is upside down) only on signals
dbcmd.ExecuteNonQuery();
}
@@ -80,7 +80,9 @@ class SqliteEncoder : Sqlite
es.laterality + "', '" + es.extraWeight + "', '" +
es.signalOrCurve + "', '" + es.filename + "', '" +
es.url + "', " + es.time + ", " + es.minHeight + ", " +
- Util.ConvertToPoint(es.smooth) + ", '" + es.description + "', 'active', '',
'')" ;
+ Util.ConvertToPoint(es.smooth) + ", '" + es.description + "', 'active', " +
+ "''," + //future2 url (this is stored later)
+ es.future3 + ")" ; //future3 inverted?
Log.WriteLine(dbcmd.CommandText.ToString());
dbcmd.ExecuteNonQuery();
diff --git a/src/util.cs b/src/util.cs
index c09b296..aca0526 100644
--- a/src/util.cs
+++ b/src/util.cs
@@ -954,7 +954,7 @@ public class Util
return System.IO.Path.Combine(
getDataDir(), "encoder", Constants.EncoderScriptGraph);
}
-
+
/********** end of encoder paths ************/
@@ -1344,6 +1344,37 @@ public class Util
return fileCurve;
}
+ //used on encoder inverted-noninverted
+ public static void ChangeSign(string fileName)
+ {
+ string data = ReadFile(fileName, true);
+ if(data != null) {
+ TextWriter writer;
+ try {
+ writer = File.CreateText(fileName);
+ } catch {return;}
+
+ using (StringReader reader = new StringReader (data)) {
+ do {
+ string line = reader.ReadLine ();
+ if (line == null)
+ break;
+ string [] ints = line.Split(new char[] {','});
+ string sep = "";
+ foreach(string istr in ints) {
+ int i = Convert.ToInt32(istr);
+ i *= -1;
+ writer.Write(sep + i.ToString());
+ sep = ", ";
+ }
+ } while(true);
+ }
+ writer.Flush();
+ ((IDisposable)writer).Dispose();
+ }
+ }
+
+
/*
* currently not used, we copy the assemblies now
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]