« Aide:Coloration syntaxique » : différence entre les versions

Contenu supprimé Contenu ajouté
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 354 :
 
[[Catégorie:Aide technique]]
<source lang="csharp">
#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ncurses.h>
 
int main(void){
//DEBUT : INITIALISATION DE L'ECRAN
initscr();
cbreak();
noecho();
nodelay(stdscr,TRUE);//l'attente de saisie d'un texte est non bloquant
//FIN : INITIALISATION DE L'ECRAN
int port;
int resr=0;
char chaine[64];
//ON INITIALIASE LES VARIABLES RELATIVES AU COMPTEUR
/*int PosiX=0;
int PosiY=0;
int dX=0;
int dY=0;*/
//
struct termios old_param;
struct termios new_param;
port=open("/dev/ttyS0",O_RDWR|O_NOCTTY|O_NDELAY);//on ouvre le fichier de port
//ON TEST L'OUVERTURE DU PORT
if (port<0){
perror("Erreur : echec d'ouverture du port");
exit(-1);
}
tcgetattr(port,&old_param);
tcgetattr(port,&new_param);
//ON MODIF CERTAINS PARAM DU PROTOCOLE
new_param.c_cflag=B1200|CS7|CLOCAL|CREAD;
new_param.c_lflag&=~(ICANON|ECHO|ECHOE|ISIG);
new_param.c_iflag=IGNBRK;//on ignore le test de verification du branchement du cable
new_param.c_oflag=0;
new_param.c_cc[VMIN]=1;
new_param.c_cc[VTIME]=0;
tcflush(port,TCIOFLUSH);//on vide le buffer
tcsetattr(port,TCSANOW,&new_param);
while(1){
 
//ON INITIALISE NOTRE FENETRE
getch();
move(4,10);
printw("%s","Go ! Vous pouvez commencer à bouger la sourie ...");
refresh();
 
 
//LECTURE DES INFORMATIONS RECUES PAR LA SOURIE
chaine[0]=1;
//synchronisation
while (chaine[0]==1){
resr=read(port,chaine,1);//on recup l'info envoyée par la souris
}
move(5,10);
printw("%s","Saisie detectée : récupération des informations");//on indique à l'utilisateur que l'on commence à traiter ses données
refresh();
 
 
//RECUPERATION DES DONNEES
move(9,10);
resr=read(port,chaine,64);//on lit les infos recues
//on affiche les infos brutes recues
if ((resr>0)){
chaine[resr]=0;
printw("%s",strcat(chaine," "));
refresh();
}
 
//ON TRAITE LES DONNES RECUES : pas encore terminée
/*
*/
//ON INCREMENTE LE COMPTEUR : pas encore terminée
/*
PosiX=(PosiX+(dX));
PosiY=(PosiY+(dY));
*/
//LA PARTIE QUI VA SUIVRE FAIT UNE MISE EN PAGE GENERALE
move(8,10);
printw("%s","Le déplacement est :");
refresh();
 
//on affiches les données relatives au compteur
move(11,10);
//printw("%s",strcat("La position en X est : ",PosiX));
printw("%s","La position en X est : 40");
move(12,10);
//printw("%s",strcat("La position en Y est : ",PosiY));
printw("%s","La position en Y est : -5");
refresh();
endwin();
refresh();
 
 
}
 
 
//FIN PARTIE
//ON DEBUTE LA FERMETURE DU PROGRAMME
tcflush(port,TCIOFLUSH);//on vide le buffer
tcsetattr(port,TCSANOW,&new_param);
 
close(port);//on ferme la communication avec le port
return(0);
}
</source>