// © 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 <PlasmaStartStop.h>

#include <Axis.h>

#include <TorchHeightControl.h>

#include <Machine.h>


const char PlasmaStartStop::myName[] =

     "PlasmaStartStop";


const char*

     PlasmaStartStop::name() {

     

     return

          myName; };


PlasmaStartStop::PlasmaStartStop( char* data ) {

     axis               = NULL;


     axisNameC          = ' ';

     int     number          = 0;

     setPoint          = 0.0;

     sscanf( data,

          "%c%d",

          &axisNameC,

          &number,

          &setPoint );

     on                    = number > 0; };


bool

     PlasmaStartStop::execute( Machine* machine ) {


     if ( ! axis ) {

          axis          = (TorchHeightControl*)machine->findAxis(

               axisNameC,

               NULL );

          if ( setPoint != 0.0 && axis && axis->isTorchAxis() ) {

               axis->setVoltage     = setPoint;

               axis->startPlasma( on ); }


          else {

               axis     = NULL;

               return true; }; };


     bool established = axis->arcEstablished();

    return on ?

          established :

          ! established; };


void

     PlasmaStartStop::report( String* msgPtr ) {


     char data[40] = "";

     if ( axis )

          snprintf( data, 40,

               " Plasma %c %s\n",

               axisNameC,

               on ?

                    "Started" :

                    "Stopped" );

     else

          snprintf( data, 40,

               "E Plasma axis %c invalid\n",

               axisNameC );


     *msgPtr

          += String( data ); };