// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved


// This software makes use of tools and libraries obtained from open source projects or released for

// use by relevant hardware manufactures. However, this software is NOT a part of any open source project.

// It is released only on a "need to know" basis for beta testers of the "RiceCNC Interpolation Engine".

// Recipents of this source code must respect the confidential nature of this software and prevent any

// distribution that could result in counterfeit copies of the "RiceCNC Interpolation Engine".


// © RiceMotion ( Robert Carl Rice ) 2012-2016 - All rights reserved

#include <VoltageFeedback.h>

#include <AnalogPin.h>


#include <inc/hw_gpio.h>

#include <driverlib/interrupt.h>

#include <driverlib/timer.h>


//#define DebugDelete 1


VoltageFeedback::VoltageFeedback(

     char*          data,

     String*          msgPtr ) {


     vsa               = NULL;

     vsb               = NULL;

     vsc               = NULL;

          

     char     vsaPinString     [8];

     char     vsbPinString     [8];

     char     vscPinString     [8];


     sscanf( data,

          " %s %s %s",

          vsaPinString,

          vsbPinString,

          vscPinString );


     vsa          = new AnalogPin(

          vsaPinString,

          msgPtr );

     if ( vsa->valid() ) {

          *msgPtr     += "\n vsa";

          vsa->fmtPin( msgPtr ); }

     else {

          delete vsa;

          vsa = NULL; };


     vsb          = new AnalogPin(

          vsbPinString,

          msgPtr );

     if ( vsb->valid() ) {

          *msgPtr     += "\n vsb";

          vsb->fmtPin( msgPtr ); }

     else {

          delete vsb;

          vsb = NULL; };


     vsc          = new AnalogPin(

          vscPinString,

          msgPtr );

     if ( vsc->valid() ) {

          *msgPtr     += "\n vsc";

          vsc->fmtPin( msgPtr ); }

     else {

          delete vsc;

          vsc = NULL; };

     };


bool

     VoltageFeedback::valid() {

     

     return

          vsa

     &&     vsb

     &&     vsc; };


VoltageFeedback::~VoltageFeedback() {


#ifdef DebugDelete

     Serial.println( " delete VoltageFeedback" );

#endif


     if ( vsa )

          delete vsa;

     if ( vsb )

          delete vsb;

     if ( vsc )

          delete vsc; };