Skip to content

Commit 40e1d21

Browse files
author
Richard Unger
committed
change StepDirListener to use RISING interrupts
1 parent b3884a4 commit 40e1d21

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/communication/StepDirListener.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void StepDirListener::init(){
1313
}
1414

1515
void StepDirListener::enableInterrupt(void (*doA)()){
16-
attachInterrupt(digitalPinToInterrupt(pin_step), doA, CHANGE);
16+
attachInterrupt(digitalPinToInterrupt(pin_step), doA, polarity);
1717
}
1818

1919
void StepDirListener::attach(float* variable){
@@ -22,15 +22,15 @@ void StepDirListener::attach(float* variable){
2222

2323
void StepDirListener::handle(){
2424
// read step status
25-
bool step = digitalRead(pin_step);
25+
//bool step = digitalRead(pin_step);
2626
// update counter only on rising edge
27-
if(step && step != step_active){
28-
if(digitalRead(pin_dir))
27+
//if(step && step != step_active){
28+
if(digitalRead(pin_dir))
2929
count++;
30-
else
30+
else
3131
count--;
32-
}
33-
step_active = step;
32+
//}
33+
//step_active = step;
3434
// if attached variable update it
3535
if(attached_variable) *attached_variable = getValue();
3636
}

src/communication/StepDirListener.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,13 @@ class StepDirListener
4747
int pin_step; //!< step pin
4848
int pin_dir; //!< direction pin
4949
long count; //!< current counter value - should be set to 0 for homing
50+
PinStatus polarity = RISING; //!< polarity of the step pin
5051

5152
private:
5253
float* attached_variable = nullptr; //!< pointer to the attached variable
5354
float counter_to_value; //!< step counter to value
54-
bool step_active = 0; //!< current step pin status (HIGH/LOW) - debouncing variable
55+
//bool step_active = 0; //!< current step pin status (HIGH/LOW) - debouncing variable
56+
5557
};
5658

5759
#endif

0 commit comments

Comments
 (0)