First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp
- Committer:
- KlaasGovaerts
- Date:
- 2018-05-02
- Revision:
- 43:eaa8348f1150
- Parent:
- 38:47c075a354b5
File content as of revision 43:eaa8348f1150:
#include "LEDDriver.h" Serial pc(USBTX,USBRX); LEDDriver::LEDDriver( Queue<int,8>* queue) { static int messageList[8]={4,4,4,4,4,4,4,4}; static DigitalOut leds[]={DigitalOut(p23),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)}; this->messageList=messageList; this->leds=leds; this->queue=queue;// prep for multithreaded } void LEDDriver::drive(int numberOfLeds) { poll(numberOfLeds,1) ; poll(numberOfLeds,2) ; Ticker ticker; while(true) { poll(numberOfLeds,1) ;//prep multi //for(int i =0;i<numberOfLeds;i++) //{ //ticker.attach(this,&LEDDriver::sendData,0.000625f); //} poll(numberOfLeds,2) ; } } void LEDDriver::run(int numberOfLeds) { drive(numberOfLeds); } void LEDDriver::ownWait(uint32_t us) { for(uint32_t i=0;i<us;i++) { for(volatile uint32_t j =0; j <3;j++) { } } } void LEDDriver::poll(int numberOfLeds,int first) { if(first==1) { for(int i =0;i<(numberOfLeds/2);i++) { //osEvent event = queue->get(); //int temp = *((int*)event.value.p); //if(temp==1||temp==1||temp==2||temp==3) { messageList[i]=1; } } } else if(first==2) { for(int i =(numberOfLeds/2);i<(numberOfLeds);i++) { //osEvent event = queue->get(); //int temp = *((int*)event.value.p); //if(temp==1||temp==1||temp==2||temp==3) { messageList[i]=1; } } } } void LEDDriver::sendData() { // 1 1 1 1 0 0 0 0 0 1 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) // 1 1 1 1 0 1 0 0 0 1 static int codedMessage1[]={1,0,1,0,1,0,1,0,0,1,1,0,0,1,0,1,0,1,1,0}; // 1 1 1 1 1 0 1 0 0 1 static int codedMessage2[]={1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,1,0}; // 1 1 1 1 1 1 0 0 0 1 static int codedMessage3[]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0}; 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 for(int led =0 ; led<8;led++) { for(int j =0;j<20;j++) { if(messageList[led]==0) { leds[led].write(codedMessage0[j]); ownWait(25);//100HZ } else if(messageList[led]==1) { leds[led].write(codedMessage1[j]); ownWait(25); } else if(messageList[led]==2) { leds[led].write(codedMessage2[j]); ownWait(25); } else if(messageList[led]==3) { leds[led].write(codedMessage3[j]); ownWait(25); } else if(messageList[led]==4) { leds[led].write(codedMessage4[j]); ownWait(25); } } } }