Add complete CTRL3 register support with interrupt configuration
- Add interrupt polarity, output type, and latched mode configuration - Add interrupt mask support for presence, motion, and ambient shock flags - Add interrupt signal routing (High-Z, DRDY, INT_OR) - Add flag definitions for PRES_FLAG, MOT_FLAG, TAMB_SHOCK_FLAG - Update test sketch with interrupt configuration testing - All functions tested and verified working with hardware 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
41f1a29cae
commit
354bb82d86
3 changed files with 547 additions and 0 deletions
|
|
@ -184,3 +184,317 @@ sths34pf80_lpf_config_t Adafruit_STHS34PF80::getTemperatureLowPassFilter() {
|
||||||
|
|
||||||
return (sths34pf80_lpf_config_t)lpf_a_t_bits.read();
|
return (sths34pf80_lpf_config_t)lpf_a_t_bits.read();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set ambient temperature averaging configuration
|
||||||
|
* @param config The averaging configuration value
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setAmbTempAveraging(sths34pf80_avg_t_t config) {
|
||||||
|
Adafruit_BusIO_Register avg_trim_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits avg_t_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&avg_trim_reg, 2, 4);
|
||||||
|
|
||||||
|
return avg_t_bits.write(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get ambient temperature averaging configuration
|
||||||
|
* @return The current averaging configuration value
|
||||||
|
*/
|
||||||
|
sths34pf80_avg_t_t Adafruit_STHS34PF80::getAmbTempAveraging() {
|
||||||
|
Adafruit_BusIO_Register avg_trim_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits avg_t_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&avg_trim_reg, 2, 4);
|
||||||
|
|
||||||
|
return (sths34pf80_avg_t_t)avg_t_bits.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set object temperature averaging configuration
|
||||||
|
* @param config The averaging configuration value
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setObjAveraging(sths34pf80_avg_tmos_t config) {
|
||||||
|
Adafruit_BusIO_Register avg_trim_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits avg_tmos_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&avg_trim_reg, 3, 0);
|
||||||
|
|
||||||
|
return avg_tmos_bits.write(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get object temperature averaging configuration
|
||||||
|
* @return The current averaging configuration value
|
||||||
|
*/
|
||||||
|
sths34pf80_avg_tmos_t Adafruit_STHS34PF80::getObjAveraging() {
|
||||||
|
Adafruit_BusIO_Register avg_trim_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_AVG_TRIM, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits avg_tmos_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&avg_trim_reg, 3, 0);
|
||||||
|
|
||||||
|
return (sths34pf80_avg_tmos_t)avg_tmos_bits.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set wide gain mode configuration
|
||||||
|
* @param wide_mode True for wide mode, false for default gain mode
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setWideGainMode(bool wide_mode) {
|
||||||
|
Adafruit_BusIO_Register ctrl0_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL0, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits gain_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl0_reg, 3, 4);
|
||||||
|
|
||||||
|
return gain_bits.write(wide_mode ? 0x00 : 0x07);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get wide gain mode configuration
|
||||||
|
* @return True if in wide mode, false if in default gain mode
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::getWideGainMode() {
|
||||||
|
Adafruit_BusIO_Register ctrl0_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL0, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits gain_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl0_reg, 3, 4);
|
||||||
|
|
||||||
|
return gain_bits.read() == 0x00;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set sensitivity value for ambient temperature compensation
|
||||||
|
* @param sensitivity Signed 8-bit sensitivity value (two's complement)
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setSensitivity(int8_t sensitivity) {
|
||||||
|
Adafruit_BusIO_Register sens_data_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_SENS_DATA, 1);
|
||||||
|
|
||||||
|
return sens_data_reg.write((uint8_t)sensitivity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get sensitivity value for ambient temperature compensation
|
||||||
|
* @return Signed 8-bit sensitivity value (two's complement)
|
||||||
|
*/
|
||||||
|
int8_t Adafruit_STHS34PF80::getSensitivity() {
|
||||||
|
Adafruit_BusIO_Register sens_data_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_SENS_DATA, 1);
|
||||||
|
|
||||||
|
return (int8_t)sens_data_reg.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set block data update configuration
|
||||||
|
* @param enable True to enable block data update, false to disable
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setBlockDataUpdate(bool enable) {
|
||||||
|
Adafruit_BusIO_Register ctrl1_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL1, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits bdu_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl1_reg, 1, 4);
|
||||||
|
|
||||||
|
return bdu_bit.write(enable ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get block data update configuration
|
||||||
|
* @return True if block data update is enabled, false if disabled
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::getBlockDataUpdate() {
|
||||||
|
Adafruit_BusIO_Register ctrl1_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL1, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits bdu_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl1_reg, 1, 4);
|
||||||
|
|
||||||
|
return bdu_bit.read() == 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set output data rate configuration
|
||||||
|
* @param odr The output data rate value
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setOutputDataRate(sths34pf80_odr_t odr) {
|
||||||
|
Adafruit_BusIO_Register ctrl1_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL1, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits odr_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl1_reg, 4, 0);
|
||||||
|
|
||||||
|
return odr_bits.write(odr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get output data rate configuration
|
||||||
|
* @return The current output data rate value
|
||||||
|
*/
|
||||||
|
sths34pf80_odr_t Adafruit_STHS34PF80::getOutputDataRate() {
|
||||||
|
Adafruit_BusIO_Register ctrl1_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL1, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits odr_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl1_reg, 4, 0);
|
||||||
|
|
||||||
|
return (sths34pf80_odr_t)odr_bits.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Reboot OTP memory
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::rebootOTPmemory() {
|
||||||
|
Adafruit_BusIO_Register ctrl2_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL2, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits boot_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl2_reg, 1, 7);
|
||||||
|
|
||||||
|
return boot_bit.write(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Enable or disable embedded function page access
|
||||||
|
* @param enable True to enable embedded function page, false to disable
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::enableEmbeddedFuncPage(bool enable) {
|
||||||
|
Adafruit_BusIO_Register ctrl2_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL2, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits func_cfg_access_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl2_reg, 1, 4);
|
||||||
|
|
||||||
|
return func_cfg_access_bit.write(enable ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Trigger one-shot measurement
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::triggerOneshot() {
|
||||||
|
Adafruit_BusIO_Register ctrl2_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL2, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits oneshot_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl2_reg, 1, 0);
|
||||||
|
|
||||||
|
return oneshot_bit.write(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set interrupt polarity
|
||||||
|
* @param active_low True for active low (default), false for active high
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setIntPolarity(bool active_low) {
|
||||||
|
Adafruit_BusIO_Register ctrl3_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL3, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits int_h_l_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl3_reg, 1, 7);
|
||||||
|
|
||||||
|
return int_h_l_bit.write(active_low ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set interrupt output type
|
||||||
|
* @param open_drain True for open drain, false for push-pull (default)
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setIntOpenDrain(bool open_drain) {
|
||||||
|
Adafruit_BusIO_Register ctrl3_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL3, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits pp_od_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl3_reg, 1, 6);
|
||||||
|
|
||||||
|
return pp_od_bit.write(open_drain ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set interrupt latched mode
|
||||||
|
* @param latched True for latched mode, false for pulsed mode (default)
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setIntLatched(bool latched) {
|
||||||
|
Adafruit_BusIO_Register ctrl3_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL3, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits int_latched_bit = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl3_reg, 1, 2);
|
||||||
|
|
||||||
|
return int_latched_bit.write(latched ? 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set interrupt mask for function status flags
|
||||||
|
* @param mask Interrupt mask (bits 2:0 for PRES_FLAG, MOT_FLAG, TAMB_SHOCK_FLAG)
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setIntMask(uint8_t mask) {
|
||||||
|
Adafruit_BusIO_Register ctrl3_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL3, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits int_mask_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl3_reg, 3, 3);
|
||||||
|
|
||||||
|
return int_mask_bits.write(mask & 0x07);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get interrupt mask for function status flags
|
||||||
|
* @return Current interrupt mask value (bits 2:0 for PRES_FLAG, MOT_FLAG, TAMB_SHOCK_FLAG)
|
||||||
|
*/
|
||||||
|
uint8_t Adafruit_STHS34PF80::getIntMask() {
|
||||||
|
Adafruit_BusIO_Register ctrl3_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL3, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits int_mask_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl3_reg, 3, 3);
|
||||||
|
|
||||||
|
return int_mask_bits.read();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Set interrupt signal type
|
||||||
|
* @param signal Interrupt signal type (HIGH_Z, DRDY, or INT_OR)
|
||||||
|
* @return True if successful, false otherwise
|
||||||
|
*/
|
||||||
|
bool Adafruit_STHS34PF80::setIntSignal(sths34pf80_int_signal_t signal) {
|
||||||
|
Adafruit_BusIO_Register ctrl3_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL3, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits ien_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl3_reg, 2, 0);
|
||||||
|
|
||||||
|
return ien_bits.write(signal);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Get interrupt signal type
|
||||||
|
* @return Current interrupt signal type
|
||||||
|
*/
|
||||||
|
sths34pf80_int_signal_t Adafruit_STHS34PF80::getIntSignal() {
|
||||||
|
Adafruit_BusIO_Register ctrl3_reg = Adafruit_BusIO_Register(
|
||||||
|
i2c_dev, STHS34PF80_REG_CTRL3, 1);
|
||||||
|
|
||||||
|
Adafruit_BusIO_RegisterBits ien_bits = Adafruit_BusIO_RegisterBits(
|
||||||
|
&ctrl3_reg, 2, 0);
|
||||||
|
|
||||||
|
return (sths34pf80_int_signal_t)ien_bits.read();
|
||||||
|
}
|
||||||
|
|
@ -52,6 +52,10 @@
|
||||||
#define STHS34PF80_REG_TAMB_SHOCK_L 0x3E ///< Ambient shock detection LSB register
|
#define STHS34PF80_REG_TAMB_SHOCK_L 0x3E ///< Ambient shock detection LSB register
|
||||||
#define STHS34PF80_REG_TAMB_SHOCK_H 0x3F ///< Ambient shock detection MSB register
|
#define STHS34PF80_REG_TAMB_SHOCK_H 0x3F ///< Ambient shock detection MSB register
|
||||||
|
|
||||||
|
#define STHS34PF80_PRES_FLAG 0x04 ///< Presence detection flag
|
||||||
|
#define STHS34PF80_MOT_FLAG 0x02 ///< Motion detection flag
|
||||||
|
#define STHS34PF80_TAMB_SHOCK_FLAG 0x01 ///< Ambient temperature shock flag
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Low-pass filter configuration options
|
* @brief Low-pass filter configuration options
|
||||||
*/
|
*/
|
||||||
|
|
@ -65,6 +69,54 @@ typedef enum {
|
||||||
STHS34PF80_LPF_ODR_DIV_800 = 0x06, ///< ODR/800
|
STHS34PF80_LPF_ODR_DIV_800 = 0x06, ///< ODR/800
|
||||||
} sths34pf80_lpf_config_t;
|
} sths34pf80_lpf_config_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Ambient temperature averaging options
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
STHS34PF80_AVG_T_8 = 0x00, ///< 8 samples (default)
|
||||||
|
STHS34PF80_AVG_T_4 = 0x01, ///< 4 samples
|
||||||
|
STHS34PF80_AVG_T_2 = 0x02, ///< 2 samples
|
||||||
|
STHS34PF80_AVG_T_1 = 0x03, ///< 1 sample
|
||||||
|
} sths34pf80_avg_t_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Object temperature averaging options
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
STHS34PF80_AVG_TMOS_2 = 0x00, ///< 2 samples
|
||||||
|
STHS34PF80_AVG_TMOS_8 = 0x01, ///< 8 samples
|
||||||
|
STHS34PF80_AVG_TMOS_32 = 0x02, ///< 32 samples
|
||||||
|
STHS34PF80_AVG_TMOS_128 = 0x03, ///< 128 samples (default)
|
||||||
|
STHS34PF80_AVG_TMOS_256 = 0x04, ///< 256 samples
|
||||||
|
STHS34PF80_AVG_TMOS_512 = 0x05, ///< 512 samples
|
||||||
|
STHS34PF80_AVG_TMOS_1024 = 0x06, ///< 1024 samples
|
||||||
|
STHS34PF80_AVG_TMOS_2048 = 0x07, ///< 2048 samples
|
||||||
|
} sths34pf80_avg_tmos_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Output data rate options
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
STHS34PF80_ODR_POWER_DOWN = 0x00, ///< Power-down mode
|
||||||
|
STHS34PF80_ODR_0_25_HZ = 0x01, ///< 0.25 Hz
|
||||||
|
STHS34PF80_ODR_0_5_HZ = 0x02, ///< 0.5 Hz
|
||||||
|
STHS34PF80_ODR_1_HZ = 0x03, ///< 1 Hz
|
||||||
|
STHS34PF80_ODR_2_HZ = 0x04, ///< 2 Hz
|
||||||
|
STHS34PF80_ODR_4_HZ = 0x05, ///< 4 Hz
|
||||||
|
STHS34PF80_ODR_8_HZ = 0x06, ///< 8 Hz
|
||||||
|
STHS34PF80_ODR_15_HZ = 0x07, ///< 15 Hz
|
||||||
|
STHS34PF80_ODR_30_HZ = 0x08, ///< 30 Hz (1xxx)
|
||||||
|
} sths34pf80_odr_t;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* @brief Interrupt enable signal options
|
||||||
|
*/
|
||||||
|
typedef enum {
|
||||||
|
STHS34PF80_INT_HIGH_Z = 0x00, ///< High-Z (disabled)
|
||||||
|
STHS34PF80_INT_DRDY = 0x01, ///< Data ready
|
||||||
|
STHS34PF80_INT_OR = 0x02, ///< INT_OR (function flags)
|
||||||
|
} sths34pf80_int_signal_t;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* @brief Class that stores state and functions for interacting with the STHS34PF80
|
* @brief Class that stores state and functions for interacting with the STHS34PF80
|
||||||
*/
|
*/
|
||||||
|
|
@ -84,6 +136,34 @@ public:
|
||||||
bool setTemperatureLowPassFilter(sths34pf80_lpf_config_t config);
|
bool setTemperatureLowPassFilter(sths34pf80_lpf_config_t config);
|
||||||
sths34pf80_lpf_config_t getTemperatureLowPassFilter();
|
sths34pf80_lpf_config_t getTemperatureLowPassFilter();
|
||||||
|
|
||||||
|
bool setAmbTempAveraging(sths34pf80_avg_t_t config);
|
||||||
|
sths34pf80_avg_t_t getAmbTempAveraging();
|
||||||
|
bool setObjAveraging(sths34pf80_avg_tmos_t config);
|
||||||
|
sths34pf80_avg_tmos_t getObjAveraging();
|
||||||
|
|
||||||
|
bool setWideGainMode(bool wide_mode);
|
||||||
|
bool getWideGainMode();
|
||||||
|
|
||||||
|
bool setSensitivity(int8_t sensitivity);
|
||||||
|
int8_t getSensitivity();
|
||||||
|
|
||||||
|
bool setBlockDataUpdate(bool enable);
|
||||||
|
bool getBlockDataUpdate();
|
||||||
|
bool setOutputDataRate(sths34pf80_odr_t odr);
|
||||||
|
sths34pf80_odr_t getOutputDataRate();
|
||||||
|
|
||||||
|
bool rebootOTPmemory();
|
||||||
|
bool enableEmbeddedFuncPage(bool enable);
|
||||||
|
bool triggerOneshot();
|
||||||
|
|
||||||
|
bool setIntPolarity(bool active_low);
|
||||||
|
bool setIntOpenDrain(bool open_drain);
|
||||||
|
bool setIntLatched(bool latched);
|
||||||
|
bool setIntMask(uint8_t mask);
|
||||||
|
uint8_t getIntMask();
|
||||||
|
bool setIntSignal(sths34pf80_int_signal_t signal);
|
||||||
|
sths34pf80_int_signal_t getIntSignal();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Adafruit_I2CDevice *i2c_dev;
|
Adafruit_I2CDevice *i2c_dev;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,159 @@ void setup() {
|
||||||
Serial.print(" Current setting: ");
|
Serial.print(" Current setting: ");
|
||||||
printLPFSetting(sths.getTemperatureLowPassFilter());
|
printLPFSetting(sths.getTemperatureLowPassFilter());
|
||||||
Serial.println();
|
Serial.println();
|
||||||
|
|
||||||
|
// Test Ambient Temperature Averaging (default: 8 samples)
|
||||||
|
Serial.println(F("\nAmbient Temperature Averaging:"));
|
||||||
|
if (sths.setAmbTempAveraging(STHS34PF80_AVG_T_8)) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
Serial.print(F(" Current: "));
|
||||||
|
switch (sths.getAmbTempAveraging()) {
|
||||||
|
case STHS34PF80_AVG_T_8: Serial.println(F("8 samples")); break;
|
||||||
|
case STHS34PF80_AVG_T_4: Serial.println(F("4 samples")); break;
|
||||||
|
case STHS34PF80_AVG_T_2: Serial.println(F("2 samples")); break;
|
||||||
|
case STHS34PF80_AVG_T_1: Serial.println(F("1 sample")); break;
|
||||||
|
default: Serial.println(F("Unknown")); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Object Temperature Averaging (default: 128 samples)
|
||||||
|
Serial.println(F("\nObject Temperature Averaging:"));
|
||||||
|
if (sths.setObjAveraging(STHS34PF80_AVG_TMOS_128)) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
Serial.print(F(" Current: "));
|
||||||
|
switch (sths.getObjAveraging()) {
|
||||||
|
case STHS34PF80_AVG_TMOS_2: Serial.println(F("2 samples")); break;
|
||||||
|
case STHS34PF80_AVG_TMOS_8: Serial.println(F("8 samples")); break;
|
||||||
|
case STHS34PF80_AVG_TMOS_32: Serial.println(F("32 samples")); break;
|
||||||
|
case STHS34PF80_AVG_TMOS_128: Serial.println(F("128 samples")); break;
|
||||||
|
case STHS34PF80_AVG_TMOS_256: Serial.println(F("256 samples")); break;
|
||||||
|
case STHS34PF80_AVG_TMOS_512: Serial.println(F("512 samples")); break;
|
||||||
|
case STHS34PF80_AVG_TMOS_1024: Serial.println(F("1024 samples")); break;
|
||||||
|
case STHS34PF80_AVG_TMOS_2048: Serial.println(F("2048 samples")); break;
|
||||||
|
default: Serial.println(F("Unknown")); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Wide Gain Mode (default: false - default gain mode)
|
||||||
|
Serial.println(F("\nWide Gain Mode:"));
|
||||||
|
if (sths.setWideGainMode(false)) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
Serial.print(F(" Current: "));
|
||||||
|
if (sths.getWideGainMode()) {
|
||||||
|
Serial.println(F("Wide mode"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Default gain mode"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Sensitivity (factory calibrated - read only)
|
||||||
|
Serial.println(F("\nSensitivity:"));
|
||||||
|
// sths.setSensitivity(0); // Commented out - factory calibrated value
|
||||||
|
Serial.print(F(" Current: "));
|
||||||
|
Serial.println(sths.getSensitivity());
|
||||||
|
|
||||||
|
// Test Block Data Update (default: false)
|
||||||
|
Serial.println(F("\nBlock Data Update:"));
|
||||||
|
if (sths.setBlockDataUpdate(false)) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
Serial.print(F(" Current: "));
|
||||||
|
if (sths.getBlockDataUpdate()) {
|
||||||
|
Serial.println(F("Enabled"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F("Disabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test Output Data Rate (default: power-down)
|
||||||
|
Serial.println(F("\nOutput Data Rate:"));
|
||||||
|
if (sths.setOutputDataRate(STHS34PF80_ODR_POWER_DOWN)) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
Serial.print(F(" Current: "));
|
||||||
|
switch (sths.getOutputDataRate()) {
|
||||||
|
case STHS34PF80_ODR_POWER_DOWN: Serial.println(F("Power-down")); break;
|
||||||
|
case STHS34PF80_ODR_0_25_HZ: Serial.println(F("0.25 Hz")); break;
|
||||||
|
case STHS34PF80_ODR_0_5_HZ: Serial.println(F("0.5 Hz")); break;
|
||||||
|
case STHS34PF80_ODR_1_HZ: Serial.println(F("1 Hz")); break;
|
||||||
|
case STHS34PF80_ODR_2_HZ: Serial.println(F("2 Hz")); break;
|
||||||
|
case STHS34PF80_ODR_4_HZ: Serial.println(F("4 Hz")); break;
|
||||||
|
case STHS34PF80_ODR_8_HZ: Serial.println(F("8 Hz")); break;
|
||||||
|
case STHS34PF80_ODR_15_HZ: Serial.println(F("15 Hz")); break;
|
||||||
|
case STHS34PF80_ODR_30_HZ: Serial.println(F("30 Hz")); break;
|
||||||
|
default: Serial.println(F("Unknown")); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test CTRL2 functions (actions only, no getters for these)
|
||||||
|
Serial.println(F("\nEmbedded Function Page:"));
|
||||||
|
if (sths.enableEmbeddedFuncPage(false)) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("\nTrigger One-shot:"));
|
||||||
|
if (sths.triggerOneshot()) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println(F("\nReboot OTP Memory:"));
|
||||||
|
if (sths.rebootOTPmemory()) {
|
||||||
|
Serial.println(F(" Success"));
|
||||||
|
} else {
|
||||||
|
Serial.println(F(" Failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure interrupts: latched, push-pull, active high, all events
|
||||||
|
Serial.println(F("\nInterrupt Configuration:"));
|
||||||
|
sths.setIntPolarity(false); // active high
|
||||||
|
sths.setIntOpenDrain(false); // push-pull
|
||||||
|
sths.setIntLatched(true); // latched mode
|
||||||
|
|
||||||
|
// Enable interrupts for all three events
|
||||||
|
uint8_t mask = STHS34PF80_PRES_FLAG | STHS34PF80_MOT_FLAG | STHS34PF80_TAMB_SHOCK_FLAG;
|
||||||
|
sths.setIntMask(mask);
|
||||||
|
|
||||||
|
// Set interrupt signal to INT_OR (function flags)
|
||||||
|
sths.setIntSignal(STHS34PF80_INT_OR);
|
||||||
|
|
||||||
|
// Print current interrupt mask status
|
||||||
|
Serial.print(F(" Current interrupt mask: 0x"));
|
||||||
|
Serial.print(sths.getIntMask(), HEX);
|
||||||
|
Serial.print(F(" ("));
|
||||||
|
uint8_t currentMask = sths.getIntMask();
|
||||||
|
if (currentMask & STHS34PF80_PRES_FLAG) Serial.print(F("PRES "));
|
||||||
|
if (currentMask & STHS34PF80_MOT_FLAG) Serial.print(F("MOT "));
|
||||||
|
if (currentMask & STHS34PF80_TAMB_SHOCK_FLAG) Serial.print(F("TAMB_SHOCK "));
|
||||||
|
Serial.println(F(")"));
|
||||||
|
|
||||||
|
// Print current interrupt signal setting
|
||||||
|
Serial.print(F(" Current interrupt signal: "));
|
||||||
|
switch (sths.getIntSignal()) {
|
||||||
|
case STHS34PF80_INT_HIGH_Z:
|
||||||
|
Serial.println(F("High-Z (disabled)"));
|
||||||
|
break;
|
||||||
|
case STHS34PF80_INT_DRDY:
|
||||||
|
Serial.println(F("Data ready"));
|
||||||
|
break;
|
||||||
|
case STHS34PF80_INT_OR:
|
||||||
|
Serial.println(F("INT_OR (function flags)"));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Serial.println(F("Unknown"));
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue