[chronojump/michrolab] Added inertial machines management



commit af7a4f9d827b902faca3cf727aea2cb2526f118c
Author: Xavier Padullés <testing chronojump org>
Date:   Fri Sep 2 15:29:57 2022 +0200

    Added inertial machines management

 arduino/michrolab/SDExample/INERMACH.TXT |   4 ++
 arduino/michrolab/commandExamples.txt    |  10 +++
 arduino/michrolab/michrolab.ino          | 107 +++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+)
---
diff --git a/arduino/michrolab/SDExample/INERMACH.TXT b/arduino/michrolab/SDExample/INERMACH.TXT
new file mode 100644
index 000000000..45f5de045
--- /dev/null
+++ b/arduino/michrolab/SDExample/INERMACH.TXT
@@ -0,0 +1,4 @@
+#id, name, description, diameters, gearedDown
+0,Prosquat,Squat machine of Proinertial,3,1
+1,Eccotek,Conical machine of Byomedic,9.27_7.8_6.17_4.7,1
+2,Cubic,Custom machine with cubic structure,2,1
diff --git a/arduino/michrolab/commandExamples.txt b/arduino/michrolab/commandExamples.txt
index 6a3111b0c..b44e8e167 100644
--- a/arduino/michrolab/commandExamples.txt
+++ b/arduino/michrolab/commandExamples.txt
@@ -63,3 +63,13 @@ get_tare:                                   //Shows the voltage reading that cor
 set_tare:                                   //Sets the voltage reading that corresponds to the null force
 tare:                                       //Starts the process to calculate the voltage reading 
corresponding to the null force
 get_transmission_format:                    //Shows how the information is transmitted (binary or text)
+
+    ## Inertial machines ##
+
+#addInertialMachine:id,name,description,diameters,gearedDown;
+addInertialMachine:0,Prosquat,Squat machine of Proinertial,3,1;
+addInertialMachine:1,Eccotek,Conical machine of Byomedic,9.27_7.8_6.17_4.7,1;
+addInertialMachine:2,Cubic,Custom machine with cubic structure,2,1;
+
+readInertialMachinesFile:
+saveInertialMachines:
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 20df69ee3..1b9ebf669 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -359,6 +359,18 @@ struct inertType {
 inertType inertTypes[100];
 unsigned int totalInertTypes = 0;
 
+struct inertMachineType {
+  unsigned int id;
+  String name;
+  String description;
+  String diameters;
+  float gearedDown;
+};
+
+inertMachineType inertMachines[10];
+unsigned int totalInertMachines = 0;
+unsigned int currentInertMachine = 0;
+
 IntervalTimer rcaTimer;
 String fullFileName;
 File dataFile;
@@ -656,6 +668,12 @@ void serialEvent() {
     totalInertTypes = 0;
   } else if (commandString == "saveInertialTypes") {
     saveInertialList();
+  } else if (commandString == "addInertialMachine") {
+    addInertMachine(parameters);
+  } else if (commandString == "saveInertialMachines") {
+    saveInertMachines();
+  } else if (commandString == "readInertialMachinesFile") {
+    readInertMachineFile();
   } else {
     Serial.println("Not a valid command");
   }
@@ -1943,3 +1961,92 @@ void printDirectory(File dir, int numTabs)
     entry.close();
   }
 }
+
+void addInertMachine(String row)
+{
+  int prevComaIndex = row.indexOf(":");
+  int nextComaIndex = row.indexOf(",");
+  //totalinertMachines = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+  inertMachines[totalInertMachines].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+
+  prevComaIndex = nextComaIndex;
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  inertMachines[totalInertMachines].name = row.substring(prevComaIndex + 1 , nextComaIndex);
+  prevComaIndex = nextComaIndex;
+
+  prevComaIndex = nextComaIndex;
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  inertMachines[totalInertMachines].description = row.substring(prevComaIndex + 1, nextComaIndex);
+  prevComaIndex = nextComaIndex;
+
+  prevComaIndex = nextComaIndex;
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  inertMachines[totalInertMachines].diameters = row.substring(prevComaIndex + 1 , nextComaIndex);
+  prevComaIndex = nextComaIndex;
+
+  prevComaIndex = nextComaIndex;
+  nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+  inertMachines[totalInertMachines].gearedDown = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+  totalInertMachines++;
+}
+
+void saveInertMachines()
+{
+  SD.remove("INERMACH.TXT");
+ 
+  File inertFile = SD.open("INERMACH.TXT", FILE_WRITE);
+
+//  if(gravFile) Serial.println("File created");
+//  else Serial.println("Error creating file");
+
+  for (unsigned int i = 0; i < totalInertMachines; i++)
+  {
+    inertFile.print(inertMachines[i].id);
+    inertFile.print("," + inertMachines[i].name);
+    inertFile.print("," + inertMachines[i].description );
+    inertFile.print("," + inertMachines[i].diameters);
+    inertFile.println("," + String(inertMachines[i].gearedDown));
+  }
+  inertFile.close();
+  Serial.println("Saved " + String(totalInertMachines) + " to INERMACH.TXT");
+}
+
+void readInertMachineFile()
+{
+  char readChar;
+  String readString = "";
+  unsigned long pos = 0;    //Position in the file
+  int numRows = 0;          //Number of valid rows in the file
+
+  File  machinesFile = SD.open("INERMACH.TXT");
+
+  if (machinesFile)
+  {
+    //Serial.println("File size = " + String(exercisesFile.size() ) );
+    while (pos <= machinesFile.size())
+    {
+      readChar = '0';
+      String readString = "";
+      while (readChar != '\n' && readChar != '\r' && pos <= machinesFile.size())
+      {
+        readChar = machinesFile.read();
+        readString = readString + readChar;
+        pos++;
+      }
+      
+      //Serial.print(readString);
+
+      //Check that it is a valid row.
+      if ( isDigit(readString[0]) )
+      {
+        numRows++;
+        currentInertMachine = numRows - 1;
+        addInertMachine(readString);
+      }
+    }
+    
+    totalInertMachines = numRows;
+    Serial.println("Total:" + String(totalInertMachines));
+  }
+  machinesFile.close();
+}


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