quentin godbert
/
t2-stm32-lift
interrupt géré compil ok sans isr
Fork of T2_STM32 by
lift.h@6:6291f032e996, 2018-02-05 (annotated)
- Committer:
- ketingue
- Date:
- Mon Feb 05 15:05:23 2018 +0000
- Revision:
- 6:6291f032e996
- Parent:
- 5:d6484db1ec5c
- Child:
- 7:62407850a97d
test2;
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 | 6:6291f032e996 | 15 | DigitalOut led1(LED1); |
ketingue | 6:6291f032e996 | 16 | |
ketingue | 6:6291f032e996 | 17 | |
Tioneb | 5:d6484db1ec5c | 18 | |
Tioneb | 5:d6484db1ec5c | 19 | class Lift { |
Tioneb | 5:d6484db1ec5c | 20 | |
Tioneb | 5:d6484db1ec5c | 21 | public: |
ketingue | 6:6291f032e996 | 22 | Lift(PinName, PinName, PinName); |
ketingue | 6:6291f032e996 | 23 | Lift(); |
ketingue | 6:6291f032e996 | 24 | ~Lift(); |
ketingue | 6:6291f032e996 | 25 | |
Tioneb | 5:d6484db1ec5c | 26 | |
Tioneb | 5:d6484db1ec5c | 27 | void Starting(); |
Tioneb | 5:d6484db1ec5c | 28 | void Stopping(); |
Tioneb | 5:d6484db1ec5c | 29 | void GoUp(); |
Tioneb | 5:d6484db1ec5c | 30 | void GoDown(); |
Tioneb | 5:d6484db1ec5c | 31 | |
Tioneb | 5:d6484db1ec5c | 32 | private: |
ketingue | 6:6291f032e996 | 33 | InterruptIn _interrupt; |
ketingue | 6:6291f032e996 | 34 | unsigned char *trye |
ketingue | 6:6291f032e996 | 35 | EventQueue queue(32, trye); |
ketingue | 6:6291f032e996 | 36 | Thread t; |
ketingue | 6:6291f032e996 | 37 | |
ketingue | 6:6291f032e996 | 38 | |
Tioneb | 5:d6484db1ec5c | 39 | bool InMotion; |
Tioneb | 5:d6484db1ec5c | 40 | char sTargetPos, |
Tioneb | 5:d6484db1ec5c | 41 | PreviousPos, |
Tioneb | 5:d6484db1ec5c | 42 | CurrentPos; |
Tioneb | 5:d6484db1ec5c | 43 | int StepPin, |
Tioneb | 5:d6484db1ec5c | 44 | spinDown, |
Tioneb | 5:d6484db1ec5c | 45 | sMiddleSensor, |
Tioneb | 5:d6484db1ec5c | 46 | CurrentSensor, |
Tioneb | 5:d6484db1ec5c | 47 | tempStepPin, |
Tioneb | 5:d6484db1ec5c | 48 | tempDirPin; |
Tioneb | 5:d6484db1ec5c | 49 | }; |
Tioneb | 5:d6484db1ec5c | 50 | |
ketingue | 6:6291f032e996 | 51 | PwmOut Step(motionspin); |
ketingue | 6:6291f032e996 | 52 | AnalogIn Step2(motionsensor); |
ketingue | 6:6291f032e996 | 53 | DigitalOut Dir2(motiondir); |
ketingue | 6:6291f032e996 | 54 | |
ketingue | 6:6291f032e996 | 55 | Lift::Lift(PinName motionspin,PinName motiondir,PinName motionsensor): _interrupt(motionsensor){ |
ketingue | 6:6291f032e996 | 56 | //t.start(callback(&queue, &EventQueue::dispatch_forever)); |
ketingue | 6:6291f032e996 | 57 | printf("Starting in context %p\r\n", Thread::gettid()); |
ketingue | 6:6291f032e996 | 58 | // The 'rise' handler will execute in IRQ context |
ketingue | 6:6291f032e996 | 59 | _interrupt.rise(Step2, &Lift::Stopping); |
ketingue | 6:6291f032e996 | 60 | // The 'fall' handler will execute in the context of thread 't' |
ketingue | 6:6291f032e996 | 61 | //_interrupt.fall(queue.event(fall_handler)); |
Tioneb | 5:d6484db1ec5c | 62 | } |
Tioneb | 5:d6484db1ec5c | 63 | |
ketingue | 6:6291f032e996 | 64 | Lift::Lift(){ |
ketingue | 6:6291f032e996 | 65 | Lift(PinName(motionspin) ,PinName(motiondir),PinName(motionsensor)); |
ketingue | 6:6291f032e996 | 66 | } |
ketingue | 6:6291f032e996 | 67 | Lift::~Lift() |
ketingue | 6:6291f032e996 | 68 | { |
ketingue | 6:6291f032e996 | 69 | |
ketingue | 6:6291f032e996 | 70 | } |
Tioneb | 5:d6484db1ec5c | 71 | |
Tioneb | 5:d6484db1ec5c | 72 | void Lift::Starting(){ |
Tioneb | 5:d6484db1ec5c | 73 | int i; |
Tioneb | 5:d6484db1ec5c | 74 | for(i=0; i<128; i++){ |
ketingue | 6:6291f032e996 | 75 | Step.write(i); |
ketingue | 6:6291f032e996 | 76 | wait(10); |
Tioneb | 5:d6484db1ec5c | 77 | } |
Tioneb | 5:d6484db1ec5c | 78 | } |
Tioneb | 5:d6484db1ec5c | 79 | |
Tioneb | 5:d6484db1ec5c | 80 | void Lift::Stopping(){ |
Tioneb | 5:d6484db1ec5c | 81 | int i; |
Tioneb | 5:d6484db1ec5c | 82 | for(i=128; i>0; i--){ |
ketingue | 6:6291f032e996 | 83 | Step.write(i); |
ketingue | 6:6291f032e996 | 84 | wait(10); |
Tioneb | 5:d6484db1ec5c | 85 | } |
Tioneb | 5:d6484db1ec5c | 86 | } |
Tioneb | 5:d6484db1ec5c | 87 | |
Tioneb | 5:d6484db1ec5c | 88 | void Lift::GoUp(){ |
ketingue | 6:6291f032e996 | 89 | Dir2.write(0); |
Tioneb | 5:d6484db1ec5c | 90 | Starting(); |
ketingue | 6:6291f032e996 | 91 | |
Tioneb | 5:d6484db1ec5c | 92 | } |
Tioneb | 5:d6484db1ec5c | 93 | |
Tioneb | 5:d6484db1ec5c | 94 | void Lift::GoDown(){ |
ketingue | 6:6291f032e996 | 95 | Dir2.write(1); |
Tioneb | 5:d6484db1ec5c | 96 | Starting(); |
Tioneb | 5:d6484db1ec5c | 97 | } |
Tioneb | 5:d6484db1ec5c | 98 |