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