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

#include <Machine.h>

#include <Pause.h>

#include <InterpolationTimer.h>

#include <Axis.h>

#include <DoorAjarCommand.h>

#include <Spindle.h>

#include <AbortCommand.h>



void

     Machine::interpolationControl(

          char*     commandPtr,

          String* msgPtr ) {


     char* data     = commandPtr + 1;


     switch ( *commandPtr ) {


// in-band - acknowledge immediately

          case PAUSE_COMMAND :

          queueCommand(

               new Pause() );

          *msgPtr

               +=     String( INTERPOLATION_CONTROL )

               +     String( PAUSE_COMMAND );

          break;


// out-of-band

          case PAUSE_INTERPOLATION :

          pause();

          break;


          case CONTINUE_INTERPOLATION :

          continueInterpolation();

          break;


          case ABORT_INTERPOLATION :

          abort();

          break;


          default :

          *msgPtr

               +=     *commandPtr

               +     "E Invalid Machine Command - Ignored"; }; };



void

     Machine::abort() {


     broadcastToAxes( &Axis::abort );

     insertAtTopBG( new AbortCommand() ); };


void

     Machine::pause() { // User pause


     insertAtTopBG( new Pause() ); };


void

     Machine::insertAtTopBG( Command* command ) {

     // Insert in-band at top-of-queue

     InterpolationTimer::disableInterpolationInterrupts();

          insertAtTop( command );

     InterpolationTimer::enableInterpolationInterrupts(); };


void

     Machine::continueInterpolation() {


     InterpolationTimer::disableInterpolationInterrupts();

          if ( currentCommand )

               currentCommand->continueInterpolation( this );

     InterpolationTimer::enableInterpolationInterrupts(); };