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

#include <Machine.h>

#include <Axis.h>

#include <Timers.h>

#include <MachineCommands.h>


const char Dwell::myName[] =

     "Dwell";


const char*

     Dwell::name() {

     

     return

          myName; };


Dwell::Dwell( char* data ) {

    float dwell               = 0.0;               // seconds

    sscanf( data, "%f", &dwell );


    dwellTime               = dwell * 1000000; // convert to microseconds

    pathTime               = 0;

     continueExecution     = false; };


bool

     Dwell::execute( Machine* machine ) {


     if ( continueExecution )

          return

               true;


     if ( pathTime == 0 )

          pathTime   = SysTick::microSecondTimer;


    if ( machine->isSeekingPosition() ) { // Wait for axes to go idle

          pathTime   = SysTick::microSecondTimer;

          return

               false; };

    return

          SysTick::microSecondTimer - pathTime >= dwellTime; };


void

     Dwell::reportInterpolationStatus(

          Machine*     machine,

          String*          msgPtr ) {


     *msgPtr  += INTERPOLATOR_DWELLING; };


void

     Dwell::continueInterpolation( Machine* machine ) {


     continueExecution  = true; };


void

     Dwell::report(

          Machine*     machine,

          String*          msgPtr ) {


    machine->reportInterpolationStatus( msgPtr ); };