help in using complex structure (imbricated)

I hope to post in good section !! and I’ll try to be clear…
I want to use imbricated structure to define timestamp per day and per week (profil) : I have limitated exemple to only 2 timestamps and 2 days : here is the definition of structure type:

typedef struct Plage //Structure pour plage horaires ( 5 bytes)
{ byte    HeurDeb; byte    MinDeb; byte    HeurFin; byte    MinFin; byte    Consigne; };

typedef struct Jour //Structure pour Jour (8 plages = 40 bytes)
{
Plage    plage1;  
Plage    plage2; 
};
typedef struct Profil //Structure pour Profil (7 jours)
{
Jour    lundi;  
Jour    mardi; 
};

then I declare the following global variable: struct Profil profil_1;
and I have no problem to initiate this data zone with simple declarations like :

profil_1.lundi.plage1.HeurDeb = 17; // 17h
profil_1.lundi.plage1.Consigne = 25; // 25°

par ex… etc…

My problem is to access to the member Consigne depending on Jour and Plage, according to the current time given by my local variables (hr, mn) so 60*hr+mn
for that I check if the local time is in the interval given by Plage parameters…
here is the extract of the code :

byte renvoyer_consigne ()
{
int time=60*hr+mn;  // nb de minutes de la journée
int timedeb,timefin;
// en mode auto definit valeur consigne suivant (choix_profil,jour,hr,mn)
  if (choix_profil == 1)
  { switch (jour)
    {
      case 1: // lun
        if (profil_1.lundi.plage1.Consigne) { // Consigne non nul donc plage definie
          timedeb=profil_1.lundi.plage1.HeurDeb*60 + profil_1.lundi.plage1.MinDeb;
          timefin=profil_1.lundi.plage1.HeurFin*60 + profil_1.lundi.plage1.MinFin;
          if (timedeb <= time <= timefin) return profil_1.lundi.plage1.Consigne; }
        if (profil_1.lundi.plage2.Consigne) { // Consigne non nul donc plage definie
          timedeb=profil_1.lundi.plage2.HeurDeb*60 + profil_1.lundi.plage2.MinDeb;
          timefin=profil_1.lundi.plage2.HeurFin*60 + profil_1.lundi.plage2.MinFin;
          if (timedeb <= time <= timefin) return profil_1.lundi.plage2.Consigne; }
      case 2: // mar
        if (profil_1.mardi.plage1.Consigne) { // Consigne non nul donc plage definie
          timedeb=profil_1.mardi.plage1.HeurDeb*60 + profil_1.mardi.plage1.MinDeb;
          timefin=profil_1.mardi.plage1.HeurFin*60 + profil_1.mardi.plage1.MinFin;
          if (timedeb <= time <= timefin) return profil_1.mardi.plage1.Consigne; }
        if (profil_1.mardi.plage2.Consigne) { // Consigne non nul donc plage definie
          timedeb=profil_1.lundi.plage2.HeurDeb*60 + profil_1.lundi.plage2.MinDeb;
          timefin=profil_1.lundi.plage2.HeurFin*60 + profil_1.lundi.plage2.MinFin;
          if (timedeb <= time <= timefin) return profil_1.lundi.plage2.Consigne; }
    }
  }
}

so how to code using pointers or anything else to be able to define 7 days x 8 timeintervals !!
I am not a pointer expert and doesn’t want code thousands of similar lines… !!

note : days = jours in french, (lundi = monday, mardi = tuesday etc…)
plage = time interval defined by first hour (HeurDeb, MinDeb) and last hour (HeurFin, MinFin)
and Consigne = 0 when plage is not used… (and target temperature if else…)

thanks for your help…

I don’t understand why you want to wrap what could be an array of bytes in a struct.

typedef struct Plage //Structure pour plage horaires ( 5 bytes)
{ byte    HeurDeb; byte    MinDeb; byte    HeurFin; byte    MinFin; byte    Consigne; };

could be

   byte timeData[5];

Then,

typedef struct Jour //Structure pour Jour (8 plages = 40 bytes)
{
Plage    plage1; 
Plage    plage2;
};

is just an array of arrays. I presume you want more instances of Plage than just the two you have here.

An array of arrays is a 2D array.

Then,

typedef struct Profil //Structure pour Profil (7 jours)
{
Jour    lundi; 
Jour    mardi;
};

is just an array of array of arrays.

An array of array of arrays is a 3D array.

   byte timeData[numDays][numEvents][5];

And it is far easier to reference the data for the nth event of the ith day of the week than it is to dig through structs of structs of structs.

Yes ! maybe you’re right… it’s just a way to represent the same thing… but it is more easier to code using structure… the question remains : is it possible to access using functions to members of my structure and how ??? (in order to reduce the code below…)

parameters of function should be : profil1, lundi, plage2 for example…
result would be : Consigne
treatment to replace by function :

if (profil_1.lundi.plage2.Consigne) if (profil_1.lundi.plage2.HeurDeb <= time <= profil_1.lundi.plage2.HeurFin) return profil_1.lundi.plage2.Consigne;

note :
I have found a new code (always with structure) more light by working directly with duration of min : HeurDeb is an int equel to 60*HHdeb+ MMdeb so the final code becomes :

// routines pour regulation
byte fixe_consigne ()
{
int time=60*hr+mn;  // nb de minutes de la journée
// en mode auto definit valeur consigne suivant (choix_profil,jour,hr,mn)
  if (choix_profil == 1)
  { switch (jour)
    {
      case 1: // lun
        if (profil_1.lundi.plage1.Consigne) { // Consigne non nul donc plage definie
          if (profil_1.lundi.plage1.HeurDeb <= time <= profil_1.lundi.plage1.HeurFin) return profil_1.lundi.plage1.Consigne; }
        if (profil_1.lundi.plage2.Consigne) if (profil_1.lundi.plage2.HeurDeb <= time <= profil_1.lundi.plage2.HeurFin) return profil_1.lundi.plage2.Consigne;      
         
      case 2: // mar
        if (profil_1.mardi.plage1.Consigne) if (profil_1.mardi.plage1.HeurDeb <= time <= profil_1.mardi.plage1.HeurFin) return profil_1.mardi.plage1.Consigne;
        if (profil_1.mardi.plage2.Consigne) if (profil_1.mardi.plage2.HeurDeb <= time <= profil_1.mardi.plage2.HeurFin) return profil_1.mardi.plage2.Consigne;     
     
      default:  return 99;   
      
      
    }  
  }
  else // profil=2
  {
  }
  
}

You do know the forum has a francophone section?

philou35: I want to use imbricated structure ...

Whatever that is.

but it is more easier to code using structure.

Well, that would explain why you are having such an easy go of it, then.

Frankly, I'd ditch the whole structure concept, and uses classes, instead. Some get and set methods to get or set the data, and you could make progress with the "structure" concept.

But, you'll write a lot more code. Not that that is a bad thing.

tks Paul for your good remarks, anyway...

I know there is a french forum but I notice that english people are sometimes better than french guies :wink:

end obviouly, the major aim of all that is to progress in structure notions ... so I will try to use pointers to address my data structure...