[chronojump/michrolab] Generic function to read exercises files
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/michrolab] Generic function to read exercises files
- Date: Mon, 22 Aug 2022 15:25:28 +0000 (UTC)
commit 4f64ff5fe48f4c5632607e7554cb0131f68abe43
Author: Xavier Padullés <testing chronojump org>
Date: Mon Aug 22 17:23:41 2022 +0200
Generic function to read exercises files
arduino/michrolab/SDExample/JumpType.txt | 6 +-
arduino/michrolab/exercsiseManage.ino | 114 ++++++++++++++++++++++---------
arduino/michrolab/menus.ino | 8 +--
arduino/michrolab/michrolab.h | 2 +-
arduino/michrolab/michrolab.ino | 59 ++++++++++------
arduino/michrolab/personsManage.ino | 2 +-
6 files changed, 130 insertions(+), 61 deletions(-)
---
diff --git a/arduino/michrolab/SDExample/JumpType.txt b/arduino/michrolab/SDExample/JumpType.txt
index ad4764ae0..a2b8379aa 100644
--- a/arduino/michrolab/SDExample/JumpType.txt
+++ b/arduino/michrolab/SDExample/JumpType.txt
@@ -1,7 +1,7 @@
#id, name, jumpLimit,timeLimit, hardTimeLimit, percentBodyWeight, fall, startIn
-24,RJ(10j),10,0,0,0,0,0
-32,RF(10ss),0,10,0,0,0,1
-39,RF(10sh),0,10,1,0,0,1
+24,RJ(5j),5,0,0,0,0,0
+32,RJ(5ss),0,5,0,0,0,1
+39,RJ(5sh),0,5,1,0,0,1
1,Free,1,0,0,0,0,1
2,SJ,1,0,0,0,0,1
3,SJl100,1,0,0,100,0,1
diff --git a/arduino/michrolab/exercsiseManage.ino b/arduino/michrolab/exercsiseManage.ino
index ae63eb823..325b3b19f 100644
--- a/arduino/michrolab/exercsiseManage.ino
+++ b/arduino/michrolab/exercsiseManage.ino
@@ -2,87 +2,137 @@ void addJump(String row)
{
int prevComaIndex = row.indexOf(":");
int nextComaIndex = row.indexOf(",");
- //currentJumpType = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
- jumpTypes[currentJumpType].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+ //currentExerciseType = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+ jumpTypes[currentExerciseType].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
prevComaIndex = nextComaIndex;
nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
- jumpTypes[currentJumpType].name = row.substring(prevComaIndex + 1 , nextComaIndex);
+ jumpTypes[currentExerciseType].name = row.substring(prevComaIndex + 1 , nextComaIndex);
prevComaIndex = nextComaIndex;
prevComaIndex = nextComaIndex;
nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
- jumpTypes[currentJumpType].jumpLimit = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+ jumpTypes[currentExerciseType].jumpLimit = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
prevComaIndex = nextComaIndex;
-
+
+ prevComaIndex = nextComaIndex;
+ nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+ jumpTypes[currentExerciseType].timeLimit = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+ prevComaIndex = nextComaIndex;
+
+ prevComaIndex = nextComaIndex;
+ nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+ jumpTypes[currentExerciseType].hardTimeLimit = (row.substring(prevComaIndex + 1 , nextComaIndex) == 1);
+ prevComaIndex = nextComaIndex;
+
+ prevComaIndex = nextComaIndex;
+ nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+ jumpTypes[currentExerciseType].percentBodyWeight = row.substring(prevComaIndex + 1 ,
nextComaIndex).toFloat();
+ prevComaIndex = nextComaIndex;
+
prevComaIndex = nextComaIndex;
nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
- jumpTypes[currentJumpType].timeLimit = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+ jumpTypes[currentExerciseType].fall = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+ prevComaIndex = nextComaIndex;
+
prevComaIndex = nextComaIndex;
-
+ jumpTypes[currentExerciseType].startIn = (row.substring(prevComaIndex + 1, prevComaIndex + 2) == "1");
+}
+
+void addGravitatory(String row)
+{
+ int prevComaIndex = row.indexOf(":");
+ int nextComaIndex = row.indexOf(",");
+ //currentExerciseType = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+ gravTypes[currentExerciseType].id = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+
prevComaIndex = nextComaIndex;
nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
- jumpTypes[currentJumpType].hardTimeLimit = (row.substring(prevComaIndex + 1 , nextComaIndex) == 1);
+ gravTypes[currentExerciseType].name = row.substring(prevComaIndex + 1 , nextComaIndex);
prevComaIndex = nextComaIndex;
-
+
prevComaIndex = nextComaIndex;
nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
- jumpTypes[currentJumpType].percentBodyWeight = row.substring(prevComaIndex + 1 , nextComaIndex).toFloat();
+ gravTypes[currentExerciseType].description = row.substring(prevComaIndex + 1, nextComaIndex);
prevComaIndex = nextComaIndex;
-
+
prevComaIndex = nextComaIndex;
nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
- jumpTypes[currentJumpType].fall = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
+ gravTypes[currentExerciseType].percentBodyWeight = row.substring(prevComaIndex + 1 ,
nextComaIndex).toFloat();
prevComaIndex = nextComaIndex;
-
+
prevComaIndex = nextComaIndex;
- jumpTypes[currentJumpType].startIn = (row.substring(prevComaIndex + 1, prevComaIndex + 2) == "1");
+ nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+ gravTypes[currentExerciseType].speed1Rm = row.substring(prevComaIndex + 1, nextComaIndex).toFloat();
}
-void readJumpTypesFile()
+void readExercisesFile(exerciseType mode)
{
char readChar;
String readString = "";
unsigned long pos = 0; //Position in the file
int numRows = 0; //Number of valid rows in the file
-
- File jumpsFile = SD.open("jumpType.txt");
- if (jumpsFile)
+ String file = "";
+
+ if (mode == jumps) {
+ //Serial.println("J");
+ file = "jumpType.txt";
+ }
+ else if (mode == gravitatory) {
+ //Serial.println("G");
+ file = "gravitat.txt";
+ }
+
+ File exercisesFile = SD.open(file);
+
+ if (exercisesFile)
{
- while (pos <= jumpsFile.size())
+ Serial.println("file size: " + String(exercisesFile.size()) );
+ while (pos <= exercisesFile.size())
{
readChar = '0';
String readString = "";
- while (readChar != '\n' && readChar != '\r' && pos<=jumpsFile.size())
+ while (readChar != '\n' && readChar != '\r' && pos <= exercisesFile.size())
{
- readChar = jumpsFile.read();
+ readChar = exercisesFile.read();
readString = readString + readChar;
pos++;
}
+
+ //Serial.print(" | ");
//Check that it is a valid row.
if ( isDigit(readString[0]) )
{
numRows++;
- currentJumpType = numRows - 1;
- addJump(readString);
- totalJumpTypes = numRows;
+ currentExerciseType = numRows - 1;
+
+ if (mode == jumps) {
+ addJump(readString);
+ totalJumpTypes = numRows;
+ } else if (mode == gravitatory) {
+ addGravitatory(readString);
+ totalGravTypes = numRows;
+ }
}
}
}
- jumpsFile.close();
+ exercisesFile.close();
}
void printJumpTypesList()
{
+ Serial.println("id, name, jumpLimit,timeLimit, hardTimeLimit, percentBodyWeight, fall, startIn");
for (unsigned int i = 0; i < totalJumpTypes; i++)
{
Serial.print(jumpTypes[i].id);
- Serial.print("," + jumpTypes[i].name + " ,");
- Serial.print(String( jumpTypes[i].jumpLimit , 2) + " ,");
- Serial.print(String( jumpTypes[i].timeLimit ) + "s ,");
- Serial.print(String( jumpTypes[i].hardTimeLimit) + " ,");
- Serial.print(String( jumpTypes[i].percentBodyWeight , 2) + "% ,");
- Serial.print(String( jumpTypes[i].fall , 2) + "cm ,");
- Serial.println(jumpTypes[i].startIn);
+ Serial.print("," + jumpTypes[i].name + ", ");
+ Serial.print(String( jumpTypes[i].jumpLimit) + "j, ");
+ Serial.print(String( jumpTypes[i].timeLimit ) + "s, ");
+ if(jumpTypes[i].hardTimeLimit) Serial.print("Yes, ");
+ else Serial.print("No, ");
+ Serial.print(String( jumpTypes[i].percentBodyWeight , 2) + "%, ");
+ Serial.print(String( jumpTypes[i].fall , 2) + "cm, ");
+ if(jumpTypes[i].startIn) Serial.println("Yes, ");
+ else Serial.println("No, ");
}
}
diff --git a/arduino/michrolab/menus.ino b/arduino/michrolab/menus.ino
index c75ec61cb..ad7ea9310 100644
--- a/arduino/michrolab/menus.ino
+++ b/arduino/michrolab/menus.ino
@@ -216,7 +216,7 @@ void selectJumpType()
drawLeftButton("Next", WHITE, BLUE);
drawRightButton("Accept", WHITE, RED);
- printTftText(jumpTypes[currentJumpType].name, 50, 100);
+ printTftText(jumpTypes[currentExerciseType].name, 50, 100);
blueButton.update();
@@ -226,11 +226,11 @@ void selectJumpType()
if(blueButton.fell())
{
//Deleting last jumpType text
- printTftText(jumpTypes[currentJumpType].name, 50, 100, BLACK);
+ printTftText(jumpTypes[currentExerciseType].name, 50, 100, BLACK);
//Printing new jump type text
- currentJumpType = (currentJumpType + 1) % totalJumpTypes;
- printTftText(jumpTypes[currentJumpType].name, 50, 100);
+ currentExerciseType = (currentExerciseType + 1) % totalJumpTypes;
+ printTftText(jumpTypes[currentExerciseType].name, 50, 100);
}
blueButton.update();
redButton.update();
diff --git a/arduino/michrolab/michrolab.h b/arduino/michrolab/michrolab.h
index 2f04ae6f5..19c2a363b 100644
--- a/arduino/michrolab/michrolab.h
+++ b/arduino/michrolab/michrolab.h
@@ -149,7 +149,7 @@ void readJumpsFile();
void addJump(String row);
//Read how many rows has the jumpTypes.txt
-void getTotalJumpTypes();
+void gettotalJumpTypes();
//Print in the Serial a list of all jump types
void printJumpTypesList();
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index a08c8785e..fa16580bf 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -100,6 +100,14 @@ enum sensorType {
none
};
+enum exerciseType {
+ jumps,
+ inertial,
+ gravitatory,
+ raceAnalyzer,
+ races
+};
+
sensorType sensor = none;
String maxString = "";
@@ -319,10 +327,21 @@ struct jumpType {
jumpType jumpTypes[100];
unsigned int totalJumpTypes = 0;
-unsigned int currentJumpType = 0;
+unsigned int currentExerciseType = 0;
int totalJumps = 0;
//In simple jumps the firstPhase is the contact. In DropJumps the first phase is flight
+struct gravitType {
+ unsigned int id;
+ String name;
+ String description;
+ float percentBodyWeight;
+ float speed1Rm;
+};
+
+gravitType gravTypes[100];
+unsigned int totalGravTypes = 0;
+
IntervalTimer rcaTimer;
void setup() {
@@ -398,8 +417,7 @@ void setup() {
readPersonsFile();
//TODO: Read jumps only if necessary
- readJumpTypesFile();
- currentJumpType = 0;
+ currentExerciseType = 0;
tft.fillScreen(BLACK);
@@ -791,7 +809,7 @@ void showBatteryLevel() {
void updateJumpTime()
{
- updateTime(0, jumpTypes[currentJumpType].timeLimit);
+ updateTime(0, jumpTypes[currentExerciseType].timeLimit);
}
//Shows time in seconds at right lower corner. If limit is present non-zero it will we a countdown
@@ -1355,6 +1373,8 @@ void showPowerResults()
void jumpsCapture()
{
+ readExercisesFile(jumps);
+ printJumpTypesList();
selectJumpType();
IntervalTimer testTime; //Timer that controls the refreshing of time in lower right corner
capturing = true;
@@ -1399,7 +1419,7 @@ void jumpsCapture()
totalTime = 0;
//Draws the time if necessary
- if ( jumpTypes[currentJumpType].timeLimit > 0 ) updateJumpTime();
+ if ( jumpTypes[currentExerciseType].timeLimit > 0 ) updateJumpTime();
//Pressing the redButton during a test ends it
while ( !redButton.fell())
@@ -1491,7 +1511,7 @@ void jumpsCapture()
//The state previous to change was WRONG
//The first change of RCA is in the state that is supposed to be at start of the test.
- if ( jumpTypes[currentJumpType].startIn == rcaState ) {
+ if ( jumpTypes[currentExerciseType].startIn == rcaState ) {
if (rcaState) { //Landing. Don't measure the Time of Flight
//Do nothing
} else if ( !rcaState) { //Take off.
@@ -1501,7 +1521,7 @@ void jumpsCapture()
}
//The state previous change was RIGHT
//The first change of RCA is to the state that is NOT supposed to be at start of the test.
- } else if ( jumpTypes[currentJumpType].startIn != rcaState) {
+ } else if ( jumpTypes[currentExerciseType].startIn != rcaState) {
waitingFirstPhase = false;
}
totalTestTime = 0;
@@ -1510,13 +1530,13 @@ void jumpsCapture()
lastRcaTime = 0;
setNumber++;
if( !rowCreated ){
- dataFile.print(String(setNumber) + "," + String(currentPerson) + "," +
String(jumpTypes[currentJumpType].id));
- Serial.print(String(setNumber) + "," + String(currentPerson) + "," +
String(jumpTypes[currentJumpType].id));
+ dataFile.print(String(setNumber) + "," + String(currentPerson) + "," +
String(jumpTypes[currentExerciseType].id));
+ Serial.print(String(setNumber) + "," + String(currentPerson) + "," +
String(jumpTypes[currentExerciseType].id));
rowCreated = true;
}
//Starting timer
- if (jumpTypes[currentJumpType].timeLimit != 0)
+ if (jumpTypes[currentExerciseType].timeLimit != 0)
{
//Hardcoded to show integers and update every second
testTime.begin(updateJumpTime, 1000000);
@@ -1525,21 +1545,21 @@ void jumpsCapture()
}
//Check jumps limit
- if (jumpTypes[currentJumpType].jumpLimit > 0 //Jumps limit set
- && totalJumps >= jumpTypes[currentJumpType].jumpLimit) //Jumps equal or exceeded to limit
+ if (jumpTypes[currentExerciseType].jumpLimit > 0 //Jumps limit set
+ && totalJumps >= jumpTypes[currentExerciseType].jumpLimit) //Jumps equal or exceeded to limit
capturing = false;
} //End of rcaFlag
//Check time limit
if ( !waitingFirstPhase
&& !timeEnded //Only check once
- && jumpTypes[currentJumpType].timeLimit > 0 //time limit set
- && totalTestTime >= (unsigned int)jumpTypes[currentJumpType].timeLimit * 1000000) //time limit
exceeded
+ && jumpTypes[currentExerciseType].timeLimit > 0 //time limit
set
+ && totalTestTime >= (unsigned int)jumpTypes[currentExerciseType].timeLimit * 1000000) //time
limit exceeded
{
timeEnded = true;
//Check if test must end. Hard time limit or soft time limit but sepping on the mat
- if ( jumpTypes[currentJumpType].hardTimeLimit //Hard time limit
- || ( !jumpTypes[currentJumpType].hardTimeLimit && rcaState ) ) //Soft time limit and in
contact with the mat
+ if ( jumpTypes[currentExerciseType].hardTimeLimit //Hard time limit
+ || ( !jumpTypes[currentExerciseType].hardTimeLimit && rcaState ) ) //Soft time limit and in
contact with the mat
{
capturing = false;
rcaFlag = false;
@@ -1563,9 +1583,9 @@ void jumpsCapture()
rowCreated = false;
//check if the user wants to perform another one
- if ( yesNoDialog("Continue with " + jumpTypes[currentJumpType].name + "?", 10, 10))
+ if ( yesNoDialog("Continue with " + jumpTypes[currentExerciseType].name + "?", 10, 10))
{
- if (jumpTypes[currentJumpType].timeLimit > 0) updateJumpTime();
+ if (jumpTypes[currentExerciseType].timeLimit > 0) updateJumpTime();
} else
break;
@@ -1747,7 +1767,7 @@ void saveSimpleJump(float lastPhaseTime)
File dataFile = SD.open(fullFileName.c_str(), FILE_WRITE);
if ( !rcaState)
{
- dataFile.print(String(currentPerson) + ";" + jumpTypes[currentJumpType].id + ";" + String(lastPhaseTime,
6) );
+ dataFile.print(String(currentPerson) + ";" + jumpTypes[currentExerciseType].id + ";" +
String(lastPhaseTime, 6) );
}
else if (rcaState)
{
@@ -1772,7 +1792,6 @@ void saveSimpleJump(float lastPhaseTime)
// //Starts de first landing
// else if (rcaState)
// {
-// dataFile.print(String(currentPerson) + ";" + jumpTypes[currentJumpType].id + ";" +
String(lastPhaseTime, 6) );
// Serial.println("Previous jump ended");
// }
// //Starting or ending the second jump
diff --git a/arduino/michrolab/personsManage.ino b/arduino/michrolab/personsManage.ino
index 41b1ea7f9..a1215c7e3 100644
--- a/arduino/michrolab/personsManage.ino
+++ b/arduino/michrolab/personsManage.ino
@@ -149,7 +149,7 @@ void updatePersonJump(int totalJumps)
tft.setTextSize(1);
tft.setTextColor(WHITE);
tft.setCursor(141, 207);
- tft.print(jumpTypes[currentJumpType].name);
+ tft.print(jumpTypes[currentExerciseType].name);
tft.setCursor(195,207);
tft.print("Person: " + addLeadingZeros(currentPerson, 2));
tft.setCursor(141, 223);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]