![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp@69:df2d20effe00, 2018-05-14 (annotated)
- Committer:
- albireo987
- Date:
- Mon May 14 18:48:24 2018 +0000
- Revision:
- 69:df2d20effe00
- Parent:
- 67:7951d11432f8
- Parent:
- 62:0b634db67ca8
merged
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 38:47c075a354b5 | 1 | #include "LEDDriver.h" |
albireo987 | 26:4c673da1a3ae | 2 | LEDDriver::LEDDriver( Queue<int,8>* queue) |
albireo987 | 6:36158325f7b0 | 3 | { |
KlaasGovaerts | 55:4e06cfb6d010 | 4 | this->queue=queue; |
KlaasGovaerts | 45:2d877f01ca7b | 5 | initArrays(); |
KlaasGovaerts | 45:2d877f01ca7b | 6 | currentLocation=0; |
albireo987 | 6:36158325f7b0 | 7 | } |
albireo987 | 6:36158325f7b0 | 8 | |
albireo987 | 6:36158325f7b0 | 9 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 6:36158325f7b0 | 10 | { |
KlaasGovaerts | 47:8fe84f455571 | 11 | if(currentLocation==0){ |
KlaasGovaerts | 55:4e06cfb6d010 | 12 | poll(numberOfLeds); |
KlaasGovaerts | 47:8fe84f455571 | 13 | } |
KlaasGovaerts | 47:8fe84f455571 | 14 | |
KlaasGovaerts | 45:2d877f01ca7b | 15 | setLEDS(currentLocation); |
KlaasGovaerts | 45:2d877f01ca7b | 16 | currentLocation++; |
KlaasGovaerts | 54:4274186bf584 | 17 | if(currentLocation>=25){ |
KlaasGovaerts | 45:2d877f01ca7b | 18 | currentLocation=0; |
KlaasGovaerts | 45:2d877f01ca7b | 19 | } |
KlaasGovaerts | 44:ffac07bff0d8 | 20 | } |
KlaasGovaerts | 44:ffac07bff0d8 | 21 | |
KlaasGovaerts | 44:ffac07bff0d8 | 22 | void LEDDriver::drive8leds(){ |
KlaasGovaerts | 44:ffac07bff0d8 | 23 | drive(8); |
albireo987 | 6:36158325f7b0 | 24 | } |
albireo987 | 6:36158325f7b0 | 25 | |
KlaasGovaerts | 55:4e06cfb6d010 | 26 | void LEDDriver::poll(int numberOfLeds) |
albireo987 | 10:7871aeacea08 | 27 | { |
KlaasGovaerts | 55:4e06cfb6d010 | 28 | for(int i =0;i<(numberOfLeds);i++) |
albireo987 | 27:29948b116e82 | 29 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 30 | osEvent event = queue->get(); |
KlaasGovaerts | 44:ffac07bff0d8 | 31 | int temp = *((int*)event.value.p); |
KlaasGovaerts | 52:45207965e160 | 32 | if(temp==0||temp==1||temp==2||temp==3||temp==4) |
albireo987 | 27:29948b116e82 | 33 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 34 | messageList[i]=temp; |
KlaasGovaerts | 52:45207965e160 | 35 | } |
KlaasGovaerts | 55:4e06cfb6d010 | 36 | } |
albireo987 | 38:47c075a354b5 | 37 | } |
albireo987 | 38:47c075a354b5 | 38 | |
KlaasGovaerts | 45:2d877f01ca7b | 39 | void LEDDriver::initArrays() |
albireo987 | 38:47c075a354b5 | 40 | { |
KlaasGovaerts | 55:4e06cfb6d010 | 41 | 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) |
KlaasGovaerts | 54:4274186bf584 | 42 | 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}; |
KlaasGovaerts | 54:4274186bf584 | 43 | 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}; |
KlaasGovaerts | 54:4274186bf584 | 44 | 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 | 55:4e06cfb6d010 | 45 | 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 | 55:4e06cfb6d010 | 46 | int tempMessageList[8]={4,4,4,4,4,4,4,4}; |
albireo987 | 67:7951d11432f8 | 47 | DigitalOut *tempLeds[]={new DigitalOut(p11),new DigitalOut(p10),new DigitalOut(p12),new DigitalOut(p13),new DigitalOut(p14),new DigitalOut(p15),new DigitalOut(p16),new DigitalOut(p17)}; |
albireo987 | 69:df2d20effe00 | 48 | |
KlaasGovaerts | 45:2d877f01ca7b | 49 | |
KlaasGovaerts | 45:2d877f01ca7b | 50 | memcpy(codedMessage0,tempCodedMessage0,sizeof(codedMessage0)); |
KlaasGovaerts | 45:2d877f01ca7b | 51 | memcpy(codedMessage1,tempCodedMessage1,sizeof(codedMessage1)); |
KlaasGovaerts | 45:2d877f01ca7b | 52 | memcpy(codedMessage2,tempCodedMessage2,sizeof(codedMessage2)); |
KlaasGovaerts | 45:2d877f01ca7b | 53 | memcpy(codedMessage3,tempCodedMessage3,sizeof(codedMessage3)); |
KlaasGovaerts | 45:2d877f01ca7b | 54 | memcpy(codedMessage4,tempCodedMessage4,sizeof(codedMessage4)); |
KlaasGovaerts | 45:2d877f01ca7b | 55 | |
KlaasGovaerts | 47:8fe84f455571 | 56 | memcpy(messageList,tempMessageList,sizeof(messageList)); |
KlaasGovaerts | 47:8fe84f455571 | 57 | |
KlaasGovaerts | 45:2d877f01ca7b | 58 | memcpy(leds,tempLeds,sizeof(leds)); |
KlaasGovaerts | 45:2d877f01ca7b | 59 | } |
KlaasGovaerts | 45:2d877f01ca7b | 60 | |
KlaasGovaerts | 45:2d877f01ca7b | 61 | void LEDDriver::setLEDS(int j){ |
albireo987 | 38:47c075a354b5 | 62 | for(int led =0 ; led<8;led++) |
albireo987 | 38:47c075a354b5 | 63 | { |
albireo987 | 38:47c075a354b5 | 64 | if(messageList[led]==0) |
albireo987 | 38:47c075a354b5 | 65 | { |
KlaasGovaerts | 48:c5cd73d93045 | 66 | leds[led]->write(codedMessage0[j]); |
albireo987 | 38:47c075a354b5 | 67 | } |
albireo987 | 38:47c075a354b5 | 68 | else if(messageList[led]==1) |
albireo987 | 38:47c075a354b5 | 69 | { |
KlaasGovaerts | 48:c5cd73d93045 | 70 | leds[led]->write(codedMessage1[j]); |
albireo987 | 38:47c075a354b5 | 71 | } |
albireo987 | 38:47c075a354b5 | 72 | else if(messageList[led]==2) |
albireo987 | 38:47c075a354b5 | 73 | { |
KlaasGovaerts | 48:c5cd73d93045 | 74 | leds[led]->write(codedMessage2[j]); |
albireo987 | 38:47c075a354b5 | 75 | } |
albireo987 | 38:47c075a354b5 | 76 | else if(messageList[led]==3) |
albireo987 | 38:47c075a354b5 | 77 | { |
KlaasGovaerts | 48:c5cd73d93045 | 78 | leds[led]->write(codedMessage3[j]); |
albireo987 | 38:47c075a354b5 | 79 | } |
KlaasGovaerts | 47:8fe84f455571 | 80 | else if(messageList[led]==4||messageList[led]==-1) |
albireo987 | 38:47c075a354b5 | 81 | { |
KlaasGovaerts | 48:c5cd73d93045 | 82 | leds[led]->write(codedMessage4[j]); |
albireo987 | 38:47c075a354b5 | 83 | } |
KlaasGovaerts | 54:4274186bf584 | 84 | } |
KlaasGovaerts | 48:c5cd73d93045 | 85 | } |
KlaasGovaerts | 48:c5cd73d93045 | 86 | |
KlaasGovaerts | 58:738f026cf667 | 87 | LEDDriver::~LEDDriver(){ |
KlaasGovaerts | 58:738f026cf667 | 88 | for(int i=0;i<8;i++){ |
KlaasGovaerts | 58:738f026cf667 | 89 | delete leds[i]; |
KlaasGovaerts | 58:738f026cf667 | 90 | } |
KlaasGovaerts | 58:738f026cf667 | 91 | } |