![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
First version
Dependencies: mbed EthernetInterface mbed-rto
LEDDriver.cpp
- Committer:
- KlaasGovaerts
- Date:
- 2018-05-15
- Revision:
- 71:5e8ba1357442
- Parent:
- 68:8b42082accc2
- Child:
- 72:d870f5503783
File content as of revision 71:5e8ba1357442:
#include "LEDDriver.h" DigitalOut led2(LED2); LEDDriver::LEDDriver( Queue<int,1>* queue) { this->queue=queue; initArrays(); currentLocation=0; } void LEDDriver::drive(int numberOfLeds) { if(currentLocation==0){ poll(numberOfLeds); } led2!=led2; setLEDS(currentLocation); currentLocation++; if(currentLocation>=25){ currentLocation=0; } } void LEDDriver::drive8leds(){ drive(8); } void LEDDriver::poll(int numberOfLeds) { osEvent event = queue->get(); if (event.status == osEventMessage){ int* LEDarray = ((int*)event.value.p); memcpy(messageList,LEDarray,8*sizeof(int)); free(LEDarray); } } void LEDDriver::initArrays() { 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) 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}; 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}; 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}; 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}; int tempMessageList[8]={4,4,4,4,4,4,4,4}; 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)}; 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(messageList,tempMessageList,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]); } else if(messageList[led]==1) { leds[led]->write(codedMessage1[j]); } else if(messageList[led]==2) { leds[led]->write(codedMessage2[j]); } else if(messageList[led]==3) { leds[led]->write(codedMessage3[j]); } else if(messageList[led]==4||messageList[led]==-1) { leds[led]->write(codedMessage4[j]); } } } LEDDriver::~LEDDriver(){ for(int i=0;i<8;i++){ delete leds[i]; } }