![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp@51:b9da0ba69a29, 2018-05-09 (annotated)
- Committer:
- KlaasGovaerts
- Date:
- Wed May 09 12:29:08 2018 +0000
- Revision:
- 51:b9da0ba69a29
- Parent:
- 48:c5cd73d93045
- Child:
- 52:45207965e160
Rode LED blinkt niet
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 | 47:8fe84f455571 | 8 | printf("Queue created\r\n"); |
KlaasGovaerts | 45:2d877f01ca7b | 9 | initArrays(); |
KlaasGovaerts | 47:8fe84f455571 | 10 | printf("Arrays initialised.\r\n"); |
KlaasGovaerts | 45:2d877f01ca7b | 11 | currentLocation=0; |
albireo987 | 6:36158325f7b0 | 12 | } |
albireo987 | 6:36158325f7b0 | 13 | |
albireo987 | 6:36158325f7b0 | 14 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 6:36158325f7b0 | 15 | { |
KlaasGovaerts | 47:8fe84f455571 | 16 | if(currentLocation==0){ |
KlaasGovaerts | 47:8fe84f455571 | 17 | poll(numberOfLeds,1); |
KlaasGovaerts | 47:8fe84f455571 | 18 | poll(numberOfLeds,2); |
KlaasGovaerts | 47:8fe84f455571 | 19 | } |
KlaasGovaerts | 47:8fe84f455571 | 20 | |
KlaasGovaerts | 45:2d877f01ca7b | 21 | setLEDS(currentLocation); |
KlaasGovaerts | 45:2d877f01ca7b | 22 | currentLocation++; |
KlaasGovaerts | 45:2d877f01ca7b | 23 | if(currentLocation>=20){ |
KlaasGovaerts | 45:2d877f01ca7b | 24 | currentLocation=0; |
KlaasGovaerts | 45:2d877f01ca7b | 25 | } |
KlaasGovaerts | 44:ffac07bff0d8 | 26 | |
KlaasGovaerts | 44:ffac07bff0d8 | 27 | /* |
albireo987 | 38:47c075a354b5 | 28 | Ticker ticker; |
albireo987 | 32:537005b4a065 | 29 | while(true) |
albireo987 | 26:4c673da1a3ae | 30 | { |
albireo987 | 27:29948b116e82 | 31 | poll(numberOfLeds,1) ;//prep multi |
KlaasGovaerts | 42:bb1d9d8a9fe4 | 32 | //for(int i =0;i<numberOfLeds;i++) |
KlaasGovaerts | 42:bb1d9d8a9fe4 | 33 | //{ |
KlaasGovaerts | 44:ffac07bff0d8 | 34 | //ticker.attach(this,&LEDDriver::sendData,0.000625f); |
KlaasGovaerts | 42:bb1d9d8a9fe4 | 35 | //} |
albireo987 | 38:47c075a354b5 | 36 | poll(numberOfLeds,2) ; |
KlaasGovaerts | 44:ffac07bff0d8 | 37 | }*/ |
albireo987 | 6:36158325f7b0 | 38 | } |
albireo987 | 6:36158325f7b0 | 39 | |
KlaasGovaerts | 44:ffac07bff0d8 | 40 | void LEDDriver::run(Ticker* ticker) |
albireo987 | 6:36158325f7b0 | 41 | { |
KlaasGovaerts | 47:8fe84f455571 | 42 | printf("ticker attached.\r\n"); |
KlaasGovaerts | 48:c5cd73d93045 | 43 | ticker->attach(this,&LEDDriver::drive8leds,10.0);//TODO faster |
KlaasGovaerts | 44:ffac07bff0d8 | 44 | } |
KlaasGovaerts | 44:ffac07bff0d8 | 45 | |
KlaasGovaerts | 44:ffac07bff0d8 | 46 | void LEDDriver::drive8leds(){ |
KlaasGovaerts | 47:8fe84f455571 | 47 | printf("tick\r\n");//TODO |
KlaasGovaerts | 44:ffac07bff0d8 | 48 | drive(8); |
albireo987 | 6:36158325f7b0 | 49 | } |
albireo987 | 6:36158325f7b0 | 50 | |
albireo987 | 10:7871aeacea08 | 51 | void LEDDriver::ownWait(uint32_t us) |
albireo987 | 10:7871aeacea08 | 52 | { |
albireo987 | 10:7871aeacea08 | 53 | for(uint32_t i=0;i<us;i++) |
albireo987 | 10:7871aeacea08 | 54 | { |
albireo987 | 38:47c075a354b5 | 55 | for(volatile uint32_t j =0; j <3;j++) |
albireo987 | 10:7871aeacea08 | 56 | { |
albireo987 | 10:7871aeacea08 | 57 | |
albireo987 | 10:7871aeacea08 | 58 | } |
albireo987 | 10:7871aeacea08 | 59 | } |
albireo987 | 26:4c673da1a3ae | 60 | } |
albireo987 | 26:4c673da1a3ae | 61 | |
albireo987 | 27:29948b116e82 | 62 | void LEDDriver::poll(int numberOfLeds,int first) |
albireo987 | 26:4c673da1a3ae | 63 | { |
albireo987 | 27:29948b116e82 | 64 | if(first==1) |
albireo987 | 27:29948b116e82 | 65 | { |
albireo987 | 27:29948b116e82 | 66 | for(int i =0;i<(numberOfLeds/2);i++) |
albireo987 | 27:29948b116e82 | 67 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 68 | osEvent event = queue->get(); |
KlaasGovaerts | 44:ffac07bff0d8 | 69 | int temp = *((int*)event.value.p); |
KlaasGovaerts | 45:2d877f01ca7b | 70 | if(temp==0||temp==1||temp==2||temp==3) |
albireo987 | 27:29948b116e82 | 71 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 72 | messageList[i]=temp; |
KlaasGovaerts | 51:b9da0ba69a29 | 73 | } |
KlaasGovaerts | 51:b9da0ba69a29 | 74 | if(temp=-1){ |
KlaasGovaerts | 51:b9da0ba69a29 | 75 | messageList[i]=4; |
KlaasGovaerts | 51:b9da0ba69a29 | 76 | } |
albireo987 | 27:29948b116e82 | 77 | } |
albireo987 | 27:29948b116e82 | 78 | } |
albireo987 | 27:29948b116e82 | 79 | else if(first==2) |
albireo987 | 38:47c075a354b5 | 80 | { |
albireo987 | 27:29948b116e82 | 81 | for(int i =(numberOfLeds/2);i<(numberOfLeds);i++) |
albireo987 | 27:29948b116e82 | 82 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 83 | osEvent event = queue->get(); |
KlaasGovaerts | 44:ffac07bff0d8 | 84 | int temp = *((int*)event.value.p); |
KlaasGovaerts | 45:2d877f01ca7b | 85 | if(temp==0||temp==1||temp==2||temp==3) |
albireo987 | 27:29948b116e82 | 86 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 87 | messageList[i]=temp; |
KlaasGovaerts | 51:b9da0ba69a29 | 88 | } |
KlaasGovaerts | 51:b9da0ba69a29 | 89 | if(temp=-1){ |
KlaasGovaerts | 51:b9da0ba69a29 | 90 | messageList[i]=4; |
albireo987 | 38:47c075a354b5 | 91 | } |
albireo987 | 27:29948b116e82 | 92 | } |
albireo987 | 32:537005b4a065 | 93 | } |
albireo987 | 38:47c075a354b5 | 94 | } |
albireo987 | 38:47c075a354b5 | 95 | |
KlaasGovaerts | 45:2d877f01ca7b | 96 | void LEDDriver::initArrays() |
albireo987 | 38:47c075a354b5 | 97 | { |
KlaasGovaerts | 45:2d877f01ca7b | 98 | // 1 1 1 1 0 0 0 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 99 | 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 | 100 | // 1 1 1 1 0 1 0 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 101 | 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 | 102 | // 1 1 1 1 1 0 1 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 103 | 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 | 104 | // 1 1 1 1 1 1 0 0 0 1 |
KlaasGovaerts | 45:2d877f01ca7b | 105 | 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 | 106 | 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 | 47:8fe84f455571 | 107 | int tempMessageList[8]={0,0,0,0,0,0,0,0};//TODO |
KlaasGovaerts | 48:c5cd73d93045 | 108 | DigitalOut *tempLeds[]={new DigitalOut(p23),new DigitalOut(p11),new DigitalOut(p12),new DigitalOut(p13),new DigitalOut(p14),new DigitalOut(p15),new DigitalOut(p16),new DigitalOut(p17)}; |
KlaasGovaerts | 47:8fe84f455571 | 109 | printf("Arrays created.\r\n"); |
KlaasGovaerts | 45:2d877f01ca7b | 110 | |
KlaasGovaerts | 45:2d877f01ca7b | 111 | memcpy(codedMessage0,tempCodedMessage0,sizeof(codedMessage0)); |
KlaasGovaerts | 45:2d877f01ca7b | 112 | memcpy(codedMessage1,tempCodedMessage1,sizeof(codedMessage1)); |
KlaasGovaerts | 45:2d877f01ca7b | 113 | memcpy(codedMessage2,tempCodedMessage2,sizeof(codedMessage2)); |
KlaasGovaerts | 45:2d877f01ca7b | 114 | memcpy(codedMessage3,tempCodedMessage3,sizeof(codedMessage3)); |
KlaasGovaerts | 45:2d877f01ca7b | 115 | memcpy(codedMessage4,tempCodedMessage4,sizeof(codedMessage4)); |
KlaasGovaerts | 47:8fe84f455571 | 116 | printf("First 5 arrays copied.\r\n"); |
KlaasGovaerts | 45:2d877f01ca7b | 117 | |
KlaasGovaerts | 47:8fe84f455571 | 118 | memcpy(messageList,tempMessageList,sizeof(messageList)); |
KlaasGovaerts | 47:8fe84f455571 | 119 | printf("messageList array copied.\r\n"); |
KlaasGovaerts | 47:8fe84f455571 | 120 | |
KlaasGovaerts | 45:2d877f01ca7b | 121 | memcpy(leds,tempLeds,sizeof(leds)); |
KlaasGovaerts | 47:8fe84f455571 | 122 | printf("LEDS array copied.\r\n"); |
KlaasGovaerts | 45:2d877f01ca7b | 123 | } |
KlaasGovaerts | 45:2d877f01ca7b | 124 | |
KlaasGovaerts | 45:2d877f01ca7b | 125 | void LEDDriver::setLEDS(int j){ |
albireo987 | 38:47c075a354b5 | 126 | for(int led =0 ; led<8;led++) |
albireo987 | 38:47c075a354b5 | 127 | { |
albireo987 | 38:47c075a354b5 | 128 | if(messageList[led]==0) |
albireo987 | 38:47c075a354b5 | 129 | { |
KlaasGovaerts | 48:c5cd73d93045 | 130 | leds[led]->write(codedMessage0[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 131 | //ownWait(25);//100HZ |
albireo987 | 38:47c075a354b5 | 132 | } |
albireo987 | 38:47c075a354b5 | 133 | else if(messageList[led]==1) |
albireo987 | 38:47c075a354b5 | 134 | { |
KlaasGovaerts | 48:c5cd73d93045 | 135 | leds[led]->write(codedMessage1[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 136 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 137 | } |
albireo987 | 38:47c075a354b5 | 138 | else if(messageList[led]==2) |
albireo987 | 38:47c075a354b5 | 139 | { |
KlaasGovaerts | 48:c5cd73d93045 | 140 | leds[led]->write(codedMessage2[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 141 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 142 | } |
albireo987 | 38:47c075a354b5 | 143 | else if(messageList[led]==3) |
albireo987 | 38:47c075a354b5 | 144 | { |
KlaasGovaerts | 48:c5cd73d93045 | 145 | leds[led]->write(codedMessage3[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 146 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 147 | } |
KlaasGovaerts | 47:8fe84f455571 | 148 | else if(messageList[led]==4||messageList[led]==-1) |
albireo987 | 38:47c075a354b5 | 149 | { |
KlaasGovaerts | 48:c5cd73d93045 | 150 | leds[led]->write(codedMessage4[j]); |
KlaasGovaerts | 45:2d877f01ca7b | 151 | //ownWait(25); |
albireo987 | 38:47c075a354b5 | 152 | } |
albireo987 | 38:47c075a354b5 | 153 | } |
KlaasGovaerts | 48:c5cd73d93045 | 154 | } |
KlaasGovaerts | 48:c5cd73d93045 | 155 | |
KlaasGovaerts | 48:c5cd73d93045 | 156 | //TODO destructor |