Skip to content

added saturation check functions #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions Adafruit_AS7341.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,12 +720,35 @@ bool Adafruit_AS7341::spectralHighTriggered(void) {
bool Adafruit_AS7341::getIsDataReady() {
Adafruit_BusIO_Register status2_reg =
Adafruit_BusIO_Register(i2c_dev, AS7341_STATUS2);
Adafruit_BusIO_RegisterBits avalid_bit =
Adafruit_BusIO_RegisterBits(&status2_reg, 1, 6);
uint8_t sreg2 = status2_reg.read();
_saturationState =
sreg2 & (AS7341_DIGITAL_SATURATION_MSK | AS7341_ANALOG_SATURATION_MSK);

return avalid_bit.read();
return sreg2 & 0x01<<6;
}

/**
* @brief Retruns true if the analog sensor is saturated. This may happen if
* the gain is too high. Result is valid for the most recent completed read.
*
* @return true: analog sensor has saturated false: has not saturated
*/
bool Adafruit_AS7341::getIsAnalogSaturated() {
return _saturationState & AS7341_ANALOG_SATURATION_MSK;
}

/**
* @brief Returns true if the digital count has saturated. This may happen if
* the integration time too high. Result is valid for the most recent
* completed read.
*
* @return true: Digital count has saturated false: has not saturated
*/
bool Adafruit_AS7341::getIsDigitalSaturated() {
return _saturationState & AS7341_DIGITAL_SATURATION_MSK;
}


/**
* @brief Configure SMUX for sensors F1-4, Clear and NIR
*
Expand Down
9 changes: 9 additions & 0 deletions Adafruit_AS7341.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
#define AS7341_SPECTRAL_INT_LOW_MSK \
0b00010000 ///< bitmask to check for a low threshold interrupt

#define AS7341_ANALOG_SATURATION_MSK \
1<<3 ///<bitmask to check for sensor saturation
#define AS7341_DIGITAL_SATURATION_MSK \
1<<4 ///<bitmask to check for digital count saturation

/**
* @brief Allowable gain multipliers for `setGain`
*
Expand Down Expand Up @@ -325,6 +330,9 @@ class Adafruit_AS7341 {
bool getGPIOValue(void);
bool setGPIOValue(bool);

bool Adafruit_AS7341::getIsDigitalSaturated();
bool Adafruit_AS7341::getIsAnalogSaturated();

protected:
virtual bool _init(int32_t sensor_id);
uint8_t last_spectral_int_source =
Expand All @@ -342,6 +350,7 @@ class Adafruit_AS7341 {
void writeRegister(byte addr, byte val);
void setSMUXLowChannels(bool f1_f4);
uint16_t _channel_readings[12];
uint8_t _saturationState;
as7341_waiting_t _readingState;
};

Expand Down