IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Impossible de lire mes fichiers SPIFFS


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut Impossible de lire mes fichiers SPIFFS
    Bonjour à tous ,

    Je recherche un croquis de test me permettant de lire des fichiers stocké sous "data"

    j'utilise actuellement un Wemos (ESP8266) et j'y stocke plusieurs fichiers sous le répertoire "data"
    dont un fichier "/config.txt"
    malgré le fait que j'arrive à téléverser mon programme et upload les fichiers ,
    je n'arrive pas à lire mon fichier "/config.txt" qui fait pourtant partis de la liste

    Si vous avez quelques conseils je suis preneur

    merci mille fois
    pascal

  2. #2
    Membre éclairé
    Homme Profil pro
    bricoleur
    Inscrit en
    Octobre 2014
    Messages
    406
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : bricoleur
    Secteur : Alimentation

    Informations forums :
    Inscription : Octobre 2014
    Messages : 406
    Par défaut
    Bonsoir,
    J'utilise cela pour lire les fichiers en data:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    void lectureData(fs::FS &fs, const char* path){
      String pageConfig ="";
      File fic = fs.open(path);  
      if(!fic || fic.isDirectory()){
        //Serial.println("lecture fichier impossible");
        afficErreurs("Erreur lecture fichier");
        return;
      }
      if(path=="/config.txt"){ 
        while(fic.available()) {pageConfig += char(fic.read());}
        String tempo(reinterpret_cast<const __FlashStringHelper*> (pageConfig.c_str()));
        pageconfig=tempo;
       }
       fic.close();
      }

  3. #3
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    ce n'est pas comme cela qu'on teste une c-String
    Citation Envoyé par mormic Voir le message
    if(path=="/config.txt")
    il faut faire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
      if(strcmp(path, "/config.txt") == 0) {
        // c'est le bon chemin de fichier
        ...
      }
    ceci ne sert à rien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
        String tempo(reinterpret_cast<const __FlashStringHelper*> (pageConfig.c_str()));
        pageconfig=tempo;
    vous avez déjà construit pageconfig

  4. #4
    Membre éclairé
    Homme Profil pro
    bricoleur
    Inscrit en
    Octobre 2014
    Messages
    406
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : bricoleur
    Secteur : Alimentation

    Informations forums :
    Inscription : Octobre 2014
    Messages : 406
    Par défaut
    String tempo(reinterpret_cast<const __FlashStringHelper*> (pageConfig.c_str()));
    pageconfig=tempo;
    ceci ne sert à rien
    oui c'est exact, cela ne sert à rien.

    if(strcmp(path, "/config.txt") == 0) {
    // c'est le bon chemin de fichier
    ...
    }
    Oui c'est plus joli.

  5. #5
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    Encore merci pour vos réponses
    mais je n'y arrive pas désolé

    en tout premier lieu
    j'ai un fichier "config.txt" que j'arrive à lire désormais à l'aide de ce croquis
    ( testé avant vos reponses)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    #define CONFIG "/config.txt"
    //==========================================================================================================
    //                        do_read_config_txt
    //==========================================================================================================
     
    bool do_read_config_txt()
    {
    	//String fileName;
    	//fileName=CONFIG ;
    	fs::File f;
    	bool val_0=false;
    	scr_show_count=0;
     
    	//f = SPIFFS.open(fileName, "r");
    	if (SPIFFS.exists( CONFIG)) {
            File f = SPIFFS.open(CONFIG, "r");
    		if (!f) {
            Serial.print("Impossible d'ouvrir '");
            Serial.print( CONFIG);
            Serial.println("' pour la lecture");
            Serial.println();
    		return false;}
    	} else {
            String s;
            Serial.print("Contents of file '");
            Serial.print(CONFIG);
            Serial.println("'");
            Serial.println();
            while (f.position()<f.size())
            {
              s=f.readStringUntil('\n');
              s.trim();
              Serial.println(s);
            } 
            f.close();
        }
        Serial.println();     
     
     
    	//if (!f) {Serial.println(CONFIG);Serial.println(F(" Erreur Lecture Fichier config.txt"));
    	//return false;}
     
    	//----------------------------
    	String name,val,str;
    	byte i=0;
    	#ifdef debug
    	Serial.println(F("-------config.txt-------------------------------"));  
    	#endif
    	//----------------------------------
      while (f.available()) {
    	str = f.readStringUntil('\n');
    	str.trim();
    	//Serial.println(str); //Printing for debugging purpose
    	int tz=str.indexOf("#") ;
    	if (tz!=0) continue;
    	//---------------------------
    	int tz2=str.indexOf(";",tz+1);
    	if (tz2==-1) continue;
    	//name
    	name=str.substring(tz+1,tz2);
    	name.trim();
    	Serial.print("name==");Serial.println(name);
     
    	//val-----------------
    	tz=tz2+1;
    	tz2=str.indexOf(";",tz);
    	if (tz2==-1) continue;
    	val=str.substring(tz,tz2);
    	val.trim();
    	if (val=="0") val_0=true;else val_0=false; //si =0 
     
    	#ifdef debug
    		Serial.print("val zero");Serial.println(val_0);
    		Serial.print("val==");Serial.println(val);
    		Serial.print("val_toint==");Serial.println(val.toInt());
    	#endif
        }
    }
     
    insigned char* buf = new unsigned char[50];
    val.getBytes(buf,50,0);
    iot_key= (const char*)buf;
    }
    else
    iot_key="";
    #ifdef debug 
    Serial.print("iot_key=");
    Serial.println(iot_key);
    #endif
    }
     
      f.close();
    #ifdef debug 
    Serial.println(F("-----end--config.txt-----------"));  
    #endif
     
    return true;
    }
    Mais si j'applique la même procédure ( même repertoire "data")
    au fichier : "/Fwifi" là çà ne va plus il n'arrive pas à le lire [?)

    en partant de vos recommendations, j'utilise donc ce croquis :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
     
    void wifiConnect()
    {
    static bool conn=false; //lorsqu'elles sont répétées à l'écran ne montrent pas
    static byte wifi_count_recon=0; //compteur ;
    //reset networking
    //if (WiFi.getPersistent() == true) 
    WiFi.persistent(false); 
    WiFi.softAPdisconnect(true);
    WiFi.disconnect();   
     
    WiFi.persistent(true);   //enable saving wifi config into SDK flash area
    delay(1000);
    /*
    if (log_file)
    {
    log_str="WIFI disconnect";
    do_log();  
    }
    */
    fs::File f; 
    const char* path ;
    const char * _ssid = "", *_pass = ""; 
    if(strcmp(path, "/Fwifi") == 0) {
     
         String str=f.readString();  
         Serial.println("read file STA");
         Serial.println(str);
         if (str.length()>0)
         {
            byte ind=str.indexOf(";");
            String s=str.substring(0,ind);
            byte ind2=str.indexOf(";",ind+1);
            String p=str.substring(ind+1,ind2);
            Serial.println(p);
            _ssid=s.c_str();
            Serial.println("ssid");
            Serial.println(_ssid);
     
            _pass=p.c_str();
            Serial.println("passw");
            Serial.println(_pass);
            f.close();
            if (!conn) tft.println();
     
              // WiFi.mode(WIFI_STA);
               WiFi.begin(_ssid, _pass);
               unsigned long startTime = millis();
               while (WiFi.status() != WL_CONNECTED) 
              {
                delay(500);
                if (!conn) tft.print(".");
                Serial.print(".");
                if ((unsigned long)(millis() - startTime) >= wifi_rep_t) break; //30sec
              }
     
              if (WiFi.status() == WL_CONNECTED) 
              {
              Serial.print("localIP==");
              Serial.println(WiFi.localIP()); 
              Serial.println(F("IP address: "));
              Serial.println(WiFi.localIP());
                if (!conn)
                {
                  tft.setTextColor(0x07E0);
                  tft.println("");
                  tft.println(F("---------------------"));
                  tft.print(F("IP= "));
                  tft.setTextColor(TFT_YELLOW);
                  tft.println(WiFi.localIP());
                  tft.setTextColor(0x07E0);
                  tft.println(F("---------------------"));
                  delay(2000);
                 }
                 conn=true;
                 wifi_count_recon=0;
     
                  /*       
                  if (log_file)
                  {
                  log_str="WIFI connect Ok";
                  do_log();  
                  }
                  */
     
              }
           }
         }else{
     
     
    tft.print("  Fichier WIFI absent ");
    tft.setTextColor(TFT_RED);
    tft.println("   ERR ");
    tft.setTextColor(0x07E0);
    }
        //SOFT------AP
    //------------------------------------------------------------------------------------
     if (WiFi.status() != WL_CONNECTED)
       {
     
        if (conn) //il y avait déjà une connexion
        {
        wifi_count_recon++;
     
        if (wifi_count_recon>=wifi_count_rep )
        {
            Serial.print(F("ESP reboot wifi_count_recon>wifi_count_rep"));  
            if (log_file)
            {
              log_str=(F("ESP reboot wifi_count_recon>wifi_count_rep"));
            do_log();  
            }
            ESP.restart();
         }
     
        if (log_file)
        {
        log_str=("wifi_count_recon=")+String(wifi_count_recon) ;
        do_log();  
        }
     
    return;
        }
     
    Serial.print(F("ERR WIFI set WIFI_AP"));
    WiFi.persistent(false); 
    WiFi.softAPdisconnect(true);
    WiFi.disconnect(); 
    WiFi.mode(WIFI_AP);
    delay(1000);
    Serial.println(WiFi.softAPConfig(local_ip, gateway, netmask) ? "Ready" : "Failed!");
    Serial.println(WiFi.softAP(ssid_ap, password_ap) ? "Ready" : "Failed!");
    WiFi.persistent(true); 
    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);     
     
    tft.fillScreen(TFT_BLACK);
    tft.setTextColor(0x07E0);
    tft.println("---------------------");
    tft.setTextColor(0x07E0);
    tft.println(F("connect to"));
    tft.println(F("ap=ESP_METEO "));
    tft.println(F("passw=11111111 "));
    tft.println("---------------------");
    tft.println(F("from the phone to come"));
    tft.print(F("http://"));
    tft.setTextColor(TFT_YELLOW);
    tft.println(myIP);
    tft.println();
    //delay(5000);
     
     
      }
    #ifdef debug 
      Serial.println("");
      WiFi.printDiag(Serial);
      Serial.println("-------------");
      Serial.println(WiFi.getMode());
      #endif
     }
    il ne lit rien , il reboot (?) , je suis paumé je ne comprends plus rien
    je précise que le fichier Fwifi est compos" comme suit :
    => ssid;mdp;

    merci pour votre aide

    pascal


    PS :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    if(strcmp(path, "/config.txt") == 0) {
    // c'est le bon chemin de fichier
    ...
    }
    j'ai essayé çà aussi mais çà me donne le message suivant :

    cannot convert 'fs::File' to 'const char*'

  6. #6
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    vous définissez path comme étant un pointeur non initialisé, il y a peu de chances qu'il pointe vers un contenu qui soit "/Fwifi"
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    const char* path ;
    const char * _ssid = "", *_pass = ""; 
    if(strcmp(path, "/Fwifi") == 0) {

  7. #7
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    Bonjour Jay M

    vous définissez path comme étant un pointeur non initialisé, il y a peu de chances qu'il pointe vers un contenu qui soit "/Fwifi"
    l'ennui c'est que je vois pas comment faire , car dans l'exemple donné par mormic , path n'est pas initialisé semble-t-il alors j'ai pensé qu'il s'initialisait avec
    if(path=="/config.txt"){ }

    est-ce comme cela que je dois faire ?

    const char* path = "/Fwifi"

  8. #8
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    Citation Envoyé par cobra38 Voir le message
    dans l'exemple donné par mormic , path n'est pas initialisé semble-t-il
    Dans son exemple path est le paramètre de la fonction void lectureData(fs::FS &fs, const char* path){ donc c'est l'appelant qui va passer le bon contenu.

    Citation Envoyé par cobra38 Voir le message
    alors j'ai pensé qu'il s'initialisait avec
    if(path=="/config.txt"){ }

    est-ce comme cela que je dois faire ?

    const char* path = "/Fwifi"
    le if est un test qui compare la valeur du pointeur au pointeur constant de "/config.txt"...

    si vous voulez une cString vous l'initialisez comme un tableau de caractères

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    char path[] = "/Fwifi"; // path sera un tableau de 6+1 char. 1 pour chaque symbole et le caractère nul ajouté par le compilateur à la fin

  9. #9
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    Merci Jay M

    Mille pardons pour le retard mais je faisais quelques essais complémentaires et j'ai fini par trouver mon souci (du moins je le pense)

    Historiquement , mon projet était de pouvoir à partir d'un croquis existant (station Météo) de mettre un écran + grand pour une meilleure visibilité
    or, je ne pouvais plus compiler mon programme car je faisais appel à des API obsolètes ( voir posts précédents )
    après avoir corrigé ce problème ( Wificlient ), je ne pouvais plus cette fois lire mes fichiers SPIFFS voir autres posts alors que j'avais mis la dernière version de ESP8266FS -> tool -> ESP8266.jar
    en fait je me suis aperçu que sous :
    ESP8266 Sketch Data Upload , il ne chargeait pas les fichiers (?) même si il affichait correctement Writting ....
    j'ai donc essayé LittleFS avec :
    ESP8266 LitteFS Data Upload et là miracle il lit mes fichiers et charge les données mais ....

    c'est sans compter ma scoumoune ...maintenant l'affichage sur l'écran est très moche ( baveux)
    alors que j'utilise le même programme initial et les mêmes datas ( voir les 2 photos jointes , l'une du programme qui fonctionne actuellement et l'autre photo du programme test )

    Serait-ce possible que la cause soit une mauvaise configuration du Wemos ?
    j'ajoute que j'ai essayé 2 type d'écrans l'un en 240x320 et l'autre en 320x480 tous les deux présentent le même défaut
    Images attachées Images attachées   

  10. #10
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    avez vous regardé la table des partitions. elles sont assez grandes pour vos données

  11. #11
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    avez vous regardé la table des partitions. elles sont assez grandes pour vos données
    serait-ce cela dont vous parlez ?


    J'ai essayé toutes les configs seules celles à 3 ou 4 MB fonctionnent

    par contre à 1MB je n'arrive plus à utiliser ESP8266 LittleFS Data Upload mais bien ESP8266 Sketch Data Upload
    Dans tous les cas ( à 3 ou 4MB ) lorsque j'utilise :
    -> ESP8266 LittleFS Data Upload , il lit les fichiers SPIFFS
    -> ESP8266 Sketch Data Upload, il charge mais ne lit pas les fichiers SPIFFS (?)
    Images attachées Images attachées  

  12. #12
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    oui ce sont bien de ces options dont je parlais

    il faut que votre partition pour les fichiers soit assez grande pour ce que vous y stockez
    si vous avez l'option OTA ça veut dire que l'espace pour le programme est divisé par 2 (il y aura de la mémoire réservée pour la réception du nouveau binaire afin de faire la bascule vers la nouvelle version)

    la table de partition est adaptable à vos besoins si vous choisissez la dernière option et fournissez la bonne configuration

  13. #13
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    la table de partition est adaptable à vos besoins si vous choisissez la dernière option et fournissez la bonne configuration
    Si je choisis la dernière option , je ne peux plus charger mes fichiers comment puis-je faire svp ?

  14. #14
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921

  15. #15
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    merci Jay M

    Expressif documente le format
    Désolé de vous décevoir mais çà reste du chinois , je ne comprend toujours pas le problème
    je précise qu'une version précédente tourne avec un affichage de TFT 240x320 depuis 2 ans sans problème
    et que c'est lorsque je veux m'affranchir du problème de l'API et WifiClient que je n'arrive plus à afficher précisément les fichiers jpg
    par contre les chiffres ou autres textes s'affichent correctement, c'est pourquoi je pense que le problème se situe non pas sur la quantité de mémoire disponible mais sur une mise à jour de librairie
    dont celle JPEGdecoder
    sur la photo joint on s'aperçoit que seules les images ne s'affichent pas correctement , elles sont
    j'ai donc regardé le fichier .ino qui traite du décodage des images mais sans succès là encore ...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
     
     
    // Return the minimum of two values a and b
    #define minimum(a,b)     (((a) < (b)) ? (a) : (b))
     
    #define USE_SPI_BUFFER // Comment out to use slower 16 bit pushColor()
     
    //====================================================================================
    //   Opens the image file and prime the Jpeg decoder
    //====================================================================================
    bool drawJpeg(String filename, int xpos, int ypos) {
     
     Serial.print(F("Drawing file: "));  Serial.println(filename);
     
      // Open the named file (the Jpeg decoder library will close it after rendering image)
    #ifdef pin_sd
    Serial.print("SD ");
    Serial.println(filename);
    File jpegFile = SD.open( filename, FILE_READ);  // or, file handle reference for SD library
     #else
    Serial.print("Spiffs ");
    Serial.println(filename);
    //fs::File jpegFile = SPIFFS.open( filename, "r");    // File handle reference for SPIFFS
    fs::File jpegFile = LittleFS.open( filename, "r");    // File handle reference for SPIFFS
     
    #endif
     
      if ( !jpegFile ) {
        Serial.print(F("ERROR: File \""));
        Serial.print(filename); 
        Serial.println (F("\" not found!"));
      jpegFile.close();
        return false;
      }
     
      // Use one of the three following methods to initialise the decoder:
      //boolean decoded = JpegDec.decodeFsFile(jpegFile); // Pass a SPIFFS file handle to the decoder,
    #ifdef pin_sd
    boolean decoded = JpegDec.decodeSdFile(jpegFile); // or pass the SD file handle to the decoder,
    #else
      boolean decoded = JpegDec.decodeFsFile(filename);  // ou transmettre le nom du fichier (le premier / distingue les fichiers SPIFFS)
    #endif                              // Note: the filename can be a String or character array type
     
      if (decoded) {
        // print information about the image to the serial port
       //jpegInfo();
     
     //if (tft2_act)     jpegRender2(xpos, ypos);
    // else
        jpegRender(xpos, ypos);
      }
      else {
        Serial.println(F("Jpeg file format not supported!"));
      jpegFile.close();
     
         return false;
      }
       jpegFile.close();
     
     
     return true;
    }
     
    //====================================================================================
    //       2 TFT jpegRender
    //====================================================================================
    #if defined (two_tft)  
    void jpegRender(int xpos, int ypos) {
     
      // retrieve infomration about the image
      //uint16_t  *pImg;
      //uint16_t mcu_w = JpegDec.MCUWidth;
      //uint16_t mcu_h = JpegDec.MCUHeight;
      uint32_t  *pImg;
      uint32_t mcu_w = JpegDec.MCUWidth;
      uint32_t mcu_h = JpegDec.MCUHeight;
      uint32_t max_x = JpegDec.width;
      uint32_t max_y = JpegDec.height;
     
      // Les images Jpeg sont dessinées sous la forme d'un ensemble de blocs d'images (tuiles) appelés unités de codage minimales (MCU).
      // Généralement, ces MCU sont des blocs de 16x16 pixels.
      // Déterminez la largeur et la hauteur des blocs d'image des bords droit et inférieur.
      uint32_t min_w = minimum(mcu_w, max_x % mcu_w);
      uint32_t min_h = minimum(mcu_h, max_y % mcu_h);
     
      // save the current image block size
      uint32_t win_w = mcu_w;
      uint32_t win_h = mcu_h;
     
      // record the current time so we can measure how long it takes to draw an image
      uint32_t drawTime = millis();
     
      // save the coordinate of the right and bottom edges to assist image cropping
      // to the screen size
      max_x += xpos;
      max_y += ypos;
     
      // read each MCU block until there are no more
     while ( JpegDec.read()) {
     //while ( JpegDec.readSwappedBytes()) {
     
        // save a pointer to the image block
        pImg = JpegDec.pImage;
     
        // calculate where the image block should be drawn on the screen
        int mcu_x = JpegDec.MCUx * mcu_w + xpos;
        int mcu_y = JpegDec.MCUy * mcu_h + ypos;
     
        // check if the image block size needs to be changed for the right edge
        if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
        else win_w = min_w;
     
        // check if the image block size needs to be changed for the bottom edge
        if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
        else win_h = min_h;
     
        // copy pixels into a contiguous block
        if (win_w != mcu_w)
        {
          for (int h = 1; h < win_h-1; h++)
          {
            memcpy(pImg + h * win_w, pImg + (h + 1) * mcu_w, win_w << 1);
          }
        }
     
        // draw image MCU block only if it will fit on the screen
     //------------------- 
     
    if (tft2_act) //active tft №2
    {
        if ( ( mcu_x + win_w) <= tft2.width() && ( mcu_y + win_h) <= tft2.height())
        {
          tft2.drawRGBBitmap(mcu_x, mcu_y, pImg, win_w, win_h);
        }
     
        else if ( ( mcu_y + win_h) >= tft2.height()) JpegDec.abort();
    }
    else
    {
        if ( ( mcu_x + win_w) <= tft.width() && ( mcu_y + win_h) <= tft.height())
        {
          tft.drawRGBBitmap(mcu_x, mcu_y, pImg, win_w, win_h);
        }
     
        else if ( ( mcu_y + win_h) >= tft.height()) JpegDec.abort();
     
     
    }
     
     //--------------------
     
      }
     
     
    }
     
    //---------------------------------------------------------------------------
    //        1 TFT jpegRender
    //---------------------------------------------------------------------------
    #else //1  tft  
    void jpegRender(int xpos, int ypos) {
     
     
      // retrieve infomration about the image
      uint16_t *pImg;
      uint16_t mcu_w = JpegDec.MCUWidth;
      uint16_t mcu_h = JpegDec.MCUHeight;
      uint32_t max_x = JpegDec.width;
      uint32_t max_y = JpegDec.height;
     
      // Jpeg images are draw as a set of image block (tiles) called Minimum Coding Units (MCUs)
      // Typically these MCUs are 16x16 pixel blocks
      // Determine the width and height of the right and bottom edge image blocks
      uint32_t min_w = minimum(mcu_w, max_x % mcu_w);
      uint32_t min_h = minimum(mcu_h, max_y % mcu_h);
     
      // save the current image block size
      uint32_t win_w = mcu_w;
      uint32_t win_h = mcu_h;
     
       // save the coordinate of the right and bottom edges to assist image cropping
      // to the screen size
      max_x += xpos;
      max_y += ypos;
     
      // read each MCU block until there are no more
      while (JpegDec.read()) { 
     
        // save a pointer to the image block
        pImg = JpegDec.pImage ;
     
        // calculate where the image block should be drawn on the screen
        int mcu_x = JpegDec.MCUx * mcu_w + xpos;  // Calculate coordinates of top left corner of current MCU
        int mcu_y = JpegDec.MCUy * mcu_h + ypos;
     
        // check if the image block size needs to be changed for the right edge
        if (mcu_x + mcu_w <= max_x) win_w = mcu_w;
        else win_w = min_w;
     
        // check if the image block size needs to be changed for the bottom edge
        if (mcu_y + mcu_h <= max_y) win_h = mcu_h;
        else win_h = min_h;
     
        // copy pixels into a contiguous block
        if (win_w != mcu_w)
        {
          uint16_t *cImg;
          int p = 0;
          cImg = pImg + win_w;
          for (int h = 1; h < win_h; h++)
          {
            p += mcu_w;
            for (int w = 0; w < win_w; w++)
            {
              *cImg = *(pImg + w + p);
              cImg++;
            }
          }
        }
     
        // calculate how many pixels must be drawn
        uint32_t mcu_pixels = win_w * win_h;
     
        tft.startWrite();
     
        // draw image MCU block only if it will fit on the screen
        if (( mcu_x + win_w ) <= tft.width() && ( mcu_y + win_h ) <= tft.height())
        {
     
          // Now set a MCU bounding window on the TFT to push pixels into (x, y, x + width - 1, y + height - 1)
          tft.setAddrWindow(mcu_x, mcu_y, win_w, win_h);
     
          // Write all MCU pixels to the TFT window
          while (mcu_pixels--) {
            // Push each pixel to the TFT MCU area
                  tft.pushColor(*pImg++);
          }
     
        }
        else if ( (mcu_y + win_h) >= tft.height()) JpegDec.abort(); // Image has run off bottom of screen so abort decoding
     
        tft.endWrite();
      }
     
     
    }
     
    #endif // 1 TFT
    Images attachées Images attachées  

  16. #16
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    OK et les JPEGs semblent en partie corrects car la forme générale est bonne

    donc la seule modification c'est que vous passé de SPIFFS à LittleFS?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    //fs::File jpegFile = SPIFFS.open( filename, "r");    // File handle reference for SPIFFS
    fs::File jpegFile = LittleFS.open( filename, "r");    // File handle reference for SPIFFS
    c'est ça ?

    et vous avez bien rechargé les fichiers avec "Tools > ESP8266 LittleFS Data Upload." (cf https://randomnerdtutorials.com/inst...tlefs-arduino/)

  17. #17
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    et vous avez bien rechargé les fichiers avec "Tools > ESP8266 LittleFS Data Upload." (cf https://randomnerdtutorials.com/inst...tlefs-arduino/)
    Oui d'ailleurs voici un extrait lors du chargement d'une fenêtre ( j'ai plusieurs fenêtres qui se chargent toutes les 20 s environ )
    où l'on voit les fichiers lus et chargés
    Images attachées Images attachées  

  18. #18
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    je pense avoir trouvé le problème
    https://forum.arduino.cc/t/3-5-spi-d...mages/592164/7

    L'écran :
    ILI9488 a besoin de 320x480x3 octets SPI.
    ILI9341 a besoin de 240x320x2 octets SPI, par exemple 350 ms

    il faut changer le programme en :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
          tft.setAddrWindow(mcu_x, mcu_y, win_w, win_h);  //new Adafruit
          uint32_t mcu_pixels = win_w * win_h;
          while (mcu_pixels--) {
            uint16_t color = *pImg++;
            color = (color >> 8) | (color  << 8);
            tft.pushColor(color); 
          }
    j'ai changé et retéléversé
    et çà l'air de mieux fonctionner ....
    votre avis ?
    Images attachées Images attachées  

  19. #19
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 921
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 921
    Par défaut
    l'écran n'a pas été changé, si ça fonctionnait avant pourquoi avoir à faire cette modification ?

    en tout cas c'est plus propre

  20. #20
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    993
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 993
    Par défaut
    l'écran n'a pas été changé, si ça fonctionnait avant pourquoi avoir à faire cette modification ?
    j'avoue ne pas comprendre le sens de la question

    A l'origine ( + 2 ans) j'ai un sketch qui fonctionne avec un écran de 240-320
    comme j'ai des modifications à y apporter je souhaitais y affecter un écran plus grans à savoir 320-480 ( ILI9488)
    or je n'arrivais plus à compiler le programme à cause notamment du problème lié à la nouvelle version API -> HTTPClient

    après correction je me suis retrouvé (toujours avec un écran 240-320) avec l'impossibilité de charger mes fichiers SPIFFS ( d'où mon appel à l'aide )
    cela était du aussi à la mise à jour des librairies et j'ai du donc passé à ESP8266LittleFS en lieu et place de ESP8266FS ( pourquoi ?)
    mais çà semble fonctionner , je charge enfin mais fichiers mais cette fois ceux sont les couleurs des images qui ne s'affichent plus correctement que soit en TFT 240-320 ou en TFT 320-480
    je pensais qu'il s'agissait de la mémoire mais en définitive pas du tout il s'agissait cette fois du type d'écran ILI9488
    le SPI réclame 3 octets au lieu de 2 (?)
    d'où la dernière modification et le passage enfin avec un écran TFT 320-480 conforme au projet final
    Voilà pour l'historique

    Une question toutefois : dois-je nécessairement changer dans tout le programme les appels aux fichiers :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    fs::File f = SPIFFS.open( filename, "r");    // File handle reference for SPIFFS
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    fs::File f = LittleFS.open( filename, "r");    // File handle reference for SPIFFS
    si oui pourquoi car j'avoue ne pas avoir compris l'exact différence

    pardon d'avoir était si long ...

Discussions similaires

  1. [UBUNTU] Impossible de compiler mes fichiers
    Par Death83 dans le forum Ubuntu
    Réponses: 32
    Dernier message: 15/01/2010, 18h16
  2. impossible d'ouvrir mes fichiers
    Par Maria1505 dans le forum Windows XP
    Réponses: 8
    Dernier message: 25/10/2007, 14h18
  3. Impossible de recupere mes fichiers.dbx
    Par ohi111 dans le forum Outlook
    Réponses: 3
    Dernier message: 19/04/2007, 18h24
  4. Réponses: 1
    Dernier message: 19/12/2005, 17h09

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo