![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
LEDDriver.cpp@39:0ab266251e86, 2018-05-02 (annotated)
- Committer:
- albireo987
- Date:
- Wed May 02 14:25:23 2018 +0000
- Revision:
- 39:0ab266251e86
- Parent:
- 38:47c075a354b5
- Child:
- 40:179591b10b44
event decommented;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 38:47c075a354b5 | 1 | #include "LEDDriver.h" |
albireo987 | 38:47c075a354b5 | 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 | 32:537005b4a065 | 15 | poll(numberOfLeds,1) ; |
albireo987 | 38:47c075a354b5 | 16 | poll(numberOfLeds,2) ; |
albireo987 | 38:47c075a354b5 | 17 | Ticker ticker; |
albireo987 | 32:537005b4a065 | 18 | while(true) |
albireo987 | 39:0ab266251e86 | 19 | { |
albireo987 | 26:29948b116e82 | 20 | poll(numberOfLeds,1) ;//prep multi |
albireo987 | 39:0ab266251e86 | 21 | ticker.attach(this,&LEDDriver::sendData,0.0002625f); |
albireo987 | 38:47c075a354b5 | 22 | poll(numberOfLeds,2) ; |
albireo987 | 9:c800045806f0 | 23 | } |
albireo987 | 2:36158325f7b0 | 24 | } |
albireo987 | 2:36158325f7b0 | 25 | |
albireo987 | 2:36158325f7b0 | 26 | void LEDDriver::run(int numberOfLeds) |
albireo987 | 2:36158325f7b0 | 27 | { |
albireo987 | 2:36158325f7b0 | 28 | drive(numberOfLeds); |
albireo987 | 2:36158325f7b0 | 29 | } |
albireo987 | 2:36158325f7b0 | 30 | |
albireo987 | 10:7871aeacea08 | 31 | void LEDDriver::ownWait(uint32_t us) |
albireo987 | 10:7871aeacea08 | 32 | { |
albireo987 | 10:7871aeacea08 | 33 | for(uint32_t i=0;i<us;i++) |
albireo987 | 10:7871aeacea08 | 34 | { |
albireo987 | 38:47c075a354b5 | 35 | for(volatile uint32_t j =0; j <3;j++) |
albireo987 | 10:7871aeacea08 | 36 | { |
albireo987 | 10:7871aeacea08 | 37 | |
albireo987 | 10:7871aeacea08 | 38 | } |
albireo987 | 10:7871aeacea08 | 39 | } |
albireo987 | 25:4c673da1a3ae | 40 | } |
albireo987 | 25:4c673da1a3ae | 41 | |
albireo987 | 26:29948b116e82 | 42 | void LEDDriver::poll(int numberOfLeds,int first) |
albireo987 | 25:4c673da1a3ae | 43 | { |
albireo987 | 26:29948b116e82 | 44 | if(first==1) |
albireo987 | 26:29948b116e82 | 45 | { |
albireo987 | 26:29948b116e82 | 46 | for(int i =0;i<(numberOfLeds/2);i++) |
albireo987 | 26:29948b116e82 | 47 | { |
albireo987 | 39:0ab266251e86 | 48 | osEvent event = queue->get(); |
albireo987 | 39:0ab266251e86 | 49 | int temp = *((int*)event.value.p); |
albireo987 | 39:0ab266251e86 | 50 | if(temp==1||temp==1||temp==2||temp==3) |
albireo987 | 26:29948b116e82 | 51 | { |
albireo987 | 39:0ab266251e86 | 52 | messageList[i]=temp; |
albireo987 | 38:47c075a354b5 | 53 | } |
albireo987 | 26:29948b116e82 | 54 | } |
albireo987 | 26:29948b116e82 | 55 | } |
albireo987 | 26:29948b116e82 | 56 | else if(first==2) |
albireo987 | 38:47c075a354b5 | 57 | { |
albireo987 | 26:29948b116e82 | 58 | for(int i =(numberOfLeds/2);i<(numberOfLeds);i++) |
albireo987 | 26:29948b116e82 | 59 | { |
albireo987 | 39:0ab266251e86 | 60 | osEvent event = queue->get(); |
albireo987 | 39:0ab266251e86 | 61 | int temp = *((int*)event.value.p); |
albireo987 | 39:0ab266251e86 | 62 | if(temp==1||temp==1||temp==2||temp==3) |
albireo987 | 26:29948b116e82 | 63 | { |
albireo987 | 39:0ab266251e86 | 64 | messageList[i]=temp; |
albireo987 | 38:47c075a354b5 | 65 | } |
albireo987 | 26:29948b116e82 | 66 | } |
albireo987 | 32:537005b4a065 | 67 | } |
albireo987 | 38:47c075a354b5 | 68 | } |
albireo987 | 38:47c075a354b5 | 69 | |
albireo987 | 38:47c075a354b5 | 70 | void LEDDriver::sendData() |
albireo987 | 38:47c075a354b5 | 71 | { |
albireo987 | 38:47c075a354b5 | 72 | // 1 1 1 1 0 0 0 0 0 1 |
albireo987 | 39:0ab266251e86 | 73 | static int codedMessage0[]={1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1};//{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 | 38:47c075a354b5 | 74 | // 1 1 1 1 0 1 0 0 0 1 |
albireo987 | 39:0ab266251e86 | 75 | static int codedMessage1[]={1,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0,1}; |
albireo987 | 38:47c075a354b5 | 76 | // 1 1 1 1 1 0 1 0 0 1 |
albireo987 | 39:0ab266251e86 | 77 | static int codedMessage2[]={1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1}; |
albireo987 | 38:47c075a354b5 | 78 | // 1 1 1 1 1 1 0 0 0 1 |
albireo987 | 39:0ab266251e86 | 79 | static int codedMessage3[]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1}; |
albireo987 | 38:47c075a354b5 | 80 | 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 | 38:47c075a354b5 | 81 | for(int led =0 ; led<8;led++) |
albireo987 | 38:47c075a354b5 | 82 | { |
albireo987 | 39:0ab266251e86 | 83 | for(int j =0;j<21;j++) |
albireo987 | 38:47c075a354b5 | 84 | { |
albireo987 | 38:47c075a354b5 | 85 | if(messageList[led]==0) |
albireo987 | 38:47c075a354b5 | 86 | { |
albireo987 | 38:47c075a354b5 | 87 | leds[led].write(codedMessage0[j]); |
albireo987 | 39:0ab266251e86 | 88 | ownWait(250);//100HZ |
albireo987 | 38:47c075a354b5 | 89 | } |
albireo987 | 38:47c075a354b5 | 90 | else if(messageList[led]==1) |
albireo987 | 38:47c075a354b5 | 91 | { |
albireo987 | 38:47c075a354b5 | 92 | leds[led].write(codedMessage1[j]); |
albireo987 | 39:0ab266251e86 | 93 | ownWait(70); |
albireo987 | 38:47c075a354b5 | 94 | } |
albireo987 | 38:47c075a354b5 | 95 | else if(messageList[led]==2) |
albireo987 | 38:47c075a354b5 | 96 | { |
albireo987 | 38:47c075a354b5 | 97 | leds[led].write(codedMessage2[j]); |
albireo987 | 39:0ab266251e86 | 98 | ownWait(70); |
albireo987 | 38:47c075a354b5 | 99 | } |
albireo987 | 38:47c075a354b5 | 100 | else if(messageList[led]==3) |
albireo987 | 38:47c075a354b5 | 101 | { |
albireo987 | 38:47c075a354b5 | 102 | leds[led].write(codedMessage3[j]); |
albireo987 | 39:0ab266251e86 | 103 | ownWait(70); |
albireo987 | 38:47c075a354b5 | 104 | } |
albireo987 | 38:47c075a354b5 | 105 | else if(messageList[led]==4) |
albireo987 | 38:47c075a354b5 | 106 | { |
albireo987 | 38:47c075a354b5 | 107 | leds[led].write(codedMessage4[j]); |
albireo987 | 39:0ab266251e86 | 108 | ownWait(70); |
albireo987 | 38:47c075a354b5 | 109 | } |
albireo987 | 38:47c075a354b5 | 110 | } |
albireo987 | 38:47c075a354b5 | 111 | } |
albireo987 | 2:36158325f7b0 | 112 | } |