Modifications

Sauter à la navigation Sauter à la recherche
652 octets ajoutés ,  15 août 2016 à 15:41
aucun résumé de modification
Ligne 1 : Ligne 1 :  
{{RASP-PYGAME-GUI-NAV}}
 
{{RASP-PYGAME-GUI-NAV}}
  −
{{traduction}}
      
== Entrée Analogique ==
 
== Entrée Analogique ==
Ligne 84 : Ligne 82 :     
== Le thread du potentiomètre ==
 
== Le thread du potentiomètre ==
A thread is used to constantly read the potentiometer. If you take the reading in-line in the scene update method then you'll slow down the screen refresh rate. This separate thread allows the screen to be redrawn in parallel with us reading a value from the ADC.
+
Un thread est utilisé pour lire continuellement la valeur du potentiomètre. Si l'on fait la lecture du potentiomètre dans la mise-à-jour de la Scene alors le taux de rafraîchissement de l'écran diminuera de façon importante.
 +
 
 +
Ce thread séparé permet à l'écran d'être redessiné en même temps (en parallèle) que la lecture de la valeur depuis l'ADC.
   −
The class is defined as a callable - hence the {{đname|__call__}} method. It takes a reference to the pitft class so we can update values on it. There's a simple termination scheme used by checking a flag on every loop. Later on you'll see how we cleanly close the program by setting this flag.
+
La classe est définie comme {{fname|callable}} appela - d'où la méthode {{fname|__call__}}. Il prend une référence vers la classe pitft de sorte qu'il est possible d'y mettre les valeurs à-jour. Il y a un schéma d'arrêt relativement simple basé sur la vérification d'un variable (un ''flag''/''drapeau'') à chaque tour de boucle. Nous verrons plus tard comment terminer proprement le programme en modifiant la variable ''flag''.
   −
So we simply read the voltage value from the ADC and set the label and progress bar position on the pitft.  
+
Donc, nous lisons simplement la valeur depuis l'ADC et modifie la valeur du libellé et la position de la barre de progression (visible sur le pitft).  
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 101 : Ligne 101 :  
     def __call__(self):
 
     def __call__(self):
 
         while not self.terminated:
 
         while not self.terminated:
             # Read channel 0 in single-ended mode using the settings above
+
             # Lecture du canal 0 en mode single-ended en utilisant la configuration ci-avant
 
             volts = adc.readADCSingleEnded(0, gain, sps) / 1000
 
             volts = adc.readADCSingleEnded(0, gain, sps) / 1000
 
             self.pitft.set_volts_label(volts)
 
             self.pitft.set_volts_label(volts)
Ligne 107 : Ligne 107 :  
</syntaxhighlight>
 
</syntaxhighlight>
    +
== Définition de l'interface utilisateur ==
 +
Nous avons ajouté quelques widget supplémentaires sur la Scene et modifié la taille des boutons (pour que tout se présente correctement).
 +
 +
Nous allons afficher la tension sur un widget label (''libellé'') et un widget progress (''barre de progression'').
   −
== Définition de l'interface utilisateur ==
+
Les méthodes {{fname|set_progress}} et {{fname|set_volts_label}} sont appelées depuis le thread PotReader pour faire la mise-à-jour des valeurs dans ces Widgets.
We've added a couple more widgets to the scene now and resized the buttons to accommodate them. We're showing the voltage on a label and a progress widget. The {{fname|set_progress}} and {{fname|set_volts_label}} methods are called from the PotReader thread to update the values in these widgets.
      
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 161 : Ligne 164 :     
== Et pour finir... ==
 
== Et pour finir... ==
To start everything going we initialise pygameui, construct the pitft class and then start the potreader thread with a reference to pitft.
+
Pour démarrer le programme nous initialisons pygameui, construisons la classe pitft class et démarrons le thread potreader avec le pitft en référence.
   −
Since we're running this extra thread we need a clean way to stop the program. A signal handler is used to trap ctrl+c and terminate the PotReader thread before calling sys.exit - otherwise the program will not close.
+
Puisque nous exécutons un thread supplémentaire, nous avons également besoin d'une '''méthode propre''' pour terminer le programme.  
 +
 
 +
Un gestionnaire de signal (''signal handler'') est utilisé pour capturer ctrl+c et terminer le thread PotReader avant d'appeler sys.exit - sinon le programme ne se fermera pas.
    
<syntaxhighlight lang="python">
 
<syntaxhighlight lang="python">
Ligne 171 : Ligne 176 :  
pitft = PiTft()
 
pitft = PiTft()
 
   
 
   
# Start the thread running the callable
+
# démarrer le thread exécutant le ''callable''
 
potreader = PotReader(pitft)
 
potreader = PotReader(pitft)
 
threading.Thread(target=potreader).start()
 
threading.Thread(target=potreader).start()
 
   
 
   
 
def signal_handler(signal, frame):
 
def signal_handler(signal, frame):
     print 'You pressed Ctrl+C!'
+
     print 'Vous avez pressé Ctrl+C!'
 
     potreader.terminate()
 
     potreader.terminate()
 
     sys.exit(0)
 
     sys.exit(0)
 
          
 
          
 +
# Enregister le gesionnaire signal_handler pour le lignal SIGINT (interruption)
 
signal.signal(signal.SIGINT, signal_handler)
 
signal.signal(signal.SIGINT, signal_handler)
 
   
 
   
Ligne 186 : Ligne 192 :  
</syntaxhighlight>
 
</syntaxhighlight>
   −
You can run this final example from the pygamelcd project:
+
== Exécuter ==
 +
Vous pouvez exécuter cet exemple final depuis le projet pygamelcd:
    
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
sudo python test5.py
 
sudo python test5.py
 
</syntaxhighlight>
 
</syntaxhighlight>
         
{{RASP-PYGAME-GUI-TRAILER}}
 
{{RASP-PYGAME-GUI-TRAILER}}
29 918

modifications

Menu de navigation