/*
 
  souder.d@gmail.com
  Date de dernière modification : 08/09/2018
  
*/

#ifndef Duinoedu_Utility_CONV_H
#define Duinoedu_Utility_CONV_H
char* p;

	//* === Version 2
	#define PCHAR(val) convInPChar(String(val)) 
	char* convInPChar(String s) {
	#if defined(__AVR__) || defined(ESP8266) 
		char stringC[32];
		int n = s.length();
		for (int i = 0; i < n; i++)
			stringC[i] = s[i];
		stringC[n] = '\0';
		Serial.print (""); 
		//Serial.println("conv ok");
		return stringC;
	
	#elif defined(ESP32)
		if(s.length()!=0){
		p = const_cast<char*>(s.c_str());
		}
		return p;
	#endif
	}
	//*/
	
	//* === Version 3
	// [ BAS NIVEAU ]
	char* stringToPChar(String &s){
		return &s[0];
	}
	
	// String => pchar
	char* PCHAR2(String &arg){
		return stringToPChar(arg);
	}

	// pcar => pchar
	char* PCHAR2(char* arg){
		return arg;
	}
	
	// Int => pchar
	char* PCHAR2(int nbr){
		static String edu_intString = String(nbr); 
		return stringToPChar(edu_intString);
	}
	

	
	
	

	

	
	
	
	

#endif

/*
char* convInPChar(String s) {
   if(s.length()!=0){
        char *p = const_cast<char*>(s.c_str());
    return p;
    }
}
*/