beta1

Dependents:   Ex_Stepper

Fork of a4998 by Keegan Hu

Revision:
2:57c57267b1da
Parent:
1:209911ee18cd
Child:
3:9e9f3cd7fff0
--- a/a4988.cpp	Sat May 05 14:11:09 2018 +0000
+++ b/a4988.cpp	Mon Jul 16 23:53:54 2018 +0000
@@ -9,14 +9,17 @@
  
 void Stepper::step(int dir, int frequency ,volatile int _remain)
 {
-    //fun = &Stepper::step_control;
     if (dir == 1) {
         direction = 0;
     } else if (dir == 0) {
         direction = 1;
     }
+    else 
+    {
+        return;
+    }
     remain = _remain;
-    step_ticker.attach(this, &Stepper::step_control,0.5/frequency);
+    step_ticker.attach(callback(this, &Stepper::step_control),0.5/frequency);
 }
  
 void Stepper::enable()
@@ -31,8 +34,9 @@
 
 void Stepper::step_control()
 {
-        if(remain == 0)
-        {         
+        if(remain <= 0)
+        {    
+            step_ticker.detach();     
             return;
         }
         
@@ -43,3 +47,31 @@
                         stepPin = 1; //STEP 0->1
                 }
 }
+
+void Stepper::longrun(int dir, int frequency)
+{
+    if (dir == 1) {
+        direction = 0;
+    } else if (dir == 0) {
+        direction = 1;
+    }
+    else 
+    {
+        return;
+    }
+    step_ticker.attach(callback(this, &Stepper::run_control),0.5/frequency);
+}
+
+void Stepper::run_control()
+{
+                if(stepPin){
+                        stepPin = 0; //STEP 1->0
+                        remain--;
+                }else{
+                        stepPin = 1; //STEP 0->1
+}
+}
+void Stepper::stoprun()
+{
+    step_ticker.detach();
+}
\ No newline at end of file