![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp
- Committer:
- KlaasGovaerts
- Date:
- 2018-05-09
- Revision:
- 45:2d877f01ca7b
- Parent:
- 44:ffac07bff0d8
- Child:
- 47:8fe84f455571
File content as of revision 45:2d877f01ca7b:
#include "LEDDriver.h" //Serial pc(USBTX,USBRX); LEDDriver::LEDDriver( Queue<int,8>* queue) { //this->messageList=messageList; //this->leds=leds; this->queue=queue;// prep for multithreaded initArrays(); currentLocation=0; } void LEDDriver::drive(int numberOfLeds) { poll(numberOfLeds,1); poll(numberOfLeds,2); setLEDS(currentLocation); currentLocation++; if(currentLocation>=20){ currentLocation=0; } /* 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(Ticker* ticker) { ticker->attach(this,&LEDDriver::drive8leds,1);//TODO faster } void LEDDriver::drive8leds(){ drive(8); } 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==0||temp==1||temp==2||temp==3) { messageList[i]=temp; } } } else if(first==2) { for(int i =(numberOfLeds/2);i<(numberOfLeds);i++) { osEvent event = queue->get(); int temp = *((int*)event.value.p); if(temp==0||temp==1||temp==2||temp==3) { messageList[i]=temp; } } } } void LEDDriver::initArrays() { // 1 1 1 1 0 0 0 0 0 1 int tempCodedMessage0[20]={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 int tempCodedMessage1[20]={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 int tempCodedMessage2[20]={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 int tempCodedMessage3[20]={1,0,1,0,1,0,1,0,1,0,1,0,0,1,0,1,0,1,1,0}; int tempCodedMessage4[20]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};//default message for multithreading int tempMessageList[8]={4,4,4,4,4,4,4,4}; DigitalOut tempLeds[]={DigitalOut(p23),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)}; memcpy(codedMessage0,tempCodedMessage0,sizeof(codedMessage0)); memcpy(codedMessage1,tempCodedMessage1,sizeof(codedMessage1)); memcpy(codedMessage2,tempCodedMessage2,sizeof(codedMessage2)); memcpy(codedMessage3,tempCodedMessage3,sizeof(codedMessage3)); memcpy(codedMessage4,tempCodedMessage4,sizeof(codedMessage4)); memcpy(tempMessageList,messageList,sizeof(messageList)); memcpy(leds,tempLeds,sizeof(leds)); } void LEDDriver::setLEDS(int j){ for(int led =0 ; led<8;led++) { 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); } } }