/** * This method sets the gain and the integration time * * If gain = false (0), device is set to low gain (1X) * If gain = high (1), device is set to high gain (16X) * If time = 0, integration will be 13.7ms * If time = 1, integration will be 101ms * If time = 2, integration will be 402ms * If time = 3, use manual start / stop * * @param gain - the gain * @param time - the time */ void TSL2561::set_timing(uint8_t gain, uint8_t time){ //! Read the timing location i2c_packet* ptr = read_timing(); //! Get timing byte if (ptr->valid_packet){ this->_timing = ptr->buffer[0]; //! Set gain (0 or 1) if (gain) this->_timing |= 0x10; else this->_timing &= ~0x10; //! Set integration time (0 to 3) this->_timing &= ~0x03; this->_timing |= (time & 0x03); //! Write the timing back write_timing(); } return; }
/** * This method starts a manual integration period. * * @return - if the command was successful */ bool TSL2561::manual_start(void){ //! We read i2c_packet* ptr = read_timing(); //! Get timing byte if (ptr->valid_packet){ //! Set integration time to 3 (manual integration) this->_timing |= 0x03; if (write_timing()){ //! Begin manual integration this->_timing |= 0x08; //! Write modified timing byte back to device if (write_timing()) return true; } } return false; }
/** * This method stops a manual integration period. * * @return bool - if the command was successful */ bool TSL2561::manual_stop(void){ //! We read i2c_packet* ptr = read_timing(); //! Get timing byte if (ptr->valid_packet){ //! Stop manual integration this->_timing &= ~0x08; //! Write modified timing byte back to device if (write_timing()) return true; } return false; }
/** * Print timing information to all streams * * @param warmDeltaT warmup time (sec) * @param sampleDeltaT sample time (sec) */ void write_timing(double warmDeltaT, double sampleDeltaT) { write_timing(warmDeltaT, sampleDeltaT, sample_writer_); write_timing(warmDeltaT, sampleDeltaT, diagnostic_writer_); write_timing(warmDeltaT, sampleDeltaT, message_writer_); }