|
@@ -33,7 +33,7 @@ Atm_AccelStepper& Atm_AccelStepper::begin(int step_pin, int dir_pin) {
|
|
*/
|
|
*/
|
|
|
|
|
|
int Atm_AccelStepper::event( int id ) {
|
|
int Atm_AccelStepper::event( int id ) {
|
|
- //updateLimitSwitch();
|
|
|
|
|
|
+ bool tempState ;
|
|
bool changed = 0 ;
|
|
bool changed = 0 ;
|
|
switch ( id ) {
|
|
switch ( id ) {
|
|
case EVT_DISABLE:
|
|
case EVT_DISABLE:
|
|
@@ -49,56 +49,55 @@ int Atm_AccelStepper::event( int id ) {
|
|
case EVT_EMERGENCY_STOP:
|
|
case EVT_EMERGENCY_STOP:
|
|
return 0;
|
|
return 0;
|
|
case EVT_ON_LIMIT_LOW:
|
|
case EVT_ON_LIMIT_LOW:
|
|
- // previous_state = limitLow_State;
|
|
|
|
-
|
|
|
|
switch(_limitLow_Mode) {
|
|
switch(_limitLow_Mode) {
|
|
|
|
|
|
case 0:
|
|
case 0:
|
|
break;
|
|
break;
|
|
case 1: //digital INPUT
|
|
case 1: //digital INPUT
|
|
// Serial.println("digital");
|
|
// Serial.println("digital");
|
|
- limitLow_State = digitalRead(_limitLow_Pin);
|
|
|
|
- limitLow_State = _limitLow_Reversed ? !limitLow_State : limitLow_State;
|
|
|
|
|
|
+ limitLow_State_raw = digitalRead(_limitLow_Pin);
|
|
|
|
+ limitLow_State_raw = _limitLow_Reversed ? !limitLow_State_raw : limitLow_State_raw;
|
|
break;
|
|
break;
|
|
case 2:
|
|
case 2:
|
|
int analogTemp = analogRead(_limitLow_Pin);
|
|
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;
|
|
|
|
- }
|
|
|
|
|
|
+ limitLow_State_raw = (_limitLow_Thresholds[0] < analogTemp) && (analogTemp < _limitLow_Thresholds[1]);
|
|
|
|
+ limitLow_State_raw = _limitLow_Reversed ? !limitLow_State_raw : limitLow_State_raw;
|
|
|
|
+ // 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;
|
|
|
|
+ // }
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ limitLow_State = limitLow_avg(limitLow_State_raw);
|
|
changed = limitLow_State != limitLow_State_prev ? 1 : 0 ;
|
|
changed = limitLow_State != limitLow_State_prev ? 1 : 0 ;
|
|
limitLow_State_prev = limitLow_State ;
|
|
limitLow_State_prev = limitLow_State ;
|
|
return changed ;
|
|
return changed ;
|
|
|
|
|
|
|
|
|
|
case EVT_ON_LIMIT_HIGH:
|
|
case EVT_ON_LIMIT_HIGH:
|
|
- // previous_state = limitHigh_State;
|
|
|
|
switch(_limitHigh_Mode) {
|
|
switch(_limitHigh_Mode) {
|
|
case 0:
|
|
case 0:
|
|
break;
|
|
break;
|
|
case 1: //digital INPUT
|
|
case 1: //digital INPUT
|
|
- limitHigh_State = digitalRead(_limitHigh_Pin);
|
|
|
|
- limitHigh_State = _limitHigh_Reversed ? !limitHigh_State : limitHigh_State;
|
|
|
|
|
|
+ limitHigh_State_raw = digitalRead(_limitHigh_Pin);
|
|
|
|
+ limitHigh_State_raw = _limitHigh_Reversed ? !limitHigh_State_raw : limitHigh_State_raw;
|
|
break;
|
|
break;
|
|
case 2:
|
|
case 2:
|
|
//Serial.println("analog");
|
|
//Serial.println("analog");
|
|
int analogTemp = analogRead(_limitHigh_Pin);
|
|
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;
|
|
|
|
- }
|
|
|
|
|
|
+ limitHigh_State_raw = (_limitHigh_Thresholds[0] < analogTemp) && (analogTemp < _limitHigh_Thresholds[1]);
|
|
|
|
+ limitHigh_State_raw = _limitHigh_Reversed ? !limitHigh_State_raw : limitHigh_State_raw;
|
|
|
|
+ // 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;
|
|
|
|
+ // }
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
|
|
+ limitHigh_State = limitHigh_avg(limitHigh_State_raw);
|
|
changed = limitHigh_State != limitHigh_State_prev ? 1 : 0;
|
|
changed = limitHigh_State != limitHigh_State_prev ? 1 : 0;
|
|
limitHigh_State_prev = limitHigh_State;
|
|
limitHigh_State_prev = limitHigh_State;
|
|
return changed;
|
|
return changed;
|
|
@@ -415,6 +414,34 @@ Atm_AccelStepper& Atm_AccelStepper::homing( bool direction ){
|
|
return *this;
|
|
return *this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+int Atm_AccelStepper::limitLow_avg(bool limistate){
|
|
|
|
+ limitLow_state_total = limitLow_state_total + limistate - limitLow_state_buf[limitLow_buf_head];
|
|
|
|
+ limitLow_state_buf[limitLow_buf_head] = limistate;
|
|
|
|
+ if ( limitLow_buf_head + 1 >= limit_buf_size ) {
|
|
|
|
+ limitLow_buf_head = 0;
|
|
|
|
+ } else {
|
|
|
|
+ limitLow_buf_head++;
|
|
|
|
+ }
|
|
|
|
+ for (int i =0; i<limit_buf_size; i++){
|
|
|
|
+ Serial.print(limitLow_state_buf[i]);
|
|
|
|
+ Serial.print(" ");
|
|
|
|
+ }
|
|
|
|
+ Serial.println();
|
|
|
|
+ return limitLow_state_total > limit_buf_size / 2; //all values should agree
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int Atm_AccelStepper::limitHigh_avg(bool limistate){
|
|
|
|
+ limitHigh_state_total = limitHigh_state_total + limistate - limitHigh_state_buf[limitHigh_buf_head];
|
|
|
|
+ limitHigh_state_buf[limitHigh_buf_head] = limistate;
|
|
|
|
+ if ( limitHigh_buf_head + 1 >= limit_buf_size ) {
|
|
|
|
+ limitHigh_buf_head = 0;
|
|
|
|
+ } else {
|
|
|
|
+ limitHigh_buf_head++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return limitHigh_state_total < limit_buf_size / 2; //all values should agree
|
|
|
|
+}
|
|
|
|
+
|
|
// Atm_AccelStepper& Atm_AccelStepper::rotationReversed(bool reversed){
|
|
// Atm_AccelStepper& Atm_AccelStepper::rotationReversed(bool reversed){
|
|
// _rotationReversed = reversed ? -1 : 1 ;
|
|
// _rotationReversed = reversed ? -1 : 1 ;
|
|
// }
|
|
// }
|