@@ -54,39 +54,65 @@ LIS3DHHSensor::LIS3DHHSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed) : de
5454 reg_ctx.write_reg = LIS3DHH_io_write;
5555 reg_ctx.read_reg = LIS3DHH_io_read;
5656 reg_ctx.handle = (void *)this ;
57+ X_isEnabled = 0U ;
58+ }
5759
60+ /* *
61+ * @brief Configure the sensor in order to be used
62+ * @retval 0 in case of success, an error code otherwise
63+ */
64+ LIS3DHHStatusTypeDef LIS3DHHSensor::begin ()
65+ {
5866 // Configure CS pin
5967 pinMode (cs_pin, OUTPUT);
60- digitalWrite (cs_pin, HIGH);
68+ digitalWrite (cs_pin, HIGH);
6169
6270 /* Enable register address automatically incremented during a multiple byte
6371 access with a serial interface. */
6472 if (lis3dhh_auto_add_inc_set (®_ctx, PROPERTY_ENABLE) != 0 )
6573 {
66- return ;
74+ return LIS3DHH_STATUS_ERROR ;
6775 }
6876
6977 /* Enable BDU */
7078 if (lis3dhh_block_data_update_set (®_ctx, PROPERTY_ENABLE) != 0 )
7179 {
72- return ;
80+ return LIS3DHH_STATUS_ERROR ;
7381 }
7482
7583 /* FIFO mode selection */
7684 if (lis3dhh_fifo_mode_set (®_ctx, LIS3DHH_BYPASS_MODE) != 0 )
7785 {
78- return ;
86+ return LIS3DHH_STATUS_ERROR ;
7987 }
8088
8189 /* Output data rate selection - power down. */
8290 if (lis3dhh_data_rate_set (®_ctx, LIS3DHH_POWER_DOWN) != 0 )
8391 {
84- return ;
92+ return LIS3DHH_STATUS_ERROR ;
8593 }
8694
8795 X_isEnabled = 0 ;
8896
89- return ;
97+ return LIS3DHH_STATUS_OK;
98+ }
99+
100+ /* *
101+ * @brief Disable the sensor and relative resources
102+ * @retval 0 in case of success, an error code otherwise
103+ */
104+ LIS3DHHStatusTypeDef LIS3DHHSensor::end ()
105+ {
106+ /* Disable acc */
107+ if (Disable_X () != LIS3DHH_STATUS_OK)
108+ {
109+ return LIS3DHH_STATUS_ERROR;
110+ }
111+
112+ /* Reset CS configuration */
113+ pinMode (cs_pin, INPUT);
114+
115+ return LIS3DHH_STATUS_OK;
90116}
91117
92118/* *
@@ -96,7 +122,7 @@ LIS3DHHSensor::LIS3DHHSensor(SPIClass *spi, int cs_pin, uint32_t spi_speed) : de
96122LIS3DHHStatusTypeDef LIS3DHHSensor::Enable_X (void )
97123{
98124 /* Check if the component is already enabled */
99- if (X_isEnabled == 1 )
125+ if (X_isEnabled == 1U )
100126 {
101127 return LIS3DHH_STATUS_OK;
102128 }
@@ -107,7 +133,7 @@ LIS3DHHStatusTypeDef LIS3DHHSensor::Enable_X(void)
107133 return LIS3DHH_STATUS_ERROR;
108134 }
109135
110- X_isEnabled = 1 ;
136+ X_isEnabled = 1U ;
111137
112138 return LIS3DHH_STATUS_OK;
113139}
@@ -119,7 +145,7 @@ LIS3DHHStatusTypeDef LIS3DHHSensor::Enable_X(void)
119145LIS3DHHStatusTypeDef LIS3DHHSensor::Disable_X (void )
120146{
121147 /* Check if the component is already disabled */
122- if (X_isEnabled == 0 )
148+ if (X_isEnabled == 0U )
123149 {
124150 return LIS3DHH_STATUS_OK;
125151 }
@@ -130,7 +156,7 @@ LIS3DHHStatusTypeDef LIS3DHHSensor::Disable_X(void)
130156 return LIS3DHH_STATUS_ERROR;
131157 }
132158
133- X_isEnabled = 0 ;
159+ X_isEnabled = 0U ;
134160
135161 return LIS3DHH_STATUS_OK;
136162}
0 commit comments