Skip to content

Commit 1a7c749

Browse files
authored
Merge pull request #4 from cparata/master
Add begin and end APIs
2 parents 4794626 + 594a647 commit 1a7c749

5 files changed

Lines changed: 47 additions & 15 deletions

File tree

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@ Arduino library to support the STTS751 digital temperature sensor
66
This sensor uses I2C to communicate.
77
For I2C it is then required to create a TwoWire interface before accessing to the sensors:
88

9-
dev_i2c = new TwoWire(I2C_SDA, I2C_SCL);
10-
dev_i2c->begin();
9+
TwoWire dev_i2c(I2C_SDA, I2C_SCL);
10+
dev_i2c.begin();
1111

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

14-
Temp = new STTS751Sensor(dev_i2c);
15-
Temp->Enable();
14+
STTS751Sensor Temp(&dev_i2c, I2C_ADDRESS);
15+
Temp.begin();
16+
Temp.Enable();
17+
18+
I2C_ADDRESS depends on the ID of the sensor and the pull-up resistor value connected to Addr/Therm pin.
19+
Please check the Datasheet for more information.
1620

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

1923
Read temperature.
2024

21-
Temp->GetTemperature(&temperature);
25+
float temperature;
26+
Temp.GetTemperature(&temperature);
2227

2328
## Documentation
2429

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ STTS751Sensor KEYWORD1
1212
# Methods and Functions (KEYWORD2)
1313
#######################################
1414

15+
begin KEYWORD2
16+
end KEYWORD2
1517
ReadID KEYWORD2
1618
Enable KEYWORD2
1719
Disable KEYWORD2

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=STM32duino STTS751
2-
version=1.0.2
2+
version=2.0.0
33
author=SRA
44
maintainer=stm32duino
55
sentence=digital temperature sensor.

src/STTS751Sensor.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,28 +52,51 @@ STTS751Sensor::STTS751Sensor(TwoWire *i2c, uint8_t address) : dev_i2c(i2c), addr
5252
reg_ctx.write_reg = STTS751_io_write;
5353
reg_ctx.read_reg = STTS751_io_read;
5454
reg_ctx.handle = (void *)this;
55-
55+
temp_is_enabled = 0U;
56+
}
57+
58+
/**
59+
* @brief Configure the sensor in order to be used
60+
* @retval 0 in case of success, an error code otherwise
61+
*/
62+
STTS751StatusTypeDef STTS751Sensor::begin()
63+
{
5664
/* Disable EVENT pin of SMBus. */
5765
if (stts751_pin_event_route_set(&reg_ctx, PROPERTY_ENABLE) != STTS751_OK)
5866
{
59-
return;
67+
return STTS751_ERROR;
6068
}
6169
/* Set default ODR */
6270
temp_odr = 1.0f;
6371
/* Set the resolution to the maximum allowed value */
6472
if (stts751_resolution_set(&reg_ctx, STTS751_12bit) != STTS751_OK)
6573
{
66-
return;
74+
return STTS751_ERROR;
6775
}
6876
/* Put the component in standby mode. */
6977
if (stts751_temp_data_rate_set(&reg_ctx, STTS751_TEMP_ODR_OFF) != STTS751_OK)
7078
{
71-
return;
79+
return STTS751_ERROR;
7280
}
73-
74-
temp_is_enabled = 0;
75-
76-
return;
81+
82+
temp_is_enabled = 0U;
83+
84+
return STTS751_OK;
85+
}
86+
87+
/**
88+
* @brief Disable the sensor and relative resources
89+
* @retval 0 in case of success, an error code otherwise
90+
*/
91+
STTS751StatusTypeDef STTS751Sensor::end()
92+
{
93+
/* Disable temperature sensor */
94+
if (Disable() != STTS751_OK)
95+
{
96+
return STTS751_ERROR;
97+
}
98+
99+
return STTS751_OK;
77100
}
78101

79102
/**

src/STTS751Sensor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class STTS751Sensor
6969
{
7070
public:
7171
STTS751Sensor(TwoWire *i2c, uint8_t address=STTS751_1xxxx_ADD_7K5);
72+
STTS751StatusTypeDef begin();
73+
STTS751StatusTypeDef end();
7274
STTS751StatusTypeDef ReadID(uint8_t *Id);
7375
STTS751StatusTypeDef Enable();
7476
STTS751StatusTypeDef Disable();

0 commit comments

Comments
 (0)