[chronojump/michrolab] Added jumps limits management. TODO: fix SD saving. 1 test per row
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/michrolab] Added jumps limits management. TODO: fix SD saving. 1 test per row
- Date: Tue, 9 Aug 2022 18:02:04 +0000 (UTC)
commit 3a18913d06f4cd15019287d4ade1a8a39ec1da7c
Author: Xavier Padullés <testing chronojump org>
Date: Tue Aug 9 17:40:11 2022 +0200
Added jumps limits management. TODO: fix SD saving. 1 test per row
arduino/michrolab/SDExample/JumpType.txt | 3 +
arduino/michrolab/menus.ino | 41 ++++++++++
arduino/michrolab/michrolab.ino | 124 +++++++++++++++++--------------
3 files changed, 112 insertions(+), 56 deletions(-)
---
diff --git a/arduino/michrolab/SDExample/JumpType.txt b/arduino/michrolab/SDExample/JumpType.txt
index 48fa8ee33..ad4764ae0 100644
--- a/arduino/michrolab/SDExample/JumpType.txt
+++ b/arduino/michrolab/SDExample/JumpType.txt
@@ -1,4 +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
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/menus.ino b/arduino/michrolab/menus.ino
index ff8139fbd..c75ec61cb 100644
--- a/arduino/michrolab/menus.ino
+++ b/arduino/michrolab/menus.ino
@@ -70,6 +70,8 @@ void showMenuEntry(unsigned int currentMenuIndex)
printTftText(currentMenu[currentMenuIndex].description, 12, 100);
}
+void drawRightButton(String label) { drawRightButton(label, WHITE, RED); }
+void drawRightButton(String label, uint16_t tColor) { drawRightButton(label, tColor, RED); }
void drawRightButton(String label, uint16_t tColor, uint16_t bColor)
{
//Red button
@@ -83,6 +85,8 @@ void drawRightButton(String label, uint16_t tColor, uint16_t bColor)
}
+void drawLeftButton(String label) { drawLeftButton(label, WHITE, BLUE); }
+void drawLeftButton(String label, uint16_t tColor) { drawLeftButton(label, tColor, BLUE); }
void drawLeftButton(String label, uint16_t tColor, uint16_t bColor)
{
//Red button
@@ -232,3 +236,40 @@ void selectJumpType()
redButton.update();
}
}
+
+bool yesNoDialog(String message, float x, float y) {
+ return yesNoDialog(message, x, y, 2);
+}
+bool yesNoDialog(String message, float x, float y, int fontSize)
+{
+ bool answer = false;
+ int len = message.length();
+ unsigned int w = 6 * fontSize * len;
+ unsigned int h = 8 * fontSize;
+ uint16_t textBackRect[w * h];
+ tft.readRect(x, y, w, h, textBackRect);
+
+ uint16_t redBackRect[78 * 32];
+ tft.readRect(242, 210, 78, 32, redBackRect);
+ drawRightButton("Yes");
+
+ uint16_t blueBackRect[78 * 32];
+ tft.readRect(0, 210, 78, 32, blueBackRect);
+ drawLeftButton("No");
+
+ printTftText(message, x, y, RED);
+ redButton.update();
+ while ( !redButton.fell() && !blueButton.fell() )
+ {
+ redButton.update();
+ blueButton.update();
+ }
+ printTftText(message, x, y, BLACK);
+ tft.writeRect(x, y, w, h, textBackRect);
+ tft.writeRect(242, 210, 78, 32, redBackRect);
+ tft.writeRect(0, 210, 78, 32, redBackRect);
+ answer = redButton.fell();
+ redButton.update();
+ blueButton.update();
+ return answer ;
+}
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 605f70c19..14a2a84d9 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -319,9 +319,10 @@ struct jumpType {
jumpType jumpTypes[100];
unsigned int totalJumpTypes = 0;
unsigned int currentJumpType = 0;
-int totalJumps = 0;
+unsigned int totalJumps = 0;
//In simple jumps the firstPhase is the contact. In DropJumps the first phase is flight
bool waitingFirstPhase = true;
+bool capturingCurrentTest = false;
IntervalTimer rcaTimer;
@@ -402,6 +403,7 @@ void setup() {
currentJumpType = 0;
tft.fillScreen(BLACK);
+
drawMenuBackground();
backMenu();
showMenuEntry(currentMenuIndex);
@@ -1335,7 +1337,10 @@ void showPowerResults()
void jumpsCapture()
{
+
selectJumpType();
+ elapsedMicros totalTestTime;
+ capturingCurrentTest = true;
float maxJump = 0;
int bestJumper = 0;
float graphRange = 50;
@@ -1359,20 +1364,33 @@ void jumpsCapture()
//Print summary results
printTftText("H:", 10, 215, 2, WHITE, false);
printTftValue(maxJump, 58, 215, 2, 2);
- while ( !redButton.fell() )
+
+ while ( !redButton.fell())
{
- while (totalJumps < jumpTypes[currentJumpType].jumpLimit && !redButton.fell())
+ while (capturingCurrentTest && !redButton.fell())
{
//Person is changed
if ( blueButton.fell() ) {
currentPerson = (currentPerson + 1) % totalPersons;
updatePersonJump(totalJumps);
+ totalJumps = 0;
waitingFirstPhase = true;
}
+ //Check if hard time limit is active
+ if ( jumpTypes[currentJumpType].hardTimeLimit ) {
+ //Check if the limit is surpassed
+ if ( jumpTypes[currentJumpType].hardTimeLimit && jumpTypes[currentJumpType].timeLimit > 0 &&
totalTestTime >= (unsigned int)jumpTypes[currentJumpType].timeLimit * 1000000)
+ {
+ capturingCurrentTest = false;
+ }
+ }
//There's been a change in the mat state. Landing or taking off.
if (rcaFlag)
{
+// Serial.print("totalTestTime: ");
+// Serial.println(totalTestTime);
+// Serial.println("rcaFlag");
rcaFlag = false;
//Elapsed time in seconds
lastSampleTime = rcaTime - lastRcaTime;
@@ -1387,6 +1405,7 @@ void jumpsCapture()
if (rcaState)
{
Serial.println("R");
+
tft.fillRect(30, 0, 290, 200, BLACK);
bars[index] = 122.6 * lastPhaseTime * lastPhaseTime; //In cm
tft.setTextColor(BLACK);
@@ -1410,6 +1429,13 @@ void jumpsCapture()
totalJumps++;
updatePersonJump(totalJumps);
+ //Check the soft time limit
+ if ( jumpTypes[currentJumpType].timeLimit > 0 && totalTestTime >= (unsigned
int)jumpTypes[currentJumpType].timeLimit * 1000000)
+ {
+ Serial.println(totalTestTime);
+ capturingCurrentTest = false;
+ }
+
//Taking off. Ends contact. start of flight time
} else if (!rcaState && !waitingFirstPhase)
{
@@ -1419,35 +1445,61 @@ void jumpsCapture()
}
else if (waitingFirstPhase) {
waitingFirstPhase = false;
- if (rcaState)
+ //Starting timer
+ totalTestTime = 0;
+ if (rcaState == jumpTypes[currentJumpType].startIn)
{
Serial.println("R");
}
- else if (!rcaState) {
+ else if (rcaState != jumpTypes[currentJumpType].startIn) {
Serial.println("r");
}
}
saveSimpleJump(lastPhaseTime);
lastRcaState = rcaState;
lastRcaTime = rcaTime;
+
+ //Limited by jumps
+ if (jumpTypes[currentJumpType].jumpLimit > 0) {
+ if (totalJumps >= jumpTypes[currentJumpType].jumpLimit) {
+ capturingCurrentTest = false;
+ }
+ }
}
redButton.update();
blueButton.update();
}
- Serial.print("jumps = ");
- Serial.println(totalJumps);
+
+ //The current test has ended
+
+// Serial.print("jumps = ");
+// Serial.println(totalJumps);
+
waitingFirstPhase = true;
- nextJump("Red: Next test", 100, 6);
+ rcaFlag = false;
totalJumps = 0;
+ setNumber++;
+ totalTestTime = 0;
+
+ //check if the user wants to perform another one
+ if ( !yesNoDialog("Continue with " + jumpTypes[currentJumpType].name + "?", 10, 10)) break;
+
+ //If the user chooses yes continue and start over in the while(capturint)
+ redButton.update();
+ blueButton.update();
+ capturingCurrentTest = true;
}
- setNumber++;
+
showJumpsResults(maxJump, bestJumper, totalJumps);
drawMenuBackground();
+ redButton.update();
+ blueButton.update();
showMenuEntry(currentMenuIndex);
}
void dropJumpsCapture()
{
+ Serial.println("In dropJumps");
//Select falling heigth (optional)
float maxJump = 0;
int bestJumper = 0;
@@ -1557,7 +1609,7 @@ void dropJumpsCapture()
index = (index + 1) % 10;
totalJumps++;
updatePersonJump(totalJumps);
- nextJump("Red: Next jump", 100, 6);
+ yesNoDialog("Red: Next jump", 100, 6);
jumpStart = rcaState;
waitingFirstPhase = true;
}
@@ -1789,53 +1841,13 @@ void resultsBackground()
}
-void nextJump() {
- nextJump("", 0, 0, 2);
-}
-void nextJump(String message, float x, float y) {
- nextJump(message, x, y, 2);
-}
-void nextJump(String message, float x, float y, int fontSize)
+void printBarsValues(int currentIndex)
{
- int len = message.length();
- unsigned int w = 6 * fontSize * len;
- unsigned int h = 8 * fontSize;
- uint16_t backRect[w * h];
- tft.readRect(x, y, w, h, backRect);
-
- printTftText(message, x, y, RED);
- redButton.update();
- while ( !redButton.fell())
+ for (int i = 9; i > 0; i--)
{
- if ( blueButton.fell() ) {
- currentPerson = (currentPerson + 1) % totalPersons;
- updatePersonJump(totalJumps);
- waitingFirstPhase = true;
- }
- blueButton.update();
- redButton.update();
+ Serial.print(bars[i]);
+ if (i == currentIndex) Serial.print("*");
+ Serial.print("\t");
}
- printTftText(message, x, y, BLACK);
- tft.writeRect(x, y, w, h, backRect);
-}
-
-void waitingRedButton() {
- nextJump("", 0, 0, 2);
-}
-void waitingRedButton(String message, float x, float y) {
- nextJump(message, x, y, 2);
-}
-void waitingRedButton(String message, float x, float y, int fontSize)
-{
- int len = message.length();
- unsigned int w = 6 * fontSize * len;
- unsigned int h = 8 * fontSize;
- uint16_t backRect[w * h];
- tft.readRect(x, y, w, h, backRect);
-
- printTftText(message, x, y, RED);
- redButton.update();
- while ( !redButton.fell()) redButton.update();
- printTftText(message, x, y, BLACK);
- tft.writeRect(x, y, w, h, backRect);
+ Serial.println();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]