quentin godbert
/
t2-stm32-lift
interrupt géré compil ok sans isr
Fork of T2_STM32 by
lift.h@8:dcaa5c9d8706, 2018-02-06 (annotated)
- Committer:
- ketingue
- Date:
- Tue Feb 06 09:27:06 2018 +0000
- Revision:
- 8:dcaa5c9d8706
- Parent:
- 7:62407850a97d
- Child:
- 9:d3dcad0c7d57
iterrupt_compil_ok_lift
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Tioneb | 5:d6484db1ec5c | 1 | //Ne pas oublier la détection de surintensité |
ketingue | 6:6291f032e996 | 2 | #include <string> |
ketingue | 6:6291f032e996 | 3 | #include "mbed.h" |
ketingue | 6:6291f032e996 | 4 | #include "mbed_events.h" |
ketingue | 6:6291f032e996 | 5 | |
ketingue | 6:6291f032e996 | 6 | using namespace std; |
Tioneb | 5:d6484db1ec5c | 7 | |
Tioneb | 5:d6484db1ec5c | 8 | #define PeakCurrent 510 // Valeur à vérifier |
ketingue | 6:6291f032e996 | 9 | #define _EVENT_SIZE 512 |
ketingue | 6:6291f032e996 | 10 | |
ketingue | 6:6291f032e996 | 11 | PinName motionspin , |
ketingue | 6:6291f032e996 | 12 | motiondir , |
ketingue | 6:6291f032e996 | 13 | motionsensor ; |
ketingue | 6:6291f032e996 | 14 | |
ketingue | 8:dcaa5c9d8706 | 15 | DigitalOut RED(D6); |
ketingue | 8:dcaa5c9d8706 | 16 | DigitalOut GRN(D5); |
ketingue | 8:dcaa5c9d8706 | 17 | DigitalOut AMB(D4); |
ketingue | 8:dcaa5c9d8706 | 18 | DigitalOut myled(LED1); |
ketingue | 6:6291f032e996 | 19 | |
ketingue | 8:dcaa5c9d8706 | 20 | Ticker timer; |
ketingue | 8:dcaa5c9d8706 | 21 | |
ketingue | 8:dcaa5c9d8706 | 22 | PwmOut Step(motionspin); |
ketingue | 8:dcaa5c9d8706 | 23 | AnalogIn Step2(motionsensor); |
ketingue | 8:dcaa5c9d8706 | 24 | DigitalOut Dir2(motiondir); |
ketingue | 6:6291f032e996 | 25 | |
Tioneb | 5:d6484db1ec5c | 26 | |
Tioneb | 5:d6484db1ec5c | 27 | class Lift { |
Tioneb | 5:d6484db1ec5c | 28 | |
Tioneb | 5:d6484db1ec5c | 29 | public: |
ketingue | 8:dcaa5c9d8706 | 30 | Lift(PinName); |
ketingue | 6:6291f032e996 | 31 | Lift(); |
ketingue | 6:6291f032e996 | 32 | ~Lift(); |
ketingue | 6:6291f032e996 | 33 | |
Tioneb | 5:d6484db1ec5c | 34 | |
Tioneb | 5:d6484db1ec5c | 35 | void Starting(); |
Tioneb | 5:d6484db1ec5c | 36 | void Stopping(); |
Tioneb | 5:d6484db1ec5c | 37 | void GoUp(); |
Tioneb | 5:d6484db1ec5c | 38 | void GoDown(); |
Tioneb | 5:d6484db1ec5c | 39 | |
Tioneb | 5:d6484db1ec5c | 40 | private: |
ketingue | 8:dcaa5c9d8706 | 41 | |
ketingue | 8:dcaa5c9d8706 | 42 | unsigned char *trye; |
ketingue | 8:dcaa5c9d8706 | 43 | // EventQueue queue(32); |
ketingue | 6:6291f032e996 | 44 | Thread t; |
ketingue | 8:dcaa5c9d8706 | 45 | InterruptIn _interrupt; |
ketingue | 6:6291f032e996 | 46 | |
Tioneb | 5:d6484db1ec5c | 47 | bool InMotion; |
Tioneb | 5:d6484db1ec5c | 48 | char sTargetPos, |
Tioneb | 5:d6484db1ec5c | 49 | PreviousPos, |
Tioneb | 5:d6484db1ec5c | 50 | CurrentPos; |
Tioneb | 5:d6484db1ec5c | 51 | int StepPin, |
Tioneb | 5:d6484db1ec5c | 52 | spinDown, |
Tioneb | 5:d6484db1ec5c | 53 | sMiddleSensor, |
Tioneb | 5:d6484db1ec5c | 54 | CurrentSensor, |
Tioneb | 5:d6484db1ec5c | 55 | tempStepPin, |
Tioneb | 5:d6484db1ec5c | 56 | tempDirPin; |
Tioneb | 5:d6484db1ec5c | 57 | }; |
Tioneb | 5:d6484db1ec5c | 58 | |
Tioneb | 5:d6484db1ec5c | 59 | |
Tioneb | 5:d6484db1ec5c | 60 | |
Tioneb | 5:d6484db1ec5c | 61 | void Lift::Starting(){ |
Tioneb | 5:d6484db1ec5c | 62 | int i; |
Tioneb | 5:d6484db1ec5c | 63 | for(i=0; i<128; i++){ |
ketingue | 6:6291f032e996 | 64 | Step.write(i); |
ketingue | 6:6291f032e996 | 65 | wait(10); |
Tioneb | 5:d6484db1ec5c | 66 | } |
Tioneb | 5:d6484db1ec5c | 67 | } |
Tioneb | 5:d6484db1ec5c | 68 | |
Tioneb | 5:d6484db1ec5c | 69 | void Lift::Stopping(){ |
Tioneb | 5:d6484db1ec5c | 70 | int i; |
Tioneb | 5:d6484db1ec5c | 71 | for(i=128; i>0; i--){ |
ketingue | 6:6291f032e996 | 72 | Step.write(i); |
ketingue | 6:6291f032e996 | 73 | wait(10); |
Tioneb | 5:d6484db1ec5c | 74 | } |
Tioneb | 5:d6484db1ec5c | 75 | } |
Tioneb | 5:d6484db1ec5c | 76 | |
Tioneb | 5:d6484db1ec5c | 77 | void Lift::GoUp(){ |
ketingue | 6:6291f032e996 | 78 | Dir2.write(0); |
Tioneb | 5:d6484db1ec5c | 79 | Starting(); |
ketingue | 6:6291f032e996 | 80 | |
Tioneb | 5:d6484db1ec5c | 81 | } |
Tioneb | 5:d6484db1ec5c | 82 | |
Tioneb | 5:d6484db1ec5c | 83 | void Lift::GoDown(){ |
ketingue | 6:6291f032e996 | 84 | Dir2.write(1); |
Tioneb | 5:d6484db1ec5c | 85 | Starting(); |
Tioneb | 5:d6484db1ec5c | 86 | } |
Tioneb | 5:d6484db1ec5c | 87 | |
ketingue | 8:dcaa5c9d8706 | 88 | |
ketingue | 8:dcaa5c9d8706 | 89 | |
ketingue | 8:dcaa5c9d8706 | 90 | Lift::Lift(PinName motionsensor): _interrupt(motionsensor){ |
ketingue | 8:dcaa5c9d8706 | 91 | //t.start(callback(&queue, &EventQueue::dispatch_forever)); |
ketingue | 8:dcaa5c9d8706 | 92 | printf("Starting in context %p\r\n", Thread::gettid()); |
ketingue | 8:dcaa5c9d8706 | 93 | _interrupt.mode(PullUp); |
ketingue | 8:dcaa5c9d8706 | 94 | // The 'rise' handler will execute in IRQ context |
ketingue | 8:dcaa5c9d8706 | 95 | _interrupt.rise(callback(this, &Lift::Stopping)); |
ketingue | 8:dcaa5c9d8706 | 96 | // The 'fall' handler will execute in the context of thread 't' |
ketingue | 8:dcaa5c9d8706 | 97 | //_interrupt.fall(queue.event(fall_handler)); |
ketingue | 8:dcaa5c9d8706 | 98 | while(1){ |
ketingue | 8:dcaa5c9d8706 | 99 | sleep(); //Sleep to save power, Interrupted by Ticker and Pulse events |
ketingue | 8:dcaa5c9d8706 | 100 | } |
ketingue | 8:dcaa5c9d8706 | 101 | } |