Skip to content

Commit b7e1afc

Browse files
committed
naming
1 parent 9ed9b34 commit b7e1afc

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,16 @@ To read the first three bytes (two for diff pressure and one CRC), it takes only
99

1010
See [sdpsensor-esp-arduino.ino](./sdpsensor-esp-arduino.ino).
1111

12+
Serial output:
13+
14+
```
15+
[ 1021][I][sdpsensor.cpp:86] initI2C(): I2C0 line initialized
16+
[ 1021][I][sdpsensor.cpp:204] reset(): SDPSensor::reset ESP_OK
17+
[ 1042][I][sdpsensor.cpp:157] initSensor(): Initialized SDP31 500Pa sensor (PID=0x03010188)
18+
[ 1133][I][sdpsensor.cpp:169] initSensor(): SDP31 pressure scale: 60
19+
[ 1133][I][sdpsensor.cpp:182] startContinuous(): SDPSensor::startContinuous ESP_OK
20+
21+
[ 2154][I][sdpsensor-esp-arduino.ino:32] loop(): raw pressure: 0, err code: ESP_OK
22+
...
23+
```
24+

sdpsensor-esp-arduino.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ void setup() {
2828
void loop() {
2929
delay(1000);
3030
int16_t pressure;
31-
esp_err_t err = sdp.readContinuousRaw(&pressure);
31+
esp_err_t err = sdp.readDiffPressure(&pressure);
3232
ESP_LOGI("sdp", "raw pressure: %d, err code: %s", pressure, esp_err_to_name(err));
3333

3434
/*

sdpsensor.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525

2626
const char *TAG_SDPSENSOR = "sdpsensor";
2727

28-
/*
28+
/**
29+
* Compute CRC from data.
2930
* See http://www.sunshine2k.de/articles/coding/crc/understanding_crc.html
31+
*
32+
* @param data - I2C read bytes of size 2
33+
* @returns crc - the CRC value from the data
3034
*/
31-
uint8_t SDPSensor::computeCRC(uint8_t* data)
35+
uint8_t computeCRC(uint8_t* data)
3236
{
3337
const uint8_t generator = 0x31; /* Polynomial */
3438
uint8_t crc = 0xFF; /* Initial value from the datasheet */
@@ -114,7 +118,7 @@ void SDPSensor::initSensor() {
114118
const uint32_t pid = (read_buffer[0] << 24) | (read_buffer[1] << 16)
115119
| (read_buffer[3] << 8) | (read_buffer[4] << 0);
116120

117-
uint32_t model_number, range_pa;
121+
uint32_t model_number, range_pa;
118122
switch (pid & 0xFFFFFF00) {
119123
case SPD31_500_PID:
120124
model_number = 31;
@@ -232,7 +236,7 @@ void SDPSensor::watchdogCheck(esp_err_t status) {
232236
}
233237

234238

235-
esp_err_t SDPSensor::readContinuousRaw(int16_t *diffPressureRaw) {
239+
esp_err_t SDPSensor::readDiffPressure(int16_t *diffPressureRaw) {
236240
uint8_t data[3] = { 0 };
237241
esp_err_t err = i2c_master_read_from_device(i2c_port, i2c_addr, data, 3,
238242
I2C_NO_TIMEOUT);
@@ -246,7 +250,7 @@ esp_err_t SDPSensor::readContinuousRaw(int16_t *diffPressureRaw) {
246250
}
247251

248252

249-
esp_err_t SDPSensor::readContinuousRawTemperature(int16_t *diffPressureRaw, float *temperature) {
253+
esp_err_t SDPSensor::readDiffPressureTemperature(int16_t *diffPressureRaw, float *temperature) {
250254
uint8_t data[6] = { 0 };
251255

252256
/*

sdpsensor.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ class SDPSensor {
1616
uint8_t i2c_addr; /* I2C address */
1717
i2c_port_t i2c_port; /* I2C master port */
1818
uint16_t pressureScale; /* Diff pressure scale */
19-
uint32_t failsCount; /* SDP successive failed reads count */
20-
uint32_t maxSuccessiveFailsCount; /* SDP max successive failed reads before SW reset */
21-
uint8_t computeCRC(uint8_t *data); /* Compute CRC from data */
19+
uint32_t failsCount; /* [watchdog] SDP successive failed reads count */
20+
uint32_t maxSuccessiveFailsCount; /* [watchdog] SDP max successive failed reads before SW reset */
2221
public:
2322

2423
/**
@@ -76,6 +75,8 @@ class SDPSensor {
7675

7776
/**
7877
* Reset the SDP sensor.
78+
* All other sensors connected to the same I2C line
79+
* (same port) will also receive the reset command.
7980
*
8081
* @returns the error code (defined in esp_err.h)
8182
*/
@@ -106,10 +107,10 @@ class SDPSensor {
106107

107108

108109
/**
109-
* Read the raw differential pressure value and save the result
110-
* in `diffPressureRaw`. To convert it to the real value in Pa,
111-
* one should divide it by the pressure scale (see
112-
* `getPressureScale()` function).
110+
* Read the raw (unnormalized) differential pressure value and
111+
* save the result in `diffPressureRaw`. To convert it to a
112+
* physical value in Pa, one should divide it by the pressure
113+
* scale (see the `getPressureScale()` function).
113114
*
114115
* This call is non-blocking (zero I2C timeout).
115116
*
@@ -120,17 +121,19 @@ class SDPSensor {
120121
* ESP_ERR_TIMEOUT - timed out
121122
* ESP_ERR_INVALID_CRC - CRC mismatch
122123
*/
123-
esp_err_t readContinuousRaw(int16_t *diffPressureRaw);
124+
esp_err_t readDiffPressure(int16_t *diffPressureRaw);
124125

125126

126127
/**
127128
* Read the raw differential pressure value AND the temperature.
128129
*
130+
* This call is non-blocking (zero I2C timeout).
131+
*
129132
* @param diffPressureRaw - a pointer to save the diff pressure
130133
* @param temperature - a pointer to save the temperature in Celsius
131134
* @returns the error code (defined in esp_err.h)
132135
*/
133-
esp_err_t readContinuousRawTemperature(int16_t *diffPressureRaw, float *temperature);
136+
esp_err_t readDiffPressureTemperature(int16_t *diffPressureRaw, float *temperature);
134137
};
135138

136139
#endif /* SDPSENSOR_H_ */

0 commit comments

Comments
 (0)