First version

Dependencies:   mbed EthernetInterface mbed-rto

Committer:
albireo987
Date:
Sun Apr 15 19:37:01 2018 +0000
Revision:
8:a987e04734dd
Parent:
6:36158325f7b0
Child:
9:c800045806f0
corrected encoding;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
albireo987 6:36158325f7b0 1 #include "LEDDriver.h"
albireo987 6:36158325f7b0 2
albireo987 6:36158325f7b0 3 LEDDriver::LEDDriver(/*Mutex* lock,*/ int sharedDirections[], int sizeOfSharedDirections)
albireo987 6:36158325f7b0 4 {
albireo987 6:36158325f7b0 5 static int start[]={1,0,1,0,1,0,1,0};
albireo987 6:36158325f7b0 6 static int stop[]={0,1,0,1,0,1,0,1};
albireo987 6:36158325f7b0 7 static int message1[20]={0};
albireo987 6:36158325f7b0 8 static int message2[20]={0};
albireo987 6:36158325f7b0 9 static int message3[20]={0};
albireo987 6:36158325f7b0 10 static int message4[20]={0};
albireo987 6:36158325f7b0 11 static int message5[20]={0};
albireo987 6:36158325f7b0 12 static int message6[20]={0};
albireo987 6:36158325f7b0 13 static int message7[20]={0};
albireo987 6:36158325f7b0 14 static int message8[20]={0};
albireo987 6:36158325f7b0 15 static int* messageList[8]={0};
albireo987 6:36158325f7b0 16 messageList[0]=message1;
albireo987 6:36158325f7b0 17 messageList[1]=message2;
albireo987 6:36158325f7b0 18 messageList[2]=message3;
albireo987 6:36158325f7b0 19 messageList[3]=message4;
albireo987 6:36158325f7b0 20 messageList[4]=message5;
albireo987 6:36158325f7b0 21 messageList[5]=message6;
albireo987 6:36158325f7b0 22 messageList[6]=message7;
albireo987 6:36158325f7b0 23 messageList[7]=message8;
albireo987 6:36158325f7b0 24 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)};
albireo987 6:36158325f7b0 25 this->start=start;
albireo987 6:36158325f7b0 26 this->stop=stop;
albireo987 6:36158325f7b0 27 //this->lock=lock;
albireo987 6:36158325f7b0 28 this->copy=Copy();
albireo987 6:36158325f7b0 29 this->messageList=messageList;
albireo987 6:36158325f7b0 30 this->leds=leds;
albireo987 6:36158325f7b0 31 copy.copyInt(this->directions,sharedDirections,sizeOfSharedDirections);
albireo987 6:36158325f7b0 32 }
albireo987 6:36158325f7b0 33
albireo987 6:36158325f7b0 34 void LEDDriver::encode(int directionValue,int led)
albireo987 6:36158325f7b0 35 {
albireo987 6:36158325f7b0 36 switch(directionValue)
albireo987 6:36158325f7b0 37 {
albireo987 6:36158325f7b0 38 case 0:
albireo987 6:36158325f7b0 39 copy.copyInt(messageList[led],start,8);
albireo987 8:a987e04734dd 40 int code0[]={0,1,0,1};
albireo987 8:a987e04734dd 41 copy.copyInt(messageList[led],code0,4,8);
albireo987 8:a987e04734dd 42 copy.copyInt(messageList[led],stop,8,12);
albireo987 6:36158325f7b0 43 break;
albireo987 6:36158325f7b0 44 case 1:
albireo987 6:36158325f7b0 45 copy.copyInt(messageList[led],start,8);
albireo987 8:a987e04734dd 46 int code1[]={0,1,1,0};
albireo987 6:36158325f7b0 47 copy.copyInt(messageList[led],code1,2,8);
albireo987 8:a987e04734dd 48 copy.copyInt(messageList[led],stop,8,12);
albireo987 6:36158325f7b0 49 break;
albireo987 6:36158325f7b0 50 case 2:
albireo987 6:36158325f7b0 51 copy.copyInt(messageList[led],start,8);
albireo987 8:a987e04734dd 52 int code2[]={1,0,0,1};
albireo987 8:a987e04734dd 53 copy.copyInt(messageList[led],code2,4,8);
albireo987 8:a987e04734dd 54 copy.copyInt(messageList[led],stop,8,12);
albireo987 6:36158325f7b0 55 break;
albireo987 6:36158325f7b0 56 case 3:
albireo987 6:36158325f7b0 57 copy.copyInt(messageList[led],start,8);
albireo987 8:a987e04734dd 58 static int code3[]={1,0,1,0};
albireo987 8:a987e04734dd 59 copy.copyInt(messageList[led],code3,4,8);
albireo987 8:a987e04734dd 60 copy.copyInt(messageList[led],stop,8,12);
albireo987 6:36158325f7b0 61 break;
albireo987 6:36158325f7b0 62 default:
albireo987 6:36158325f7b0 63 return;
albireo987 6:36158325f7b0 64 }
albireo987 6:36158325f7b0 65 this->messageList[led]=messageList[led];
albireo987 6:36158325f7b0 66 }
albireo987 6:36158325f7b0 67
albireo987 6:36158325f7b0 68 int LEDDriver::getDirection(int id)
albireo987 6:36158325f7b0 69 {
albireo987 8:a987e04734dd 70 int direction = directions[id];
albireo987 6:36158325f7b0 71 return direction;
albireo987 6:36158325f7b0 72 }
albireo987 6:36158325f7b0 73
albireo987 6:36158325f7b0 74 void LEDDriver::drive(int numberOfLeds)
albireo987 6:36158325f7b0 75 {
albireo987 6:36158325f7b0 76 for(int j=0;j<20;j++)
albireo987 6:36158325f7b0 77 {
albireo987 6:36158325f7b0 78 encodeAll(numberOfLeds);
albireo987 6:36158325f7b0 79 for(int i =0;i<numberOfLeds;i++)
albireo987 6:36158325f7b0 80 {
albireo987 6:36158325f7b0 81 int* message={messageList[j]};
albireo987 6:36158325f7b0 82 leds[i].write(message[j]);
albireo987 6:36158325f7b0 83 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
albireo987 6:36158325f7b0 84 // gefinetuned worden.
albireo987 6:36158325f7b0 85 }
albireo987 6:36158325f7b0 86 }
albireo987 6:36158325f7b0 87 }
albireo987 6:36158325f7b0 88
albireo987 6:36158325f7b0 89 void LEDDriver::run(int numberOfLeds)
albireo987 6:36158325f7b0 90 {
albireo987 6:36158325f7b0 91 drive(numberOfLeds);
albireo987 6:36158325f7b0 92 }
albireo987 6:36158325f7b0 93
albireo987 6:36158325f7b0 94 void LEDDriver::encodeAll(int numberOfLeds)
albireo987 6:36158325f7b0 95 {
albireo987 6:36158325f7b0 96 for(int i = 0;i<numberOfLeds;i++)
albireo987 6:36158325f7b0 97 {
albireo987 6:36158325f7b0 98 encode(getDirection(i),i);
albireo987 6:36158325f7b0 99 }
albireo987 6:36158325f7b0 100 }