Browse Source

bug fixe on data receved with arduino

Valentin 2 years ago
parent
commit
764ee78830

+ 2 - 2
Pigou/arduinoPort.pf

@@ -1,3 +1,3 @@
-A;COM3
-B;COM4
+A;COM4
+B;COM6
 C;COM2

+ 35 - 35
Pigou/config.pf

@@ -1,70 +1,70 @@
 B;9
-C;16
+C;11
 B;13
-C;20
+C;11
 B;11
-C;18
+C;11
 B;12
-C;19
+C;11
 B;10
-C;17
+C;11
 A;10
-C;2
-B;3
-C;8
-C;9
+C;11
+C;13
+C;11
+C;11
 B;0
-C;5
+C;11
 B;2
-C;7
+C;11
 B;1
-C;6
+C;11
 A;11
-C;3
+C;11
 A;12
+C;11
+C;11
 C;4
-C;10
-C;4
-C;26
+C;11
 C;7
-C;31
+C;11
 C;6
-C;28
+C;11
 C;5
-C;27
-C;29
-C;30
+C;11
+C;11
+C;11
 C;8
-C;32
 C;11
-C;34
+C;11
+C;11
 C;10
 C;12
 C;13
 C;11
-C;35
+C;11
 C;9
-C;33
+C;11
 C;0
-C;22
+C;11
 B;6
 B;7
 B;8
-C;15
+C;11
 C;1
-C;23
+C;11
 C;2
-C;24
+C;11
 B;5
-C;14
+C;11
 B;4
-C;13
+C;11
 B;14
-C;21
+C;11
 C;3
-C;25
-C;12
-A;0
+C;11
+C;11
+C;11
 A;1
 A;2
 A;3

+ 18 - 0
Pigou/src/fr/deltastar/pigou/communication/SerialClient.java

@@ -10,6 +10,7 @@ import java.io.BufferedReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
+import java.sql.Timestamp;
 import java.util.TooManyListenersException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -28,6 +29,8 @@ public class SerialClient implements ComClientInterface, SerialPortEventListener
     private BufferedReader in;
     private PrintWriter out;
     
