Ejemplo n.º 1
0
int TSL2561_INTR_HIGH_THRESHOLD(TSL2561 *sensor, uint16_t threshold)
{
	int rc;
	
	rc = tsl2561_write16(sensor, TSL2561_COMMAND_BIT | TSL2561_WORD_BIT | TSL2561_REGISTER_THRESHHOLDH_LOW, threshold);

	if (rc != 0) // invalid read or sensor error
		return -1;
	else
		return 0;
}
Ejemplo n.º 2
0
/**
 * Sets the upper and lower interrupt thresholds
 *
 * @param The sensor interface
 * @param rate    Sets the rate of interrupts to the host processor:
 *                - 0   Every ADC cycle generates interrupt
 *                - 1   Any value outside of threshold range
 *                - 2   2 integration time periods out of range
 *                - 3   3 integration time periods out of range
 *                - 4   4 integration time periods out of range
 *                - 5   5 integration time periods out of range
 *                - 6   6 integration time periods out of range
 *                - 7   7 integration time periods out of range
 *                - 8   8 integration time periods out of range
 *                - 9   9 integration time periods out of range
 *                - 10  10 integration time periods out of range
 *                - 11  11 integration time periods out of range
 *                - 12  12 integration time periods out of range
 *                - 13  13 integration time periods out of range
 *                - 14  14 integration time periods out of range
 *                - 15  15 integration time periods out of range
 * @param lower   The lower threshold
 * @param upper   The upper threshold
 *
 * @return 0 on success, non-zero on failure
 */
int
tsl2561_setup_interrupt(struct sensor_itf *itf, uint8_t rate, uint16_t lower,
                        uint16_t upper)
{
    int rc;
    uint8_t intval;

    /* Set lower threshold */
    rc = tsl2561_write16(itf, TSL2561_COMMAND_BIT | TSL2561_WORD_BIT |
                         TSL2561_REGISTER_THRESHHOLDL_LOW, lower);
    if (rc) {
        goto err;
    }

    /* Set upper threshold */
    rc = tsl2561_write16(itf, TSL2561_COMMAND_BIT | TSL2561_WORD_BIT |
                         TSL2561_REGISTER_THRESHHOLDH_LOW, upper);
    if (rc) {
        goto err;
    }

    /* Set rate */
    rc = tsl2561_read8(itf, TSL2561_COMMAND_BIT | TSL2561_REGISTER_INTERRUPT,
                       &intval);
    if (rc) {
        goto err;
    }
    /* Maintain the INTR Control Select bits */
    rate = (intval & 0xF0) | (rate & 0xF);
    rc = tsl2561_write8(itf, TSL2561_COMMAND_BIT | TSL2561_REGISTER_INTERRUPT,
                        rate);
    if (rc) {
        goto err;
    }

    return 0;
err:
    return rc;
}