intConfigSD_KeyIndex(char*key){//At the moment a binary search algorithm is used for simplicity, if it will be necessary (Eg. tons of key), an hash search algorithm will be implemented.
staticconstchar*cfgSD_KEY[]={//Keep this in lexicographical order for better search performance(O(Nlog2(N)) insted of O(N*N)) (if you don't keep this sorted, the algorithm for find the key index won't work, keep attention.)
#ifdef POWER_CONSUMPTION
"PWR",
#endif
"TME",
};
enumcfgSD_ENUM{//This need to be in the same order as cfgSD_KEY
//if the extruder motor is idle for more than SECONDS, and the temperature over MINTEMP, some filament is retracted. The filament retracted is re-added before the next extrusion
//or when the target temperature is less than EXTRUDE_MINTEMP and the actual temperature is greater than IDLE_OOZING_MINTEMP and less than IDLE_OOZING_FEEDRATE
//or when the target temperature is less than EXTRUDE_MINTEMP.
externintextruder_multiply[EXTRUDERS];// sets extrude multiply factor (in percent) for each extruder individually
externfloatfilament_size[EXTRUDERS];// cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
externunsignedlongprinter_usage_seconds;//this can old about 136 year before go overflow. If you belive that you can live more than this please contact me.
ln_ignore=false;//We've reached a new line try to find a key again
continue;
}
if(ln_ignore)continue;
if(ln_char==' '){
ln_space=true;
continue;
}
if(ln_char=='='){
key[ln_buf]='\0';
len_k=ln_buf;
key_found=true;
break;//key finded and buffered
}
if(ln_char==';'||ln_buf+1>=len_k||ln_space&&ln_buf>0){//comments on key is not allowd. Also key len can't be longer than len_k or contain spaces. Stop buffering and try the next line
ln_ignore=true;
continue;
}
ln_space=false;
key[ln_buf]=ln_char;
ln_buf++;
}
if(!key_found){//definitly there isn't no more key that can be readed in the file
key[0]='\0';
value[0]='\0';
len_k=0;
len_v=0;
return;
}
ln_buf=0;
ln_ignore=false;
while(!eof()){//READ VALUE
ln_char=(char)get();
if(ln_char=='\n'){
value[ln_buf]='\0';
len_v=ln_buf;
break;//new line reached, we can stop
}
if(ln_ignore||ln_char==' '&&ln_buf==0)continue;//ignore also initial spaces of the value
if(ln_char==';'||ln_buf+1>=len_v){//comments reached or value len longer than len_v. Stop buffering and go to the next line.
//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset