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