_FILL(char c, int len) for Streaming library

An addition for the Streaming library from Mikal Hart

include this in the Streaming.h

struct _FILL 
{ 
  char ch; 
  int len;
  _FILL(char c, int l): ch(c), len(l) 
  {}
};

inline Print &operator <<(Print &obj, const _FILL &arg)
{ for (int i=0; i< arg.len; i++) obj.write(arg.ch); return obj; }

some examples

Serial << _FILL('=', 20) << endl;

or

int table[10] = {5,10,4,6,8,12,6,5,3,2};
for (int i=0; i<10; i++)
{
  Serial << _FILL('*', table[i]) << endl;
}

another trick for streaming.h (not optimized but might still be useful)

struct _TIME 
{ 
  uint8_t hour; 
  uint8_t minu; 
  uint8_t sec; 
  _TIME(uint8_t h, uint8_t m, uint8_t s): hour(h), minu(m), sec(s) 
  {}
};

inline Print &operator <<(Print &obj, const _TIME &arg)
{ obj.print(((arg.hour<10)?"0":""));    obj.print(int(arg.hour)); 
  obj.print(((arg.minu<10)?":0":":"));  obj.print(int(arg.minu)); 
  obj.print(((arg.sec<10)?":0":":"));   obj.print(int(arg.sec)); 
  return obj; }

another one, you could make a _TEMPC and a _TEMPF (Celsius Fahrenheit)

struct _TEMP 
{ 
  float temp; 
  int digits;
  _TEMP(float t, int d=0): temp(t), digits(d)
  {}
};

inline Print &operator <<(Print &obj, const _TEMP &arg)
{ obj.print(arg.temp, arg.digits); obj.print("Celsius"); return obj; }

final one for today, just to explore what can be done within the streaming lib.

struct _FUNC 
{ 
  double val; 
  double (*foo)(double);
  _FUNC(double v, double (*f)(double)): val(v) 
  {
  foo = f;
  }
};

inline Print &operator <<(Print &obj, const _FUNC &arg)
{ obj.print(arg.foo(arg.val), 4); return obj; }

you an use this to call a math function on a number as follows:

#include <Streaming.h>

void setup()
{
  Serial.begin(115200);
  for (uint8_t a = 0; a < 25; a++)
  {
    Serial << _FUNC(a, sinSqr) << endl;
  }
}

void loop() {}

double sinSqr(double p)
{
  return sin(p) * sin(p);
}

Hi, I'm looking into the streaming lib and found your link
would you mind explaining what some of this stuff does?
I'm trying to make some examples for myself for future reference
Thank you

Best way is to give them a try of course.

_FILL(char, len) repeats a char len times.
so
Serial << _FILL('=', 20) << endl;
outputs


int table[10] = {5,10,4,6,8,12,6,5,3,2};
for (int i=0; i<10; i++)
{
Serial << _FILL('', table) << endl;*
}
makes a simple histogram from a table
```











```
better would be Serial << table << "\t" << FILL('', table) << endl;
which would add the value before the stars => This could be merged into a _HISTO(char, len)
TIME() prints the time,*
The others are more playing.