|
@@ -34,6 +34,7 @@ Atm_AccelStepper& Atm_AccelStepper::begin(int step_pin, int dir_pin) {
|
|
|
|
|
|
int Atm_AccelStepper::event( int id ) {
|
|
|
//updateLimitSwitch();
|
|
|
+ bool changed ;
|
|
|
switch ( id ) {
|
|
|
case EVT_DISABLE:
|
|
|
return 0;
|
|
@@ -48,49 +49,61 @@ int Atm_AccelStepper::event( int id ) {
|
|
|
case EVT_EMERGENCY_STOP:
|
|
|
return 0;
|
|
|
case EVT_ON_LIMIT_LOW:
|
|
|
- previous_state = limitLow_State;
|
|
|
+ // previous_state = limitLow_State;
|
|
|
switch(_limitLow_Mode) {
|
|
|
case 0:
|
|
|
- return 0;
|
|
|
+ changed = limitLow_State != limitLow_State_prev ? 1 : 0 ;
|
|
|
+ break;
|
|
|
case 1: //digital INPUT
|
|
|
// Serial.println("digital");
|
|
|
limitLow_State = digitalRead(_limitLow_Pin);
|
|
|
limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
|
|
|
- return limitLow_State != previous_state;
|
|
|
+ changed = limitLow_State != limitLow_State_prev ? 1 : 0 ;
|
|
|
+ break;
|
|
|
case 2:
|
|
|
int analogTemp = analogRead(_limitLow_Pin);
|
|
|
limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
|
|
|
limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
|
|
|
if(limitLow_State){
|
|
|
- delay(3);
|
|
|
- analogTemp = analogRead(_limitLow_Pin);
|
|
|
- limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
|
|
|
- limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
|
|
|
- }
|
|
|
- return limitLow_State != previous_state;
|
|
|
+ delay(3);
|
|
|
+ analogTemp = analogRead(_limitLow_Pin);
|
|
|
+ limitLow_State = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
|
|
|
+ limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
|
|
|
+ }
|
|
|
+ changed = limitLow_State != limitLow_State_prev ? 1 : 0 ;
|
|
|
+ break;
|
|
|
}
|
|
|
+ limitLow_State_prev = limitLow_State ;
|
|
|
+ return changed ;
|
|
|
+
|
|
|
case EVT_ON_LIMIT_HIGH:
|
|
|
- previous_state = limitHigh_State;
|
|
|
+ // previous_state = limitHigh_State;
|
|
|
switch(_limitHigh_Mode) {
|
|
|
case 0:
|
|
|
- return 0;
|
|
|
+ changed = limitHigh_State != limitHigh_State_prev ? 1 : 0;
|
|
|
+ break;
|
|
|
case 1: //digital INPUT
|
|
|
limitHigh_State = digitalRead(_limitHigh_Pin);
|
|
|
limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
|
|
|
- return limitHigh_State != previous_state;
|
|
|
+ changed = limitHigh_State != limitHigh_State_prev ? 1 : 0;
|
|
|
+ break;
|
|
|
case 2:
|
|
|
//Serial.println("analog");
|
|
|
int analogTemp = analogRead(_limitHigh_Pin);
|
|
|
limitHigh_State = (_limitHigh_Thresholds[0] < analogTemp) && (analogTemp < _limitHigh_Thresholds[1]);
|
|
|
limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
|
|
|
- if(limitHigh_State){
|
|
|
- delay(3);
|
|
|
- analogTemp = analogRead(_limitHigh_Pin);
|
|
|
- limitHigh_State = (_limitHigh_Thresholds[0] < analogTemp) && (analogTemp < _limitHigh_Thresholds[1]);
|
|
|
- limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
|
|
|
- }
|
|
|
- return limitHigh_State != previous_state;
|
|
|
+ if(limitHigh_State){
|
|
|
+ delay(3);
|
|
|
+ analogTemp = analogRead(_limitHigh_Pin);
|
|
|
+ limitHigh_State = (_limitHigh_Thresholds[0] < analogTemp) && (analogTemp < _limitHigh_Thresholds[1]);
|
|
|
+ limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
|
|
|
+ }
|
|
|
+ changed = limitHigh_State != limitHigh_State_prev ? 1 : 0;
|
|
|
+ break;
|
|
|
}
|
|
|
+ limitHigh_State_prev = limitHigh_State_prev;
|
|
|
+ return changed;
|
|
|
+
|
|
|
case EVT_ON_TARGET:
|
|
|
return runMode ? 0 : _currentStep == _targetStep;
|
|
|
case EVT_HOMING_LOW:
|