[chronojump/michrolab] Fixed last key value in selectValuesDialog
- From: Xavier Padullés <xpadulles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump/michrolab] Fixed last key value in selectValuesDialog
- Date: Thu, 9 Jun 2022 08:34:11 +0000 (UTC)
commit c1318de67d59064020ed01c38110209b97007fdd
Author: Xavier Padullés <testing chronojump org>
Date: Thu Jun 9 10:33:31 2022 +0200
Fixed last key value in selectValuesDialog
arduino/michrolab/menus.ino | 12 +++++++-----
arduino/michrolab/michrolab.ino | 7 +++----
arduino/michrolab/personsManage.ino | 2 +-
3 files changed, 11 insertions(+), 10 deletions(-)
---
diff --git a/arduino/michrolab/menus.ino b/arduino/michrolab/menus.ino
index 9e819ea19..9d270ef71 100644
--- a/arduino/michrolab/menus.ino
+++ b/arduino/michrolab/menus.ino
@@ -101,13 +101,14 @@ void drawLeftButton(String label, uint16_t tColor, uint16_t bColor)
}
//Dialog for selecting float value
-float selectValueDialog(String title, String description, String rangesString, String incString, unsigned
int decimals)
+float selectValueDialog(String description, String rangesString, String incString, unsigned int decimals)
{
//ranges are of the format "1,10,500"
//increments are in the format of "2,10"
//From 1..10 increment by 2
//From 10..500 increment by 10
//increments must have the number of ranges elements -1
+ //Maximum number of ranges is 10 (11 key values)
int prevColon = 0;
int nextColon = rangesString.indexOf(",");
unsigned int rangesNum = 0;
@@ -119,7 +120,7 @@ float selectValueDialog(String title, String description, String rangesString, S
prevColon = nextColon + 1;
nextColon = rangesString.indexOf(",", prevColon);
} while (nextColon != -1);
- float rangesValues[10];
+ float rangesValues[11];
float incValues[10];
//Assigning key values of the ranges
@@ -149,8 +150,8 @@ float selectValueDialog(String title, String description, String rangesString, S
//Delete description
tft.fillRect(0, 50, 320, 190, BLACK);
- tft.setCursor(30, 80);
- tft.print(title);
+// tft.setCursor(30, 80);
+// tft.print(title);
//Explanation of the process
tft.setTextColor(WHITE);
@@ -181,13 +182,14 @@ float selectValueDialog(String title, String description, String rangesString, S
printTftFormat(value, 236, 174, 2, decimals);
value += incValues[currentSegment - 1];
- if (abs(value - rangesValues[rangesNum]) < 0.0001) {
+ if (abs(value - rangesValues[rangesNum] - incValues[currentSegment - 1]) < 0.0001) {
tft.setTextColor(BLACK);
printTftFormat(value, 236, 174, 2, decimals);
value = rangesValues[0];
currentSegment = 1;
drawLeftButton("+" + String(incValues[currentSegment - 1], decimals), WHITE, BLUE);
}
+ //Sometimes float values are not exatcly the expected one
if (abs(value - rangesValues[currentSegment]) < 0.0001)
{
currentSegment++;
diff --git a/arduino/michrolab/michrolab.ino b/arduino/michrolab/michrolab.ino
index 1486ae81b..66e8a6ba3 100644
--- a/arduino/michrolab/michrolab.ino
+++ b/arduino/michrolab/michrolab.ino
@@ -371,7 +371,6 @@ void setup() {
totalPersons = getTotalPerson();
readPersonsFile();
-
for (int i = 0; i < 10; i++) {
currentMenu[i].title = mainMenu[i].title;
currentMenu[i].description = mainMenu[i].description;
@@ -731,7 +730,7 @@ void changingRCA() {
}
void calibrateTFT(void) {
- float weight = selectValueDialog("", "Select the weight to use", "1,5,100", "1,5", 0);
+ float weight = selectValueDialog("Select the weight to use", "1,5,100", "1,5", 0);
String calibrateCommand = "calibrate:" + String(weight, DEC) + ";";
calibrate(calibrateCommand);
tft.setTextColor(WHITE);
@@ -1171,7 +1170,7 @@ void startEncoderCapture(void)
avgVelocity = 0;
maxAvgVelocity = 0;
lastVelocity = 0;
- selectValueDialog("Load", "Select the load you are\ngoing to move", "0,5,20,200", "0.5,1,5", 1);
+ selectValueDialog("Select the load you are\ngoing to move", "0,5,20,200", "0.5,1,5", 1);
capture();
}
@@ -1334,7 +1333,7 @@ void startJumpsCapture()
void setForceGoal()
{
- forceGoal = selectValueDialog("", "Select the force goal in Newtons.\nAn horizontal red line will be
drawn", "10,50,1000,10000", "10,100,500", 0);
+ forceGoal = selectValueDialog("Select the force goal in Newtons.\nAn horizontal red line will be drawn",
"10,50,1000,10000", "10,100,500", 0);
Serial.println(forceGoal);
menuItemsNum = systemMenuItems;
showMenuEntry(currentMenuIndex);
diff --git a/arduino/michrolab/personsManage.ino b/arduino/michrolab/personsManage.ino
index 1f5dc46f5..341745d2a 100644
--- a/arduino/michrolab/personsManage.ino
+++ b/arduino/michrolab/personsManage.ino
@@ -142,7 +142,7 @@ void updatePersonSet()
void selectGroup()
{
- group = selectValueDialog("", "Select the group number", "0,9", "1", 0);
+ group = selectValueDialog("Select the group number", "0,9", "1", 0);
EEPROM.put(groupAddress, group);
totalPersons = getTotalPerson();
readPersonsFile();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]