![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp@38:47c075a354b5, 2018-05-02 (annotated)
- Committer:
- albireo987
- Date:
- Wed May 02 12:44:26 2018 +0000
- Revision:
- 38:47c075a354b5
- Parent:
- 32:537005b4a065
- Child:
- 42:bb1d9d8a9fe4
- Child:
- 43:eaa8348f1150
- Child:
- 63:0ab266251e86
ticker werkend ;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
albireo987 | 38:47c075a354b5 | 1 | #include "LEDDriver.h" |
albireo987 | 38:47c075a354b5 | 2 | Serial pc(USBTX,USBRX); |
albireo987 | 26:4c673da1a3ae | 3 | LEDDriver::LEDDriver( Queue<int,8>* queue) |
albireo987 | 6:36158325f7b0 | 4 | { |
albireo987 | 26:4c673da1a3ae | 5 | static int messageList[8]={4,4,4,4,4,4,4,4}; |
albireo987 | 10:7871aeacea08 | 6 | static DigitalOut leds[]={DigitalOut(p23),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)}; |
albireo987 | 6:36158325f7b0 | 7 | this->messageList=messageList; |
albireo987 | 6:36158325f7b0 | 8 | this->leds=leds; |
albireo987 | 26:4c673da1a3ae | 9 | this->queue=queue;// prep for multithreaded |
albireo987 | 26:4c673da1a3ae | 10 | |
albireo987 | 6:36158325f7b0 | 11 | } |
albireo987 | 6:36158325f7b0 | 12 | |
albireo987 | 6:36158325f7b0 | 13 | void LEDDriver::drive(int numberOfLeds) |
albireo987 | 6:36158325f7b0 | 14 | { |
albireo987 | 32:537005b4a065 | 15 | poll(numberOfLeds,1) ; |
albireo987 | 38:47c075a354b5 | 16 | poll(numberOfLeds,2) ; |
albireo987 | 38:47c075a354b5 | 17 | Ticker ticker; |
albireo987 | 32:537005b4a065 | 18 | while(true) |
albireo987 | 26:4c673da1a3ae | 19 | { |
albireo987 | 27:29948b116e82 | 20 | poll(numberOfLeds,1) ;//prep multi |
albireo987 | 38:47c075a354b5 | 21 | for(int i =0;i<numberOfLeds;i++) |
albireo987 | 38:47c075a354b5 | 22 | { |
albireo987 | 38:47c075a354b5 | 23 | ticker.attach(this,&LEDDriver::sendData,0.000000625f); |
albireo987 | 38:47c075a354b5 | 24 | } |
albireo987 | 38:47c075a354b5 | 25 | poll(numberOfLeds,2) ; |
albireo987 | 9:c800045806f0 | 26 | } |
albireo987 | 6:36158325f7b0 | 27 | } |
albireo987 | 6:36158325f7b0 | 28 | |
albireo987 | 6:36158325f7b0 | 29 | void LEDDriver::run(int numberOfLeds) |
albireo987 | 6:36158325f7b0 | 30 | { |
albireo987 | 6:36158325f7b0 | 31 | drive(numberOfLeds); |
albireo987 | 6:36158325f7b0 | 32 | } |
albireo987 | 6:36158325f7b0 | 33 | |
albireo987 | 10:7871aeacea08 | 34 | void LEDDriver::ownWait(uint32_t us) |
albireo987 | 10:7871aeacea08 | 35 | { |
albireo987 | 10:7871aeacea08 | 36 | for(uint32_t i=0;i<us;i++) |
albireo987 | 10:7871aeacea08 | 37 | { |
albireo987 | 38:47c075a354b5 | 38 | for(volatile uint32_t j =0; j <3;j++) |
albireo987 | 10:7871aeacea08 | 39 | { |
albireo987 | 10:7871aeacea08 | 40 | |
albireo987 | 10:7871aeacea08 | 41 | } |
albireo987 | 10:7871aeacea08 | 42 | } |
albireo987 | 26:4c673da1a3ae | 43 | } |
albireo987 | 26:4c673da1a3ae | 44 | |
albireo987 | 27:29948b116e82 | 45 | void LEDDriver::poll(int numberOfLeds,int first) |
albireo987 | 26:4c673da1a3ae | 46 | { |
albireo987 | 27:29948b116e82 | 47 | if(first==1) |
albireo987 | 27:29948b116e82 | 48 | { |
albireo987 | 27:29948b116e82 | 49 | for(int i =0;i<(numberOfLeds/2);i++) |
albireo987 | 27:29948b116e82 | 50 | { |
albireo987 | 38:47c075a354b5 | 51 | //osEvent event = queue->get(); |
albireo987 | 38:47c075a354b5 | 52 | //int temp = *((int*)event.value.p); |
albireo987 | 38:47c075a354b5 | 53 | //if(temp==1||temp==1||temp==2||temp==3) |
albireo987 | 27:29948b116e82 | 54 | { |
albireo987 | 38:47c075a354b5 | 55 | messageList[i]=1; |
albireo987 | 38:47c075a354b5 | 56 | } |
albireo987 | 27:29948b116e82 | 57 | } |
albireo987 | 27:29948b116e82 | 58 | } |
albireo987 | 27:29948b116e82 | 59 | else if(first==2) |
albireo987 | 38:47c075a354b5 | 60 | { |
albireo987 | 27:29948b116e82 | 61 | for(int i =(numberOfLeds/2);i<(numberOfLeds);i++) |
albireo987 | 27:29948b116e82 | 62 | { |
albireo987 | 38:47c075a354b5 | 63 | //osEvent event = queue->get(); |
albireo987 | 38:47c075a354b5 | 64 | //int temp = *((int*)event.value.p); |
albireo987 | 38:47c075a354b5 | 65 | //if(temp==1||temp==1||temp==2||temp==3) |
albireo987 | 27:29948b116e82 | 66 | { |
albireo987 | 38:47c075a354b5 | 67 | messageList[i]=1; |
albireo987 | 38:47c075a354b5 | 68 | } |
albireo987 | 27:29948b116e82 | 69 | } |
albireo987 | 32:537005b4a065 | 70 | } |
albireo987 | 38:47c075a354b5 | 71 | } |
albireo987 | 38:47c075a354b5 | 72 | |
albireo987 | 38:47c075a354b5 | 73 | void LEDDriver::sendData() |
albireo987 | 38:47c075a354b5 | 74 | { |
albireo987 | 38:47c075a354b5 | 75 | // 1 1 1 1 0 0 0 0 0 1 |
albireo987 | 38:47c075a354b5 | 76 | static int codedMessage0[]={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 | 77 | // 1 1 1 1 0 1 0 0 0 1 |
albireo987 | 38:47c075a354b5 | 78 | static int codedMessage1[]={1,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0}; |
albireo987 | 38:47c075a354b5 | 79 | // 1 1 1 1 1 0 1 0 0 1 |
albireo987 | 38:47c075a354b5 | 80 | static int codedMessage2[]={1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0}; |
albireo987 | 38:47c075a354b5 | 81 | // 1 1 1 1 1 1 0 0 0 1 |
albireo987 | 38:47c075a354b5 | 82 | static int codedMessage3[]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0}; |
albireo987 | 38:47c075a354b5 | 83 | static int codedMessage4[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};//default message for multithreading |
albireo987 | 38:47c075a354b5 | 84 | for(int led =0 ; led<8;led++) |
albireo987 | 38:47c075a354b5 | 85 | { |
albireo987 | 38:47c075a354b5 | 86 | for(int j =0;j<20;j++) |
albireo987 | 38:47c075a354b5 | 87 | { |
albireo987 | 38:47c075a354b5 | 88 | if(messageList[led]==0) |
albireo987 | 38:47c075a354b5 | 89 | { |
albireo987 | 38:47c075a354b5 | 90 | leds[led].write(codedMessage0[j]); |
albireo987 | 38:47c075a354b5 | 91 | ownWait(25);//100HZ |
albireo987 | 38:47c075a354b5 | 92 | } |
albireo987 | 38:47c075a354b5 | 93 | else if(messageList[led]==1) |
albireo987 | 38:47c075a354b5 | 94 | { |
albireo987 | 38:47c075a354b5 | 95 | leds[led].write(codedMessage1[j]); |
albireo987 | 38:47c075a354b5 | 96 | ownWait(25); |
albireo987 | 38:47c075a354b5 | 97 | } |
albireo987 | 38:47c075a354b5 | 98 | else if(messageList[led]==2) |
albireo987 | 38:47c075a354b5 | 99 | { |
albireo987 | 38:47c075a354b5 | 100 | leds[led].write(codedMessage2[j]); |
albireo987 | 38:47c075a354b5 | 101 | ownWait(25); |
albireo987 | 38:47c075a354b5 | 102 | } |
albireo987 | 38:47c075a354b5 | 103 | else if(messageList[led]==3) |
albireo987 | 38:47c075a354b5 | 104 | { |
albireo987 | 38:47c075a354b5 | 105 | leds[led].write(codedMessage3[j]); |
albireo987 | 38:47c075a354b5 | 106 | ownWait(25); |
albireo987 | 38:47c075a354b5 | 107 | } |
albireo987 | 38:47c075a354b5 | 108 | else if(messageList[led]==4) |
albireo987 | 38:47c075a354b5 | 109 | { |
albireo987 | 38:47c075a354b5 | 110 | leds[led].write(codedMessage4[j]); |
albireo987 | 38:47c075a354b5 | 111 | ownWait(25); |
albireo987 | 38:47c075a354b5 | 112 | } |
albireo987 | 38:47c075a354b5 | 113 | } |
albireo987 | 38:47c075a354b5 | 114 | } |
albireo987 | 6:36158325f7b0 | 115 | } |