[chronojump] ForceSensor binary read negative values
- From: Xavier de Blas <xaviblas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump] ForceSensor binary read negative values
- Date: Mon, 7 Jan 2019 15:36:23 +0000 (UTC)
commit df5a257eecc2015a9d6a946dc55007f7bf627cdb
Author: Xavier de Blas <xaviblas gmail com>
Date: Mon Jan 7 16:35:35 2019 +0100
ForceSensor binary read negative values
src/forcePlatform.cs | 8 +++++++-
src/gui/forceSensor.cs | 10 +++++++++-
2 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/forcePlatform.cs b/src/forcePlatform.cs
index 49ab5109..299a689b 100644
--- a/src/forcePlatform.cs
+++ b/src/forcePlatform.cs
@@ -146,7 +146,13 @@ public class ForcePlatform
{
int b0 = sp.ReadByte(); //least significative
int b1 = sp.ReadByte(); //most significative
- dataRow.Add(256 * b1 + b0);
+
+ int readedNum = 256 * b1 + b0;
+ //care for negative values
+ if(readedNum > 32768)
+ readedNum = -1 * (65536 - readedNum);
+
+ dataRow.Add(readedNum);
}
printDataRow(dataRow);
diff --git a/src/gui/forceSensor.cs b/src/gui/forceSensor.cs
index 15a396af..f08c4b3e 100644
--- a/src/gui/forceSensor.cs
+++ b/src/gui/forceSensor.cs
@@ -116,6 +116,7 @@ public partial class ChronoJumpWindow
SerialPort portFS; //Attention!! Don't reopen port because arduino makes reset and tare,
calibration... is lost
bool portFSOpened;
+
Gdk.GC pen_black_force_capture;
Gdk.GC pen_red_force_capture;
Gdk.GC pen_gray_force_capture;
@@ -612,7 +613,14 @@ public partial class ChronoJumpWindow
{
int b0 = portFS.ReadByte(); //least significative
int b1 = portFS.ReadByte(); //most significative
- dataRow.Add(256 * b1 + b0);
+
+ int readedNum = 256 * b1 + b0;
+ //care for negative values
+ if(readedNum > 32768)
+ readedNum = -1 * (65536 - readedNum);
+
+ dataRow.Add(readedNum);
+ //LogB.Information(string.Format("b0: {0}, b1: {1}, readedNum: {2}", b0, b1,
readedNum));
}
return dataRow;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]