Modifications

Sauter à la navigation Sauter à la recherche
418 octets ajoutés ,  4 avril 2019 à 17:08
aucun résumé de modification
Ligne 183 : Ligne 183 :  
{{ADFImage|IR-codecompareok.jpg}}
 
{{ADFImage|IR-codecompareok.jpg}}
   −
This loop, as it goes through each pulse, does a little math. It compares the absolute ('''abs()''') difference between the code we heard and the code we're trying to match abs(oncode - ApplePlaySignal[i*2 + 0]) and then makes sure that the error is less than FUZZINESS percent of the code length (oncode * FUZZINESS / 100)
+
Cette fonction {{fname|loop()}}, est exécutée pour chaque impulsion, fait quelques opérations mathématique. Elle compare la différence absolue ({{fname|abs()}}) entre ce que code réceptionne (IR reçu) et le code auquel nous essayons de le faire correspondre {{fname|abs(oncode - ApplePlaySignal[i*2 + 0])}} et ensuire s'assurer que l'erreur est inférieure FUZZINESS pourcent de la longueur du code
 +
( {{fname| oncode * FUZZINESS / 100}} )
   −
We found we had to tweak the stored values a little to make them match up 100% each time. IR is not a precision-timed protocol so having to make the FUZZINESS 20% or more is not a bad thing
+
Il est généralement nécessaire d'adapter un peu les valeurs stockées pour obtenir 100% correspondance à chaque fois. Le signal infrarouge n'est pas un protocol qui s'appuie sur la précision temporelle (''not a precision-timed protocol''), par conséquent une marge d'erreur de 20% (FUZZINESS=20%) et plus n'est pas une mauvaise chose.
    
Finally, we can turn the '''loop()''' into its own function which will retunr '''true''' or '''false''' depending on whether it matched the code we ask it to. We also commented out the printing functions
 
Finally, we can turn the '''loop()''' into its own function which will retunr '''true''' or '''false''' depending on whether it matched the code we ask it to. We also commented out the printing functions
    
  <nowiki>
 
  <nowiki>
    boolean IRcompare(int numpulses, int Signal[]) {
+
boolean IRcompare(int numpulses, int Signal[]) {
 
     for (int i=0; i< numpulses-1; i++) {
 
     for (int i=0; i< numpulses-1; i++) {
    int oncode = pulses[i][1] * RESOLUTION / 10;
+
        int oncode = pulses[i][1] * RESOLUTION / 10;
    int offcode = pulses[i+1][0] * RESOLUTION / 10;
+
        int offcode = pulses[i+1][0] * RESOLUTION / 10;
    /*
+
 
    Serial.print(oncode); // the ON signal we heard
+
        /*
    Serial.print(" - ");
+
        Serial.print(oncode); // Le signal ON reçu
    Serial.print(Signal[i*2 + 0]); // the ON signal we want
+
        Serial.print(" - ");
    */
+
        Serial.print(Signal[i*2 + 0]); // Le signal ON attendu
    // check to make sure the error is less than FUZZINESS percent
+
        */
    if ( abs(oncode - Signal[i*2 + 0]) <= (Signal[i*2 + 0] * FUZZINESS / 100)) {
+
        // Vérifier que l'erreur est inférieure à FUZZINESS pourcent
    //Serial.print(" (ok)");
+
        if ( abs(oncode - Signal[i*2 + 0]) <= (Signal[i*2 + 0] * FUZZINESS / 100)) {
    } else {
+
            //Serial.print(" (ok)");
    //Serial.print(" (x)");
+
        } else {
    // we didn't match perfectly, return a false match
+
            //Serial.print(" (x)");
    return false;
+
            // Pas de correspondance parfaite, retourner false
    }
+
            return false;
     /*
+
        }
    Serial.print(" \t"); // tab
+
      
    Serial.print(offcode); // the OFF signal we heard
+
        /*
    Serial.print(" - ");
+
        Serial.print(" \t"); // tabulation
    Serial.print(Signal[i*2 + 1]); // the OFF signal we want
+
        Serial.print(offcode); // Le signal OFF reçu
    */
+
        Serial.print(" - ");
    if ( abs(offcode - Signal[i*2 + 1]) <= (Signal[i*2 + 1] * FUZZINESS / 100)) {
+
        Serial.print(Signal[i*2 + 1]); // Le signal OFF que nous attendons
    //Serial.print(" (ok)");
+
        */
    } else {
+
        if ( abs(offcode - Signal[i*2 + 1]) <= (Signal[i*2 + 1] * FUZZINESS / 100)) {
    //Serial.print(" (x)");
+
          //Serial.print(" (ok)");
    // we didn't match perfectly, return a false match
+
        } else {
    return false;
+
          //Serial.print(" (x)");
    }
+
          // Pas de correspondance parfaite, retourner false
    //Serial.println();
+
          return false;
 +
        }
 +
        //Serial.println();
 
     }
 
     }
     // Everything matched!
+
     // Tout correspond!
 
     return true;
 
     return true;
    }
+
}
 
</nowiki>
 
</nowiki>
  −
      
We then took more IR command data for the 'rewind' and 'fastforward' buttons and put all the code array data into ircodes.h to keep the main sketch from being too long and unreadable ([http://github.com/adafruit/IR-Commander vous pouvez obtenir tout le code depuis le GitHib d'AdaFruit)
 
We then took more IR command data for the 'rewind' and 'fastforward' buttons and put all the code array data into ircodes.h to keep the main sketch from being too long and unreadable ([http://github.com/adafruit/IR-Commander vous pouvez obtenir tout le code depuis le GitHib d'AdaFruit)
Ligne 251 : Ligne 252 :  
     }
 
     }
 
</nowiki>
 
</nowiki>
  −
      
We check against all the codes we know about and print out whenever we get a match. You could now take this code and turn it into something else, like a robot that moves depending on what button is pressed.
 
We check against all the codes we know about and print out whenever we get a match. You could now take this code and turn it into something else, like a robot that moves depending on what button is pressed.
29 895

modifications

Menu de navigation