1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| /*************************************************/
/* */
/* Lecture d'un fichier en Mémoire Flash */
/* */
/*************************************************/
#include <string.h>
#include "LittleFS.h"
const char* MyPath="/Fichier.txt";
File MyFile;
int Flag;
/*---------------------------*/
/* Structure de la ligne Lue */
/*---------------------------*/
typedef struct {
char Saison[2];
char Heure[5];
char Systeme[2];
char Taux[4];
char Eof[2];
} MyStruct;
MyStruct MyLine;
/*-------------------------------------*/
/* Lecture du fichier en mémoire Flash */
/*-------------------------------------*/
void Lecture(void)
{
memset(&MyLine, 0, sizeof(MyLine));
MyFile.readBytes((char*)&MyLine.Saison, 1);
MyFile.readBytes((char*)&MyLine.Heure, 4);
MyFile.readBytes((char*)&MyLine.Systeme,1);
MyFile.readBytes((char*)&MyLine.Taux, 3);
MyFile.readBytes((char*)&MyLine.Eof, 2);
Serial.println("--------------");
Serial.printf("Saison : %s\r\n", MyLine.Saison);
Serial.printf("Heure : %s\r\n", MyLine.Heure);
Serial.printf("Systeme : %s\r\n", MyLine.Systeme);
Serial.printf("Taux : %s\r\n", MyLine.Taux);
Serial.println("--------------");
}
/*-----------*/
/* Démarrage */
/*-----------*/
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("\e[1;31m+----------+\e[0m");
Serial.println("\e[1;31m| LittleFS |\e[0m");
Serial.println("\e[1;31m+----------+\e[0m\r\n");
if(!LittleFS.begin(true))
{
Serial.println("Erreur LittleFS");
return;
}
MyFile = LittleFS.open(MyPath, FILE_READ);
Flag = 1;
}
/*-----------------*/
/* Boucle Générale */
/*-----------------*/
void loop()
{
if (MyFile.available())
{
if (Flag)
{
Lecture();
Flag = 0;
}
sleep(1);
if (!strcmp(MyLine.Heure, "0700"))
{
Serial.println("Ligne 1 Traitée !");
Flag = 1;
}
if (!strcmp(MyLine.Heure, "0800"))
{
Serial.println("Ligne 2 Traitée !");
Flag = 1;
}
if (!strcmp(MyLine.Heure, "0900"))
{
Serial.println("Ligne 3 Traitée !");
Flag = 1;
}
if (!strcmp(MyLine.Heure, "1000"))
{
Serial.println("Ligne 4 Traité !");
Flag = 1;
}
}
else
{
Serial.println("--------------");
Serial.println("Fin du fichier");
MyFile.close();
MyFile = LittleFS.open(MyPath, FILE_READ);
}
} |
Partager