#include <Arduino.h>

#include "Rfx_config.h"

#include <Rfx_printfns_r1.h>

void setup()
  char s1[] = "rfx printf()";
  double pi = 3.14159;

  fpf("\nThis is a basic demo of %s.\n\n",s1);
  for (int k = 0; k < 10; k++)
    fpf(" %s %d\n",s1,k);
  fpf("\nit prints floats like %f too!\n",pi);    
  fpf("all using very little ram (free_ram() = %d)\n",free_ram());
  fpln("all the fancy specifier/flag stuff is supported, (the only thing \n"
       "not supported is exponential format for floats).");

  fpln("\nHere's some of the fancy stuff, including two non-standard extensions useful \n"
         "for Arduino applications:\n");
  fpln("1) a %P specifiers to allow direct printing of AVR flash (i.e, \"PSTR()\") strings, and");
  fpln("2) a %S specifier to allow direct printing of Arduino Strings/C++ strings.\n");

  fpln("See some format specifier test examples below:\n");

  int i = -100;
  int8_t h = i; // a short int
  double f = (double)i;
  String cppstr = "This is an Arduino/C++ String";

  fpf("this is a test of fpf, i = %d, f = %9.2f, g = %.2g\n",i,f,f);

  fpf("\nthis may be a flash string...\n");
  prf("but this definitely isn't!\n\n");

  char test_str[] = "Here's a string to play around with for width and justificaton formatting...";

  fpf("%s\n", test_str);
  fpf(":%%s: = :%s:\n", test_str);
  fpf(":%%20s: = :%20s:\n", test_str);
  fpf(":%%.10s: = :%.10s:\n", test_str);
  fpf(":%%20.10s: = :%20.10s:\n", test_str);
  fpf(":%%-20.10s: = :%-20.10s:\n\n", test_str);

  const char *test_pstr = PSTR("And here's a PSTR (flash) string to play around with...");

  fpf("%P\n", test_pstr);
  fpf(":%%P: = :%P:\n", test_pstr);
  fpf(":%%20P: = :%20P:\n", test_pstr);
  fpf(":%%.10P: = :%.10P:\n", test_pstr);
  fpf(":%%20.10P: = :%20.10P:\n", test_pstr);
  fpf(":%%-20.10P: = :%-20.10P:\n\n", test_pstr);

  fpf("test of fpf, i = %i, u = %u, x = %x, o = %o, b = %b, f = %9.2f, g = %.2g\n",i,i,i,i,i,f,f);
  fpf("test of fpf, #i = %#i, #u = %#u, #x = %#x, #o = %#o, #b = %#b, #f = %#9.2f, #g = %#.2g\n",i,i,i,i,i,f,f);
  fpf("test of fpf, #hi = %#hi, #hu = %#hu, #hx = %#hx, #ho = %#ho, #hb = %#hb\n",h,h,h,h,h);

  int n;
  fpf("test of fpf, %%n,%n i = %i, u = %u, x = %x, o = %o, b = %b\n",&n,n,n,n,n,n);
  fpf("fpf, width trick %%*d = %*d\n",5,10);
  fpf("fpf, width and precision trick %%*.*f = %*.*f\n",7,3,3.14159);

  String* S = &cppstr;

  int len = S->length();
  char c = (*S)[0];
  fpf("fpf, C++ str: %%d = %d, %%c = %c\n",len,c);
  fpf("fpf, C++ str: %%S = %S\n",&cppstr);

void loop()