| | |
| | | float div = 0.0; |
| | | |
| | | unsigned char reg_data[REG_COUNT]; |
| | | unsigned char buf; |
| | | int chn0_data = 0; |
| | | int chn1_data = 0; |
| | | |
| | |
| | | /* Read register Channel0 and channel1 data from register */ |
| | | for(i=0; i<REG_COUNT; i++) |
| | | { |
| | | tsl2561_readreg(fd, regs_addr[i], ®_data[i]); |
| | | rv = tsl2561_readreg(fd, regs_addr[i], ®_data[i]); |
| | | if( rv < 0) |
| | | goto failed; |
| | | } |
| | | |
| | | chn0_data = reg_data[1]*256 + reg_data[0]; /* Channel0 = DATA0HIGH<<8 + DATA0LOW */ |
| | |
| | | if( chn0_data<=0 || chn1_data<0 ) |
| | | { |
| | | rv = -2; |
| | | goto OUT; |
| | | goto cleanup; |
| | | } |
| | | |
| | | div = (float)chn1_data / (float)chn0_data; |
| | |
| | | else if( div>1.3 ) |
| | | *lux = 0.0; |
| | | |
| | | OUT: |
| | | cleanup: |
| | | tsl2561_power(fd, OFF); |
| | | |
| | | failed: |
| | | close(fd); |
| | | return rv; |
| | | } |