5252HTS221Sensor::HTS221Sensor (TwoWire *i2c) : dev_i2c(i2c)
5353{
5454 address = HTS221_I2C_ADDRESS;
55+ };
5556
57+ /* *
58+ * @brief Configure the sensor in order to be used
59+ * @retval 0 in case of success, an error code otherwise
60+ */
61+ HTS221StatusTypeDef HTS221Sensor::begin ()
62+ {
5663 /* Power down the device */
5764 if ( HTS221_DeActivate ( (void *)this ) == HTS221_ERROR )
5865 {
59- return ;
66+ return HTS221_STATUS_ERROR ;
6067 }
6168
6269 /* Enable BDU */
6370 if ( HTS221_Set_BduMode ( (void *)this , HTS221_ENABLE ) == HTS221_ERROR )
6471 {
65- return ;
72+ return HTS221_STATUS_ERROR ;
6673 }
6774
6875 if (SetODR (1 .0f ) == HTS221_STATUS_ERROR)
6976 {
70- return ;
77+ return HTS221_STATUS_ERROR ;
7178 }
72- };
7379
80+ return HTS221_STATUS_OK;
81+ }
7482
75- /* * Constructor
76- * @param i2c object of an helper class which handles the I2C peripheral
77- * @param address the address of the component's instance
83+ /* *
84+ * @brief Disable the sensor and relative resources
85+ * @retval 0 in case of success, an error code otherwise
7886 */
79- HTS221Sensor::HTS221Sensor (TwoWire *i2c, uint8_t address) : dev_i2c(i2c), address(address )
87+ HTS221StatusTypeDef HTS221Sensor::end ( )
8088{
81- /* Power down the device */
82- if ( HTS221_DeActivate ( ( void *) this ) == HTS221_ERROR )
89+ /* Disable humidity and temperature sensor */
90+ if ( Disable () != HTS221_STATUS_OK )
8391 {
84- return ;
85- }
86-
87- /* Enable BDU */
88- if ( HTS221_Set_BduMode ( (void *)this , HTS221_ENABLE ) == HTS221_ERROR )
89- {
90- return ;
92+ return HTS221_STATUS_ERROR;
9193 }
9294
93- if (SetODR (1 .0f ) == HTS221_STATUS_ERROR)
94- {
95- return ;
96- }
97- };
95+ return HTS221_STATUS_OK;
96+ }
9897
9998/* *
10099 * @brief Enable HTS221
@@ -117,7 +116,7 @@ HTS221StatusTypeDef HTS221Sensor::Enable(void)
117116 */
118117HTS221StatusTypeDef HTS221Sensor::Disable (void )
119118{
120- /* Power up the device */
119+ /* Power off the device */
121120 if ( HTS221_DeActivate ( (void *)this ) == HTS221_ERROR )
122121 {
123122 return HTS221_STATUS_ERROR;
0 commit comments