First version

Dependencies:   mbed EthernetInterface mbed-rto

LEDDriver.cpp

Committer:
albireo987
Date:
2018-04-25
Revision:
25:1dc7dfe499fd
Parent:
10:7871aeacea08

File content as of revision 25:1dc7dfe499fd:

#include "LEDDriver.h"
    
LEDDriver::LEDDriver( int* sharedDirections, int sizeOfSharedDirections)
{
    static int messageList[8]={0};
    static DigitalOut leds[]={DigitalOut(p23),DigitalOut(p11),DigitalOut(p12),DigitalOut(p13),DigitalOut(p14),DigitalOut(p15),DigitalOut(p16),DigitalOut(p17)};
    this->copy=Copy();
    this->messageList=messageList;
    this->leds=leds;
    copy.copyInt((directions),sharedDirections,sizeOfSharedDirections);    
}

void LEDDriver::determineMessage(int directionValue,int 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;
            }
        else if(directionValue==4)
            {
                messageList[led]=4;
            }
}

int LEDDriver::getDirection(int id)
{
    int direction= directions[id];  
    return direction;
}

void LEDDriver::drive(int numberOfLeds)
{
    determineAll(numberOfLeds);//needs to be removed after multithreading
    //   1    1  1   1   0   0   0   0   0   1 links
    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  rechts
    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 rechtdoor
    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  achteruit
    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 if no directions are received yet
   while(true)
    {
      //  determineAll(numberOfLeds); prep for multithreading
        for(int j=0;j<20;j++)
        {
             for(int i =0;i<numberOfLeds;i++)
             {
                    if(messageList[i]==0)
                    {
                        leds[i].write(codedMessage0[j]);
                        ownWait(10);//100=708 HZ 10 = 7.08 kHZ
                   }
                    else if(messageList[i]==1)
                    {
                        leds[i].write(codedMessage1[j]);
                        ownWait(10);
                    }
                    else if(messageList[i]==2)
                    {
                        leds[i].write(codedMessage2[j]);
                        ownWait(10);
                    }
                    else if(messageList[i]==3)
                    {
                        leds[i].write(codedMessage3[j]);
                        ownWait(10);
                    }
                    else if(messageList[i]==4)
                    {
                        leds[i].write(codedMessage4[j]);
                        ownWait(10);
                    }
             }   
        }    
    }
}

void LEDDriver::run(int numberOfLeds)
{
    drive(numberOfLeds);
}

void LEDDriver::determineAll(int numberOfLeds)
{
    for(int i = 0;i<numberOfLeds;i++)
    {
        determineMessage(getDirection(i),i);    
    }   
}

void LEDDriver::ownWait(uint32_t us)
{
   for(uint32_t i=0;i<us;i++)
        {
            for(volatile uint32_t j =0; j <96;j++)
            {

            }
        }
}