Skip to content

Commit

Permalink
Removing delay() use from SGP41 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
precurse committed Jun 19, 2023
1 parent f629aa7 commit fc0ef41
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 349 deletions.
2 changes: 1 addition & 1 deletion I2CDEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ Index | Define | Driver | Device | Address(es) | Description
79 | USE_GDK101 | xsns_106 | GDK101 | 0x18 - 0x1B | Gamma Radiation Sensor
80 | USE_TC74 | xsns_108 | TC74 | 0x48 - 0x4F | Temperature sensor
81 | USE_PCA9557 | xdrv_69 | PCA95xx | 0x18 - 0x1F | 8-bit I/O expander as virtual button/switch/relay
109 | USE_SGP41 | xsns_109 | SGP41 | 0x59 | Gas (TVOC/NOx index)
82 | USE_SGP41 | xsns_109 | SGP41 | 0x59 | Gas (TVOC/NOx index)
150 changes: 0 additions & 150 deletions lib/lib_i2c/arduino-i2c-sgp41/src/SensirionI2CSgp40.cpp

This file was deleted.

113 changes: 0 additions & 113 deletions lib/lib_i2c/arduino-i2c-sgp41/src/SensirionI2CSgp40.h

This file was deleted.

54 changes: 26 additions & 28 deletions lib/lib_i2c/arduino-i2c-sgp41/src/SensirionI2CSgp41.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
/*
* THIS FILE IS AUTOMATICALLY GENERATED
*
* I2C-Generator: 0.3.0
* Yaml Version: 0.1.0
* Template Version: 0.7.0-62-g3d691f9
*/
/*
* Copyright (c) 2021, Sensirion AG
* Copyright (c) 2023, Andrew Klaus (Removing delay functions)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -50,9 +44,8 @@ void SensirionI2CSgp41::begin(TwoWire& i2cBus) {
_i2cBus = &i2cBus;
}

uint16_t SensirionI2CSgp41::executeConditioning(uint16_t defaultRh,
uint16_t defaultT,
uint16_t& srawVoc) {
uint16_t SensirionI2CSgp41::sendConditioningCmd(uint16_t defaultRh,
uint16_t defaultT) {
uint16_t error;
uint8_t buffer[8];
SensirionI2CTxFrame txFrame =
Expand All @@ -66,11 +59,13 @@ uint16_t SensirionI2CSgp41::executeConditioning(uint16_t defaultRh,

error = SensirionI2CCommunication::sendFrame(SGP41_I2C_ADDRESS, txFrame,
*_i2cBus);
if (error) {
return error;
}
return error;
}

delay(50);
uint16_t SensirionI2CSgp41::readConditioningValue(uint16_t& srawVoc){
// This must run at least 50ms after initiateConditioning
uint16_t error;
uint8_t buffer[8];

SensirionI2CRxFrame rxFrame(buffer, 8);
error = SensirionI2CCommunication::receiveFrame(SGP41_I2C_ADDRESS, 3,
Expand All @@ -83,10 +78,8 @@ uint16_t SensirionI2CSgp41::executeConditioning(uint16_t defaultRh,
return error;
}

uint16_t SensirionI2CSgp41::measureRawSignals(uint16_t relativeHumidity,
uint16_t temperature,
uint16_t& srawVoc,
uint16_t& srawNox) {
uint16_t SensirionI2CSgp41::sendRawSignalsCmd(uint16_t relativeHumidity,
uint16_t temperature) {
uint16_t error;
uint8_t buffer[8];
SensirionI2CTxFrame txFrame =
Expand All @@ -100,13 +93,16 @@ uint16_t SensirionI2CSgp41::measureRawSignals(uint16_t relativeHumidity,

error = SensirionI2CCommunication::sendFrame(SGP41_I2C_ADDRESS, txFrame,
*_i2cBus);
if (error) {
return error;
}
return error;
}

delay(50);
uint16_t SensirionI2CSgp41::readRawSignalsValue(uint16_t& srawVoc,
uint16_t& srawNox) {
// This must run 50ms after initiateRawSignals

SensirionI2CRxFrame rxFrame(buffer, 8);
uint16_t error;
uint8_t buffer[6];
SensirionI2CRxFrame rxFrame(buffer, 6);
error = SensirionI2CCommunication::receiveFrame(SGP41_I2C_ADDRESS, 6,
rxFrame, *_i2cBus);
if (error) {
Expand All @@ -118,19 +114,21 @@ uint16_t SensirionI2CSgp41::measureRawSignals(uint16_t relativeHumidity,
return error;
}

uint16_t SensirionI2CSgp41::executeSelfTest(uint16_t& testResult) {
uint16_t SensirionI2CSgp41::sendSelfTestCmd() {
uint16_t error;
uint8_t buffer[3];
SensirionI2CTxFrame txFrame =
SensirionI2CTxFrame::createWithUInt16Command(0x280E, buffer, 3);

error = SensirionI2CCommunication::sendFrame(SGP41_I2C_ADDRESS, txFrame,
*_i2cBus);
if (error) {
return error;
}
return error;
}

delay(320);
uint16_t SensirionI2CSgp41::readSelfTestValue(uint16_t& testResult) {
// Must run 320ms after initiateSelfTest
uint16_t error;
uint8_t buffer[3];

SensirionI2CRxFrame rxFrame(buffer, 3);
error = SensirionI2CCommunication::receiveFrame(SGP41_I2C_ADDRESS, 3,
Expand Down
Loading

0 comments on commit fc0ef41

Please sign in to comment.