+    private long lastTimeInputPressed;
+    
     private ListenerComInterface listenerCom;
     
     /**
@@ -53,6 +56,7 @@ public class SerialClient implements ComClientInterface, SerialPortEventListener
             }
             //connexion au port com et configuration
             this.serialPort = (SerialPort)this.portIdentifier.open(nameCom, 2000);
+            this.lastTimeInputPressed = System.currentTimeMillis();
             this.serialPort.setSerialPortParams(Constants.SERIALCOM_DEBIT_COMMUNICATION, SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
             this.in = new BufferedReader(new InputStreamReader(serialPort.getInputStream()));
             
@@ -90,6 +94,20 @@ public class SerialClient implements ComClientInterface, SerialPortEventListener
                     this.in.read(result);
                     input = input + String.valueOf(result[0]) + String.valueOf(result[1]);
                 } while (input.trim().length() < 2);
+                //filtrage des espaces
+                input = input.replaceAll(" ", "");
+
+                //pour pallier au problème de la carte qui envoi une trop grande quantité d'infos au départ
+                //si la dernière action est trop rapide elle ne peut provenir d'un humain
+                if ((System.currentTimeMillis() - this.lastTimeInputPressed) < 250) {
+                    System.out.println("Stopping input too fast");
+                    this.lastTimeInputPressed = System.currentTimeMillis();
+                    return;
+                }
+                this.lastTimeInputPressed = System.currentTimeMillis();
+
+                //envoi de l'infos
+                System.out.println("Data receved : " + input);
                 listenerCom.onDataReceved(input);
                 if (StatusComViewController.getInstance() != null)
                     StatusComViewController.getInstance().addDataInput(input);

+ 1 - 1
Pigou/src/fr/deltastar/pigou/constant/Constants.java

@@ -84,7 +84,7 @@ public class Constants {
     public static String AUTOCONFIG_VIEW_NB_OUTPUT = "%d / %d output";
     public static String AUTOCONFIG_VIEW_NB_TOTAL = "Total progress %d / %d I/O";
     public static String AUTOCONFIG_MSG_CHOOSEOUTPUT = "Please choose a valid output before next";
-    public static String AUTO_CONFIG_MSG_OUTPUTPROGRESS = "Configuration output in progress look at Deltastar and clic on the component on";
+    public static String AUTO_CONFIG_MSG_OUTPUTPROGRESS = "Configuration output in progress, clic on the start button and look at Deltastar and clic on the component on";
     public static String AUTO_CONFIG_MSG_OUTPUTFINISH = "Configuration output is finish, launch configuration input";
     public static String AUTO_CONFIG_MSG_FINISH = "Configuration finished, have fun !";
     

+ 26 - 3
Pigou/src/fr/deltastar/pigou/controller/SettingsAutoConfigController.java

@@ -10,6 +10,7 @@ import fr.deltastar.pigou.model.panel.Component;
 import fr.deltastar.pigou.model.panel.DeltaStar;
 import fr.deltastar.pigou.service.ServicePigou;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.ResourceBundle;
 import javafx.application.Platform;
@@ -29,6 +30,8 @@ public class SettingsAutoConfigController extends BaseViewController implements
     private List<Component> listComponentsOutput;
     private List<Component> listComponentsInput;
     
+    private int[] listInputAlreadyPressed;
+    
     private List<ComArduino> listComArduino;
     
     //utiliser pour la boucle de paramétrage
@@ -71,6 +74,10 @@ public class SettingsAutoConfigController extends BaseViewController implements
         this.totalNb = this.listComponentsInput.size() + this.listComponentsOutput.size();
         this.totalNbOutput = this.listComponentsOutput.size();
         
+        this.listInputAlreadyPressed = new int[this.totalNbInput];
+        for (int i = 0; i < this.listInputAlreadyPressed.length; i++)
+            this.listInputAlreadyPressed[i] = -1;
+        
         this.lNbOutput.setText(String.format(Constants.AUTOCONFIG_VIEW_NB_OUTPUT, this.currentNbOutputArduino, this.totalNbOutput));
         this.lNbInput.setText(String.format(Constants.AUTOCONFIG_VIEW_NB_INPUT, this.currentNbInput, this.totalNbInput));
         this.lNbTotal.setText(String.format(Constants.AUTOCONFIG_VIEW_NB_TOTAL, this.currentNbTotal, this.totalNb));
@@ -84,6 +91,13 @@ public class SettingsAutoConfigController extends BaseViewController implements
      */
     @FXML
     public void btnNextClick() {
+        //cas du premier clic
+        if (this.btnNext.getText().equals("Start")) {
+            this.btnNext.setText("Next");
+            this.nextStep();
+            return;
+        }
+        
         //recupere output selectionné
         Component cSelect = this.ttvpOutput.getSelectedComponent();
         if (cSelect != null) {
@@ -110,9 +124,19 @@ public class SettingsAutoConfigController extends BaseViewController implements
     public void onDataReceved(String data) {
         //empèche une étape suivante tant qu'on a pas finis le mode output
         if (this.totalNbOutput == this.currentNbOutput) {
+            //si touche déja préssé on l'ignore
+            int dataInt = Integer.parseInt(data);
+            for (int i = 0; i < this.listInputAlreadyPressed.length; i++) {
+                if (this.listInputAlreadyPressed[i] == dataInt) {
+                    System.out.println("Input " + dataInt + " is already pressed");
+                    return;
+                }
+            }
+            this.listInputAlreadyPressed[this.currentNbInput - 1] = dataInt;
+            
             //Arduino C est le seul a fournir les entrées
             this.currentComponentInput.setComArduino(ServicePigou.getComArduinoService().getArduinoC());
-            this.currentComponentInput.setIdPos(Integer.parseInt(data));
+            this.currentComponentInput.setIdPos(dataInt);
             this.nextStep();
         }
     }
@@ -198,7 +222,7 @@ public class SettingsAutoConfigController extends BaseViewController implements
         if (ServicePigou.getComArduinoService().isFullConnected()) {
             this.listComArduino = ServicePigou.getComArduinoService().getAllArduino();
             ServicePigou.getMessageService().displayInfo(Constants.AUTO_CONFIG_MSG_OUTPUTPROGRESS);
-            this.nextStep();
+            //this.nextStep();
         }
     }
 
@@ -208,5 +232,4 @@ public class SettingsAutoConfigController extends BaseViewController implements
         super.navigate(ListView.SETTINGS);
     }
     
-    
 }

+ 1 - 1
Pigou/src/fr/deltastar/pigou/view/SettingsAutoConfig.fxml

@@ -29,7 +29,7 @@
             </Label>
             <ProgressBar fx:id="pbTotal" layoutX="52.0" layoutY="539.0" prefHeight="35.0" prefWidth="735.0" progress="0.0" stylesheets="@../resources/css/baseStyle.css"/>
             <Label fx:id="lNbOutput" layoutX="52.0" layoutY="404.0" text="1 / 40 output" textFill="WHITE" />
-            <Button fx:id="btnNext" layoutX="351.0" layoutY="424.0" mnemonicParsing="false" prefHeight="43.0" prefWidth="92.0" text="Next" onAction="#btnNextClick" />
+            <Button fx:id="btnNext" layoutX="351.0" layoutY="424.0" mnemonicParsing="false" prefHeight="43.0" prefWidth="92.0" text="Start" onAction="#btnNextClick" />
             <Label fx:id="lNbTotal" layoutX="52.0" layoutY="510.0" text="Total progress 1 / 80 I/O" textFill="WHITE" />
             <Label fx:id="lNbInput" layoutX="494.0" layoutY="174.0" text="1 / 40 input" textFill="WHITE" visible="false"  />
          </children>

BIN
panel/DSC_0071.JPG