[chronojump/michrolab] Initial code for jump types management
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/michrolab] Initial code for jump types management
- Date: Mon, 18 Jul 2022 17:40:32 +0000 (UTC)
commit 07336c3dee979b4061fb4a3982e481be3410b2e2
Author: Xavier Padullés <testing chronojump org>
Date: Mon Jul 18 19:39:24 2022 +0200
Initial code for jump types management
arduino/michrolab/exercsiseManage.ino | 97 +++++++++++++++++++++++++++++++++++
arduino/michrolab/michrolab.ino | 14 +++++
2 files changed, 111 insertions(+)
---
diff --git a/arduino/michrolab/exercsiseManage.ino b/arduino/michrolab/exercsiseManage.ino
new file mode 100644
index 000000000..51ed3427e
--- /dev/null
+++ b/arduino/michrolab/exercsiseManage.ino
@@ -0,0 +1,97 @@
+void readJumpsFile(){
+ /*
+ Example of jumpsTypes.txt
+ 0,SJ,1
+ 1,CMJ,1
+ 2,ABK,1
+ 3,DJna,0
+ 4,SJl,1
+ */
+ String row = "";
+ char readChar;
+ File jumpsFile = SD.open("jumpTypes.txt");
+ if (jumpsFile)
+ {
+ currentJumpType = 0;
+ jumpsFile.seek(0);
+
+ // read from the file until there's nothing else in it:
+ while (currentJumpType < totalJumpTypes)
+ {
+ readChar = jumpsFile.read();
+ Serial.println("-");
+ if (readChar != '\n' && readChar != '\r')
+ {
+ row = row + readChar;
+ } else if (readChar == '\n' || readChar == '\r')
+ {
+ addJump(row);
+ row = "";
+ currentJumpType++;
+ }
+ Serial.println(row);
+ }
+ // close the file:
+ jumpsFile.close();
+ } else {
+ // if the file didn't open, print an error:
+ Serial.println("error opening jumpTypes.txt");
+ }
+}
+
+void addJump(String row)
+{
+ int prevComaIndex = row.indexOf(":");
+ int nextComaIndex = row.indexOf(",");
+ currentJumpType = row.substring(prevComaIndex + 1, nextComaIndex).toInt();
+ jumpTypes[currentJumpType].id = currentJumpType;
+
+ if (currentJumpType >= totalJumpTypes) totalJumpTypes = currentJumpType + 1;
+ prevComaIndex = nextComaIndex;
+ nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+ jumpTypes[currentJumpType].name = row.substring(prevComaIndex + 1 , nextComaIndex);
+ prevComaIndex = nextComaIndex;
+
+ nextComaIndex = row.indexOf(",", prevComaIndex + 1 );
+ jumpTypes[currentJumpType].startIn = (row.substring(prevComaIndex + 1 , nextComaIndex) == "1");
+}
+
+unsigned int getTotalJumpTypes()
+{
+ char readChar;
+ String readString = "";
+ File jumpsFile = SD.open("jumpTypes.txt");
+ if (jumpsFile)
+ {
+ //Start reading from the last byte
+ unsigned long pos = jumpsFile.size() - 4;
+
+ //Reading the jump number of the last row
+ while (readChar != '\n' && readChar != '\r')
+ {
+ jumpsFile.seek(pos);
+ readChar = jumpsFile.peek();
+ pos--;
+ }
+ pos++;
+ jumpsFile.seek(pos);
+ readChar = jumpsFile.read();
+ while (readChar != ',')
+ {
+ readChar = jumpsFile.read();
+ readString = readString + readChar;
+ }
+ }
+ totalJumpTypes = readString.toInt() + 1;
+ return (totalJumpTypes);
+}
+
+void printJumpTypesList()
+{
+ for (unsigned int i = 0; i < totalJumpTypes; i++)
+ {
+ Serial.print(jumpTypes[i].id);
+ Serial.print("," + jumpTypes[i].name + ",");
+ Serial.println(jumpTypes[i].startIn);
+ }
+}
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 7556dec6f..0621dc574 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -301,6 +301,16 @@ struct personType {
unsigned int totalPersons = 0;
personType persons[100];
+struct jumpType {
+ int id;
+ String name;
+ bool startIn; //If the time of contact is required, start outside or start inside but make a previous
jump
+};
+
+jumpType jumpTypes[100];
+unsigned int totalJumpTypes = 0;
+unsigned int currentJumpType = 0;
+
IntervalTimer rcaTimer;
void setup() {
@@ -387,6 +397,10 @@ void setup() {
// delay(100);
// }
+ Serial.println(getTotalJumpTypes());
+ readJumpsFile();
+ printJumpTypesList();
+
tft.fillScreen(BLACK);
drawMenuBackground();
showMenuEntry(currentMenuIndex);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]