#include <runningAvg.h>
#include <serialStr.h>

/*
  Running average.

  This class was developed as a super simple to use data smoother. You decide, when creating
  it, how many data points you would like to smooth your data over. Then each time you add a
  data point it returns the running average of the last n points that were added. Simple to
  use, easy to understand.

  Enjoy!

  -jim lee

*/

runningAvg  smoother(5);    // Our smoother. You can change the number of datapoints it will act on.
serialStr   serialManager;  // And object that grabs user input from the serial port. (Handy!)


// Standard setup stuff..
void setup(void) {

   Serial.begin(57600);						                      // Fire up the serial stuff.
   serialManager.setCallback(gotStr);                   // Tell the serial manager who to call with input.
   Serial.println(F("Enter numbers, one at a time."));  // Tell Mrs user to start inputting numbers.
   Serial.println(F("This will average the last 5 you entered."));	//
}

// This gets called when the user types enter in the serial monitor.
void gotStr(char* inStr) {

   float aValue;                       // The float version of the number you typed.
   float ave;                          // The Average that the smoother will return to us.

   aValue = atof(inStr);               // Read what we got as a float value. (Decimal number)
   ave = smoother.addData(aValue);     // Pop this number into our smoother. Out pops the average.
   Serial.print(F("Entered    : "));   // Displaying  this stuff on the serial monitor.
   Serial.println(aValue,4);
   Serial.println(F("Average   : "));
   Serial.println(ave,4);
   Serial.println(F("--------------"));
   Serial.println();
}


// Standard loop stuff..
void loop(void) {
   
   idle();  // Lets the background code run. (The serialStr thing);
}