#pragma once #if defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) #ifdef TEENSYSTEP_H #include #include class Atm_Teenstep: public Machine { public: enum { DISABLED, ENABLED, RUNNING, STOPPING, EMERGENCY_STOP, HOMING_HIGH, HOMING_LOW }; // STATES enum { EVT_HOMING_LOW, EVT_HOMING_HIGH, EVT_MOVE_TIMEOUT, EVT_LIMIT_HIGH, EVT_LIMIT_LOW, EVT_EMERGENCYSTOP, EVT_STOP, EVT_ONTARGET, EVT_MOVE, EVT_DISABLE, EVT_ENABLE, ELSE }; // EVENTS Atm_Teenstep( void ) : Machine() {}; Atm_Teenstep& begin( Stepper & motorRef, StepControl & stepControlRef ); Atm_Teenstep& trace( Stream & stream ); Atm_Teenstep& trigger( int event ); int state( void ); Atm_Teenstep& onChange( Machine& machine, int event = 0 ); Atm_Teenstep& onChange( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& onChangeposition( Machine& machine, int event = 0 ); Atm_Teenstep& onChangeposition( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& onLimithigh( Machine& machine, int event = 0 ); Atm_Teenstep& onLimithigh( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& onLimitlow( Machine& machine, int event = 0 ); Atm_Teenstep& onLimitlow( atm_cb_push_t callback, int idx = 0 ); Atm_Teenstep& homing_low( void ); Atm_Teenstep& homing_high( void ); Atm_Teenstep& move_timeout( void ); Atm_Teenstep& limit_high( void ); Atm_Teenstep& limit_low( void ); Atm_Teenstep& emergencystop( void ); Atm_Teenstep& stop( void ); Atm_Teenstep& ontarget( void ); Atm_Teenstep& move( void ); Atm_Teenstep& disable( void ); Atm_Teenstep& enable( void ); Atm_Teenstep& move( long int stepRel ); Atm_Teenstep& moveTo( long int stepAbs ); Atm_Teenstep& homing( bool direction ); Atm_Teenstep& setLimitType( int limitType = 0); Atm_Teenstep& setLimitPins( int limitPinLow); Atm_Teenstep& setLimitPins( int limitPinLow, int limitPinHigh); Atm_Teenstep& limitReversed( bool reversed ); Atm_Teenstep& limitThresholds( int limitThreshold0, int limitThreshold1, int limitThreshold2, int limitThreshold3); bool limitState[2] ; // up to two limits, at least one for homing virtual Atm_Teenstep& onOSC( void ); virtual Atm_Teenstep& sendOSC( void ); Stepper * motor; StepControl * controller; Atm_Teenstep& setEnablePin( int enablePin ); Atm_Teenstep& enableReversed( bool reverse ); bool enabled ; private: enum { ENT_DISABLED, ENT_ENABLED, ENT_RUNNING, LP_RUNNING, ENT_STOPPING, ENT_EMERGENCY_STOP, ENT_HOMING_HIGH, EXT_HOMING_HIGH, ENT_HOMING_LOW, EXT_HOMING_LOW }; // ACTIONS enum { ON_CHANGE, ON_CHANGEPOSITION, ON_LIMITHIGH, ON_LIMITLOW, CONN_MAX }; // CONNECTORS atm_connector connectors[CONN_MAX]; int event( int id ); void action( int id ); atm_timer_millis idle_timer ; int IDLE_TIMEOUT_DURATION = 500000 ; atm_timer_millis moving_timer ; int MOVING_TIMEOUT_DURATION = 12000000 ; atm_counter homing_counterout ; long int _currentStep = 0; long int _targetStep = 0; long int _maxStep ; int _enablePin = -1; bool _enableReversed = 0 ; int _limitPin[2]; enum { NONE, DIGITAL_1, DIGITAL_2, ANALOG_1 }; int _limitType; //type of limit switch, from list over bool _limitReversed ; //invert logic of limit switches int _limitThresholds[4] ; //analog value range for two analog limits void updateLimitSwitch(); }; #endif #endif /* Automaton::ATML::begin - Automaton Markup Language ENABLED RUNNING DISABLED EMERGENCY_STOP EMERGENCY_STOP EMERGENCY_STOP STOPPING ENABLED RUNNING EMERGENCY_STOP EMERGENCY_STOP EMERGENCY_STOP RUNNING RUNNING ENABLED ENABLED EMERGENCY_STOP EMERGENCY_STOP STOPPING EMERGENCY_STOP ENABLED EMERGENCY_STOP STOPPING Automaton::ATML::end */