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

#include <SetMaxInterpolationSpeed.h>

#include <Dwell.h>



void

     Machine::feedrateControl(

          char*     commandPtr,

          String* msgPtr ) {


     char* data     = commandPtr + 1;


     switch ( *commandPtr ) {


// in-band - acknowledge immediately

          case SET_FEEDRATE :

          queueCommand(

               new SetFeedrate( data ) );

          *msgPtr

               +=     String( FEEDRATE_CONTROL )

               +     String( SET_FEEDRATE );

          break;


          case MAX_INTERPOLATION_SPEED :

          queueCommand(

               new SetMaxInterpolationSpeed( data ) );

          *msgPtr

               +=     String( FEEDRATE_CONTROL )

               +     String( MAX_INTERPOLATION_SPEED );

          break;


          case DWELL :

          queueCommand(

               new Dwell( data ) );

          *msgPtr

               +=     String( FEEDRATE_CONTROL )

               +     String( DWELL );

          break;


// out-of-band

          case FEEDRATE_OVERRIDE :

          feedrateOverride(

               data,

               msgPtr );

          break;


          default :

          *msgPtr

               +=     *commandPtr

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



void

     Machine::feedrateOverride(

          char*     data,

          String* msgPtr ) {


    float       feedrateIPS;            // inches per second

     sscanf( data,

          " %f",

          &feedrateIPS );


     snprintf( data, 40,

          "%c%c %.3f",

          FEEDRATE_CONTROL,

          FEEDRATE_OVERRIDE,

          feedrateIPS );

     *msgPtr  += String( data );


     // Only keep the square of the feedrate to optimize Pythagorean speed comparison

     sqFeedrateIPS     = feedrateIPS * feedrateIPS; };