![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp@79:ebff08a66ff3, 2018-05-16 (annotated)
- Committer:
- albireo987
- Date:
- Wed May 16 10:12:54 2018 +0000
- Revision:
- 79:ebff08a66ff3
- Parent:
- 78:8efde3e9e3fb
- Child:
- 80:dbda5092950e
DRIVER HEX;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 38:47c075a354b5 | 1 | #include "LEDDriver.h" |
albireo987 | 78:8efde3e9e3fb | 2 | Serial pc(USBTX,USBRX); |
albireo987 | 26:4c673da1a3ae | 3 | LEDDriver::LEDDriver( Queue<int,8>* queue) |
albireo987 | 6:36158325f7b0 | 4 | { |
KlaasGovaerts | 55:4e06cfb6d010 | 5 | this->queue=queue; |
KlaasGovaerts | 45:2d877f01ca7b | 6 | initArrays(); |
KlaasGovaerts | 45:2d877f01ca7b | 7 | currentLocation=0; |
albireo987 | 78:8efde3e9e3fb | 8 | mask=16777216; |
albireo987 | 79:ebff08a66ff3 | 9 | codedMessage0=0x1F54AAD;//32852653;// 2796202 commented message is frequency measure message(standard square wave) 4:('1')+2 ticker 0.002f. (250Hz, 10ms down) |
albireo987 | 79:ebff08a66ff3 | 10 | codedMessage1=0x1F54CAD;//32853165 |
albireo987 | 79:ebff08a66ff3 | 11 | codedMessage2=0x1F552AD;//32854701; |
albireo987 | 79:ebff08a66ff3 | 12 | codedMessage3=0x1F554AD;//32855213; |
albireo987 | 79:ebff08a66ff3 | 13 | codedMessage4=0; |
albireo987 | 6:36158325f7b0 | 14 | } |
albireo987 | 6:36158325f7b0 | 15 | |
albireo987 | 6:36158325f7b0 | 16 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 6:36158325f7b0 | 17 | { |
albireo987 | 78:8efde3e9e3fb | 18 | if(currentLocation>=25){ |
albireo987 | 78:8efde3e9e3fb | 19 | currentLocation=0; |
albireo987 | 78:8efde3e9e3fb | 20 | mask = 16777216; |
albireo987 | 78:8efde3e9e3fb | 21 | } |
KlaasGovaerts | 47:8fe84f455571 | 22 | if(currentLocation==0){ |
KlaasGovaerts | 55:4e06cfb6d010 | 23 | poll(numberOfLeds); |
KlaasGovaerts | 47:8fe84f455571 | 24 | } |
albireo987 | 78:8efde3e9e3fb | 25 | setLEDS(mask); |
albireo987 | 78:8efde3e9e3fb | 26 | mask=mask>>1; |
KlaasGovaerts | 45:2d877f01ca7b | 27 | currentLocation++; |
albireo987 | 78:8efde3e9e3fb | 28 | |
KlaasGovaerts | 44:ffac07bff0d8 | 29 | } |
KlaasGovaerts | 44:ffac07bff0d8 | 30 | |
KlaasGovaerts | 44:ffac07bff0d8 | 31 | void LEDDriver::drive8leds(){ |
KlaasGovaerts | 44:ffac07bff0d8 | 32 | drive(8); |
albireo987 | 6:36158325f7b0 | 33 | } |
albireo987 | 6:36158325f7b0 | 34 | |
KlaasGovaerts | 55:4e06cfb6d010 | 35 | void LEDDriver::poll(int numberOfLeds) |
albireo987 | 10:7871aeacea08 | 36 | { |
albireo987 | 78:8efde3e9e3fb | 37 | for(int i =7;i<(numberOfLeds);i++) |
albireo987 | 27:29948b116e82 | 38 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 39 | osEvent event = queue->get(); |
KlaasGovaerts | 44:ffac07bff0d8 | 40 | int temp = *((int*)event.value.p); |
KlaasGovaerts | 52:45207965e160 | 41 | if(temp==0||temp==1||temp==2||temp==3||temp==4) |
albireo987 | 27:29948b116e82 | 42 | { |
KlaasGovaerts | 44:ffac07bff0d8 | 43 | messageList[i]=temp; |
KlaasGovaerts | 52:45207965e160 | 44 | } |
KlaasGovaerts | 55:4e06cfb6d010 | 45 | } |
albireo987 | 38:47c075a354b5 | 46 | } |
albireo987 | 38:47c075a354b5 | 47 | |
KlaasGovaerts | 45:2d877f01ca7b | 48 | void LEDDriver::initArrays() |
albireo987 | 38:47c075a354b5 | 49 | { |
KlaasGovaerts | 55:4e06cfb6d010 | 50 | int tempMessageList[8]={4,4,4,4,4,4,4,4}; |
albireo987 | 67:7951d11432f8 | 51 | 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 | 52 | |
KlaasGovaerts | 47:8fe84f455571 | 53 | memcpy(messageList,tempMessageList,sizeof(messageList)); |
KlaasGovaerts | 45:2d877f01ca7b | 54 | memcpy(leds,tempLeds,sizeof(leds)); |
KlaasGovaerts | 45:2d877f01ca7b | 55 | } |
KlaasGovaerts | 45:2d877f01ca7b | 56 | |
albireo987 | 78:8efde3e9e3fb | 57 | void LEDDriver::setLEDS(int mask){ |
albireo987 | 38:47c075a354b5 | 58 | for(int led =0 ; led<8;led++) |
albireo987 | 38:47c075a354b5 | 59 | { |
albireo987 | 38:47c075a354b5 | 60 | if(messageList[led]==0) |
albireo987 | 38:47c075a354b5 | 61 | { |
albireo987 | 78:8efde3e9e3fb | 62 | leds[led]->write(codedMessage0&mask); |
albireo987 | 38:47c075a354b5 | 63 | } |
albireo987 | 38:47c075a354b5 | 64 | else if(messageList[led]==1) |
albireo987 | 38:47c075a354b5 | 65 | { |
albireo987 | 78:8efde3e9e3fb | 66 | leds[led]->write(codedMessage1&mask); |
albireo987 | 38:47c075a354b5 | 67 | } |
albireo987 | 38:47c075a354b5 | 68 | else if(messageList[led]==2) |
albireo987 | 38:47c075a354b5 | 69 | { |
albireo987 | 78:8efde3e9e3fb | 70 | leds[led]->write((codedMessage2)&mask); |
albireo987 | 38:47c075a354b5 | 71 | } |
albireo987 | 38:47c075a354b5 | 72 | else if(messageList[led]==3) |
albireo987 | 38:47c075a354b5 | 73 | { |
albireo987 | 78:8efde3e9e3fb | 74 | leds[led]->write((codedMessage3)&mask); |
albireo987 | 38:47c075a354b5 | 75 | } |
KlaasGovaerts | 47:8fe84f455571 | 76 | else if(messageList[led]==4||messageList[led]==-1) |
albireo987 | 38:47c075a354b5 | 77 | { |
albireo987 | 78:8efde3e9e3fb | 78 | leds[led]->write((codedMessage4)&mask); |
albireo987 | 38:47c075a354b5 | 79 | } |
KlaasGovaerts | 54:4274186bf584 | 80 | } |
KlaasGovaerts | 48:c5cd73d93045 | 81 | } |
KlaasGovaerts | 48:c5cd73d93045 | 82 | |
KlaasGovaerts | 58:738f026cf667 | 83 | LEDDriver::~LEDDriver(){ |
KlaasGovaerts | 58:738f026cf667 | 84 | for(int i=0;i<8;i++){ |
KlaasGovaerts | 58:738f026cf667 | 85 | delete leds[i]; |
KlaasGovaerts | 58:738f026cf667 | 86 | } |
KlaasGovaerts | 58:738f026cf667 | 87 | } |