interrupt géré compil ok sans isr

Fork of T2_STM32 by Atechsys

Revision:
6:6291f032e996
Parent:
5:d6484db1ec5c
Child:
7:62407850a97d
--- a/lift.h	Mon Feb 05 08:10:13 2018 +0000
+++ b/lift.h	Mon Feb 05 15:05:23 2018 +0000
@@ -1,12 +1,28 @@
 //Ne pas oublier la détection de surintensité
+#include <string>
+#include "mbed.h"
+#include "mbed_events.h"
+
+using namespace std;
 
 #define PeakCurrent     510   //   Valeur à vérifier
+#define _EVENT_SIZE 512
+
+  PinName motionspin  ,
+         motiondir    ,
+         motionsensor ;
+
+DigitalOut led1(LED1);
+
+
 
 class Lift {
 
   public:
-  Lift(int, int, int);
-  ~Lift(void);
+  Lift(PinName, PinName, PinName);
+  Lift();
+  ~Lift();
+  
 
   void Starting();
   void Stopping();
@@ -14,6 +30,12 @@
   void GoDown();
   
   private:
+ InterruptIn _interrupt;
+ unsigned char *trye
+ EventQueue queue(32, trye);
+Thread t;
+
+  
   bool InMotion;
   char sTargetPos, 
        PreviousPos, 
@@ -26,38 +48,51 @@
        tempDirPin;    
 };
 
-
-Lift::Lift( LIFTSTEPPIN, LIFT_DIRPIN, LIFT_CURRENTSENSOR){ 
-  DigitalOut Step(LIFTSTEPPIN);
-  DigitalOut Dir(LIFTDIRPIN);
+  PwmOut Step(motionspin);
+  AnalogIn Step2(motionsensor);
+  DigitalOut Dir2(motiondir);
+  
+Lift::Lift(PinName motionspin,PinName motiondir,PinName motionsensor): _interrupt(motionsensor){ 
+    //t.start(callback(&queue, &EventQueue::dispatch_forever));
+    printf("Starting in context %p\r\n", Thread::gettid());
+    // The 'rise' handler will execute in IRQ context
+    _interrupt.rise(Step2, &Lift::Stopping);
+    // The 'fall' handler will execute in the context of thread 't'
+    //_interrupt.fall(queue.event(fall_handler));
 }
 
+Lift::Lift(){
+    Lift(PinName(motionspin) ,PinName(motiondir),PinName(motionsensor));
+}
+Lift::~Lift()
+{
+    
+}
 
 void Lift::Starting(){
   int i;
   for(i=0; i<128; i++){
-    SendPWM_Carre(i, StepPin);
-    delay(10);
+    Step.write(i);
+    wait(10);
   }
 }
 
 void Lift::Stopping(){
   int i;
   for(i=128; i>0; i--){
-    SendPWM_Carre(i, StepPin);
-    delay(10);
+    Step.write(i);
+    wait(10);
   }
 }
 
 void Lift::GoUp(){
-  DirPin = 0;
+  Dir2.write(0);
   Starting();
-  Started();
+  
 }
 
 void Lift::GoDown(){
-  DirPin = 1;
+  Dir2.write(1);
   Starting();
 }
 
-#endif
\ No newline at end of file