code de la carte IHM avant les bugs et avant le travail effectué avec Melchior

Dependencies:   mbed SerialHalfDuplex SDFileSystem liaison_Bluetooth ident_crac DISCO-F469NI_portrait

Committer:
goldmas
Date:
Sat Jul 17 11:07:17 2021 +0000
Revision:
38:9d6a3ccc0582
Parent:
29:ff575aff301f
Dernier code de la coupe de fracne 2021

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gabrieltetar 1:7e925468f9d9 1 #include "global.h"
gabrieltetar 1:7e925468f9d9 2
gabrieltetar 1:7e925468f9d9 3
gabrieltetar 1:7e925468f9d9 4
gabrieltetar 1:7e925468f9d9 5
slowness 29:ff575aff301f 6 SDFileSystem sd(PB_15, PB_14,PD_3,PH_6,"sd");
gabrieltetar 1:7e925468f9d9 7
gabrieltetar 1:7e925468f9d9 8
gabrieltetar 1:7e925468f9d9 9 enum E_InstructionType charToInstructionType(char type)
gabrieltetar 1:7e925468f9d9 10 {
gabrieltetar 1:7e925468f9d9 11 switch(type)
gabrieltetar 1:7e925468f9d9 12 {
gabrieltetar 1:7e925468f9d9 13 case 'B': return MV_BEZIER;
gabrieltetar 1:7e925468f9d9 14 case 'C': return MV_COURBURE;
gabrieltetar 1:7e925468f9d9 15 case 'L': return MV_LINE;
gabrieltetar 1:7e925468f9d9 16 case 'T': return MV_TURN;
gabrieltetar 1:7e925468f9d9 17 case 'X': return MV_XYT;
gabrieltetar 1:7e925468f9d9 18 case 'R': return MV_RECALAGE;
gabrieltetar 1:7e925468f9d9 19 case 'A': return ACTION;
gabrieltetar 1:7e925468f9d9 20 case 'P': return POSITION_DEBUT;
gabrieltetar 1:7e925468f9d9 21 default: return UNKNOWN;
gabrieltetar 1:7e925468f9d9 22 }
gabrieltetar 1:7e925468f9d9 23 }
gabrieltetar 1:7e925468f9d9 24
gabrieltetar 1:7e925468f9d9 25 enum E_InstructionDirection charToInstructionDirection(char type)
gabrieltetar 1:7e925468f9d9 26 {
gabrieltetar 1:7e925468f9d9 27 switch(type)
gabrieltetar 1:7e925468f9d9 28 {
gabrieltetar 1:7e925468f9d9 29 case 'B': return BACKWARD;
gabrieltetar 1:7e925468f9d9 30 case 'F': return FORWARD;
gabrieltetar 1:7e925468f9d9 31 case 'R': return RELATIVE;
gabrieltetar 1:7e925468f9d9 32 case 'A': return ABSOLUTE;
gabrieltetar 1:7e925468f9d9 33 case 'L': return LEFT;
gabrieltetar 1:7e925468f9d9 34 default: return NODIRECTION;
gabrieltetar 1:7e925468f9d9 35 }
gabrieltetar 1:7e925468f9d9 36 }
gabrieltetar 1:7e925468f9d9 37
gabrieltetar 1:7e925468f9d9 38 enum E_InstructionPrecisionOuRecalage charToInstructionPrecisionOuRecalage(char type)
gabrieltetar 1:7e925468f9d9 39 {
gabrieltetar 1:7e925468f9d9 40 switch(type)
gabrieltetar 1:7e925468f9d9 41 {
gabrieltetar 1:7e925468f9d9 42 case 'P': return PRECISION;
gabrieltetar 1:7e925468f9d9 43 case 'X': return RECALAGE_X;
gabrieltetar 1:7e925468f9d9 44 case 'Y': return RECALAGE_Y;
gabrieltetar 1:7e925468f9d9 45 case 'T': return RECALAGE_T;
gabrieltetar 1:7e925468f9d9 46 default: return NOPRECISION;
gabrieltetar 1:7e925468f9d9 47 }
gabrieltetar 1:7e925468f9d9 48 }
gabrieltetar 1:7e925468f9d9 49
gabrieltetar 1:7e925468f9d9 50 enum E_InstructionNextActionType charToInstructionNextActionType(char type)
gabrieltetar 1:7e925468f9d9 51 {
gabrieltetar 1:7e925468f9d9 52 switch(type)
gabrieltetar 1:7e925468f9d9 53 {
gabrieltetar 1:7e925468f9d9 54 case 'J': return JUMP;
gabrieltetar 1:7e925468f9d9 55 case 'W': return WAIT;
gabrieltetar 1:7e925468f9d9 56 case 'E': return ENCHAINEMENT;
gabrieltetar 1:7e925468f9d9 57 case 'M': return MECANIQUE;
gabrieltetar 1:7e925468f9d9 58 case 'C': return CAPTEUR;
gabrieltetar 1:7e925468f9d9 59 default: return NONEXTACTION;
gabrieltetar 1:7e925468f9d9 60 }
gabrieltetar 1:7e925468f9d9 61 }
gabrieltetar 1:7e925468f9d9 62
gabrieltetar 1:7e925468f9d9 63 enum E_InstructionNextActionJumpType charToInstructionNextActionJumpType(char type)
gabrieltetar 1:7e925468f9d9 64 {
gabrieltetar 1:7e925468f9d9 65 switch(type)
gabrieltetar 1:7e925468f9d9 66 {
gabrieltetar 1:7e925468f9d9 67 case 'T': return JUMP_TIME;
gabrieltetar 1:7e925468f9d9 68 case 'P': return JUMP_POSITION;
gabrieltetar 1:7e925468f9d9 69 default: return NONEXTACTIONJUMPTYPE;
gabrieltetar 1:7e925468f9d9 70 }
gabrieltetar 1:7e925468f9d9 71 }
gabrieltetar 1:7e925468f9d9 72
gabrieltetar 1:7e925468f9d9 73 /****************************************************************************************/
gabrieltetar 1:7e925468f9d9 74 /* FUNCTION NAME: stringToInstruction */
gabrieltetar 1:7e925468f9d9 75 /* DESCRIPTION : Conversion d'une ligne du fichier de strat en instruction */
gabrieltetar 1:7e925468f9d9 76 /****************************************************************************************/
gabrieltetar 1:7e925468f9d9 77 struct S_Instruction stringToInstruction(char line[]) {
gabrieltetar 1:7e925468f9d9 78 struct S_Instruction instruction;
gabrieltetar 1:7e925468f9d9 79
gabrieltetar 1:7e925468f9d9 80 char instructionOrder;
gabrieltetar 1:7e925468f9d9 81 char instructionDirection;
gabrieltetar 1:7e925468f9d9 82 char instructionPrecision;
gabrieltetar 1:7e925468f9d9 83 char instructionNextActionType;
gabrieltetar 1:7e925468f9d9 84 char instructionJumpAction;
gabrieltetar 1:7e925468f9d9 85 int errorCode = 0;
gabrieltetar 1:7e925468f9d9 86 /*
gabrieltetar 1:7e925468f9d9 87 Info sur la fonction sscanf
gabrieltetar 1:7e925468f9d9 88 %d -> Entier signé
gabrieltetar 1:7e925468f9d9 89 %u -> Entié non signé
gabrieltetar 1:7e925468f9d9 90 %c -> char
gabrieltetar 1:7e925468f9d9 91 */
gabrieltetar 1:7e925468f9d9 92 errorCode = sscanf(line, "%hd,%c,%c,%hu,%hu,%hd,%c,%c,%c,%hu,%hu,%hd,%hd,%hu,%hu,%hd",
gabrieltetar 1:7e925468f9d9 93 &instruction.lineNumber,
gabrieltetar 1:7e925468f9d9 94 &instructionOrder,
gabrieltetar 1:7e925468f9d9 95 &instructionDirection,
gabrieltetar 1:7e925468f9d9 96 &instruction.arg1,
gabrieltetar 1:7e925468f9d9 97 &instruction.arg2,
gabrieltetar 1:7e925468f9d9 98 &instruction.arg3,
gabrieltetar 1:7e925468f9d9 99 &instructionPrecision,
gabrieltetar 1:7e925468f9d9 100 &instructionNextActionType,
gabrieltetar 1:7e925468f9d9 101 &instructionJumpAction,
gabrieltetar 1:7e925468f9d9 102 &instruction.JumpTimeOrX,
gabrieltetar 1:7e925468f9d9 103 &instruction.JumpY,
gabrieltetar 1:7e925468f9d9 104 &instruction.nextLineOK,
gabrieltetar 1:7e925468f9d9 105 &instruction.nextLineError,
gabrieltetar 1:7e925468f9d9 106 &instruction.arg4,
gabrieltetar 1:7e925468f9d9 107 &instruction.arg5,
gabrieltetar 1:7e925468f9d9 108 &instruction.arg6
gabrieltetar 1:7e925468f9d9 109 );
gabrieltetar 1:7e925468f9d9 110 /*
gabrieltetar 1:7e925468f9d9 111 if(errorCode != 13) {
gabrieltetar 1:7e925468f9d9 112 errorInstructionLoop();//L'instruction est pas bonne !!
gabrieltetar 1:7e925468f9d9 113 }*/
gabrieltetar 1:7e925468f9d9 114
gabrieltetar 1:7e925468f9d9 115 instruction.order = charToInstructionType(instructionOrder);
gabrieltetar 1:7e925468f9d9 116 instruction.direction = charToInstructionDirection(instructionDirection);
gabrieltetar 1:7e925468f9d9 117 instruction.precision = charToInstructionPrecisionOuRecalage(instructionPrecision);
gabrieltetar 1:7e925468f9d9 118 instruction.nextActionType = charToInstructionNextActionType(instructionNextActionType);
gabrieltetar 1:7e925468f9d9 119 instruction.jumpAction = charToInstructionNextActionJumpType(instructionJumpAction);
gabrieltetar 1:7e925468f9d9 120
gabrieltetar 1:7e925468f9d9 121
gabrieltetar 1:7e925468f9d9 122 return instruction;
gabrieltetar 1:7e925468f9d9 123 }
gabrieltetar 1:7e925468f9d9 124
gabrieltetar 1:7e925468f9d9 125 /****************************************************************************************/
gabrieltetar 1:7e925468f9d9 126 /* FUNCTION NAME: loadAllInstruction */
gabrieltetar 1:7e925468f9d9 127 /* DESCRIPTION : Charger toutes les instructions du fichier de stratégie */
gabrieltetar 1:7e925468f9d9 128 /* Il faut utiliser strcpy(cheminFileStart,"/local/strat.txt"); */
gabrieltetar 1:7e925468f9d9 129 /* pour indiquer le fichier à utiliser */
gabrieltetar 1:7e925468f9d9 130 /****************************************************************************************/
gabrieltetar 1:7e925468f9d9 131 void loadAllInstruction( signed char Strategie) {
gabrieltetar 1:7e925468f9d9 132
gabrieltetar 1:7e925468f9d9 133 struct S_Instruction instruction;
gabrieltetar 1:7e925468f9d9 134 char LineBuffer[SIZE];
gabrieltetar 1:7e925468f9d9 135 printf("Reading file : ");
gabrieltetar 1:7e925468f9d9 136 printf(strat_sd[Strategie]);
gabrieltetar 1:7e925468f9d9 137 printf("\n");
gabrieltetar 1:7e925468f9d9 138 strcpy(PATH[Strategie],"/sd/");
gabrieltetar 1:7e925468f9d9 139 strcat(PATH[Strategie],strat_sd[Strategie]);
gabrieltetar 1:7e925468f9d9 140 strcat(PATH[Strategie],".txt");
gabrieltetar 1:7e925468f9d9 141 FILE *testFile = fopen(PATH[Strategie], "rt"); //Ouverture du fichier en mode lecture seul au format string
gabrieltetar 1:7e925468f9d9 142
gabrieltetar 1:7e925468f9d9 143 nb_instructions = 0;
gabrieltetar 1:7e925468f9d9 144 while (fgets(LineBuffer, SIZE, testFile) != NULL) {
gabrieltetar 1:7e925468f9d9 145 instruction = stringToInstruction(LineBuffer);
gabrieltetar 1:7e925468f9d9 146 strat_instructions[nb_instructions] = instruction;
gabrieltetar 1:7e925468f9d9 147 if(strat_instructions[nb_instructions].order == UNKNOWN) {
gabrieltetar 1:7e925468f9d9 148 Button STRAT_1 (0, 30, 190, 110, PATH[Strategie]);
gabrieltetar 1:7e925468f9d9 149 STRAT_1.Draw(0xFFF0F0F0, 0);
gabrieltetar 1:7e925468f9d9 150 errorInstructionLoop();//L'instruction est pas bonne !!
gabrieltetar 1:7e925468f9d9 151 }
gabrieltetar 1:7e925468f9d9 152 //printf(LineBuffer);
gabrieltetar 1:7e925468f9d9 153 //debug_Instruction(instruction);
gabrieltetar 1:7e925468f9d9 154 nb_instructions++;
gabrieltetar 1:7e925468f9d9 155 }
gabrieltetar 1:7e925468f9d9 156 printf("nb instruction = %d\n",nb_instructions);
gabrieltetar 1:7e925468f9d9 157 fclose(testFile);
gabrieltetar 1:7e925468f9d9 158
gabrieltetar 1:7e925468f9d9 159 }
gabrieltetar 1:7e925468f9d9 160
gabrieltetar 1:7e925468f9d9 161 /****************************************************************************************/
gabrieltetar 1:7e925468f9d9 162 /* FUNCTION NAME: FileExists */
gabrieltetar 1:7e925468f9d9 163 /* DESCRIPTION : Permet de vérifier si un fichier existe */
gabrieltetar 1:7e925468f9d9 164 /****************************************************************************************/
gabrieltetar 1:7e925468f9d9 165 int FileExists(const char *fname)
gabrieltetar 1:7e925468f9d9 166 {
gabrieltetar 1:7e925468f9d9 167 FILE *file;
gabrieltetar 1:7e925468f9d9 168 if (file == fopen(fname, "r"))
gabrieltetar 1:7e925468f9d9 169 {
gabrieltetar 1:7e925468f9d9 170 fclose(file);
gabrieltetar 1:7e925468f9d9 171 return 1;
gabrieltetar 1:7e925468f9d9 172 }
gabrieltetar 1:7e925468f9d9 173 return 0;
gabrieltetar 1:7e925468f9d9 174 }