#pragma once #include #include class Atm_AccelStepper: public Machine { public: enum { DISABLE, ENABLED, RUNNING, STOP, HOMING_LOW, HOMING_HIGH, LIMIT_LOW, LIMIT_HIGH }; // STATES enum { EVT_DISABLE, EVT_ENABLE, EVT_ENABLED_TIMEOUT, EVT_MOVE, EVT_STOP, EVT_EMERGENCY_STOP, EVT_ON_LIMIT_LOW, EVT_ON_LIMIT_HIGH, EVT_ON_TARGET, ELSE }; // EVENTS Atm_AccelStepper( void ) : Machine() {}; Atm_AccelStepper& begin( int step_pin, int dir_pin ); Atm_AccelStepper& trace( Stream & stream ); Atm_AccelStepper& trigger( int event ); int state( void ); Atm_AccelStepper& onChangeposition( Machine& machine, int event = 0 ); Atm_AccelStepper& onChangeposition( atm_cb_push_t callback, int idx = 0 ); Atm_AccelStepper& onChangestate( Machine& machine, int event = 0 ); Atm_AccelStepper& onChangestate( atm_cb_push_t callback, int idx = 0 ); Atm_AccelStepper& onOnlimithigh( Machine& machine, int event = 0 ); Atm_AccelStepper& onOnlimithigh( atm_cb_push_t callback, int idx = 0 ); Atm_AccelStepper& onOnlimitlow( Machine& machine, int event = 0 ); Atm_AccelStepper& onOnlimitlow( atm_cb_push_t callback, int idx = 0 ); Atm_AccelStepper& onOntarget( Machine& machine, int event = 0 ); Atm_AccelStepper& onOntarget( atm_cb_push_t callback, int idx = 0 ); Atm_AccelStepper& onStop( Machine& machine, int event = 0 ); Atm_AccelStepper& onStop( atm_cb_push_t callback, int idx = 0 ); Atm_AccelStepper& disable( void ); Atm_AccelStepper& enable( void ); //Atm_AccelStepper& move( void ); Atm_AccelStepper& stop( void ); Atm_AccelStepper& emergency_stop( void ); Atm_AccelStepper& on_limit_low( void ); Atm_AccelStepper& on_limit_high( void ); Atm_AccelStepper& on_target( void ); AccelStepper *stepper; Atm_AccelStepper& move( long int stepRel ); Atm_AccelStepper& moveTo( long int stepAbs ); Atm_AccelStepper& rotate( long int speed ); Atm_AccelStepper& homing( bool direction ); int runMode = 0; // 0 uses run() for positioning, 1 uses runSpeed() for constant speed Atm_AccelStepper& setEnablePin( int enablePin ); Atm_AccelStepper& enableReversed( bool reverse ); bool enabled ; Atm_AccelStepper& limitLow_set(int mode = 0, int pin = -1, int reversed=0); Atm_AccelStepper& limitLow_setThresholds (int threshold_low=510, int threshold_high = 1024); Atm_AccelStepper& limitHigh_set(int mode = 0, int pin = -1, int reversed=0); Atm_AccelStepper& limitHigh_setThresholds (int threshold_low=510, int threshold_high = 1024); bool limitLow_State; bool limitHigh_State; private: enum { ENT_DISABLED, ENT_ENABLED,ENT_RUNNING, LP_RUNNING, ENT_STOP, LP_STOP, ENT_HOMING_LOW, EXT_HOMING_LOW, ENT_HOMING_HIGH, EXT_HOMING_HIGH, ENT_LIMIT_LOW, ENT_LIMIT_HIGH }; // ACTIONS enum { ON_CHANGEPOSITION, ON_CHANGESTATE, ON_ONLIMITHIGH, ON_ONLIMITLOW, ON_ONTARGET, ON_STOP, CONN_MAX }; // CONNECTORS atm_connector connectors[CONN_MAX]; int event( int id ); void action( int id ); long int _currentStep = 0; long int _targetStep = 0; long int _maxStep ; int _enablePin = -1; bool _enableReversed = 0 ; atm_timer_millis idle_timer ; int IDLE_TIMEOUT_DURATION = 500000 ; int _limitLow_Pin; int _limitLow_Mode; //0 no limit, 1 digital, 2 analog with thresholds bool _limitLow_Reversed ; //invert logic of limit switches int _limitLow_Thresholds[2] ; //analog value range for two analog limits int _limitHigh_Pin; int _limitHigh_Mode; //0 no limit, 1 digital, 2 analog with thresholds bool _limitHigh_Reversed ; //invert logic of limit switches int _limitHigh_Thresholds[2] ; //analog value range for two analog limits void updateLimitSwitch(); }; /* Automaton::ATML::begin - Automaton Markup Language ENABLED DISABLED DISABLED STOP STOP DISABLED STOP STOP LIMIT_LOW LIMIT_HIGH ENABLED DISABLED STOP STOP DISABLED STOP STOP ENABLED DISABLED STOP STOP ENABLED STOP STOP LIMIT_LOW STOP STOP LIMIT_HIGH Automaton::ATML::end */