Skip to content

Commit

Permalink
Merge pull request #3 from cparata/master
Browse files Browse the repository at this point in the history
Add begin and end APIs
  • Loading branch information
cparata authored Jan 27, 2021
2 parents a7f70ab + 25e2e91 commit bb730c4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ Arduino library to support the STTS22H digital temperature sensor
This sensor uses I2C to communicate.
For I2C it is then required to create a TwoWire interface before accessing to the sensors:

dev_i2c = new TwoWire(I2C_SDA, I2C_SCL);
dev_i2c->begin();
TwoWire dev_i2c(I2C_SDA, I2C_SCL);
dev_i2c.begin();

An instance can be created and enbaled when the I2C bus is used following the procedure below:
An instance can be created and enabled when the I2C bus is used following the procedure below:

Temp = new STTS22HSensor(dev_i2c);
Temp->Enable();
STTS22HSensor Temp(&dev_i2c);
Temp.begin();
Temp.Enable();

The access to the sensor values is done as explained below:

Read temperature.

Temp->GetTemperature(&temperature);
float temperature;
Temp.GetTemperature(&temperature);

## Documentation

Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ STTS22HSensor KEYWORD1
# Methods and Functions (KEYWORD2)
#######################################

begin KEYWORD2
end KEYWORD2
ReadID KEYWORD2
Enable KEYWORD2
Disable KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=STM32duino STTS22H
version=1.0.1
version=2.0.0
author=SRA
maintainer=stm32duino
sentence=digital temperature sensor.
Expand Down
39 changes: 31 additions & 8 deletions src/STTS22HSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,31 +52,54 @@ STTS22HSensor::STTS22HSensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), addr
reg_ctx.write_reg = STTS22H_io_write;
reg_ctx.read_reg = STTS22H_io_read;
reg_ctx.handle = (void *)this;
temp_is_enabled = 0U;
}

/**
* @brief Configure the sensor in order to be used
* @retval 0 in case of success, an error code otherwise
*/
STTS22HStatusTypeDef STTS22HSensor::begin()
{
/* Set default ODR */
temp_odr = 1.0f;

/* Enable BDU */
if(stts22h_block_data_update_set(&reg_ctx, PROPERTY_ENABLE) != STTS22H_OK)
{
return;
return STTS22H_ERROR;
}

/* Enable Automatic Address Increment */
if(stts22h_auto_increment_set(&reg_ctx, PROPERTY_ENABLE) != STTS22H_OK)
{
return;
return STTS22H_ERROR;
}

/* Put the component in standby mode. */
if (stts22h_temp_data_rate_set(&reg_ctx, STTS22H_POWER_DOWN) != STTS22H_OK)
{
return;
return STTS22H_ERROR;
}

temp_is_enabled = 0;

return;
temp_is_enabled = 0U;

return STTS22H_OK;
}

/**
* @brief Disable the sensor and relative resources
* @retval 0 in case of success, an error code otherwise
*/
STTS22HStatusTypeDef STTS22HSensor::end()
{
/* Disable temperature sensor */
if (Disable() != STTS22H_OK)
{
return STTS22H_ERROR;
}

return STTS22H_OK;
}

/**
Expand Down Expand Up @@ -116,7 +139,7 @@ STTS22HStatusTypeDef STTS22HSensor::Enable()
return STTS22H_ERROR;
}

temp_is_enabled = 1;
temp_is_enabled = 1U;

return STTS22H_OK;
}
Expand Down Expand Up @@ -145,7 +168,7 @@ STTS22HStatusTypeDef STTS22HSensor::Disable()
return STTS22H_ERROR;
}

temp_is_enabled = 0;
temp_is_enabled = 0U;

return STTS22H_OK;
}
Expand Down
2 changes: 2 additions & 0 deletions src/STTS22HSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class STTS22HSensor
{
public:
STTS22HSensor(TwoWire *i2c, uint8_t address=STTS22H_I2C_ADD_H);
STTS22HStatusTypeDef begin();
STTS22HStatusTypeDef end();
STTS22HStatusTypeDef ReadID(uint8_t *Id);
STTS22HStatusTypeDef Enable();
STTS22HStatusTypeDef Disable();
Expand Down

0 comments on commit bb730c4

Please sign in to comment.