//note this has crc bytes embedded, per datasheet, so provide 12 byte buf int SI7021::getSerialBytes(byte * buf) { _writeReg(SERIAL1_READ, sizeof SERIAL1_READ); _readReg(buf, 6); _writeReg(SERIAL2_READ, sizeof SERIAL2_READ); _readReg(buf + 6, 6); // could verify crc here and return only the 8 bytes that matter return 1; }
//note this has crc bytes embedded, per datasheet, so provide 12 byte buf int SI7021::getUIDBytes(byte * buf) { _writeReg(UID1_READ, sizeof UID1_READ); _readReg(buf, 6); _writeReg(UID2_READ, sizeof UID2_READ); _readReg(buf + 6, 6); // could verify crc here and return only the 8 bytes that matter return 1; }
void SI7021::_command(byte cmd, byte * buf ) { _writeReg(&cmd, sizeof cmd); #if defined(ARDUINO_ARCH_ESP8266) delay(25); #endif _readReg(buf, 2); }
void cSI7021::_command(uint8_t cmd, uint8_t * buf ) { _writeReg(&cmd, 1); #if defined(ARDUINO_ARCH_ESP8266) delay(25); #endif _readReg(buf, 2); }
void TCS3414::setGain(byte gain, byte prescaler) { /* switch(gain) { case GAIN_4: this->gain = 4; break; case GAIN_16: this->gain = 16; break; case GAIN_64: this->gain = 64; break; case GAIN_1: default: this->gain = 1; break; }; if (prescaler > 0) this->prescaler = 1 << prescaler; else this->prescaler = 1; */ _writeReg(REG_GAIN, gain | prescaler); }
void TCS3414::init(int mode) { switch(mode) { case TCS3414_LEVELINTERRUPTMODE: // the process below will set an interrupt each time the value of the CLEAR channel goes above 65530 (overflow, right ?) setLevelThreshold(REG_LOW_THRESH, 0x0000); setLevelThreshold(REG_HIGH_THRESH, 4000); _writeReg(REG_INT_SOURCE, INT_SOURCE_CLEAR); // set the interrupt source to the CLEAR channel break; case TCS3414_FREEMODE: default: _writeReg(REG_TIMING, INTEG_MODE_FREE | INTEG_PARAM_INTTIME_12MS); _writeReg(REG_INT, INTR_CTL_DISABLE); setGain(GAIN_1, PRESCALER_1); // set default gain value and prescaler value // _writeReg(REG_CTL, 0x03); // Enable ADCs; break; }; }
void SI7021::setHeater(bool on) { byte userbyte; if (on) { userbyte = 0x3E; } else { userbyte = 0x3A; } byte userwrite[] = {USER1_WRITE, userbyte}; _writeReg(userwrite, sizeof userwrite); }
void senselSetLEDBrightnessAll(uint8 brightness) { int i; uint8 led_buf[16]; for(i = 0; i < 16; i++) led_buf[i] = brightness; _writeReg(SENSEL_REG_LED_BRIGHTNESS, 16, led_buf); }
void TCS3414::setIntegrationTime(byte itime) { // this->itime = itime & 0x0F; _writeReg(REG_TIMING, itime); }
bool senselSetFrameContentControl(uint8 content) { return _writeReg(SENSEL_REG_SCAN_CONTENT_CONTROL, 1, &content); }
void senselSetLEDBrightness(int idx, uint8 brightness) { _writeReg(SENSEL_REG_LED_BRIGHTNESS + idx, 1, &brightness); }
bool senselStartScanning() { uint8 val = 1; return _writeReg(SENSEL_REG_SCAN_ENABLED, 1, &val); }
bool senselStopScanning(void) { uint8 val = 0; return _writeReg(SENSEL_REG_SCAN_ENABLED, 1, &val); }
// @return 0 on success, -errno on failure int writeReg(int reg, uint8_t val) { return _writeReg(reg, val); }
void TCS3414::disableADC() { _writeReg(REG_CTL, CTL_POWER); }
void TCS3414::enableADC() { _writeReg(REG_CTL, CTL_ADC_EN | CTL_POWER); }
void SI7021::_command(byte cmd, byte * buf ) { _writeReg(&cmd, sizeof cmd); delay(25); //for ESP8266 _readReg(buf, 3); // 1 - data, 2 - data, 3 - CRC }
void TCS3414::powerOn() { _writeReg(REG_CTL, CTL_POWER); }