change tsl code to easily get values
This commit is contained in:
parent
a037d80c5d
commit
8798202171
|
@ -1,7 +1,7 @@
|
|||
// Code from the following github repo: https://github.com/ControlEverythingCommunity/TSL2561/blob/master/C/TSL2561.c
|
||||
#include "include/TSL2561.h"
|
||||
|
||||
void getLux(int file)
|
||||
void printSpectrum(int file)
|
||||
{
|
||||
// Read 4 bytes of data from register(0x0C | 0x80)
|
||||
// ch0 lsb, ch0 msb, ch1 lsb, ch1 msb
|
||||
|
@ -15,13 +15,50 @@ void getLux(int file)
|
|||
else
|
||||
{
|
||||
// Convert the data
|
||||
float ch0 = (data[1] * 256 + data[0]);
|
||||
float ch1 = (data[3] * 256 + data[2]);
|
||||
|
||||
float ch0 = (data[1] * 256 + data[0]); //Full Spectrum(IR + Visible)
|
||||
float ch1 = (data[3] * 256 + data[2]); //Infrared Value
|
||||
// Output data to screen
|
||||
printf("Full Spectrum(IR + Visible) : %.2f lux \n", ch0);
|
||||
printf("Infrared Value : %.2f lux \n", ch1);
|
||||
printf("Visible Value : %.2f lux \n", (ch0 - ch1));
|
||||
printf("Full Spectrum(IR + Visible) : %.1f lux \n", ch0);
|
||||
printf("Infrared Value : %.1f lux \n", ch1);
|
||||
printf("Visible Value : %.1f lux \n", (ch0 - ch1));
|
||||
}
|
||||
}
|
||||
|
||||
float getFullSpectrum(int file)
|
||||
{
|
||||
// Read 4 bytes of data from register(0x0C | 0x80)
|
||||
// ch0 lsb, ch0 msb, ch1 lsb, ch1 msb
|
||||
char reg[1] = {0x0C | 0x80};
|
||||
write(file, reg, 1);
|
||||
char data[4] = {0};
|
||||
if(read(file, data, 4) != 4)
|
||||
{
|
||||
printf("Erorr : Input/output Erorr \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert the data
|
||||
float ch0 = (data[1] * 256 + data[0]); //Full Spectrum(IR + Visible)
|
||||
return ch0;
|
||||
}
|
||||
}
|
||||
|
||||
float getInfraredLight(int file)
|
||||
{
|
||||
// Read 4 bytes of data from register(0x0C | 0x80)
|
||||
// ch0 lsb, ch0 msb, ch1 lsb, ch1 msb
|
||||
char reg[1] = {0x0C | 0x80};
|
||||
write(file, reg, 1);
|
||||
char data[4] = {0};
|
||||
if(read(file, data, 4) != 4)
|
||||
{
|
||||
printf("Erorr : Input/output Erorr \n");
|
||||
}
|
||||
else
|
||||
{
|
||||
// Convert the data
|
||||
float ch1 = (data[3] * 256 + data[2]); //Infrared Value
|
||||
return ch1;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +95,11 @@ void TSL2561()
|
|||
while(1)
|
||||
{
|
||||
sleep(1/fe);
|
||||
getLux(file);
|
||||
float a = getFullSpectrum(file);
|
||||
float b = getInfraredLight(file);
|
||||
printf("%.1f\n",a);
|
||||
printf("%.1f\n",b);
|
||||
printSpectrum(file);
|
||||
}
|
||||
}
|
||||
void main(){
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
long **getRawDataArray(char *rawDataFileName, int N , int M);
|
||||
void printArrayData(long** p, int N, int M);
|
||||
void freeArray(long **p, int N);
|
||||
bool checkArrayFullyFill(long **p, int N );
|
|
@ -8,5 +8,7 @@
|
|||
|
||||
char *bus = "/dev/i2c-1";
|
||||
|
||||
void getLux(int file);
|
||||
void printSpectrum(int file);
|
||||
float getFullSpectrum(int file);
|
||||
float getInfraredLight(int file);
|
||||
int init_TSL2561(char *bus);
|
||||
|
|
Loading…
Reference in a new issue