diff --git a/Test moteurs/Makefile b/Test moteurs/Makefile new file mode 100644 index 0000000..ac49da8 --- /dev/null +++ b/Test moteurs/Makefile @@ -0,0 +1,17 @@ +CC=gcc +CFLAGS=-Wall -g +LDFLAGS= +EXEC=moteur + +all: $(EXEC) + +moteur : moteur.c + gcc -o $@ $^ + +.PHONY: clean mrproper + +clean: + rm -rf *.o + +mrproper: clean + rm -rf $(EXEC) diff --git a/Test moteurs/Makefile~ b/Test moteurs/Makefile~ new file mode 100644 index 0000000..066eac8 --- /dev/null +++ b/Test moteurs/Makefile~ @@ -0,0 +1,17 @@ +CC=gcc +CFLAGS=-Wall +LDFLAGS= +EXEC=moteur + +all: $(EXEC) + +moteur : moteur.c + gcc -o $@ $^ + +.PHONY: clean mrproper + +clean: + rm -rf *.o + +mrproper: clean + rm -rf $(EXEC) diff --git a/Test moteurs/moteur b/Test moteurs/moteur index 57f883f..193afe6 100755 Binary files a/Test moteurs/moteur and b/Test moteurs/moteur differ diff --git a/Test moteurs/moteur.c b/Test moteurs/moteur.c index 50874eb..d8d2a7d 100644 --- a/Test moteurs/moteur.c +++ b/Test moteurs/moteur.c @@ -1,58 +1,86 @@ #include #include + + +//screen /dev/ttyACM0 int main(){ FILE* fichier; char* port_serie = "/dev/ttyACM0"; - char buffer[30]; + char q; + int angle[2] = {0,0}; + int coeff = 1; - char c = '1'; - double angle[2]; + while(getchar() != 'q'){ - fichier = fopen(port_serie,"r+"); + //Ouverture tty + fichier = fopen(port_serie,"w"); if(fichier==NULL){ printf("Impossible d'ouvrir %s\n",port_serie); - return 0; + perror("fopen failed for /dev/ttyACM0" ); + exit( EXIT_FAILURE ); } - while(c != 'q'){ + /* //Lecture tty printf("Valeurs moteurs xxx et yyy actuelles :\n"); - - - read(angle,sizeof(double),1,fichier); - read(angle+1,sizeof(double),1,fichier); - //fscanf(fichier,"%d %d",angle,angle+1); - - printf("\nxxx=%lf; yyy=%lf\n",angle[0]*0.001,angle[1]*0.001); - - - -/* - fichier = fopen(port_serie,"w+"); - if(fichier==NULL){ - printf("Impossible d'ouvrir %s\n",port_serie); - return 0; - }*/ - printf("\n Valeurs moteurs xxx,yyy ?\n"); - scanf("%lf %lf",angle,angle+1); - - fprintf(fichier,"%lf %lf",angle[0]*0.001,angle[1]*0.001); -/* - fwrite(angle,1,sizeof(int),fichier); - fwrite(angle+1,1,sizeof(int),fichier);*/ - - printf("\nq pour quitter\n"); - - c = getchar(); - c = getchar(); - + fscanf(fichier,"%d %d",angle,angle+1); + printf("\nxxx=%d; yyy=%d\n",angle[0]*coeff,angle[1]*coeff); + */ + //Ecriture tty + printf("\n Valeurs moteurs xxx,yyy ? "); + + while(scanf(" %d %d", angle,angle+1) != 2){ + printf("Angles incorrects, mets les bonnes valeurs cette fois...\n"); + getchar(); + } + + fprintf(fichier,"%d\n",angle[0]*coeff); + fprintf(fichier,"%d\n",angle[1]*coeff); + printf("Valeur actuelles : xxx=%d yyy=%d\n", angle[0],angle[1]); - + //Quitter + fclose(fichier); + printf("\nq pour quitter\n"); + scanf(" %c",&q); + if(q == 'q') break; } - fclose(fichier); + return 0; } +/*fwrite et fread + + read(angle,sizeof(int),1,fichier); + read(angle+1,sizeof(int),1,fichier); + + fwrite(angle,1,sizeof(int),fichier); + fwrite(angle+1,1,sizeof(int),fichier); +*/ + +/*putc() + char buffer[255]; + char* c; + char* c0; + int num; + c=buffer; + c0=buffer; + for(num=0;num<2;){ + printf("a\n"); + *c=getc(stdin); // echo input back to terminal + fputc(*c,fichier); + if(*c == 'q') + break ; + if((*c == '\n') || (*c == '\r') || (*c == '\0') || (*c == ' ') || (*c == ',')) + { + // + *c='\0'; + angle[num]=atoi(c0); + c0=c+1; + num++; + } + c++; + } +*/ diff --git a/Test moteurs/moteur.c~ b/Test moteurs/moteur.c~ new file mode 100644 index 0000000..1e72717 --- /dev/null +++ b/Test moteurs/moteur.c~ @@ -0,0 +1,86 @@ +#include +#include + + +//screen /dev/ttyACM0 + +int main(){ + + FILE* fichier; + + char* port_serie = "/dev/ttyACM0"; + char q; + int angle[2] = {0,0}; + int coeff = 1; + + while(getchar() != 'q'){ + + //Ouverture tty + fichier = fopen(port_serie,"w"); + if(fichier==NULL){ + printf("Impossible d'ouvrir %s\n",port_serie); + perror("fopen failed for /dev/ttyACM0" ); + exit( EXIT_FAILURE ); + } + + + /* //Lecture tty + printf("Valeurs moteurs xxx et yyy actuelles :\n"); + fscanf(fichier,"%d %d",angle,angle+1); + printf("\nxxx=%d; yyy=%d\n",angle[0]*coeff,angle[1]*coeff); +*/ + //Ecriture tty + printf("\n Valeurs moteurs xxx,yyy ? "); + + while(scanf(" %d %d", angle,angle+1) != 2){ + printf("Angles incorrects, mets les bonnes valeurs cette fois...\n"); + getchar(); + } + + fprintf(fichier,"%d\n",angle[0]*coeff); + fprintf(fichier,"%d\n",angle[1]*coeff); + printf("Valeur actuelles : xxx=%d yyy=%d\n", angle[0],angle[1]); + + + //Quitter + fclose(fichier); + printf("\nq pour quitter\n"); + scanf(" %c",&q); + if(q == 'q') break; + } + + return 0; +} +/*fwrite et fread + + read(angle,sizeof(int),1,fichier); + read(angle+1,sizeof(int),1,fichier); + + fwrite(angle,1,sizeof(int),fichier); + fwrite(angle+1,1,sizeof(int),fichier); +*/ + +/*putc() + char buffer[255]; + char* c; + char* c0; + int num; + c=buffer; + c0=buffer; + for(num=0;num<2;){ + printf("a\n"); + *c=getc(stdin); // echo input back to terminal + fputc(*c,fichier); + if(*c == 'q') + break ; + if((*c == '\n') || (*c == '\r') || (*c == '\0') || (*c == ' ') || (*c == ',')) + { + // + *c='\0'; + angle[num]=atoi(c0); + c0=c+1; + num++; + } + c++; + } +*/ diff --git a/Test moteurs/t.txt b/Test moteurs/t.txt deleted file mode 100644 index 92880af..0000000 --- a/Test moteurs/t.txt +++ /dev/null @@ -1 +0,0 @@ -1 1 \ No newline at end of file diff --git a/Test moteurs/tt.txt b/Test moteurs/tt.txt deleted file mode 100644 index f34c70a..0000000 Binary files a/Test moteurs/tt.txt and /dev/null differ diff --git a/Test moteurs/ttyACM0 b/Test moteurs/ttyACM0 index e69de29..6ed281c 100644 --- a/Test moteurs/ttyACM0 +++ b/Test moteurs/ttyACM0 @@ -0,0 +1,2 @@ +1 +1