hi guys,
sorry for this post if i will make some error or if i'm disturbing you and in the last for my bad english
the reason that has 'port' me to inquire this question ... is a little think that is less in the Serial[x] object
it don't has the opportunity to use the soft and usefull mode to implement the power of the printf function
positive charateristics .........
i have implemented a workaround to implement the printf to use with Serial object ......
unfortunattly i have try to derive the HardwareSerial directly but the code is compiled correctly but in
the run the solution don't work in 'totally' .....
the second version (the workaround) work correctly ... but it's needed to include and create the istance
BSerial .....
can you implement only the 'printf' function part in the possible new version of the HardwareSerial
object class? .... i will include follow the source code .....
Thank you
have a nice day
Roberto74 ($B0FFE)
// = = = = = = = = = = = = = = = = = = = = = = = =
// THIS WORK AROUND WORK CORRECTLY
// = = = = = = = = = = = = = = = = = = = = = = = =
// if necessary include <stdarg.h>
class BSerial
{
public:
static const size_t N_CHAR_OUTPUT_BUFFER_SIZE = 256;
// - - - - - - - - - -
public:
BSerial(HardwareSerial* P1_HardwareSerial_pac)
{
this->P1_HardwareSerial= P1_HardwareSerial_pac;
}
// - - - - - - - - - -
public:
int printf(String P1_string, ...)
{
va_list arg_ptr;
va_start(arg_ptr, P1_string);
int N_write_Char = vsnprintf(A_EndBuffer, BSerial::N_CHAR_OUTPUT_BUFFER_SIZE, &P1_string[0], arg_ptr);
va_end(arg_ptr);
if (N_write_Char < (int) BSerial::N_CHAR_OUTPUT_BUFFER_SIZE)
{
P1_string[N_write_Char+1] = '\0';
}
else
{
return -(N_write_Char + 1 - (int) BSerial::N_CHAR_OUTPUT_BUFFER_SIZE);
}
this->P1_HardwareSerial->print(A_EndBuffer);
return N_write_Char;
}
// - - - - - - - - - -
private:
char A_EndBuffer[BSerial::N_CHAR_OUTPUT_BUFFER_SIZE];
// - - - - - - - - - -
public:
HardwareSerial* P1_HardwareSerial;
};
// = = = = = = = = = = = = = = = = = = = = = = = =
// = = = = = = = = = = = = = = = = = = = = = = = =
// THIS PROBABLY MORE RIGHT IMPLEMENTATION IS COMPILE CORRECTLY BUT PRINT ONLY TWO CHARS
// = = = = = = = = = = = = = = = = = = = = = = = =
/*
// se necessario includere <stdarg.h>
class BSerialT: public HardwareSerial
{
public:
static const size_t N_CHAR_OUTPUT_BUFFER_SIZE = 256;
// - - - - - - - - - -
public:
BSerialT(HardwareSerial& Ps1_HardwareSerial_pac): HardwareSerial(Ps1_HardwareSerial_pac)
{
}
// - - - - - - - - - -
public:
~BSerialT()
{
}
// - - - - - - - - - -
public:
int printf(String P1_string, ...)
{
va_list arg_ptr;
va_start(arg_ptr, P1_string);
int N_write_Char = vsnprintf(A_EndBuffer, BSerialT::N_CHAR_OUTPUT_BUFFER_SIZE, &P1_string[0], arg_ptr);
va_end(arg_ptr);
if (N_write_Char < (int) BSerialT::N_CHAR_OUTPUT_BUFFER_SIZE)
{
P1_string[N_write_Char+1] = '\0';
}
else
{
return -(N_write_Char + 1 - (int) BSerialT::N_CHAR_OUTPUT_BUFFER_SIZE);
}
this->println(A_EndBuffer);
return N_write_Char;
}
// - - - - - - - - - -
private:
char A_EndBuffer[BSerialT::N_CHAR_OUTPUT_BUFFER_SIZE];
// - - - - - - - - - -
};
*/
// = = = = = = = = = = = = = = = = = = = = = = = =