Modifications

Sauter à la navigation Sauter à la recherche
807 octets ajoutés ,  23 novembre 2013 à 20:38
Ligne 477 : Ligne 477 :  
}</nowiki>
 
}</nowiki>
   −
Set up a function to handle analog calls in the same fashion, except setting the key to A instead of D when working with the analog input pins :  
+
Mettre en place une fonction qui gère les appels analogique. Cette fonction est fort similaire à celle qui gère les appels digitaux, excepté que la clé utilise un A à la place d'un D pour stocker la valeur dans de la broche d'entrée dans le DataStore :  
    
  <nowiki>void analogCommand(YunClient client) {
 
  <nowiki>void analogCommand(YunClient client) {
 
   int pin, value;
 
   int pin, value;
 
+
  // Obtenir le numéro de broche depuis l'URL
 
   pin = client.parseInt();
 
   pin = client.parseInt();
    +
  // S'il y a une "/" après...
 
   if (client.read() == '/') {
 
   if (client.read() == '/') {
 +
    // cela signifie que l'on fixe la valeur de la broche
 
     value = client.parseInt();
 
     value = client.parseInt();
 
     analogWrite(pin, value);
 
     analogWrite(pin, value);
   −
     // Send feedback to client
+
     // renvoyer une réponse au client
 
     client.print(F("Pin D"));
 
     client.print(F("Pin D"));
 
     client.print(pin);
 
     client.print(pin);
Ligne 494 : Ligne 496 :  
     client.println(value);
 
     client.println(value);
    +
    // Valeur de la clé pour le DataStore
 
     String key = "D";
 
     String key = "D";
 
     key += pin;
 
     key += pin;
 +
    // Stockage de la "Clé = Valeur" dans le DataStore
 
     Bridge.put(key, String(value));
 
     Bridge.put(key, String(value));
 
   }
 
   }
 
   else {
 
   else {
 +
    // Si pas de "/" après le numéro de broche, c'est que
 +
    // l'on désire lire la valeur de la broche
 
     value = analogRead(pin);
 
     value = analogRead(pin);
    +
    // renvoyer une réponse au client
 
     client.print(F("Pin A"));
 
     client.print(F("Pin A"));
 
     client.print(pin);
 
     client.print(pin);
Ligne 506 : Ligne 513 :  
     client.println(value);
 
     client.println(value);
    +
    // Stockage de la "Clé = Valeur" dans le DataStore
 
     String key = "A";
 
     String key = "A";
 
     key += pin;
 
     key += pin;
Ligne 512 : Ligne 520 :  
}</nowiki>
 
}</nowiki>
   −
Create one more function to handle pin mode changes. Accept the YunClient as the argument, and create a local variable to hold the pin number. Read the pin value just as you did in the digital and analog functions.  
+
Créer une ou plusieurs fonctions pour gérer les changement de mode des broches. Accepter un YunClient comme argument, et créer une variable locale pour maintenir le numéro de broches. Lire la valeur de la broche comme nous l'avons fait dans les fonctions de traitement des commandes "digital" et "analog".  
    
  <nowiki>void modeCommand(YunClient client) {
 
  <nowiki>void modeCommand(YunClient client) {
 
   int pin;
 
   int pin;
 +
  // Obtenir le numéro de broche depuis l'URL
 
   pin = client.parseInt();</nowiki>
 
   pin = client.parseInt();</nowiki>
   −
Check to make sure the URL is valid
+
Vérifier que l'URL est bien valide. Il fait absolument un paramètre en plus, et donc un "/" après le numéro de broche
    
  <nowiki>  if (client.read() != '/') {
 
  <nowiki>  if (client.read() != '/') {
Ligne 525 : Ligne 534 :  
   }</nowiki>
 
   }</nowiki>
   −
If it's a valid URL, store the URL as a string. If the mode is an ''input'' or ''output'', configure the pin and report it to client. If the string doesn't match those values, return an error.  
+
Et si l'URL est If it's a valid URL, store the URL as a string. If the mode is an ''input'' or ''output'', configure the pin and report it to client. If the string doesn't match those values, return an error.  
    
  <nowiki>  if (mode == "input") {
 
  <nowiki>  if (mode == "input") {
29 917

modifications

Menu de navigation