avec dfu
Fork of Utils by
Utils.cpp@16:74cb32bb162f, 2018-05-03 (annotated)
- Committer:
- POTLESS_2
- Date:
- Thu May 03 08:42:58 2018 +0000
- Revision:
- 16:74cb32bb162f
- Parent:
- 15:a8c19ad9c11d
- Child:
- 17:af9dbae179c1
derni?re version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
POTLESS_2 | 0:794c15bd30b0 | 1 | #include "mbed.h" |
POTLESS_2 | 0:794c15bd30b0 | 2 | #include "Utils.h" |
POTLESS_2 | 0:794c15bd30b0 | 3 | |
POTLESS_2 | 9:fa2818db80cf | 4 | //SDBlockDevice bd(Flash_MOSI, Flash_MISO, Flash_SCK, Flash_CS); |
POTLESS_2 | 9:fa2818db80cf | 5 | SPIFBlockDevice bd(Flash_MOSI, Flash_MISO, Flash_SCK, Flash_CS); |
POTLESS_2 | 11:a41267cffa61 | 6 | |
POTLESS_2 | 2:5af7a1fb1903 | 7 | FATFileSystem Root("Root"); |
POTLESS_2 | 0:794c15bd30b0 | 8 | |
POTLESS_2 | 3:01677db45b2a | 9 | int Exist_Val = 0; |
POTLESS_2 | 3:01677db45b2a | 10 | |
POTLESS_2 | 11:a41267cffa61 | 11 | //Init des PIN i2c pour l'eeprom |
POTLESS_2 | 11:a41267cffa61 | 12 | I2C I2C_EEPROM(SDA_PIN, SCL_PIN); |
POTLESS_2 | 11:a41267cffa61 | 13 | |
POTLESS_2 | 0:794c15bd30b0 | 14 | void return_error(int ret_val) |
POTLESS_2 | 0:794c15bd30b0 | 15 | { |
POTLESS_2 | 4:872676dd87a4 | 16 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 17 | if (ret_val) { |
POTLESS_2 | 12:9dd7c462a2c0 | 18 | DEEP_DEBUG(" Problème Flash = %d\r\n", ret_val); |
POTLESS_2 | 3:01677db45b2a | 19 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 20 | } else { |
POTLESS_2 | 12:9dd7c462a2c0 | 21 | DEEP_DEBUG(" Flash -> OK.\r\n"); |
POTLESS_2 | 3:01677db45b2a | 22 | Exist_Val = 1; |
POTLESS_2 | 6:8bae97034114 | 23 | } |
POTLESS_2 | 6:8bae97034114 | 24 | wait_ms(100); |
POTLESS_2 | 0:794c15bd30b0 | 25 | } |
POTLESS_2 | 0:794c15bd30b0 | 26 | |
POTLESS_2 | 0:794c15bd30b0 | 27 | void errno_error(void* ret_val) |
POTLESS_2 | 0:794c15bd30b0 | 28 | { |
POTLESS_2 | 4:872676dd87a4 | 29 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 30 | if (ret_val == NULL) { |
POTLESS_2 | 12:9dd7c462a2c0 | 31 | DEEP_DEBUG(" Problème Flash = %d \r\n", errno); |
POTLESS_2 | 3:01677db45b2a | 32 | Exist_Val = 0; |
POTLESS_2 | 6:8bae97034114 | 33 | } else { |
POTLESS_2 | 12:9dd7c462a2c0 | 34 | DEEP_DEBUG(" Flash -> OK.\r\n"); |
POTLESS_2 | 3:01677db45b2a | 35 | Exist_Val = 1; |
POTLESS_2 | 6:8bae97034114 | 36 | } |
POTLESS_2 | 6:8bae97034114 | 37 | wait_ms(100); |
POTLESS_2 | 0:794c15bd30b0 | 38 | } |
POTLESS_2 | 0:794c15bd30b0 | 39 | |
POTLESS_2 | 15:a8c19ad9c11d | 40 | void UTILS::Flash_Infos(Serial *serial_port) |
POTLESS_2 | 8:23fd400c4edd | 41 | { |
POTLESS_2 | 16:74cb32bb162f | 42 | serial_port->printf("?\r\n"); |
POTLESS_2 | 16:74cb32bb162f | 43 | |
POTLESS_2 | 15:a8c19ad9c11d | 44 | serial_port->printf(" Flash size : %llu Mb\r\n", bd.size() / 1048576); |
POTLESS_2 | 15:a8c19ad9c11d | 45 | serial_port->printf(" Flash read size : %llu\r\n", bd.get_read_size()); |
POTLESS_2 | 15:a8c19ad9c11d | 46 | serial_port->printf(" Flash program size : %llu\r\n", bd.get_program_size()); |
POTLESS_2 | 15:a8c19ad9c11d | 47 | serial_port->printf(" Flash erase size : %llu\r\n", bd.get_erase_size()); |
POTLESS_2 | 8:23fd400c4edd | 48 | } |
POTLESS_2 | 8:23fd400c4edd | 49 | |
POTLESS_2 | 15:a8c19ad9c11d | 50 | void UTILS::Get_File_Size(Serial *serial_port, char* File_Name) |
POTLESS_2 | 11:a41267cffa61 | 51 | { |
POTLESS_2 | 16:74cb32bb162f | 52 | serial_port->printf("?\r\n"); |
POTLESS_2 | 16:74cb32bb162f | 53 | |
POTLESS_2 | 15:a8c19ad9c11d | 54 | char filename[50]; |
POTLESS_2 | 8:23fd400c4edd | 55 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 8:23fd400c4edd | 56 | |
POTLESS_2 | 8:23fd400c4edd | 57 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 11:a41267cffa61 | 58 | errno_error(fd); |
POTLESS_2 | 11:a41267cffa61 | 59 | |
POTLESS_2 | 8:23fd400c4edd | 60 | fseek(fd, 0, SEEK_END); |
POTLESS_2 | 8:23fd400c4edd | 61 | int size = ftell(fd); |
POTLESS_2 | 8:23fd400c4edd | 62 | fseek(fd, 0, SEEK_SET); |
POTLESS_2 | 11:a41267cffa61 | 63 | |
POTLESS_2 | 8:23fd400c4edd | 64 | fclose(fd); |
POTLESS_2 | 11:a41267cffa61 | 65 | |
POTLESS_2 | 15:a8c19ad9c11d | 66 | serial_port->printf(" Taille du fichier %s = %d Kb\r\n", filename, size / 1024); |
POTLESS_2 | 8:23fd400c4edd | 67 | } |
POTLESS_2 | 8:23fd400c4edd | 68 | |
POTLESS_2 | 0:794c15bd30b0 | 69 | void UTILS::Store_A_Val(float Val_To_Store, char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 70 | { |
POTLESS_2 | 0:794c15bd30b0 | 71 | |
POTLESS_2 | 15:a8c19ad9c11d | 72 | char filename[50]; |
POTLESS_2 | 15:a8c19ad9c11d | 73 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 74 | |
POTLESS_2 | 0:794c15bd30b0 | 75 | FILE* fd = fopen(filename, "w"); |
POTLESS_2 | 0:794c15bd30b0 | 76 | errno_error(fd); |
POTLESS_2 | 0:794c15bd30b0 | 77 | fprintf(fd, "%f\r\n", Val_To_Store); |
POTLESS_2 | 0:794c15bd30b0 | 78 | fclose(fd); |
POTLESS_2 | 0:794c15bd30b0 | 79 | |
POTLESS_2 | 12:9dd7c462a2c0 | 80 | DEEP_DEBUG(" \r\n %s sauvegardée = %f\r\n", filename, Val_To_Store); |
POTLESS_2 | 0:794c15bd30b0 | 81 | |
POTLESS_2 | 0:794c15bd30b0 | 82 | } |
POTLESS_2 | 0:794c15bd30b0 | 83 | |
POTLESS_2 | 0:794c15bd30b0 | 84 | float UTILS::Read_A_Val(char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 85 | { |
POTLESS_2 | 0:794c15bd30b0 | 86 | char buffer[10] = {0}; |
POTLESS_2 | 0:794c15bd30b0 | 87 | char c = {0}; |
POTLESS_2 | 0:794c15bd30b0 | 88 | char *token; |
POTLESS_2 | 0:794c15bd30b0 | 89 | int i = 0; |
POTLESS_2 | 0:794c15bd30b0 | 90 | |
POTLESS_2 | 15:a8c19ad9c11d | 91 | char filename[50]; |
POTLESS_2 | 15:a8c19ad9c11d | 92 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 93 | |
POTLESS_2 | 12:9dd7c462a2c0 | 94 | DEEP_DEBUG(" \n Récupération de %s...\r\n", filename); |
POTLESS_2 | 0:794c15bd30b0 | 95 | |
POTLESS_2 | 0:794c15bd30b0 | 96 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 0:794c15bd30b0 | 97 | errno_error(fd); |
POTLESS_2 | 6:8bae97034114 | 98 | |
POTLESS_2 | 0:794c15bd30b0 | 99 | while ((c != '\n') && (i < 10)) { |
POTLESS_2 | 0:794c15bd30b0 | 100 | c = fgetc(fd); |
POTLESS_2 | 0:794c15bd30b0 | 101 | buffer[i] = c; |
POTLESS_2 | 0:794c15bd30b0 | 102 | i++; |
POTLESS_2 | 0:794c15bd30b0 | 103 | } |
POTLESS_2 | 0:794c15bd30b0 | 104 | |
POTLESS_2 | 0:794c15bd30b0 | 105 | token = strtok(buffer, "\n"); |
POTLESS_2 | 0:794c15bd30b0 | 106 | |
POTLESS_2 | 0:794c15bd30b0 | 107 | float val = atof(token); |
POTLESS_2 | 0:794c15bd30b0 | 108 | |
POTLESS_2 | 12:9dd7c462a2c0 | 109 | DEEP_DEBUG(" Valeur Récupérée = %f\r\n", val); |
POTLESS_2 | 0:794c15bd30b0 | 110 | |
POTLESS_2 | 0:794c15bd30b0 | 111 | fclose(fd); |
POTLESS_2 | 0:794c15bd30b0 | 112 | |
POTLESS_2 | 0:794c15bd30b0 | 113 | return val; |
POTLESS_2 | 0:794c15bd30b0 | 114 | } |
POTLESS_2 | 0:794c15bd30b0 | 115 | |
POTLESS_2 | 0:794c15bd30b0 | 116 | |
POTLESS_2 | 6:8bae97034114 | 117 | void UTILS::Write_Flash_File(char* To_Store, char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 118 | { |
POTLESS_2 | 2:5af7a1fb1903 | 119 | char filename[50]; |
POTLESS_2 | 2:5af7a1fb1903 | 120 | sprintf(filename, "/Root/%s", (string)File_Name); |
POTLESS_2 | 6:8bae97034114 | 121 | |
POTLESS_2 | 0:794c15bd30b0 | 122 | FILE* fd = fopen(filename, "a"); |
POTLESS_2 | 6:8bae97034114 | 123 | |
POTLESS_2 | 0:794c15bd30b0 | 124 | errno_error(fd); |
POTLESS_2 | 0:794c15bd30b0 | 125 | fprintf(fd, "%s\r\n", To_Store); |
POTLESS_2 | 0:794c15bd30b0 | 126 | fclose(fd); |
POTLESS_2 | 0:794c15bd30b0 | 127 | |
POTLESS_2 | 12:9dd7c462a2c0 | 128 | DEEP_DEBUG(" Enregistrement de %s OK\r\n\r\n", filename); |
POTLESS_2 | 0:794c15bd30b0 | 129 | } |
POTLESS_2 | 0:794c15bd30b0 | 130 | |
POTLESS_2 | 6:8bae97034114 | 131 | /* |
POTLESS_2 | 6:8bae97034114 | 132 | void UTILS::Read_Flash_File(char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 133 | { |
POTLESS_2 | 15:a8c19ad9c11d | 134 | char filename[50]; |
POTLESS_2 | 2:5af7a1fb1903 | 135 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 6:8bae97034114 | 136 | |
POTLESS_2 | 0:794c15bd30b0 | 137 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 0:794c15bd30b0 | 138 | errno_error(fd); |
POTLESS_2 | 0:794c15bd30b0 | 139 | |
POTLESS_2 | 6:8bae97034114 | 140 | //printf(" Contenu du fichier :\r\n\r\n"); |
POTLESS_2 | 6:8bae97034114 | 141 | char buff[100] = {0}; |
POTLESS_2 | 11:a41267cffa61 | 142 | |
POTLESS_2 | 11:a41267cffa61 | 143 | while (!feof(fd)) { |
POTLESS_2 | 0:794c15bd30b0 | 144 | int size = fread(&buff[0], 1, 15, fd); |
POTLESS_2 | 11:a41267cffa61 | 145 | fwrite(&buff[0], 1, size, stdout); |
POTLESS_2 | 0:794c15bd30b0 | 146 | } |
POTLESS_2 | 6:8bae97034114 | 147 | //printf("\r\n Fin du fichier.\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 148 | fclose(fd); |
POTLESS_2 | 11:a41267cffa61 | 149 | |
POTLESS_2 | 6:8bae97034114 | 150 | } |
POTLESS_2 | 6:8bae97034114 | 151 | */ |
POTLESS_2 | 6:8bae97034114 | 152 | |
POTLESS_2 | 15:a8c19ad9c11d | 153 | void UTILS::Read_Flash_File(Serial *serial_port, char* File_Name) |
POTLESS_2 | 15:a8c19ad9c11d | 154 | { |
POTLESS_2 | 16:74cb32bb162f | 155 | serial_port->printf("?\r\n"); |
POTLESS_2 | 16:74cb32bb162f | 156 | |
POTLESS_2 | 15:a8c19ad9c11d | 157 | if (File_Exist(File_Name)) { |
POTLESS_2 | 15:a8c19ad9c11d | 158 | char filename[50]; |
POTLESS_2 | 15:a8c19ad9c11d | 159 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 6:8bae97034114 | 160 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 11:a41267cffa61 | 161 | errno_error(fd); |
POTLESS_2 | 6:8bae97034114 | 162 | char s1[100]; |
POTLESS_2 | 8:23fd400c4edd | 163 | printf("\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 164 | DEBUG(" Contenu du fichier :\r\n\r\n"); |
POTLESS_2 | 6:8bae97034114 | 165 | while (!feof(fd)) { |
POTLESS_2 | 6:8bae97034114 | 166 | memset(s1, 0, sizeof(s1)); |
POTLESS_2 | 6:8bae97034114 | 167 | fgets(s1, sizeof(s1), fd); |
POTLESS_2 | 16:74cb32bb162f | 168 | serial_port->printf("%s", s1); |
POTLESS_2 | 6:8bae97034114 | 169 | } |
POTLESS_2 | 11:a41267cffa61 | 170 | fclose(fd); |
POTLESS_2 | 15:a8c19ad9c11d | 171 | DEBUG("\r\n Fin du fichier.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 172 | } |
POTLESS_2 | 0:794c15bd30b0 | 173 | } |
POTLESS_2 | 0:794c15bd30b0 | 174 | |
POTLESS_2 | 15:a8c19ad9c11d | 175 | bool UTILS::File_Exist(char* File_Name) |
POTLESS_2 | 3:01677db45b2a | 176 | { |
POTLESS_2 | 15:a8c19ad9c11d | 177 | char filename[50]; |
POTLESS_2 | 15:a8c19ad9c11d | 178 | sprintf(filename, "/Root/%s", File_Name); |
POTLESS_2 | 6:8bae97034114 | 179 | |
POTLESS_2 | 3:01677db45b2a | 180 | FILE* fd = fopen(filename, "r"); |
POTLESS_2 | 3:01677db45b2a | 181 | errno_error(fd); |
POTLESS_2 | 6:8bae97034114 | 182 | |
POTLESS_2 | 6:8bae97034114 | 183 | if (Exist_Val == 0) { |
POTLESS_2 | 10:21f3ff5d6a3d | 184 | DEBUG(" Le fichier %s n'existe pas....\r\n", filename); |
POTLESS_2 | 4:872676dd87a4 | 185 | fclose(fd); |
POTLESS_2 | 3:01677db45b2a | 186 | return false; |
POTLESS_2 | 5:0f3b6e6677ef | 187 | } |
POTLESS_2 | 6:8bae97034114 | 188 | |
POTLESS_2 | 6:8bae97034114 | 189 | if (Exist_Val == 1) { |
POTLESS_2 | 3:01677db45b2a | 190 | fclose(fd); |
POTLESS_2 | 3:01677db45b2a | 191 | return true; |
POTLESS_2 | 6:8bae97034114 | 192 | } |
POTLESS_2 | 3:01677db45b2a | 193 | } |
POTLESS_2 | 3:01677db45b2a | 194 | |
POTLESS_2 | 6:8bae97034114 | 195 | void UTILS::Delete_Flash_File(char* File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 196 | { |
POTLESS_2 | 15:a8c19ad9c11d | 197 | char filename[50]; |
POTLESS_2 | 6:8bae97034114 | 198 | sprintf(filename, "%s", File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 199 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 200 | error = Root.remove(filename); |
POTLESS_2 | 0:794c15bd30b0 | 201 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 202 | |
POTLESS_2 | 12:9dd7c462a2c0 | 203 | DEBUG(" Fichier %s effacé.\r\n", filename); |
POTLESS_2 | 0:794c15bd30b0 | 204 | } |
POTLESS_2 | 0:794c15bd30b0 | 205 | |
POTLESS_2 | 6:8bae97034114 | 206 | void UTILS::Clean_Flash() |
POTLESS_2 | 6:8bae97034114 | 207 | { |
POTLESS_2 | 12:9dd7c462a2c0 | 208 | DEBUG(" Nettoyage de la Flash.\r\n"); |
POTLESS_2 | 12:9dd7c462a2c0 | 209 | //float Saved_O2 = UTILS::Read_A_Val("Calibration_O2"); |
POTLESS_2 | 16:74cb32bb162f | 210 | int Saved_Motor_P = (int)UTILS::Read_A_Val("Servo_Poumon.sys"); |
POTLESS_2 | 16:74cb32bb162f | 211 | int Saved_Motor_F = (int)UTILS::Read_A_Val("Servo_Fuite.sys"); |
POTLESS_2 | 15:a8c19ad9c11d | 212 | int ARNSRS_ID = (int)UTILS::Read_A_Val("ARNSRS_ID.sys"); |
POTLESS_2 | 6:8bae97034114 | 213 | UTILS::UnMount_Flash(); |
POTLESS_2 | 6:8bae97034114 | 214 | UTILS::Format_Flash(); |
POTLESS_2 | 6:8bae97034114 | 215 | UTILS::Mount_Flash(); |
POTLESS_2 | 12:9dd7c462a2c0 | 216 | //UTILS::Store_A_Val(Saved_O2, "Calibration_O2"); |
POTLESS_2 | 16:74cb32bb162f | 217 | UTILS::Store_A_Val(Saved_Motor_P, "Servo_Poumon.sys"); |
POTLESS_2 | 16:74cb32bb162f | 218 | UTILS::Store_A_Val(Saved_Motor_F, "Servo_Fuite.sys"); |
POTLESS_2 | 15:a8c19ad9c11d | 219 | UTILS::Store_A_Val(ARNSRS_ID, "ARNSRS_ID.sys"); |
POTLESS_2 | 12:9dd7c462a2c0 | 220 | DEBUG(" Flash nettoyée.\r\n"); |
POTLESS_2 | 12:9dd7c462a2c0 | 221 | DEBUG(" Redémmarage code.\r\n"); |
POTLESS_2 | 13:ff0f36a6d800 | 222 | UTILS::UnMount_Flash(); |
POTLESS_2 | 11:a41267cffa61 | 223 | NVIC_SystemReset(); |
POTLESS_2 | 6:8bae97034114 | 224 | } |
POTLESS_2 | 6:8bae97034114 | 225 | |
POTLESS_2 | 15:a8c19ad9c11d | 226 | void UTILS::Clean_Flash_All() |
POTLESS_2 | 15:a8c19ad9c11d | 227 | { |
POTLESS_2 | 15:a8c19ad9c11d | 228 | DEBUG(" Nettoyage complet de la Flash.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 229 | UTILS::UnMount_Flash(); |
POTLESS_2 | 15:a8c19ad9c11d | 230 | UTILS::Format_Flash(); |
POTLESS_2 | 15:a8c19ad9c11d | 231 | NVIC_SystemReset(); |
POTLESS_2 | 15:a8c19ad9c11d | 232 | } |
POTLESS_2 | 15:a8c19ad9c11d | 233 | |
POTLESS_2 | 6:8bae97034114 | 234 | void UTILS::Rename_Flash_File(char* Old_File_Name, char* New_File_Name) |
POTLESS_2 | 0:794c15bd30b0 | 235 | { |
POTLESS_2 | 15:a8c19ad9c11d | 236 | char Oldfilename[50]; |
POTLESS_2 | 2:5af7a1fb1903 | 237 | sprintf(Oldfilename, "/Root/%s", Old_File_Name); |
POTLESS_2 | 15:a8c19ad9c11d | 238 | char Newfilename[50]; |
POTLESS_2 | 2:5af7a1fb1903 | 239 | sprintf(Newfilename, "/Root/%s", New_File_Name); |
POTLESS_2 | 0:794c15bd30b0 | 240 | |
POTLESS_2 | 0:794c15bd30b0 | 241 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 242 | error = Root.rename(Oldfilename, Newfilename); |
POTLESS_2 | 0:794c15bd30b0 | 243 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 244 | |
POTLESS_2 | 12:9dd7c462a2c0 | 245 | DEBUG(" Fichier %s renommé en %s.\r\n", Oldfilename, Newfilename); |
POTLESS_2 | 0:794c15bd30b0 | 246 | } |
POTLESS_2 | 0:794c15bd30b0 | 247 | |
POTLESS_2 | 6:8bae97034114 | 248 | void UTILS::Mount_Flash() |
POTLESS_2 | 0:794c15bd30b0 | 249 | { |
POTLESS_2 | 6:8bae97034114 | 250 | //Montage Flash |
POTLESS_2 | 10:21f3ff5d6a3d | 251 | DEBUG(" Montage Flash \"/Root\". \r\n\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 252 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 253 | error = Root.mount(&bd); |
POTLESS_2 | 0:794c15bd30b0 | 254 | return_error(error); |
POTLESS_2 | 1:a937433a95c8 | 255 | if (error > 0) { |
POTLESS_2 | 0:794c15bd30b0 | 256 | //On re format s'il n'y a as de file system...normalement une seul fois... |
POTLESS_2 | 10:21f3ff5d6a3d | 257 | DEBUG("Pas de File system, on format... "); |
POTLESS_2 | 6:8bae97034114 | 258 | Format_Flash(); |
POTLESS_2 | 0:794c15bd30b0 | 259 | } |
POTLESS_2 | 0:794c15bd30b0 | 260 | } |
POTLESS_2 | 0:794c15bd30b0 | 261 | |
POTLESS_2 | 6:8bae97034114 | 262 | void UTILS::UnMount_Flash() |
POTLESS_2 | 0:794c15bd30b0 | 263 | { |
POTLESS_2 | 6:8bae97034114 | 264 | //De Montage Flash |
POTLESS_2 | 10:21f3ff5d6a3d | 265 | DEBUG(" Demontage Flash \"/Root\". \r\n\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 266 | int error = 0; |
POTLESS_2 | 2:5af7a1fb1903 | 267 | error = Root.unmount(); |
POTLESS_2 | 0:794c15bd30b0 | 268 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 269 | } |
POTLESS_2 | 0:794c15bd30b0 | 270 | |
POTLESS_2 | 6:8bae97034114 | 271 | void UTILS::Format_Flash() |
POTLESS_2 | 0:794c15bd30b0 | 272 | { |
POTLESS_2 | 6:8bae97034114 | 273 | //Formatage Flash |
POTLESS_2 | 10:21f3ff5d6a3d | 274 | DEBUG(" Formatage Flash\r\n\r\n"); |
POTLESS_2 | 0:794c15bd30b0 | 275 | int error = 0; |
POTLESS_2 | 4:872676dd87a4 | 276 | error = FATFileSystem::format(&bd); |
POTLESS_2 | 2:5af7a1fb1903 | 277 | return_error(error); |
POTLESS_2 | 2:5af7a1fb1903 | 278 | } |
POTLESS_2 | 2:5af7a1fb1903 | 279 | |
POTLESS_2 | 15:a8c19ad9c11d | 280 | void UTILS::Dir_Flash(Serial *serial_port, char* Dir_Name) |
POTLESS_2 | 2:5af7a1fb1903 | 281 | { |
POTLESS_2 | 2:5af7a1fb1903 | 282 | int error = 0; |
POTLESS_2 | 3:01677db45b2a | 283 | int nb = 0; |
POTLESS_2 | 12:9dd7c462a2c0 | 284 | DEEP_DEBUG("\r\n Ouverture du répertoire %s\r\n", Dir_Name); |
POTLESS_2 | 15:a8c19ad9c11d | 285 | char Dirname[50]; |
POTLESS_2 | 2:5af7a1fb1903 | 286 | sprintf(Dirname, "/Root/%s", Dir_Name); |
POTLESS_2 | 6:8bae97034114 | 287 | |
POTLESS_2 | 2:5af7a1fb1903 | 288 | DIR* dir = opendir(Dirname); |
POTLESS_2 | 2:5af7a1fb1903 | 289 | |
POTLESS_2 | 2:5af7a1fb1903 | 290 | struct dirent* de; |
POTLESS_2 | 12:9dd7c462a2c0 | 291 | DEBUG(" Fichiers du répertoire :\r\n\r\n"); |
POTLESS_2 | 6:8bae97034114 | 292 | while((de = readdir(dir)) != NULL) { |
POTLESS_2 | 16:74cb32bb162f | 293 | serial_port->printf("%s\r\n", &(de->d_name)[0]); |
POTLESS_2 | 6:8bae97034114 | 294 | fflush(stdout); |
POTLESS_2 | 6:8bae97034114 | 295 | nb++; |
POTLESS_2 | 6:8bae97034114 | 296 | } |
POTLESS_2 | 16:74cb32bb162f | 297 | |
POTLESS_2 | 16:74cb32bb162f | 298 | serial_port->printf("!\r\n"); |
POTLESS_2 | 16:74cb32bb162f | 299 | |
POTLESS_2 | 10:21f3ff5d6a3d | 300 | DEBUG("\r\n Nombre de fichiers = %d\r\n", nb); |
POTLESS_2 | 12:9dd7c462a2c0 | 301 | DEEP_DEBUG(" Fermeture du répertoire.\r\n"); |
POTLESS_2 | 6:8bae97034114 | 302 | error = closedir(dir); |
POTLESS_2 | 0:794c15bd30b0 | 303 | return_error(error); |
POTLESS_2 | 0:794c15bd30b0 | 304 | } |
POTLESS_2 | 0:794c15bd30b0 | 305 | |
POTLESS_2 | 16:74cb32bb162f | 306 | |
POTLESS_2 | 3:01677db45b2a | 307 | int UTILS::File_Index() |
POTLESS_2 | 3:01677db45b2a | 308 | { |
POTLESS_2 | 3:01677db45b2a | 309 | int error = 0; |
POTLESS_2 | 3:01677db45b2a | 310 | int nb = 0; |
POTLESS_2 | 6:8bae97034114 | 311 | |
POTLESS_2 | 3:01677db45b2a | 312 | DIR* dir = opendir("/Root/"); |
POTLESS_2 | 3:01677db45b2a | 313 | struct dirent* de; |
POTLESS_2 | 6:8bae97034114 | 314 | while((de = readdir(dir)) != NULL) { |
POTLESS_2 | 6:8bae97034114 | 315 | nb++; |
POTLESS_2 | 3:01677db45b2a | 316 | } |
POTLESS_2 | 3:01677db45b2a | 317 | error = closedir(dir); |
POTLESS_2 | 3:01677db45b2a | 318 | return_error(error); |
POTLESS_2 | 6:8bae97034114 | 319 | |
POTLESS_2 | 3:01677db45b2a | 320 | return nb - 2; |
POTLESS_2 | 3:01677db45b2a | 321 | } |
POTLESS_2 | 3:01677db45b2a | 322 | |
POTLESS_2 | 0:794c15bd30b0 | 323 | //Remapping d'une valeur dans une autre échelle |
POTLESS_2 | 0:794c15bd30b0 | 324 | float UTILS::Remap(float x, float in_min, float in_max, float out_min, float out_max) |
POTLESS_2 | 0:794c15bd30b0 | 325 | { |
POTLESS_2 | 0:794c15bd30b0 | 326 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; |
POTLESS_2 | 0:794c15bd30b0 | 327 | } |
POTLESS_2 | 0:794c15bd30b0 | 328 | |
POTLESS_2 | 0:794c15bd30b0 | 329 | //Contraint une valeur entre deux limites |
POTLESS_2 | 0:794c15bd30b0 | 330 | float UTILS::constrain(float x, float a, float b) |
POTLESS_2 | 0:794c15bd30b0 | 331 | { |
POTLESS_2 | 0:794c15bd30b0 | 332 | if(x < a) { |
POTLESS_2 | 0:794c15bd30b0 | 333 | return a; |
POTLESS_2 | 0:794c15bd30b0 | 334 | } else if(b < x) { |
POTLESS_2 | 0:794c15bd30b0 | 335 | return b; |
POTLESS_2 | 0:794c15bd30b0 | 336 | } else |
POTLESS_2 | 0:794c15bd30b0 | 337 | return x; |
POTLESS_2 | 6:8bae97034114 | 338 | } |
POTLESS_2 | 6:8bae97034114 | 339 | |
POTLESS_2 | 15:a8c19ad9c11d | 340 | void UTILS::Help(Serial *serial_port) |
POTLESS_2 | 6:8bae97034114 | 341 | { |
POTLESS_2 | 16:74cb32bb162f | 342 | serial_port->printf("?\r\n"); |
POTLESS_2 | 16:74cb32bb162f | 343 | |
POTLESS_2 | 15:a8c19ad9c11d | 344 | serial_port->printf(" COMMANDES GENERALES\r\n\r\n"); |
POTLESS_2 | 14:fbf4be649b6a | 345 | /* |
POTLESS_2 | 15:a8c19ad9c11d | 346 | serial_port->printf(" help = liste des commandes.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 347 | serial_port->printf(" start = démmarage des sorties moniteur.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 348 | serial_port->printf(" stop = arrêt des sorties moniteur.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 349 | serial_port->printf(" time X = met la RTC à l'heure, X en UNIX TIME.\n\r"); |
POTLESS_2 | 14:fbf4be649b6a | 350 | */ |
POTLESS_2 | 15:a8c19ad9c11d | 351 | serial_port->printf(" ARNSRS_ID X = entrée de l'identifiant de l'appareil X.\r\n"); |
POTLESS_2 | 14:fbf4be649b6a | 352 | /* |
POTLESS_2 | 15:a8c19ad9c11d | 353 | serial_port->printf(" sleep = mise en veille.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 354 | serial_port->printf(" reset = reset de la carte.\r\n\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 355 | serial_port->printf(" COMMANDES MEMOIRE\r\n\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 356 | serial_port->serial_port->printf(" rec = démarrage / arrêt enregistrement.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 357 | serial_port->printf(" flash_i = informations sur la flash.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 358 | serial_port->printf(" flash_u = démonte la flash. A faire avant de débrancher ou recharger un code.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 359 | serial_port->printf(" flash_m = monte la flash.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 360 | serial_port->printf(" flash_c = nettoyage flash, suppression des fichiers LOG.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 361 | serial_port->printf(" dir = liste des fichiers de la flash.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 362 | serial_port->printf(" del X = effacer le fichier LOG_X.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 363 | serial_port->printf(" get X = récupérer le contenu du fichier LOG_X.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 364 | serial_port->printf(" file_s X = récupérer la taille du fichier LOG_X.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 365 | //serial_port->printf(" file_i X = récupérer les informations sur le fichier LOG_X.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 366 | serial_port->printf(" COMMANDES MOTEURS\r\n\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 367 | serial_port->printf(" c_pou X = changement consigne volet poumon à X.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 368 | serial_port->printf(" c_fui X = changement consigne volet fuite à X.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 369 | serial_port->printf(" calib_p = calibration à 0 du volet poumon.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 370 | serial_port->printf(" calib_f = calibration à 0 du volet fuite.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 371 | serial_port->printf(" secu = mise des volets en mode sécu.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 372 | serial_port->printf(" check_F = sortie des valeurs 0 moteurs et ARNSRS_ID enregistrées.\r\n"); |
POTLESS_2 | 14:fbf4be649b6a | 373 | */ |
POTLESS_2 | 14:fbf4be649b6a | 374 | |
POTLESS_2 | 15:a8c19ad9c11d | 375 | serial_port->printf(" COMMANDES CAPTEURS\r\n\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 376 | serial_port->printf(" Head_ID X = Numérote le numéro X d'identification de la sensor Head dans l'eeprom.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 377 | serial_port->printf(" O2_1_ID X = Numérote le numéro X d'identification de la cellule O2 1 dans l'eeprom.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 378 | serial_port->printf(" O2_2_ID X = Numérote le numéro X d'identification de la cellule O2 2 dans l'eeprom.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 379 | serial_port->printf(" CO2_ID X = Numérote le numéro X d'identification du capteur CO2 dans l'eeprom.\r\n"); |
POTLESS_2 | 16:74cb32bb162f | 380 | //serial_port->printf(" check_E = sortie des valeurs de calibration enregistrées dans l'eeprom.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 381 | serial_port->printf(" calib_O2 X = calibration des cellules O2 dans l'air avec X itérations.\r\n"); |
POTLESS_2 | 12:9dd7c462a2c0 | 382 | |
POTLESS_2 | 15:a8c19ad9c11d | 383 | serial_port->printf(" Les commandes pour le Mini-r sont à entrer conformément à la doc. Les plus utilisée :\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 384 | serial_port->printf(" G = calibration du capteur CO2 dans l'air.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 385 | serial_port->printf(" K 0 = arrêt du capteur CO2.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 386 | serial_port->printf(" K 1 = capteur CO2 mode streaming.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 387 | serial_port->printf(" K 2 = capteur CO2 mode spooling.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 388 | serial_port->printf(" A X = digi filter X. X égal à 32, 64, 128...\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 389 | //serial_port->printf("\r\n"); |
POTLESS_2 | 6:8bae97034114 | 390 | fflush(stdout); |
POTLESS_2 | 11:a41267cffa61 | 391 | } |
POTLESS_2 | 11:a41267cffa61 | 392 | |
POTLESS_2 | 11:a41267cffa61 | 393 | void UTILS::clean_line_EEPROM(unsigned int eeaddress, int address) |
POTLESS_2 | 11:a41267cffa61 | 394 | { |
POTLESS_2 | 12:9dd7c462a2c0 | 395 | DEEP_DEBUG(" Effacage de la ligne à l'adresse %d de l'eeprom.\r\n", eeaddress); |
POTLESS_2 | 11:a41267cffa61 | 396 | |
POTLESS_2 | 11:a41267cffa61 | 397 | int size = 64; |
POTLESS_2 | 11:a41267cffa61 | 398 | char deleteData[] = {" "}; |
POTLESS_2 | 11:a41267cffa61 | 399 | |
POTLESS_2 | 11:a41267cffa61 | 400 | char i2cBuffer[size + 2]; |
POTLESS_2 | 11:a41267cffa61 | 401 | i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB |
POTLESS_2 | 11:a41267cffa61 | 402 | i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB |
POTLESS_2 | 11:a41267cffa61 | 403 | |
POTLESS_2 | 11:a41267cffa61 | 404 | for (int i = 0; i < size; i++) { |
POTLESS_2 | 11:a41267cffa61 | 405 | i2cBuffer[i + 2] = deleteData[i]; |
POTLESS_2 | 11:a41267cffa61 | 406 | } |
POTLESS_2 | 11:a41267cffa61 | 407 | |
POTLESS_2 | 11:a41267cffa61 | 408 | int result = I2C_EEPROM.write(address, i2cBuffer, size + 2, false); |
POTLESS_2 | 11:a41267cffa61 | 409 | wait_ms(6); |
POTLESS_2 | 11:a41267cffa61 | 410 | |
POTLESS_2 | 12:9dd7c462a2c0 | 411 | DEEP_DEBUG(" Ligne à l'adresse %d de l'eeprom effacée.\r\n", eeaddress); |
POTLESS_2 | 11:a41267cffa61 | 412 | } |
POTLESS_2 | 11:a41267cffa61 | 413 | |
POTLESS_2 | 11:a41267cffa61 | 414 | //Max 63 bit en écriture |
POTLESS_2 | 11:a41267cffa61 | 415 | void UTILS::write_EEPROM(char *data, unsigned int eeaddress, int address) |
POTLESS_2 | 11:a41267cffa61 | 416 | { |
POTLESS_2 | 11:a41267cffa61 | 417 | //Nettoyage de la ligne ou on va stocker la nouvelle data |
POTLESS_2 | 11:a41267cffa61 | 418 | clean_line_EEPROM(eeaddress); |
POTLESS_2 | 11:a41267cffa61 | 419 | |
POTLESS_2 | 11:a41267cffa61 | 420 | // On calcul de la taille de la chaine a enregistrer |
POTLESS_2 | 11:a41267cffa61 | 421 | char size = 0; |
POTLESS_2 | 11:a41267cffa61 | 422 | do { |
POTLESS_2 | 11:a41267cffa61 | 423 | size++; |
POTLESS_2 | 11:a41267cffa61 | 424 | } while (data[size]); |
POTLESS_2 | 11:a41267cffa61 | 425 | |
POTLESS_2 | 11:a41267cffa61 | 426 | char i2cBuffer[size + 2]; |
POTLESS_2 | 11:a41267cffa61 | 427 | i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB |
POTLESS_2 | 11:a41267cffa61 | 428 | i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB |
POTLESS_2 | 11:a41267cffa61 | 429 | |
POTLESS_2 | 11:a41267cffa61 | 430 | for (int i = 0; i < size; i++) { |
POTLESS_2 | 11:a41267cffa61 | 431 | i2cBuffer[i + 2] = data[i]; |
POTLESS_2 | 11:a41267cffa61 | 432 | } |
POTLESS_2 | 11:a41267cffa61 | 433 | |
POTLESS_2 | 11:a41267cffa61 | 434 | int res = I2C_EEPROM.write(address, i2cBuffer, size + 2, false); |
POTLESS_2 | 11:a41267cffa61 | 435 | |
POTLESS_2 | 11:a41267cffa61 | 436 | wait_ms(6); |
POTLESS_2 | 11:a41267cffa61 | 437 | |
POTLESS_2 | 12:9dd7c462a2c0 | 438 | DEEP_DEBUG(" Chaine écrite à l'adresse %d de l'eeprom : %s\r\n", eeaddress , data); |
POTLESS_2 | 11:a41267cffa61 | 439 | } |
POTLESS_2 | 11:a41267cffa61 | 440 | |
POTLESS_2 | 12:9dd7c462a2c0 | 441 | char* UTILS::read_EEPROM(unsigned int eeaddress , int address) |
POTLESS_2 | 12:9dd7c462a2c0 | 442 | { |
POTLESS_2 | 12:9dd7c462a2c0 | 443 | //On lit toute la ligne |
POTLESS_2 | 12:9dd7c462a2c0 | 444 | int size = 17; |
POTLESS_2 | 12:9dd7c462a2c0 | 445 | static char data[17]; |
POTLESS_2 | 12:9dd7c462a2c0 | 446 | |
POTLESS_2 | 12:9dd7c462a2c0 | 447 | char i2cBuffer[2]; |
POTLESS_2 | 12:9dd7c462a2c0 | 448 | i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB |
POTLESS_2 | 12:9dd7c462a2c0 | 449 | i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB |
POTLESS_2 | 12:9dd7c462a2c0 | 450 | |
POTLESS_2 | 12:9dd7c462a2c0 | 451 | // Reset eeprom pointer address |
POTLESS_2 | 12:9dd7c462a2c0 | 452 | int result = I2C_EEPROM.write(address, i2cBuffer, 2, false); |
POTLESS_2 | 12:9dd7c462a2c0 | 453 | wait_ms(6); |
POTLESS_2 | 12:9dd7c462a2c0 | 454 | |
POTLESS_2 | 12:9dd7c462a2c0 | 455 | // Read eeprom |
POTLESS_2 | 12:9dd7c462a2c0 | 456 | I2C_EEPROM.read(address, data, size); |
POTLESS_2 | 12:9dd7c462a2c0 | 457 | wait_ms(6); |
POTLESS_2 | 12:9dd7c462a2c0 | 458 | |
POTLESS_2 | 12:9dd7c462a2c0 | 459 | DEEP_DEBUG(" Char lu à l'adresse %d de l'eeprom : %s\r\n", eeaddress, &data); |
POTLESS_2 | 12:9dd7c462a2c0 | 460 | |
POTLESS_2 | 12:9dd7c462a2c0 | 461 | return data; |
POTLESS_2 | 12:9dd7c462a2c0 | 462 | } |
POTLESS_2 | 12:9dd7c462a2c0 | 463 | |
POTLESS_2 | 12:9dd7c462a2c0 | 464 | void UTILS::read_C_EEPROM(char *data, unsigned int eeaddress ,int address) |
POTLESS_2 | 12:9dd7c462a2c0 | 465 | { |
POTLESS_2 | 12:9dd7c462a2c0 | 466 | //On lit toute la ligne |
POTLESS_2 | 12:9dd7c462a2c0 | 467 | int size = 64; |
POTLESS_2 | 12:9dd7c462a2c0 | 468 | |
POTLESS_2 | 12:9dd7c462a2c0 | 469 | char i2cBuffer[2]; |
POTLESS_2 | 12:9dd7c462a2c0 | 470 | i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB |
POTLESS_2 | 12:9dd7c462a2c0 | 471 | i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB |
POTLESS_2 | 12:9dd7c462a2c0 | 472 | |
POTLESS_2 | 12:9dd7c462a2c0 | 473 | // Reset eeprom pointer address |
POTLESS_2 | 12:9dd7c462a2c0 | 474 | int result = I2C_EEPROM.write(address, i2cBuffer, 2, false); |
POTLESS_2 | 12:9dd7c462a2c0 | 475 | wait_ms(6); |
POTLESS_2 | 12:9dd7c462a2c0 | 476 | |
POTLESS_2 | 12:9dd7c462a2c0 | 477 | // Read eeprom |
POTLESS_2 | 12:9dd7c462a2c0 | 478 | I2C_EEPROM.read(address, data, size); |
POTLESS_2 | 12:9dd7c462a2c0 | 479 | wait_ms(6); |
POTLESS_2 | 12:9dd7c462a2c0 | 480 | |
POTLESS_2 | 12:9dd7c462a2c0 | 481 | DEEP_DEBUG(" Char lu à l'adresse %d de l'eeprom : %s\r\n", eeaddress, data); |
POTLESS_2 | 12:9dd7c462a2c0 | 482 | } |
POTLESS_2 | 11:a41267cffa61 | 483 | |
POTLESS_2 | 11:a41267cffa61 | 484 | float UTILS::read_F_EEPROM(unsigned int eeaddress ,int address) |
POTLESS_2 | 11:a41267cffa61 | 485 | { |
POTLESS_2 | 11:a41267cffa61 | 486 | //On lit toute la ligne |
POTLESS_2 | 11:a41267cffa61 | 487 | int size = 64; |
POTLESS_2 | 11:a41267cffa61 | 488 | char data[64]; |
POTLESS_2 | 11:a41267cffa61 | 489 | |
POTLESS_2 | 11:a41267cffa61 | 490 | char i2cBuffer[2]; |
POTLESS_2 | 11:a41267cffa61 | 491 | i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB |
POTLESS_2 | 11:a41267cffa61 | 492 | i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB |
POTLESS_2 | 11:a41267cffa61 | 493 | |
POTLESS_2 | 11:a41267cffa61 | 494 | int result = I2C_EEPROM.write(address, i2cBuffer, 2, false); |
POTLESS_2 | 11:a41267cffa61 | 495 | wait_ms(6); |
POTLESS_2 | 11:a41267cffa61 | 496 | |
POTLESS_2 | 11:a41267cffa61 | 497 | I2C_EEPROM.read(address, data, size); |
POTLESS_2 | 11:a41267cffa61 | 498 | wait_ms(6); |
POTLESS_2 | 11:a41267cffa61 | 499 | |
POTLESS_2 | 11:a41267cffa61 | 500 | float result_F = atof(data); |
POTLESS_2 | 12:9dd7c462a2c0 | 501 | DEEP_DEBUG(" Float lu à l'adresse %d de l'eeprom : %f\r\n", eeaddress, result_F); |
POTLESS_2 | 11:a41267cffa61 | 502 | return result_F; |
POTLESS_2 | 11:a41267cffa61 | 503 | } |
POTLESS_2 | 11:a41267cffa61 | 504 | |
POTLESS_2 | 11:a41267cffa61 | 505 | |
POTLESS_2 | 11:a41267cffa61 | 506 | int UTILS::read_I_EEPROM(unsigned int eeaddress ,int address) |
POTLESS_2 | 11:a41267cffa61 | 507 | { |
POTLESS_2 | 11:a41267cffa61 | 508 | //On lit toute la ligne |
POTLESS_2 | 11:a41267cffa61 | 509 | int size = 64; |
POTLESS_2 | 11:a41267cffa61 | 510 | char data[64]; |
POTLESS_2 | 11:a41267cffa61 | 511 | |
POTLESS_2 | 11:a41267cffa61 | 512 | char i2cBuffer[2]; |
POTLESS_2 | 11:a41267cffa61 | 513 | i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB |
POTLESS_2 | 11:a41267cffa61 | 514 | i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB |
POTLESS_2 | 11:a41267cffa61 | 515 | |
POTLESS_2 | 11:a41267cffa61 | 516 | int result = I2C_EEPROM.write(address, i2cBuffer, 2, false); |
POTLESS_2 | 11:a41267cffa61 | 517 | wait_ms(6); |
POTLESS_2 | 11:a41267cffa61 | 518 | |
POTLESS_2 | 11:a41267cffa61 | 519 | I2C_EEPROM.read(address, data, size); |
POTLESS_2 | 11:a41267cffa61 | 520 | wait_ms(6); |
POTLESS_2 | 11:a41267cffa61 | 521 | |
POTLESS_2 | 11:a41267cffa61 | 522 | int result_I = atoi(data); |
POTLESS_2 | 12:9dd7c462a2c0 | 523 | DEEP_DEBUG(" Int lu à l'adresse %d l'eeprom : %d\r\n", eeaddress, result_I); |
POTLESS_2 | 11:a41267cffa61 | 524 | return result_I; |
POTLESS_2 | 11:a41267cffa61 | 525 | } |
POTLESS_2 | 11:a41267cffa61 | 526 | |
POTLESS_2 | 11:a41267cffa61 | 527 | void UTILS::clean_EEPROM(int address) |
POTLESS_2 | 11:a41267cffa61 | 528 | { |
POTLESS_2 | 11:a41267cffa61 | 529 | DEBUG(" Nettoyage total de l'Eeprom (64 colonnes, 4096 lignes).\r\n"); |
POTLESS_2 | 11:a41267cffa61 | 530 | int i; |
POTLESS_2 | 11:a41267cffa61 | 531 | int pointer; |
POTLESS_2 | 11:a41267cffa61 | 532 | char deleteData[] = {" "}; |
POTLESS_2 | 11:a41267cffa61 | 533 | for (i = 0; i < 4096; i++) { |
POTLESS_2 | 11:a41267cffa61 | 534 | pointer = 64 * i; |
POTLESS_2 | 11:a41267cffa61 | 535 | clean_line_EEPROM(pointer, address); |
POTLESS_2 | 11:a41267cffa61 | 536 | } |
POTLESS_2 | 11:a41267cffa61 | 537 | DEBUG("Eeprom néttoyée.\r\n"); |
POTLESS_2 | 15:a8c19ad9c11d | 538 | } |