[chronojump/michrolab] Group selecting in system menu



commit 02f235d1b9a4a9c77b891fcc867c4bbe490dca5a
Author: Xavier Padullés <testing chronojump org>
Date:   Wed Jun 8 22:27:07 2022 +0200

    Group selecting in system menu

 arduino/michrolab/michrolab.ino     | 16 +++++++++++++---
 arduino/michrolab/personsManage.ino | 20 +++++++++++++++-----
 2 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index e5a54ee59..cb6bbe038 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -70,6 +70,7 @@ int numRepetitions = 0;
 int tareAddress = 0;
 int calibrationAddress = 4;
 int forceGoalAddress = 8;
+int groupAddress = 12;
 
 
 #define DOUT  2
@@ -169,6 +170,7 @@ menuEntry mainMenu[10] = {
 int mainMenuItems = 8;
 
 menuEntry systemMenu[10] {
+  { "Group", "Select the group you are going to use.\nUp to 9 groups can be\nselected", &selectGroup},
   { "Tare", "Set the offset of the\nsensor.", &tare },
   { "Calibrate", "Set the equivalence\nbetween the sensor values\nand the force measured.", &calibrateTFT },
   { "Force Goal", "Set the goal force for\nsteadiness measurements.", &setForceGoal },
@@ -177,11 +179,10 @@ menuEntry systemMenu[10] {
   { "Exit", "Goes back to main menu", &backMenu },
   { "", "", &backMenu},
   { "", "", &backMenu},
-  { "", "", &backMenu},
   { "", "", &backMenu}
 };
 
-int systemMenuItems = 6;
+int systemMenuItems = 7;
 
 menuEntry currentMenu[10];
 
@@ -285,6 +286,7 @@ unsigned int setNumber = 0;
 unsigned int dirNumber;
 String dirName = "";
 String fileName = "";
+unsigned short group = 0;
 
 struct personType {
   unsigned int index;
@@ -328,7 +330,15 @@ void setup() {
 
   EEPROM.get(forceGoalAddress, forceGoal);
   if (isnan(forceGoal)) {
-    EEPROM.put(forceGoal, 300);
+    EEPROM.put(forceGoalAddress, 300);
+  }
+
+  EEPROM.get(groupAddress, group);
+  Serial.print("Group: ");
+  Serial.println(group);
+  if (group == 65535) {
+    group = 0;
+    EEPROM.put(groupAddress, 0);
   }
 
   //Start TFT
diff --git a/arduino/michrolab/personsManage.ino b/arduino/michrolab/personsManage.ino
index be4601558..0ec91db8f 100644
--- a/arduino/michrolab/personsManage.ino
+++ b/arduino/michrolab/personsManage.ino
@@ -60,10 +60,10 @@ void readPersonsFile()
   */
   String row = "";
   char readChar;
-  File  personsFile = SD.open("persons.txt");
+  String filename = "group"+String(group)+".txt";
+  File  personsFile = SD.open(filename);
   if (personsFile)
   {
-
     currentPerson = 0;
     personsFile.seek(0);
 
@@ -85,7 +85,7 @@ void readPersonsFile()
     personsFile.close();
   } else {
     // if the file didn't open, print an error:
-    Serial.println("error opening persons.txt");
+    Serial.println("error opening " + filename);
   }
 }
 
@@ -93,7 +93,8 @@ unsigned int getTotalPerson()
 {
   char readChar;
   String readString = "";
-  File  personsFile = SD.open("persons.txt");
+  String filename = "group"+String(group)+".txt";
+  File  personsFile = SD.open(filename);
   if (personsFile)
   {
     //Start reading from the last byte
@@ -115,7 +116,6 @@ unsigned int getTotalPerson()
       readString = readString + readChar;
     }
   }
-
   totalPersons = readString.toInt() + 1;
   return (totalPersons);
 }
@@ -139,3 +139,13 @@ void updatePersonSet()
   tft.print(persons[currentPerson].name + " " + persons[currentPerson].surname);
   tft.setTextSize(2);
 }
+
+void selectGroup()
+{
+  group = selectValueDialog("", "Select the group number", "0,9", "1", 0);
+  EEPROM.put(groupAddress, group);
+  totalPersons = getTotalPerson();
+  readPersonsFile();
+  menuItemsNum = systemMenuItems;
+  showMenuEntry(currentMenuIndex);
+}


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