![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp@45:2d877f01ca7b, 2018-05-09 (annotated)
- Committer:
- KlaasGovaerts
- Date:
- Wed May 09 07:24:39 2018 +0000
- Revision:
- 45:2d877f01ca7b
- Parent:
- 44:ffac07bff0d8
- Child:
- 47:8fe84f455571
Verschillende dingen geprobeerd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 38:47c075a354b5 | 1 | #include "LEDDriver.h" |
KlaasGovaerts | 45:2d877f01ca7b | 2 | //Serial pc(USBTX,USBRX); |
albireo987 | 26:4c673da1a3ae | 3 | LEDDriver::LEDDriver( Queue<int,8>* queue) |
albireo987 | 6:36158325f7b0 | 4 | { |
KlaasGovaerts | 45:2d877f01ca7b | 5 | //this->messageList=messageList; |
KlaasGovaerts | 45:2d877f01ca7b | 6 | //this->leds=leds; |
albireo987 | 26:4c673da1a3ae | 7 | this->queue=queue;// prep for multithreaded |
KlaasGovaerts | 45:2d877f01ca7b | 8 | initArrays(); |
KlaasGovaerts | 45:2d877f01ca7b | 9 | currentLocation=0; |
albireo987 | 6:36158325f7b0 | 10 | } |
albireo987 | 6:36158325f7b0 | 11 | |
albireo987 | 6:36158325f7b0 | 12 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 6:36158325f7b0 | 13 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 14 | poll(numberOfLeds,1); |
KlaasGovaerts | 44:ffac07bff0d8 | 15 | poll(numberOfLeds,2); |
KlaasGovaerts | 45:2d877f01ca7b | 16 | setLEDS(currentLocation); |
KlaasGovaerts | 45:2d877f01ca7b | 17 | currentLocation++; |
KlaasGovaerts | 45:2d877f01ca7b | 18 | if(currentLocation>=20){ |
KlaasGovaerts | 45:2d877f01ca7b | 19 | currentLocation=0; |
KlaasGovaerts | 45:2d877f01ca7b | 20 | } |
KlaasGovaerts | 44:ffac07bff0d8 | 21 | |
KlaasGovaerts | 44:ffac07bff0d8 | 22 | /* |
albireo987 | 38:47c075a354b5 | 23 | Ticker ticker; |
albireo987 | 32:537005b4a065 | 24 | while(true) |
albireo987 | 26:4c673da1a3ae | 25 | { |
albireo987 | 27:29948b116e82 | 26 | poll(numberOfLeds,1) ;//prep multi |
KlaasGovaerts | 42:bb1d9d8a9fe4 | 27 | //for(int i =0;i<numberOfLeds;i++) |
KlaasGovaerts | 42:bb1d9d8a9fe4 | 28 | //{ |
KlaasGovaerts | 44:ffac07bff0d8 | 29 | //ticker.attach(this,&LEDDriver::sendData,0.000625f); |
KlaasGovaerts | 42:bb1d9d8a9fe4 | 30 | //} |
albireo987 | 38:47c075a354b5 | 31 | poll(numberOfLeds,2) ; |
KlaasGovaerts | 44:ffac07bff0d8 | 32 | }*/ |
albireo987 | 6:36158325f7b0 | 33 | } |
albireo987 | 6:36158325f7b0 | 34 | |
KlaasGovaerts | 44:ffac07bff0d8 | 35 | void LEDDriver::run(Ticker* ticker) |
albireo987 | 6:36158325f7b0 | 36 | { |
KlaasGovaerts | 45:2d877f01ca7b | 37 | ticker->attach(this,&LEDDriver::drive8leds,1);//TODO faster |
KlaasGovaerts | 44:ffac07bff0d8 | 38 | } |
KlaasGovaerts | 44:ffac07bff0d8 | 39 | |
KlaasGovaerts | 44:ffac07bff0d8 | 40 | void LEDDriver::drive8leds(){ |
KlaasGovaerts | 44:ffac07bff0d8 | 41 | drive(8); |
albireo987 | 6:36158325f7b0 | 42 | } |
albireo987 | 6:36158325f7b0 | 43 | |
albireo987 | 10:7871aeacea08 | 44 | void LEDDriver::ownWait(uint32_t us) |
albireo987 | 10:7871aeacea08 | 45 | { |
albireo987 | 10:7871aeacea08 | 46 | for(uint32_t i=0;i<us;i++) |
albireo987 | 10:7871aeacea08 | 47 | { |
albireo987 | 38:47c075a354b5 | 48 | for(volatile uint32_t j =0; j <3;j++) |
albireo987 | 10:7871aeacea08 | 49 | { |
albireo987 | 10:7871aeacea08 | 50 | |
albireo987 | 10:7871aeacea08 | 51 | } |
albireo987 | 10:7871aeacea08 | 52 | } |
albireo987 | 26:4c673da1a3ae | 53 | } |
albireo987 | 26:4c673da1a3ae | 54 | |
albireo987 | 27:29948b116e82 | 55 | void LEDDriver::poll(int numberOfLeds,int first) |
albireo987 | 26:4c673da1a3ae | 56 | { |
albireo987 | 27:29948b116e82 | 57 | if(first==1) |
albireo987 | 27:29948b116e82 | 58 | { |
albireo987 | 27:29948b116e82 | 59 | for(int i =0;i<(numberOfLeds/2);i++) |
albireo987 | 27:29948b116e82 | 60 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 61 | osEvent event = queue->get(); |
KlaasGovaerts | 44:ffac07bff0d8 | 62 | int temp = *((int*)event.value.p); |
KlaasGovaerts | 45:2d877f01ca7b | 63 | if(temp==0||temp==1||temp==2||temp==3) |
albireo987 | 27:29948b116e82 | 64 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 65 | messageList[i]=temp; |
albireo987 | 38:47c075a354b5 | 66 | } |
albireo987 | 27:29948b116e82 | 67 | } |
albireo987 | 27:29948b116e82 | 68 | } |
albireo987 | 27:29948b116e82 | 69 | else if(first==2) |
albireo987 | 38:47c075a354b5 | 70 | { |
albireo987 | 27:29948b116e82 | 71 | for(int i =(numberOfLeds/2);i<(numberOfLeds);i++) |
albireo987 | 27:29948b116e82 | 72 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 73 | osEvent event = queue->get(); |
KlaasGovaerts | 44:ffac07bff0d8 | 74 | int temp = *((int*)event.value.p); |
KlaasGovaerts | 45:2d877f01ca7b | 75 | if(temp==0||temp==1||temp==2||temp==3) |
albireo987 | 27:29948b116e82 | 76 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 77 | messageList[i]=temp; |
albireo987 | 38:47c075a354b5 | 78 | } |
albireo987 | 27:29948b116e82 | 79 | } |
albireo987 | 32:537005b4a065 | 80 | } |
albireo987 | 38:47c075a354b5 | 81 | } |
albireo987 | 38:47c075a354b5 | 82 | |
KlaasGovaerts | 45:2d877f01ca7b | 83 | void LEDDriver::initArrays() |
albireo987 | 38:47c075a354b5 | 84 | { |
KlaasGovaerts | 45:2d877f01ca7b | 85 | // 1 1 1 1 0 0 0 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 86 | int tempCodedMessage0[20]={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 | 87 | // 1 1 1 1 0 1 0 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 88 | int tempCodedMessage1[20]={1,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0}; |
albireo987 | 38:47c075a354b5 | 89 | // 1 1 1 1 1 0 1 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 90 | int tempCodedMessage2[20]={1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0}; |
albireo987 | 38:47c075a354b5 | 91 | // 1 1 1 1 1 1 0 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 92 | int tempCodedMessage3[20]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0}; |
KlaasGovaerts | 45:2d877f01ca7b | 93 | int tempCodedMessage4[20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};//default message for multithreading |
KlaasGovaerts | 45:2d877f01ca7b | 94 | int tempMessageList[8]={4,4,4,4,4,4,4,4}; |
KlaasGovaerts | 45:2d877f01ca7b | 95 | DigitalOut tempLeds[]={DigitalOut(p23),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)}; |
KlaasGovaerts | 45:2d877f01ca7b | 96 | |
KlaasGovaerts | 45:2d877f01ca7b | 97 | memcpy(codedMessage0,tempCodedMessage0,sizeof(codedMessage0)); |
KlaasGovaerts | 45:2d877f01ca7b | 98 | memcpy(codedMessage1,tempCodedMessage1,sizeof(codedMessage1)); |
KlaasGovaerts | 45:2d877f01ca7b | 99 | memcpy(codedMessage2,tempCodedMessage2,sizeof(codedMessage2)); |
KlaasGovaerts | 45:2d877f01ca7b | 100 | memcpy(codedMessage3,tempCodedMessage3,sizeof(codedMessage3)); |
KlaasGovaerts | 45:2d877f01ca7b | 101 | memcpy(codedMessage4,tempCodedMessage4,sizeof(codedMessage4)); |
KlaasGovaerts | 45:2d877f01ca7b | 102 | |
KlaasGovaerts | 45:2d877f01ca7b | 103 | memcpy(tempMessageList,messageList,sizeof(messageList)); |
KlaasGovaerts | 45:2d877f01ca7b | 104 | memcpy(leds,tempLeds,sizeof(leds)); |
KlaasGovaerts | 45:2d877f01ca7b | 105 | } |
KlaasGovaerts | 45:2d877f01ca7b | 106 | |
KlaasGovaerts | 45:2d877f01ca7b | 107 | void LEDDriver::setLEDS(int j){ |
albireo987 | 38:47c075a354b5 | 108 | for(int led =0 ; led<8;led++) |
albireo987 | 38:47c075a354b5 | 109 | { |
albireo987 | 38:47c075a354b5 | 110 | if(messageList[led]==0) |
albireo987 | 38:47c075a354b5 | 111 | { |
albireo987 | 38:47c075a354b5 | 112 | leds[led].write(codedMessage0[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 113 | //ownWait(25);//100HZ |
albireo987 | 38:47c075a354b5 | 114 | } |
albireo987 | 38:47c075a354b5 | 115 | else if(messageList[led]==1) |
albireo987 | 38:47c075a354b5 | 116 | { |
albireo987 | 38:47c075a354b5 | 117 | leds[led].write(codedMessage1[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 118 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 119 | } |
albireo987 | 38:47c075a354b5 | 120 | else if(messageList[led]==2) |
albireo987 | 38:47c075a354b5 | 121 | { |
albireo987 | 38:47c075a354b5 | 122 | leds[led].write(codedMessage2[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 123 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 124 | } |
albireo987 | 38:47c075a354b5 | 125 | else if(messageList[led]==3) |
albireo987 | 38:47c075a354b5 | 126 | { |
albireo987 | 38:47c075a354b5 | 127 | leds[led].write(codedMessage3[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 128 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 129 | } |
albireo987 | 38:47c075a354b5 | 130 | else if(messageList[led]==4) |
albireo987 | 38:47c075a354b5 | 131 | { |
albireo987 | 38:47c075a354b5 | 132 | leds[led].write(codedMessage4[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 133 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 134 | } |
albireo987 | 38:47c075a354b5 | 135 | } |
albireo987 | 6:36158325f7b0 | 136 | } |