![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
LEDDriver.cpp@58:4e06cfb6d010, 2018-05-09 (annotated)
- Committer:
- KlaasGovaerts
- Date:
- Wed May 09 13:34:15 2018 +0000
- Revision:
- 58:4e06cfb6d010
- Parent:
- 56:4274186bf584
- Child:
- 59:f0ddd28b1766
Code opgekuist.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 38:47c075a354b5 | 1 | #include "LEDDriver.h" |
albireo987 | 25:4c673da1a3ae | 2 | LEDDriver::LEDDriver( Queue<int,8>* queue) |
albireo987 | 2:36158325f7b0 | 3 | { |
KlaasGovaerts | 58:4e06cfb6d010 | 4 | this->queue=queue; |
KlaasGovaerts | 47:2d877f01ca7b | 5 | initArrays(); |
KlaasGovaerts | 47:2d877f01ca7b | 6 | currentLocation=0; |
albireo987 | 2:36158325f7b0 | 7 | } |
albireo987 | 2:36158325f7b0 | 8 | |
albireo987 | 2:36158325f7b0 | 9 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 2:36158325f7b0 | 10 | { |
KlaasGovaerts | 49:8fe84f455571 | 11 | if(currentLocation==0){ |
KlaasGovaerts | 58:4e06cfb6d010 | 12 | poll(numberOfLeds); |
KlaasGovaerts | 49:8fe84f455571 | 13 | } |
KlaasGovaerts | 49:8fe84f455571 | 14 | |
KlaasGovaerts | 47:2d877f01ca7b | 15 | setLEDS(currentLocation); |
KlaasGovaerts | 47:2d877f01ca7b | 16 | currentLocation++; |
KlaasGovaerts | 56:4274186bf584 | 17 | if(currentLocation>=25){ |
KlaasGovaerts | 47:2d877f01ca7b | 18 | currentLocation=0; |
KlaasGovaerts | 47:2d877f01ca7b | 19 | } |
KlaasGovaerts | 46:ffac07bff0d8 | 20 | } |
KlaasGovaerts | 46:ffac07bff0d8 | 21 | |
KlaasGovaerts | 46:ffac07bff0d8 | 22 | void LEDDriver::drive8leds(){ |
KlaasGovaerts | 46:ffac07bff0d8 | 23 | drive(8); |
albireo987 | 2:36158325f7b0 | 24 | } |
albireo987 | 2:36158325f7b0 | 25 | |
KlaasGovaerts | 58:4e06cfb6d010 | 26 | void LEDDriver::poll(int numberOfLeds) |
albireo987 | 10:7871aeacea08 | 27 | { |
KlaasGovaerts | 58:4e06cfb6d010 | 28 | for(int i =0;i<(numberOfLeds);i++) |
albireo987 | 26:29948b116e82 | 29 | { |
KlaasGovaerts | 46:ffac07bff0d8 | 30 | osEvent event = queue->get(); |
KlaasGovaerts | 46:ffac07bff0d8 | 31 | int temp = *((int*)event.value.p); |
KlaasGovaerts | 54:45207965e160 | 32 | if(temp==0||temp==1||temp==2||temp==3||temp==4) |
albireo987 | 26:29948b116e82 | 33 | { |
KlaasGovaerts | 46:ffac07bff0d8 | 34 | messageList[i]=temp; |
KlaasGovaerts | 54:45207965e160 | 35 | } |
KlaasGovaerts | 58:4e06cfb6d010 | 36 | } |
albireo987 | 38:47c075a354b5 | 37 | } |
albireo987 | 38:47c075a354b5 | 38 | |
KlaasGovaerts | 47:2d877f01ca7b | 39 | void LEDDriver::initArrays() |
albireo987 | 38:47c075a354b5 | 40 | { |
KlaasGovaerts | 47:2d877f01ca7b | 41 | // 1 1 1 1 0 0 0 0 0 1 |
KlaasGovaerts | 58:4e06cfb6d010 | 42 | int tempCodedMessage0[25]=/*{1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1};*/{1,1,1,1,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0,1};// commented message is frequency measure message(standard square wave) 4:('1')+2 ticker 0.002f. (250Hz, 10ms down) |
albireo987 | 38:47c075a354b5 | 43 | // 1 1 1 1 0 1 0 0 0 1 |
KlaasGovaerts | 56:4274186bf584 | 44 | int tempCodedMessage1[25]={1,1,1,1,1,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0,1}; |
albireo987 | 38:47c075a354b5 | 45 | // 1 1 1 1 1 0 1 0 0 1 |
KlaasGovaerts | 56:4274186bf584 | 46 | int tempCodedMessage2[25]={1,1,1,1,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0,1}; |
albireo987 | 38:47c075a354b5 | 47 | // 1 1 1 1 1 1 0 0 0 1 |
KlaasGovaerts | 56:4274186bf584 | 48 | int tempCodedMessage3[25]={1,1,1,1,1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0,1}; |
KlaasGovaerts | 58:4e06cfb6d010 | 49 | int tempCodedMessage4[25]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
KlaasGovaerts | 58:4e06cfb6d010 | 50 | int tempMessageList[8]={4,4,4,4,4,4,4,4}; |
KlaasGovaerts | 50:c5cd73d93045 | 51 | 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 | 49:8fe84f455571 | 52 | printf("Arrays created.\r\n"); |
KlaasGovaerts | 47:2d877f01ca7b | 53 | |
KlaasGovaerts | 47:2d877f01ca7b | 54 | memcpy(codedMessage0,tempCodedMessage0,sizeof(codedMessage0)); |
KlaasGovaerts | 47:2d877f01ca7b | 55 | memcpy(codedMessage1,tempCodedMessage1,sizeof(codedMessage1)); |
KlaasGovaerts | 47:2d877f01ca7b | 56 | memcpy(codedMessage2,tempCodedMessage2,sizeof(codedMessage2)); |
KlaasGovaerts | 47:2d877f01ca7b | 57 | memcpy(codedMessage3,tempCodedMessage3,sizeof(codedMessage3)); |
KlaasGovaerts | 47:2d877f01ca7b | 58 | memcpy(codedMessage4,tempCodedMessage4,sizeof(codedMessage4)); |
KlaasGovaerts | 49:8fe84f455571 | 59 | printf("First 5 arrays copied.\r\n"); |
KlaasGovaerts | 47:2d877f01ca7b | 60 | |
KlaasGovaerts | 49:8fe84f455571 | 61 | memcpy(messageList,tempMessageList,sizeof(messageList)); |
KlaasGovaerts | 49:8fe84f455571 | 62 | printf("messageList array copied.\r\n"); |
KlaasGovaerts | 49:8fe84f455571 | 63 | |
KlaasGovaerts | 47:2d877f01ca7b | 64 | memcpy(leds,tempLeds,sizeof(leds)); |
KlaasGovaerts | 49:8fe84f455571 | 65 | printf("LEDS array copied.\r\n"); |
KlaasGovaerts | 47:2d877f01ca7b | 66 | } |
KlaasGovaerts | 47:2d877f01ca7b | 67 | |
KlaasGovaerts | 47:2d877f01ca7b | 68 | void LEDDriver::setLEDS(int j){ |
albireo987 | 38:47c075a354b5 | 69 | for(int led =0 ; led<8;led++) |
albireo987 | 38:47c075a354b5 | 70 | { |
albireo987 | 38:47c075a354b5 | 71 | if(messageList[led]==0) |
albireo987 | 38:47c075a354b5 | 72 | { |
KlaasGovaerts | 50:c5cd73d93045 | 73 | leds[led]->write(codedMessage0[j]); |
albireo987 | 38:47c075a354b5 | 74 | } |
albireo987 | 38:47c075a354b5 | 75 | else if(messageList[led]==1) |
albireo987 | 38:47c075a354b5 | 76 | { |
KlaasGovaerts | 50:c5cd73d93045 | 77 | leds[led]->write(codedMessage1[j]); |
albireo987 | 38:47c075a354b5 | 78 | } |
albireo987 | 38:47c075a354b5 | 79 | else if(messageList[led]==2) |
albireo987 | 38:47c075a354b5 | 80 | { |
KlaasGovaerts | 50:c5cd73d93045 | 81 | leds[led]->write(codedMessage2[j]); |
albireo987 | 38:47c075a354b5 | 82 | } |
albireo987 | 38:47c075a354b5 | 83 | else if(messageList[led]==3) |
albireo987 | 38:47c075a354b5 | 84 | { |
KlaasGovaerts | 50:c5cd73d93045 | 85 | leds[led]->write(codedMessage3[j]); |
albireo987 | 38:47c075a354b5 | 86 | } |
KlaasGovaerts | 49:8fe84f455571 | 87 | else if(messageList[led]==4||messageList[led]==-1) |
albireo987 | 38:47c075a354b5 | 88 | { |
KlaasGovaerts | 50:c5cd73d93045 | 89 | leds[led]->write(codedMessage4[j]); |
albireo987 | 38:47c075a354b5 | 90 | } |
KlaasGovaerts | 56:4274186bf584 | 91 | } |
KlaasGovaerts | 50:c5cd73d93045 | 92 | } |
KlaasGovaerts | 50:c5cd73d93045 | 93 | |
KlaasGovaerts | 50:c5cd73d93045 | 94 | //TODO destructor |