RaspberrPi project source code
guowenxue
4 hours ago 3ef6cf39749c00366b12aef9f023aac3bda16f2d
project/modules/tsl2561.c
@@ -150,7 +150,6 @@
    float               div = 0.0;
    unsigned char       reg_data[REG_COUNT];
    unsigned char       buf;
    int                 chn0_data = 0;
    int                 chn1_data = 0;
@@ -173,7 +172,9 @@
    /* Read register Channel0 and channel1 data from register */
    for(i=0; i<REG_COUNT; i++)
    {
        tsl2561_readreg(fd, regs_addr[i], &reg_data[i]);
        rv = tsl2561_readreg(fd, regs_addr[i], &reg_data[i]);
        if( rv < 0)
            goto failed;
    }
    chn0_data = reg_data[1]*256 + reg_data[0]; /* Channel0 = DATA0HIGH<<8 + DATA0LOW  */
@@ -182,7 +183,7 @@
    if( chn0_data<=0 || chn1_data<0 )
    {
        rv = -2;
        goto OUT;
        goto cleanup;
    }
    div = (float)chn1_data / (float)chn0_data;
@@ -202,8 +203,10 @@
    else if( div>1.3 )
        *lux = 0.0;
OUT:
cleanup:
    tsl2561_power(fd, OFF);
failed:
    close(fd);
    return rv;
}