principal

Dependencies:   mbed fastlib vga640x400

Files at this revision

API Documentation at this revision

Comitter:
yokoland95
Date:
Thu Jun 13 15:56:16 2019 +0000
Parent:
1:8229db8e7d08
Commit message:
blabla

Changed in this revision

FICHIER/exmain.cpp Show annotated file Show diff for this revision Revisions of this file
FICHIER/fichier.h Show annotated file Show diff for this revision Revisions of this file
FICHIER/fonctionFichier.cpp Show annotated file Show diff for this revision Revisions of this file
main.c Show annotated file Show diff for this revision Revisions of this file
vga640x400.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FICHIER/exmain.cpp	Thu Jun 13 15:56:16 2019 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "fichier.h"
+  
+ 
+LocalFileSystem local("local");             // Create the local filesystem under the name "local"
+ 
+int exmain() {
+    int i,j,nb;
+    /*
+    FILE *fp = fopen("/local/out.txt", "w");  // Open "out.txt" on the local file system for writing
+    fprintf(fp, "coucou clement World!");
+    fclose(fp);
+    //remove("/local/out.txt");                 // Removes the file "out.txt" from the local file system
+    */
+    
+    DIR *d = opendir("/local");               // Opens the root directory of the local file system
+    struct dirent *p;
+    while((p = readdir(d)) != NULL) {         // Print the names of the files in the local file system
+      printf("%s\n\r", p->d_name);              // to stdout.
+    }
+    closedir(d);
+
+
+    FILE *fp = fopen("/local/form.csv", "r"); 
+    if(!fp) { 
+        error("Could not open file!\n\r");
+    }
+    
+    
+    char ligne[500];
+    char* morceau;
+    /*-------------------------------------------*/ 
+    /* COMPTE LE NOMBRE DE LIGNE DANS LE FICHIER */
+    /*-------------------------------------------*/ 
+    printf("nombre de ligne %d\n\r", nb = nombre_ligne_fichier(fp));
+    
+    for( i = 2; i <= nb; i++){     
+        /*-----------------------------------*/ 
+        /* RETOURNE LE CONTENU DE LA LIGNE X */
+        /*-----------------------------------*/ 
+        retourne_ligne(i,ligne,fp);
+        printf("ligne %d est %s\n\r",i,ligne);
+    
+        /*-----------------------------------*/ 
+        /* RETOURNE L'ÉLÉMENT X DE LA LIGNE  */
+        /*-----------------------------------*/ 
+        morceau = retourne_element_ligne(1, ligne);
+        printf("la question est: %s \n\r", morceau);
+        
+        /*-----------------------------------*/ 
+        /* RETOURNE L'ÉLÉMENT X DE LA LIGNE  */
+        /*-----------------------------------*/ 
+        for(j = 1; j < 5; j++){
+            morceau = retourne_element_ligne(j+1, ligne);
+            printf("Reponse %d: %s \n\r",j, morceau);
+        }
+    
+        /*----------------------------------------*/ 
+        /* RETOURNE LA BONNE REPONSE DE LA LIGNE  */
+        /*----------------------------------------*/     
+        j = num_bonne_reponse(ligne);
+        morceau = retourne_element_ligne(j+1, ligne);
+        printf("bonne reponse est la %d: %s \n\r",j, morceau);
+    
+        /*-----------------------------------*/ 
+        /* RETOURNE L'ÉLÉMENT X DE LA LIGNE  */
+        /*-----------------------------------*/ 
+        morceau = retourne_element_ligne(7, ligne);
+        printf("la raison: %s \n\r", morceau);
+    }
+    fclose(fp);
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FICHIER/fichier.h	Thu Jun 13 15:56:16 2019 +0000
@@ -0,0 +1,23 @@
+#include "mbed.h"  
+    /*-------------------------------------------*/ 
+    /* COMPTE LE NOMBRE DE LIGNE DANS LE FICHIER */
+    /*-------------------------------------------*/ 
+int nombre_ligne_fichier(FILE* fp);
+
+    /*-----------------------------------*/ 
+    /* RETOURNE LE CONTENU DE LA LIGNE X */
+    /*-----------------------------------*/ 
+void retourne_ligne(int num, char ligne[500], FILE* fp);
+
+    /*-----------------------------------*/ 
+    /* RETOURNE L'ÉLÉMENT X DE LA LIGNE  */
+    /*-----------------------------------*/ 
+char* retourne_element_ligne(int num, char ligne[500]);
+
+
+    /*----------------------------------------*/ 
+    /* RETOURNE Le NUM DE LA BONNE REPONSE D  */
+    /*----------------------------------------*/  
+int num_bonne_reponse( char ligne[500]);
+
+void lancer_question(void);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/FICHIER/fonctionFichier.cpp	Thu Jun 13 15:56:16 2019 +0000
@@ -0,0 +1,63 @@
+#include "mbed.h"
+#include "fichier.h"
+
+
+
+    /*-------------------------------------------*/ 
+    /* COMPTE LE NOMBRE DE LIGNE DANS LE FICHIER */
+    /*-------------------------------------------*/ 
+int nombre_ligne_fichier(FILE* fp){
+    int total = 0;
+    char ligne[500];  
+    rewind(fp);
+    
+    while ( fgets(ligne, 500, fp) != NULL){
+        total++;;
+    }
+    rewind(fp);
+    return total;
+}
+
+    /*-----------------------------------*/ 
+    /* RETOURNE LE CONTENU DE LA LIGNE X */
+    /*-----------------------------------*/ 
+ void retourne_ligne(int num, char ligne[500], FILE* fp){
+    int cmpt = 1;
+    rewind(fp); 
+    
+    fgets(ligne, 500, fp);
+    
+    while( cmpt != num){
+        fgets(ligne, 500, fp);
+        cmpt++;
+    }
+    
+    rewind(fp);
+    return;
+     
+}
+
+char* retourne_element_ligne(int num, char ligne[500]){
+    int cmpt = 1;
+    char *element;
+    char stock[500];
+    
+    strcpy(stock, ligne);
+    element = strtok(stock, ";");
+    //printf ("stock : %s\n\r", element);
+    while( cmpt != num){
+        element = strtok( NULL, ";");
+        cmpt++;
+        //printf ("stock : %s\n\r", element);
+        element = element;
+    }
+    return element;    
+}
+    
+int num_bonne_reponse( char ligne[500]){
+    char* element;
+    int reponse;
+    element = retourne_element_ligne(6, ligne); 
+    reponse = atoi( element ); 
+    return reponse;
+    }
\ No newline at end of file
--- a/main.c	Wed Jun 12 08:19:57 2019 +0000
+++ b/main.c	Thu Jun 13 15:56:16 2019 +0000
@@ -1,42 +1,388 @@
 #include "mbed.h"              
 #include "vga640x400/vga640x400.h"
+#include <string.h>
+#include <fichier.h>
 
-Serial pc(USBTX, USBRX); // tx, rx
+
+
+// P8 et P25 pour horloge, P5 data
+//Serial pc(USBTX, USBRX); // tx, rx
+// This must be an SPI MOSI pin.
+#define DATA_PIN p11
+
 
 extern unsigned char font_lin[256*16];
+Ticker timer1;
 
-int main() {
-    font = font_lin;
-    char phrase[] = "Bonjour, je m'appelle clement, j'habite a Bondoufle et j'aime bricoler. je mange du poulet, du riz et du fromage";
-    //char phrase[] = "Bonjour, jean-mich";
+InterruptIn CAPT(p15 );
+
+DigitalIn BPA(p17);
+DigitalIn BPB(p18);
+DigitalIn BPC(p19);
+DigitalIn BPD(p20);
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+void int_timer(void);
+void int_capt(void);
+void int_capt2(void);
+void vide(void);
+void tourne_roue(void);
+
+int passage;
+
+
+void lancer_action(void){
 
-    //char bufferPrase1 [] = "";
-    int longueurPhrase = 0; //ATTENTION +1 car carractère de fin
+    FILE *fp = fopen("/local/act.csv", "r"); 
+    if(!fp) { 
+        error("Could not open file!\n\r");
+    }
+    
+    //
+    
+    char ligne[500];
+    char stock[500];
+    char* morceau;
+    bool passe = false;
+    
+    int a = 1;
+    while( a == 1)
+        a = (rand() % nombre_ligne_fichier(fp)) +1;
+     
+    printf("rand = %d\n\r",a);
+    int b;
+    
+    
+    //
+    clear_buffer();
+    /*-----------------------------------*/ 
+    /* RETOURNE LE CONTENU DE LA LIGNE X */
+    /*-----------------------------------*/ 
+    retourne_ligne(a,ligne,fp);
+    
+    printf("LIGNE CHOISI: %s\n\r", ligne);
+        
+    /*--------------------------------*/ 
+    /* AFFICHE L'ACTION A LECRAN      */
+    /*--------------------------------*/ 
+    morceau = retourne_element_ligne(1, ligne);
+    strcpy(stock, morceau);
+    printf("l'action est: %s \n\r", text_buffer);
+    for (int i=0 ; i<strlen(stock)+1; i ++)
+        text_buffer[(320+i)^1] = stock[i]; 
+        
+         
+    a =0;
+    while (text_buffer[a] != '\0'){
+        a++;
+        } 
+    printf("a comptage : %d\n\r", a); 
     
-    longueurPhrase = sizeof(phrase);
+    /*-----------------------------------*/ 
+    /* AFFICHE LE TEMPS A LECRAN         */
+    /*-----------------------------------*/ 
+    strcpy(stock, "RESTER APPUYER SUR UN BOUTON POUR PASSER ->");
+    for (int j=0 ; j<strlen(stock)+1; j++)
+        text_buffer[(880+j)^1] = stock[j];
+        
+    morceau = retourne_element_ligne(2, ligne);
+    b = atoi(morceau);
+         
+    while(b >= 0 ){
+        wait(0.9);
+        sprintf(stock, "%3d", b);
+        printf("COMPTEUR: %s\n\r", stock);
+        for (int i=0 ; i<strlen(stock)+1; i ++)
+            text_buffer[((a/80+1)*80+i)^1] = stock[i];
+        b--;
+        if(! (BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1) ){
+            passe = true;
+            clear_buffer();
+            while(!(BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1) ){     
+            } 
+            b=-1;    
+        }
+        
+    }
     
-    pc.printf("AZERTY\n\r");
-    pc.printf("%d\n\r", longueurPhrase);
+    /*
+    if (!passe){
+        printf("dans le pas passe\n\r");
+        clear_buffer(); 
+        strcpy(stock, "APPUYER SUR UN BOUTON POUR CONTINUER ->            ");
+        for (int j=0 ; j<strlen(stock)+1; j++)
+            text_buffer[(880+j)^1] = stock[j];
+        while(BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1){  
+        }
+        while(! (BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1) ){     
+        }  
+        clear_buffer();
+        passe = false;  
+    }
+     */ 
+    /*--------------------------------*/ 
+    /* AFFICHE LA RAISON A LECRAN     */
+    /*--------------------------------*/ 
+
 
     
+    morceau = retourne_element_ligne(3, ligne);
+    strcpy(stock, morceau);
+    for (int j=0 ; j<strlen(stock); j++)
+        text_buffer[(400+j)^1] = stock[j];
+    
+    wait(0.5);
+    strcpy(stock, "LANCER LA ROUE POUR REJOUER");
+    for (int j=0 ; j<strlen(stock)+1; j++)
+        text_buffer[(1120+j)^1] = stock[j];
 
-    /*for (int i=0 ; i<sizeof(phrase); i ++)
-    {
-        bufferPrase1 [i] = phrase[i]; //80 caractères par lignes
-        pc.printf("%c", bufferPrase1[i]);
-    }*/
- 
-    ////////////Affichage///////////////
-    // xor 1 to compensate for character order (10325476 et cetera)
-    // moved to userspace instead of rendering loop for obvious reasons
-    for (int i=0; i<400; i++)
-        text_buffer[i^1] = 0xff;
+    tourne_roue();
+    /*
+    while(BPA == 1){  
+    }
+    
+    while(BPA == 0){  
+    }  
+    */
+    fclose(fp);
+    printf("FIN\n\r");  
+    
+}
+
+void lancer_question(void){
+
+    FILE *fp = fopen("/local/form.csv", "r"); 
+    if(!fp) { 
+        error("Could not open file!\n\r");
+    }
+    
+    //
+    
+    char ligne[500];
+    char stock[500];
+    char* morceau;
+    int a = (rand() % nombre_ligne_fichier(fp)) +1;
+    printf("rand = %d\n\r",a);
+    int b;
+    
+    
+    //
+    clear_buffer();
+    /*-----------------------------------*/ 
+    /* RETOURNE LE CONTENU DE LA LIGNE X */
+    /*-----------------------------------*/ 
+    retourne_ligne(a,ligne,fp);
+    
+    /*
+    for (int i=0 ; i<strlen(ligne)+1; i ++)
+        text_buffer[(400+i)^1] = ligne[i]; //80 caractères par lignes
+    
+    printf("ligne est %s\n\r",ligne);
+    wait(5);
+    clear_buffer();
+    */
+        
+    /*-----------------------------------*/ 
+    /* AFFICHE LA QUESTION A LECRAN      */
+    /*-----------------------------------*/ 
+    morceau = retourne_element_ligne(1, ligne);
+    strcpy(stock, morceau);
+    for (int i=0 ; i<strlen(stock)+1; i ++)
+        text_buffer[(400+i)^1] = stock[i]; 
+    printf("la question est: %s \n\r", text_buffer);    
+       
+      
+    a =0;
+    while (text_buffer[a] != '\0'){
+        a++;
+        } 
+    printf("a comptage : %d\n\r", a); 
+    /*-----------------------------------*/ 
+    /* AFFICHE LES REPONSES A LECRAN     */
+    /*-----------------------------------*/ 
+
+    for(int i = 1; i < 5; i++){
+        morceau = retourne_element_ligne(i+1, ligne);
+        printf("Reponse %d: %s \n\r",i, morceau);
+        strcpy(stock, morceau);
+        for (int j=0 ; j<strlen(stock)+1; j++)
+            text_buffer[((a/80+1)*80+j+i*160)^1] = stock[j];
+    }
+
      
-    for (int i=0 ; i<sizeof(phrase); i ++)
-        text_buffer[(400+i)^1] = phrase[i]; //80 caractères par lignes
-   
+    while(BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1){ 
+    }
+
+    
+    unsigned int ba, bb, bc, bd;
+    
+    ba = BPA;
+    bb = BPB;
+    bc = BPC;
+    bd = BPD;
+
+    while(! (BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1) ){     
+        }    
+
+
+    printf("a: %d \n\r", ba);
+    printf("a: %d \n\r", bb);
+    printf("a: %d \n\r", bc);
+    printf("a: %d \n\r", bd);
+    if(!ba)
+        b = 1;
+    else if(!bb)
+        b = 2;
+    else if(!bc)
+        b = 3;
+    else if(!bd)
+        b = 4;
+        
+    clear_buffer(); 
+
+      
+    /*----------------------------------------*/ 
+    /* AFFICHE LA BONNE REPONSES A LECRAN     */
+    /*----------------------------------------*/ 
 
+    a = num_bonne_reponse(ligne);
+    
+    
+    if(a == b){
+        strcpy(stock, "BONNE REPONSE =)");
+        for (int j=0 ; j<strlen(stock)+1; j++)
+            text_buffer[(1+j)^1] = stock[j];
+    }
+    else{
+        strcpy(stock, "MAUVAISE REPONSE =(");
+        for (int j=0 ; j<strlen(stock)+1; j++)
+            text_buffer[(1+j)^1] = stock[j];
+    }
+    morceau = retourne_element_ligne(a+1, ligne);
+    strcpy(stock, morceau);
+    for (int j=0 ; j<strlen(stock)+1; j++)
+        text_buffer[(400+j)^1] = stock[j];
+    
+        
+    strcpy(stock, " PARCE QUE ->");
+    for (int j=0 ; j<strlen(stock)+1; j++)
+            text_buffer[(560+j)^1] = stock[j];
+            
+            
+    morceau = retourne_element_ligne(7, ligne);    
+    strcpy(stock, morceau);
+        for (int j=0 ; j<strlen(stock); j++)
+            text_buffer[(640+j)^1] = stock[j];        
+    
+    wait(0.5);
+    strcpy(stock, "LANCER LA ROUE POUR REJOUER");
+    for (int j=0 ; j<strlen(stock)+1; j++)
+        text_buffer[(1120+j)^1] = stock[j];
+    
+    
+    tourne_roue();
+    /*while(BPA == 1){  
+    }
+    
+    while(BPA == 0){  
+    }
+      
+        
+    while(BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1){ 
+    }
+    
+    while(! (BPA == 1 && BPB == 1 && BPC == 1 && BPD == 1) ){     
+    }     
+    */
+    fclose(fp);
+    printf("FIN\n\r");  
+    
+}
+
+void acceuil(void){
+    
+    clear_buffer();
+    char stock[500];
+    
+    strcpy(stock, "BIENVENUE A ROU[E]COLO");
+    for (int j=0 ; j<strlen(stock)+1; j++)
+        text_buffer[(400+j)^1] = stock[j];
+        
+    strcpy(stock, "LANCER LA ROUE POUR JOUER");
+    for (int j=0 ; j<strlen(stock)+1; j++)
+        text_buffer[(1120+j)^1] = stock[j];
+
+    tourne_roue();
+    /*
+    while(BPA == 1){  
+    }
+    
+    while(BPA == 0){  
+    }  
+    */
+    
+    return;  
+}
+
+void vide(void){
+    }
+    
+void int_timer(void){
+    passage = 2;
+    }
+
+void int_capt(){
+    passage = 1;
+    }
+
+void int_capt2(){
+    timer1.attach(&int_timer, 3);
+    }  
+    
+void tourne_roue(void){
+    CAPT.rise(&int_capt);
+    CAPT.fall(&int_capt);
+    
+    passage=0;
+    while(passage == 0){
+       printf("passage 0 \n\r");
+    }
+    
+    timer1.attach(&int_timer, 3);
+    CAPT.rise(&int_capt2);
+    CAPT.fall(&int_capt2);
+    
+    while(passage == 1){
+        printf("passage 1 \n\r");
+    }
+    printf("passage 2\n\r");
+    timer1.detach();
+    CAPT.rise(&vide);
+    CAPT.fall(&vide);  
+}  
+
+int main() {
+    LocalFileSystem local("local");
+    
+
+    font = font_lin;
     init_vga();
     
-    while(1);
+    
+    acceuil();
+    
+    
+    //
+    while(1){
+       
+        if(CAPT.read() == 1)
+            lancer_action(); 
+        else
+            lancer_question();
+         
+    }
 }
\ No newline at end of file
--- a/vga640x400.lib	Wed Jun 12 08:19:57 2019 +0000
+++ b/vga640x400.lib	Thu Jun 13 15:56:16 2019 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Ivop/code/vga640x400/#78fa88bb24cb
+https://os.mbed.com/teams/Porjet-AWA-Rouecolo/code/vga640x400/#6e362b7be26b