-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
532 lines (438 loc) · 14.2 KB
/
menu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
//Chargement des librairies standard
#include <stdio.h>
#include <stdlib.h>
//Chargement de la librairie mathsh pour la puissance de 10
#include <math.h>
//Chargement de la librairie windows.h pour gérer les fichier en partie et la fonction sleep
#include <windows.h>
# define TAILLE_CHAINE_CHAR 21
# define ALPHA 0.992
#include "menu.h"
#include "divers.h"
#include "lecture.h"
#include "affichage.h"
#include "calcul.h"
#include "filtreFIR.h"
#include "filtreIIR.h"
#include "ftd2xx.h"
int menu()
{
printf("\n PROJET INFORMATIQUE CSI3 2013 - OXYMETRE DE POULS - PERROT/RAOULT\n\n");//titre de la fenêtre
printf("\t Choix de la fonction a tester:\n");
printf("\t 1--> Programme entier\n");
printf("\t 2--> Fonction Lecture et Centrage\n");
printf("\t 3--> Filtre FIR\n");
printf("\t 4--> Filtre IIR\n");
printf("\t 5--> Fonction Calcul\n");
printf("\t 6--> Fonction Affichage\n\n");
printf("\t 0--> QUITTER\n");
char touche;//on déclare la variable qui va stocker le code de la touche qui va être appuyée
touche=getch();
if(touche=='1')//si la touche appuyée est 1 alors:
{
system("cls");//on efface le terminal
return 1;//on retourne 1
}
else if(touche=='2')//si la touche appuyée est 2 alors:
{
system("cls");//on efface le terminal
return 2;//on return 2
}
else if(touche=='3')//si la touche appuyée est 2 alors:
{
system("cls");//on efface le terminal
return 3;//on return 3
}
else if(touche=='4')//si la touche appuyée est 2 alors:
{
system("cls");//on efface le terminal
return 4;//on return 4
}
else if(touche=='5')//si la touche appuyée est 2 alors:
{
system("cls");//on efface le terminal
return 5;//on return 5
}
else if(touche=='6')//si la touche appuyée est 2 alors:
{
system("cls");//on efface le terminal
return 6;//on return 6
}
else if(touche=='0')//si la touche appuyée est 2 alors:
{
system("cls");//on efface le terminal
return 0;//on return 0
}
else// si la touche est autre que 1 ou 2
{
system("cls");// on efface le treminal
return menu();//on réapplelle la fonction choixmode jusqu'à ce que la touche appuyée soit 1 ou 2
}
}
//------------main----------------------------------------------------------------------------------------------------------
void programmeEntier()
{
int n=0;
int fin=0;
int mode=choixMode();
struct maillon *adressACr_brut= NULL;
struct maillon *adressACir_brut= NULL;
float *ac_fir=calloc(2,sizeof(float));
float *ac_fir_iir=calloc(2,sizeof(float));
float *ac_fir_prec=calloc(2,sizeof(float));
float *ac_fir_iir_prec=calloc(2,sizeof(float));
struct tab4 oxy;
struct pointeurs *AC_R=malloc(4*sizeof(int)+4*sizeof(float));
struct pointeurs *AC_IR=malloc(4*sizeof(int)+4*sizeof(float));
AC_R->compteurPrecedent;
AC_R->compteur=0;
AC_R->passageZero=0;
AC_R->ena_compteur=0;
AC_R->maximum=0;
AC_R->minimum=0;
AC_R->maximum_prec=0;
AC_R->minimum_prec=0;
AC_IR->compteurPrecedent=0;
AC_IR->compteur=0;
AC_IR->passageZero=0;
AC_IR->ena_compteur=0;
AC_IR->maximum=0;
AC_IR->minimum=0;
AC_IR->maximum_prec=0;
AC_IR->minimum_prec=0;
float *dataBrut;
//char *data_precedent=calloc(21, sizeof(char));
FILE* fichier;
FILE* fichier_c = fopen("test_c.dat", "w+");
FILE* fichier_f1 = fopen("test_f1.dat", "w+");
FILE* fichier_f2 = fopen("test_f2.dat", "w+");
if(mode==1)
{
fichier = fopen("record1.dat", "r");
}
else if(mode ==2)
{
flux=FT_Open;
}
remove(".verrouData");//on supprime le fichier verroudata pour que l'interface graphique puisse lire le fichier data.txt
while(fin != 1)
{
printf("%d\n",n);
//
dataBrut = Lecture(fichier , mode);
fprintf (fichier_c,"%d,%d,%d,%d\n\n",(int)dataBrut[0],(int)dataBrut[1],(int)dataBrut[2],(int)dataBrut[3]);
if ((int)dataBrut[1]==9999)
{
fin =1;
}
// printf(" %f,%f,%f,%f\n", dataBrut[0],dataBrut[1],dataBrut[2],dataBrut[3]);
adressACr_brut=insertMaillon(dataBrut[0],adressACr_brut,51);// a corriger 51 et pas 50 !!!!
adressACir_brut=insertMaillon(dataBrut[2],adressACir_brut,51);
ac_fir = FlitreFIR(adressACr_brut,adressACir_brut);
fprintf (fichier_f1,"%d,%d,%d,%d\n\n",(int)ac_fir[0],(int)dataBrut[1],(int)ac_fir[1],(int)dataBrut[3]);
ac_fir_iir = FlitreIIR(ac_fir,ac_fir_prec, ac_fir_iir_prec);
fprintf (fichier_f2,"%d,%d,%d,%d\n\n",(int) ac_fir_iir [0],(int)dataBrut[1],(int) ac_fir_iir[1],(int)dataBrut[3]);
ac_fir_iir_prec = ac_fir_iir ;
ac_fir_prec = ac_fir;
// printf(" %f\t %f\n",ac_fir_iir[0],ac_fir_iir[1]);
oxy.DCr=dataBrut[1];
oxy.DCir=dataBrut[3];
oxy.ACir_actuel=ac_fir_iir[1];
oxy.ACr_actuel=ac_fir_iir[0];
affichage(calcul(oxy,AC_R,AC_IR));
oxy.ACr_prec=oxy.ACr_actuel;
oxy.ACir_prec=oxy.ACir_actuel;
// Sleep(2);
n++;
}
printf(" Fini! \n Appuyer sur une touche pour revenir au menu\n");
getch();
system("cls");
topMenu(menu());
if(mode==1)
{
fclose(fichier);
}
fclose(fichier_c);
fclose(fichier_f1);
fclose(fichier_f2);
//libération de la mémoire des pointeurs
free(adressACir_brut);
free(adressACr_brut);
free(ac_fir);
free(ac_fir_iir);
free(ac_fir_prec);
free(ac_fir_iir_prec);
free(AC_R);
free(AC_IR);
}
/*
void testLecture()
{
FILE* fichier = fopen("record_test_lecture.dat", "r");
FILE* fichier_resultat = fopen("record_test_lecture_resultat.dat", "w+");
if( fichier == NULL)
{
printf("impossible d'ouvrire le fichier record_test_lecture.dat car il n'existe pas\n");
}
else
{
char *tab=NULL;
float *tab_num=NULL;
int fin=0;
char * data_prec=calloc(21,sizeof(char));
while(fin!=1)
{
tab=gestionErreurs(recupFichier(fichier),data_prec);
tab_num = conversion(tab);
if ((int)tab[1]==9999)
{
fin =1;
}
else
{
printf("resutat=%d,%d,%d,%d\n",(int)tab_num[0],(int)tab_num[1],(int)tab_num[2],(int)tab_num[3]);
fprintf (fichier_resultat,"%d,%d,%d,%d\n",(int)tab[0],(int)tab[1],(int)tab[2],(int)tab[3]);
}
data_prec=tab;
}
free(tab);
free(tab_num);
free(data_prec);
}
printf("appuyer sur une touche pour revenir au menu\n");
getch();
fclose(fichier);
fclose(fichier_resultat);
system("cls");
topMenu(menu());
}
*/
void testCentrage()
{
FILE* fichier = fopen("record_test_centrage.dat", "r");
FILE* fichier_resultat = fopen("record_test_centrage_resultat.dat", "w+");
if( fichier == NULL)
{
printf("Impossible d'ouvrir le fichier record_test_centrage.dat car il n'existe pas\n");
}
else
{
float *tab=NULL;
int fin=0;
// char *data_precedent=calloc(21, sizeof(char));
while(fin != 1)
{
Sleep(2);
tab = Lecture(fichier,1);
if ((int)tab[1]==9999)
{
fin =1;
}
else
{
printf("resultat=%d,%d,%d,%d\n",(int)tab[0],(int)tab[1],(int)tab[2],(int)tab[3]);
fprintf (fichier_resultat,"%d,%d,%d,%d\n",(int)tab[0],(int)tab[1],(int)tab[2],(int)tab[3]);
}
}
}
printf("Appuyer sur une touche pour revenir au menu\n");
getch();
fclose(fichier);
fclose(fichier_resultat);
system("cls");
topMenu(menu());
}
void testFiltreFIR()
{
FILE* fichier = fopen("record_test_filreFIR.dat", "r");
FILE* fichier_resultat = fopen("record_test_filreFIR_resultat.dat", "w+");
if( fichier == NULL)
{
printf("Impossible d'ouvrir le fichier record_test_filtreFIR.dat car il n'existe pas\n");
}
else
{
float *tab=NULL;
struct maillon *pliste=NULL;
int nouvelleValeur;
int n=0;
while(fscanf(fichier, "%d", &nouvelleValeur) != EOF)
{
Sleep(2);
printf("valeur lue = %d\n",nouvelleValeur);
pliste = insertMaillon(nouvelleValeur,pliste,51);
//bon normalement le filtre prend la liste chainée de ac-r et ac-ir mais là comme c'est un test je prend 2 fois la même
tab=FlitreFIR(pliste,pliste);
//pareil ici j'affiche que une valeure de sortie de mon filtre parce que l'autre c'est la même vu qu'on a les 2 mêmes listes chainées en entéres du FIR
printf("resultat = %d\n",(int)tab[0]);
fprintf (fichier_resultat,"%d\n\n",(int)tab[0]);
}
}
printf("Appuyer sur une touche pour revenir au menu\n");
getch();
fclose(fichier);
fclose(fichier_resultat);
system("cls");
topMenu(menu());
}
void testFiltreIIR()
{
FILE* fichier = fopen("record_test_filreIIR.dat", "r");
FILE* fichier_resultat = fopen("record_test_filreIIR_resultat.dat", "w+");
if( fichier == NULL)
{
printf("Impossible d'ouvrir le fichier record_test_filtreIIR.dat car il n'existe pas\n");
}
else
{
float *tab=calloc(2,sizeof(float));
struct maillon *pliste=NULL;
float *val_fir=calloc(2,sizeof(float));
float *val_fir_prec=calloc(2,sizeof(float));
float *val_iir=calloc(2,sizeof(float));
float *val_iir_prec=calloc(2,sizeof(float));
int n=0;
while(fscanf(fichier, "%f", &val_fir[0]) != EOF)
{
Sleep(2);
printf("Valeur lue = %d\n",(int)val_fir[0]);
//bon normalement le filtre prend la liste chainée de ac-r et ac-ir mais là comme c'est un test je prend 2 fois la même
tab=FlitreIIR(val_fir,val_fir_prec,val_iir_prec);
//pareil ici j'affiche que une valeure de sortie de mon filtre parce que l'autre c'est la même vu qu'on a les 2 mêmes listes chainées en entéres du FIR
printf("Resultat = %f\n\n",tab[0]);
fprintf (fichier_resultat,"%d\n\n",(int)tab[0]);
val_fir_prec[0]=val_fir[0];
val_iir_prec[0]=tab[0];
}
}
printf("Appuyer sur une touche pour revenir au menu\n");
getch();
fclose(fichier);
fclose(fichier_resultat);
system("cls");
topMenu(menu());
}
void testCalcul()
{
FILE* fichier = fopen("record_test_calcul.dat", "r");
FILE* fichier_resultat = fopen("record_test_calcul_resultat.dat", "w+");
if( fichier == NULL)
{
printf("Impossible d'ouvrir le fichier record_test_calcul.dat car il n'existe pas\n");
}
else
{
int *tab=NULL;
struct tab4 oxy;
struct pointeurs *AC_R=malloc(4*sizeof(int)+4*sizeof(float));
struct pointeurs *AC_IR=malloc(4*sizeof(int)+4*sizeof(float));
AC_R->compteurPrecedent;
AC_R->compteur=0;
AC_R->passageZero=0;
AC_R->ena_compteur=0;
AC_R->maximum=0;
AC_R->minimum=0;
AC_R->maximum_prec=0;
AC_R->minimum_prec=0;
AC_IR->compteurPrecedent=0;
AC_IR->compteur=0;
AC_IR->passageZero=0;
AC_IR->ena_compteur=0;
AC_IR->maximum=0;
AC_IR->minimum=0;
AC_IR->maximum_prec=0;
AC_IR->minimum_prec=0;
while(fscanf(fichier, "%f,%f,%f,%f", &oxy.ACr_actuel, &oxy.DCr, &oxy.ACir_actuel, &oxy.DCir) != EOF)
{
Sleep(2);
printf("Valeurs lues=%f,%f,%f,%f\n", oxy.ACr_actuel, oxy.DCr, oxy.ACir_actuel, oxy.DCir);
tab=calcul(oxy,AC_R,AC_IR);
oxy.ACr_prec=oxy.ACr_actuel;
oxy.ACir_prec=oxy.ACir_actuel;
printf("spo2=%d, bpm=%d\n",tab[0],tab[1]);
fprintf(fichier_resultat,"spo2=%d, bpm=%d\n\n",tab[0],tab[1]);
}
}
printf("Appuyer sur une touche pour revenir au menu\n");
getch();
fclose(fichier);
fclose(fichier_resultat);
system("cls");
topMenu(menu());
}
void testAffichage()
{
FILE* fichier = fopen("record_test_affichage.dat", "r");
if( fichier == NULL)
{
printf("Impossible d'ouvrir le fichier record_test_affichage.dat car il n'existe pas\n");
}
else
{
int *valSortie=calloc(2,sizeof(int));
int n=0;
while(fscanf(fichier, "%d,%d", &valSortie[0], &valSortie[1]) != EOF)
{
Sleep(100);
printf("Valeurs lues= %d,%d\t",valSortie[0],valSortie[1]);
affichage(valSortie);
n++;
}
}
printf("Appuyer sur une touche pour revenir au menu\n");
getch();
fclose(fichier);
system("cls");
topMenu(menu());
}
/*void quitter()
{
printf("voulez-vous quitter? [o/n]\n");
char touche1;//on déclare la variable qui va stocker le code de la touche qui va être appuyée
touche1=getch();
if(touche1=='o')//si la touche appuyée est 1 alors:
{
system("cls");//on efface le terminal
}
else if(touche1=='n')//si la touche appuyée est 1 alors:
{
system("cls");//on efface le terminal
menu();
}
else
{
system("cls");//on efface le terminal
quitter();
}
}
*/
void topMenu(int menu)
{
switch(menu)
{
case 1:
programmeEntier();
break;
case 2:
testCentrage();
break;
case 3:
testFiltreFIR();
break;
case 4:
testFiltreIIR();
break;
case 5:
testCalcul();
break;
case 6:
testAffichage();
break;
case 0:
break;
default:
programmeEntier();
break;
}
}