[chronojump] RaceAnalyzer. Added functions to manage the baud rate



commit 43f9cb688befe152c514b3bef91d11b3fc67a5b2
Author: Xavier Padullés <x padulles gmail com>
Date:   Thu Jun 20 16:08:22 2019 +0200

    RaceAnalyzer. Added functions to manage the baud rate

 arduino/raceAnalyzer/raceAnalyzer.ino | 37 +++++++++++++++++++++++++++++++++--
 src/gui/runEncoder.cs                 |  2 +-
 2 files changed, 36 insertions(+), 3 deletions(-)
---
diff --git a/arduino/raceAnalyzer/raceAnalyzer.ino b/arduino/raceAnalyzer/raceAnalyzer.ino
index 5e5e397c..c142be07 100644
--- a/arduino/raceAnalyzer/raceAnalyzer.ino
+++ b/arduino/raceAnalyzer/raceAnalyzer.ino
@@ -26,7 +26,7 @@ int offsetAddress = 2;
 float calibrationFactor = 0.140142;
 int calibrationAddress = 4;
 
-float metersPerPulse = 0.0033569564;
+float metersPerPulse = 0.003003;
 int metersPerPulseAddress = 8;
 
 //Wether the sensor has to capture or not
@@ -38,10 +38,17 @@ boolean procesSample = false;
 //wether the tranmission is in binary format or not
 boolean binaryFormat = false;
 
+//baud rate of the serial communication
+unsigned long baudRate = 1000000;
+
 void setup() {
+
   pinMode (encoderPinA, INPUT);
   pinMode (encoderPinB, INPUT);
-  Serial.begin (115200);
+  Serial.begin (baudRate);
+  Serial.print("Initial setup: Baud rate : ");
+  Serial.println(baudRate);
+
   Wire.setClock(1000000);
 
   EEPROM.get(ppsAddress, pps);
@@ -200,6 +207,10 @@ void serialEvent()
     set_offset(inputString);
   } else if (commandString == "get_mpp") {
     get_mpp();
+  } else if (commandString == "get_baud_rate") {
+    get_baud_rate();
+  } else if (commandString == "set_baud_rate") {
+    set_baud_rate(inputString);
   } else {
     Serial.println("Not a valid command");
   }
@@ -384,3 +395,25 @@ void get_mpp(void)
 {
   Serial.println(metersPerPulse, 8);
 }
+
+void get_baud_rate(void)
+{
+  Serial.println(baudRate);
+}
+
+void set_baud_rate(String inputString)
+{
+  String baudRateString = get_command_argument(inputString);
+  baudRate = baudRateString.toInt();
+  //Serial.end();
+  Serial.print("InpuptString = ");
+  Serial.println(baudRateString);
+  Serial.print("Going to change the baud rate ");
+  Serial.println(baudRate);
+  Serial.flush();
+  Serial.begin(baudRate);
+  Serial.flush();
+  delay(10000);
+  Serial.print("Setting baud rate to ");
+  Serial.println(baudRate);
+}
diff --git a/src/gui/runEncoder.cs b/src/gui/runEncoder.cs
index c1bfbef1..979990b8 100644
--- a/src/gui/runEncoder.cs
+++ b/src/gui/runEncoder.cs
@@ -94,7 +94,7 @@ public partial class ChronoJumpWindow
                LogB.Information(" RE connect 3 ");
                event_execute_label_message.Text = "Connecting ...";
 
-               portRE = new SerialPort(runEncoderPortName, 115200); //runEncoder
+               portRE = new SerialPort(runEncoderPortName, 1000000); //runEncoder
                LogB.Information(" RE connect 4: opening port...");
 
                try {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]