![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
LEDDriver.cpp@25:4c673da1a3ae, 2018-04-25 (annotated)
- Committer:
- albireo987
- Date:
- Wed Apr 25 13:17:55 2018 +0000
- Revision:
- 25:4c673da1a3ae
- Parent:
- 10:7871aeacea08
- Child:
- 26:29948b116e82
driver commit queue
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 2:36158325f7b0 | 1 | #include "LEDDriver.h" |
albireo987 | 25:4c673da1a3ae | 2 | Serial pc(USBTX,USBRX); |
albireo987 | 25:4c673da1a3ae | 3 | LEDDriver::LEDDriver( Queue<int,8>* queue) |
albireo987 | 2:36158325f7b0 | 4 | { |
albireo987 | 25:4c673da1a3ae | 5 | static int messageList[8]={4,4,4,4,4,4,4,4}; |
albireo987 | 10:7871aeacea08 | 6 | static DigitalOut leds[]={DigitalOut(p23),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)}; |
albireo987 | 2:36158325f7b0 | 7 | this->messageList=messageList; |
albireo987 | 2:36158325f7b0 | 8 | this->leds=leds; |
albireo987 | 25:4c673da1a3ae | 9 | this->queue=queue;// prep for multithreaded |
albireo987 | 25:4c673da1a3ae | 10 | |
albireo987 | 2:36158325f7b0 | 11 | } |
albireo987 | 2:36158325f7b0 | 12 | |
albireo987 | 2:36158325f7b0 | 13 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 2:36158325f7b0 | 14 | { |
albireo987 | 25:4c673da1a3ae | 15 | // 1 1 1 1 0 0 0 0 0 1 |
albireo987 | 10:7871aeacea08 | 16 | static int codedMessage0[]={1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0};//{1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0}; currently frequency measure message(standard square wave) |
albireo987 | 9:c800045806f0 | 17 | // 1 1 1 1 0 1 0 0 0 1 |
albireo987 | 9:c800045806f0 | 18 | static int codedMessage1[]={1,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0}; |
albireo987 | 9:c800045806f0 | 19 | // 1 1 1 1 1 0 1 0 0 1 |
albireo987 | 9:c800045806f0 | 20 | static int codedMessage2[]={1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0}; |
albireo987 | 9:c800045806f0 | 21 | // 1 1 1 1 1 1 0 0 0 1 |
albireo987 | 9:c800045806f0 | 22 | static int codedMessage3[]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0}; |
albireo987 | 25:4c673da1a3ae | 23 | static int codedMessage4[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};//default message for multithreading |
albireo987 | 10:7871aeacea08 | 24 | while(true) |
albireo987 | 25:4c673da1a3ae | 25 | { |
albireo987 | 25:4c673da1a3ae | 26 | poll(numberOfLeds) ;//prep multi |
albireo987 | 9:c800045806f0 | 27 | for(int j=0;j<20;j++) |
albireo987 | 9:c800045806f0 | 28 | { |
albireo987 | 9:c800045806f0 | 29 | for(int i =0;i<numberOfLeds;i++) |
albireo987 | 9:c800045806f0 | 30 | { |
albireo987 | 9:c800045806f0 | 31 | if(messageList[i]==0) |
albireo987 | 9:c800045806f0 | 32 | { |
albireo987 | 9:c800045806f0 | 33 | leds[i].write(codedMessage0[j]); |
albireo987 | 25:4c673da1a3ae | 34 | ownWait(1);//7.511kHZ |
albireo987 | 10:7871aeacea08 | 35 | } |
albireo987 | 9:c800045806f0 | 36 | else if(messageList[i]==1) |
albireo987 | 9:c800045806f0 | 37 | { |
albireo987 | 9:c800045806f0 | 38 | leds[i].write(codedMessage1[j]); |
albireo987 | 25:4c673da1a3ae | 39 | ownWait(1); |
albireo987 | 9:c800045806f0 | 40 | } |
albireo987 | 9:c800045806f0 | 41 | else if(messageList[i]==2) |
albireo987 | 9:c800045806f0 | 42 | { |
albireo987 | 9:c800045806f0 | 43 | leds[i].write(codedMessage2[j]); |
albireo987 | 25:4c673da1a3ae | 44 | ownWait(1); |
albireo987 | 9:c800045806f0 | 45 | } |
albireo987 | 9:c800045806f0 | 46 | else if(messageList[i]==3) |
albireo987 | 9:c800045806f0 | 47 | { |
albireo987 | 9:c800045806f0 | 48 | leds[i].write(codedMessage3[j]); |
albireo987 | 25:4c673da1a3ae | 49 | ownWait(1); |
albireo987 | 25:4c673da1a3ae | 50 | } |
albireo987 | 25:4c673da1a3ae | 51 | else if(messageList[i]==4) |
albireo987 | 25:4c673da1a3ae | 52 | { |
albireo987 | 25:4c673da1a3ae | 53 | leds[i].write(codedMessage4[j]); |
albireo987 | 25:4c673da1a3ae | 54 | ownWait(1); |
albireo987 | 9:c800045806f0 | 55 | } |
albireo987 | 9:c800045806f0 | 56 | } |
albireo987 | 9:c800045806f0 | 57 | } |
albireo987 | 9:c800045806f0 | 58 | } |
albireo987 | 2:36158325f7b0 | 59 | } |
albireo987 | 2:36158325f7b0 | 60 | |
albireo987 | 2:36158325f7b0 | 61 | void LEDDriver::run(int numberOfLeds) |
albireo987 | 2:36158325f7b0 | 62 | { |
albireo987 | 2:36158325f7b0 | 63 | drive(numberOfLeds); |
albireo987 | 2:36158325f7b0 | 64 | } |
albireo987 | 2:36158325f7b0 | 65 | |
albireo987 | 10:7871aeacea08 | 66 | void LEDDriver::ownWait(uint32_t us) |
albireo987 | 10:7871aeacea08 | 67 | { |
albireo987 | 10:7871aeacea08 | 68 | for(uint32_t i=0;i<us;i++) |
albireo987 | 10:7871aeacea08 | 69 | { |
albireo987 | 10:7871aeacea08 | 70 | for(volatile uint32_t j =0; j <96;j++) |
albireo987 | 10:7871aeacea08 | 71 | { |
albireo987 | 10:7871aeacea08 | 72 | |
albireo987 | 10:7871aeacea08 | 73 | } |
albireo987 | 10:7871aeacea08 | 74 | } |
albireo987 | 25:4c673da1a3ae | 75 | } |
albireo987 | 25:4c673da1a3ae | 76 | |
albireo987 | 25:4c673da1a3ae | 77 | void LEDDriver::poll(int numberOfLeds) |
albireo987 | 25:4c673da1a3ae | 78 | { |
albireo987 | 25:4c673da1a3ae | 79 | for(int i =0;i<numberOfLeds;i++) |
albireo987 | 25:4c673da1a3ae | 80 | { |
albireo987 | 25:4c673da1a3ae | 81 | osEvent event = queue->get(); |
albireo987 | 25:4c673da1a3ae | 82 | int temp = *((int*)event.value.p); |
albireo987 | 25:4c673da1a3ae | 83 | if(temp==1||temp==1||temp==2||temp==3) |
albireo987 | 25:4c673da1a3ae | 84 | { |
albireo987 | 25:4c673da1a3ae | 85 | messageList[i]=temp; |
albireo987 | 25:4c673da1a3ae | 86 | } |
albireo987 | 25:4c673da1a3ae | 87 | } |
albireo987 | 2:36158325f7b0 | 88 | } |