quentin godbert
/
t2-stm32-lift
interrupt géré compil ok sans isr
Fork of T2_STM32 by
lift.h
- Committer:
- ketingue
- Date:
- 2018-02-05
- Revision:
- 7:62407850a97d
- Parent:
- 6:6291f032e996
- Child:
- 8:dcaa5c9d8706
File content as of revision 7:62407850a97d:
//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(PinName, PinName, PinName); Lift(); ~Lift(); void Starting(); void Stopping(); void GoUp(); void GoDown(); private: InterruptIn _interrupt; unsigned char *trye EventQueue queue(32); Thread t; bool InMotion; char sTargetPos, PreviousPos, CurrentPos; int StepPin, spinDown, sMiddleSensor, CurrentSensor, tempStepPin, tempDirPin; }; 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++){ Step.write(i); wait(10); } } void Lift::Stopping(){ int i; for(i=128; i>0; i--){ Step.write(i); wait(10); } } void Lift::GoUp(){ Dir2.write(0); Starting(); } void Lift::GoDown(){ Dir2.write(1); Starting(); }