Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 148 → Rev 154

/PIC Stuff/PIC_27J13/lux_TSL2561.c
33,8 → 33,8
DBG_PRINT_LUX("\r\n");
 
// Set default integration time and gain
LUX_SetTiming(tsl2561_data_p->integration);
LUX_SetGain(tsl2561_data_p->gain);
LUX_Set_Timing(tsl2561_data_p->integration);
LUX_Set_Gain(tsl2561_data_p->gain);
 
// Start the chip in power-down mode
LUX_Disable();
41,30 → 41,30
}
 
void LUX_Enable() {
LUX_Write2Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON);
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWERON);
}
 
void LUX_Disable() {
LUX_Write2Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF);
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_CONTROL, TSL2561_CONTROL_POWEROFF);
}
 
void LUX_SetGain(tsl2561Gain_t gain) {
void LUX_Set_Gain(tsl2561Gain_t gain) {
LUX_Enable();
tsl2561_data_p->gain = gain;
LUX_Write2Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data_p->integration | tsl2561_data_p->gain);
LUX_Disable();
}
 
void LUX_SetTiming(tsl2561IntegrationTime_t integration) {
void LUX_Set_Timing(tsl2561IntegrationTime_t integration) {
LUX_Enable();
tsl2561_data_p->integration = integration;
LUX_Write2Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
LUX_Write_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_REGISTER_TIMING,
tsl2561_data_p->integration | tsl2561_data_p->gain);
LUX_Disable();
}
 
unsigned long LUX_CalculateLux(unsigned int ch0, unsigned int ch1) {
unsigned long LUX_Calculate_Lux(unsigned int ch0, unsigned int ch1) {
unsigned long chScale, channel0, channel1, ratio1, ratio, temp, lux;
unsigned int b, m;
 
149,7 → 149,7
return lux;
}
 
unsigned long LUX_GetFullLuminosity() {
unsigned long LUX_Get_Full_Luminosity() {
unsigned long x;
 
// Enable the device by setting the control bit to 0x03
176,9 → 176,9
break;
}
 
x = LUX_Read2Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
x = LUX_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN1_LOW);
x <<= 16;
x |= LUX_Read2Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
x |= LUX_Read_2_Bytes(TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_CHAN0_LOW);
 
LUX_Disable();
 
185,8 → 185,8
return x;
}
 
unsigned int LUX_GetLuminosity(unsigned char channel) {
unsigned long x = LUX_GetFullLuminosity();
unsigned int LUX_Get_Luminosity(unsigned char channel) {
unsigned long x = LUX_Get_Full_Luminosity();
 
if (channel == 0) {
// Reads two byte value from channel 0 (visible + infrared)
203,7 → 203,7
return 0;
}
 
void LUX_Write2Bytes(unsigned char reg, unsigned char value) {
void LUX_Write_2_Bytes(unsigned char reg, unsigned char value) {
unsigned char buffer[2], result;
buffer[0] = reg;
buffer[1] = value;
213,7 → 213,7
} while (!result);
}
 
unsigned int LUX_Read2Bytes(unsigned char reg) {
unsigned int LUX_Read_2_Bytes(unsigned char reg) {
unsigned char result, length, buffer[2];
unsigned int ret;