demo versie 16/05
Dependencies: EthernetInterface mbed-rto mbed
Fork of ProjectVLC by
Diff: LEDDriver.cpp
- Revision:
- 9:c800045806f0
- Parent:
- 8:a987e04734dd
- Child:
- 10:7871aeacea08
diff -r a987e04734dd -r c800045806f0 LEDDriver.cpp --- a/LEDDriver.cpp Sun Apr 15 19:37:01 2018 +0000 +++ b/LEDDriver.cpp Wed Apr 18 10:06:48 2018 +0000 @@ -1,89 +1,87 @@ #include "LEDDriver.h" - -LEDDriver::LEDDriver(/*Mutex* lock,*/ int sharedDirections[], int sizeOfSharedDirections) +Serial pc(USBTX,USBRX); + +LEDDriver::LEDDriver(/*Mutex* lock,*/ int* sharedDirections, int sizeOfSharedDirections) { - static int start[]={1,0,1,0,1,0,1,0}; - static int stop[]={0,1,0,1,0,1,0,1}; - static int message1[20]={0}; - static int message2[20]={0}; - static int message3[20]={0}; - static int message4[20]={0}; - static int message5[20]={0}; - static int message6[20]={0}; - static int message7[20]={0}; - static int message8[20]={0}; - static int* messageList[8]={0}; - messageList[0]=message1; - messageList[1]=message2; - messageList[2]=message3; - messageList[3]=message4; - messageList[4]=message5; - messageList[5]=message6; - messageList[6]=message7; - messageList[7]=message8; - static DigitalOut leds[]={DigitalOut(p10),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17),DigitalOut(p18),DigitalOut(p19),DigitalOut(p20)}; - this->start=start; - this->stop=stop; + static int messageList[8]={0}; + static DigitalOut leds[]={DigitalOut(p10),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)}; //this->lock=lock; this->copy=Copy(); this->messageList=messageList; this->leds=leds; - copy.copyInt(this->directions,sharedDirections,sizeOfSharedDirections); + copy.copyInt((directions),sharedDirections,sizeOfSharedDirections); } void LEDDriver::encode(int directionValue,int led) { - switch(directionValue) - { - case 0: - copy.copyInt(messageList[led],start,8); - int code0[]={0,1,0,1}; - copy.copyInt(messageList[led],code0,4,8); - copy.copyInt(messageList[led],stop,8,12); - break; - case 1: - copy.copyInt(messageList[led],start,8); - int code1[]={0,1,1,0}; - copy.copyInt(messageList[led],code1,2,8); - copy.copyInt(messageList[led],stop,8,12); - break; - case 2: - copy.copyInt(messageList[led],start,8); - int code2[]={1,0,0,1}; - copy.copyInt(messageList[led],code2,4,8); - copy.copyInt(messageList[led],stop,8,12); - break; - case 3: - copy.copyInt(messageList[led],start,8); - static int code3[]={1,0,1,0}; - copy.copyInt(messageList[led],code3,4,8); - copy.copyInt(messageList[led],stop,8,12); - break; - default: - return; - } - this->messageList[led]=messageList[led]; + if(directionValue==0) + { + messageList[led]=0; + } + else if(directionValue==1) + { + messageList[led]=1; + } + else if(directionValue==2) + { + messageList[led]=2; + } + else if(directionValue==3) + { + messageList[led]=3; + } } int LEDDriver::getDirection(int id) { - int direction = directions[id]; + int direction= directions[id]; return direction; } void LEDDriver::drive(int numberOfLeds) { - for(int j=0;j<20;j++) + int delay = 25; + encodeAll(numberOfLeds);// 1 1 1 1 0 0 0 0 0 1 + static int codedMessage0[]={1,0,1,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,1,0}; + // 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}; + while(true) { - encodeAll(numberOfLeds); - for(int i =0;i<numberOfLeds;i++) - { - int* message={messageList[j]}; - leds[i].write(message[j]); - wait_ms(0.25);//500Hz 1/500 gewenste periode 8/90MHz(#leds/fclock) basis periode dus verhouding van de perioden / Clock is uiteindelijke frequentie (grof) moet manueel - // gefinetuned worden. - } - } + for(int j=0;j<20;j++) + { + for(int i =0;i<numberOfLeds;i++) + { + if(messageList[i]==0) + { + leds[i].write(codedMessage0[j]); + pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage0[j]); + wait_ms(delay);//500Hz 1/500 gewenste periode 8/90MHz(#leds/fclock) basis periode dus verhouding van de perioden / Clock is uiteindelijke frequentie (grof) moet manueel + } // gefinetuned worden. + else if(messageList[i]==1) + { + leds[i].write(codedMessage1[j]); + pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage1[j]); + wait_ms(delay); + } + else if(messageList[i]==2) + { + leds[i].write(codedMessage2[j]); + pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage2[j]); + wait_ms(delay); + } + else if(messageList[i]==3) + { + leds[i].write(codedMessage3[j]); + pc.printf("led%d,message%d:%d\n\r",i,j,codedMessage3[j]); + wait_ms(delay); + } + } + } + } } void LEDDriver::run(int numberOfLeds)