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