projet_ees_et5

Fork of TSL1401 by Polytech_TP_EES_M3PI

TSL1401.cpp

Committer:
lesuperguerrier
Date:
2018-03-09
Revision:
2:a6b3b12eaaa6
Parent:
1:7a8ca2147516

File content as of revision 2:a6b3b12eaaa6:

#include "TSL1401.h"
#include "FastIO.h"
#include "FastAnalogIn.h"
/* Macro */
#define TAOS_SI_HIGH    TAOS_SI = 1
#define TAOS_SI_LOW     TAOS_SI = 0
#define TAOS_CLK_HIGH   TAOS_CLK = 1
#define TAOS_CLK_LOW    TAOS_CLK = 0

FastAnalogIn AA1(p20,0);
/* Constructor */
TSL1401::TSL1401(PinName s, PinName c, PinName a )
{

    SI = s;
    CLK = c;
    A0 = new AnalogIn( a );
}
/* Destructor */
TSL1401::~TSL1401()
{
    if( A0 != NULL)
    {
        delete  A0;
    }
}
/* Image Caputure */
int *TSL1401::Capture( int LineStart, int LineStop)
{
    int i;

    
 /*   DigitalOut TAOS_SI(SI);
    DigitalOut TAOS_CLK(CLK);
 */   
    Max = 0,Min = 70000;
    TAOS_SI_HIGH;
    TAOS_CLK_HIGH;
    TAOS_CLK_HIGH;
    TAOS_SI_LOW;
    ImageData[0] = 0;
    volatile int *pp=ImageData;
    TAOS_CLK_LOW;
 /*   for(i = 1; i < LineStart; i++) {        
        TAOS_CLK_HIGH; 
        TAOS_CLK_HIGH;           
        TAOS_CLK_LOW;
    }
*/
    for(i = LineStart; i < LineStop; i++) {                  
        TAOS_CLK_HIGH;
//        TAOS_CLK_HIGH;
        TAOS_CLK_HIGH;
 //       ImageData[i] = A0->read_u16();  // inputs data from camera (one pixel each time through loop) 
       // ImageData[i] 
            *pp = AA1.read_u16();
        TAOS_CLK_LOW;
        Max = ( Max < *pp ? *pp : Max);  
      //  Max = ( Max < ImageData[i] ? ImageData[i] : Max);  
        /*if(Max < ImageData[i]){
            Max = ImageData[i];
        } 
*/
        Min = (Min > *pp ? *pp : Min);
        pp++;
        //Min = (Min > ImageData[i] ? ImageData[i] : Min);
         
    }
    return ImageData;
}