Skip to content

Commit e7bb031

Browse files
Changes from code review
See code review comments doc for more details
1 parent 07bdb11 commit e7bb031

File tree

7 files changed

+18
-84
lines changed

7 files changed

+18
-84
lines changed

Examples/Example1_BasicReadings/Example1_BasicReadings.ino

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ void setup()
3232

3333
void loop()
3434
{
35-
bool dataReady = mySensor.getDataReady();
36-
35+
sths34pf80_tmos_drdy_status_t dataReady;
36+
mySensor.getDataReady(&dataReady);
37+
3738
// Check whether sensor has new data - run through loop if data is ready
38-
if(dataReady == 1)
39+
if(dataReady.drdy == 1)
3940
{
4041
sths34pf80_tmos_func_status_t status;
4142
mySensor.getStatus(&status);
@@ -57,63 +58,3 @@ void loop()
5758

5859
}
5960

60-
61-
62-
63-
64-
65-
66-
// #include "SparkFun_STHS34PF80_Arduino_Library.h"
67-
// #include <Wire.h>
68-
69-
// STHS34PF80_I2C mySensor;
70-
71-
// // Global Presence Value
72-
// int16_t presenceVal = 0;
73-
74-
// void setup()
75-
// {
76-
// Serial.begin(115200);
77-
// Serial.println("STHS34PF80 Example 5: Arduino Serial Plotter Presence Output");
78-
79-
// // Begin I2C
80-
// if(Wire.begin() == false)
81-
// {
82-
// Serial.println("I2C Error - check I2C Address");
83-
// while(1);
84-
// }
85-
86-
// // Establish communication with device
87-
// if(mySensor.begin() != 0)
88-
// {
89-
// Serial.println("Sensor failed to begin - Check wiring.");
90-
// while(1);
91-
// }
92-
93-
// Serial.println("Open the Serial Plotter for graphical viewing");
94-
95-
// // Default ODR: 1Hz
96-
97-
// delay(1000);
98-
// }
99-
100-
// void loop()
101-
// {
102-
103-
// bool dataReady = mySensor.getDataReady();
104-
105-
// if(dataReady == 1)
106-
// {
107-
// sths34pf80_tmos_func_status_t status;
108-
// mySensor.getStatus(&status);
109-
110-
111-
// // If the flag is high, then read out the information
112-
// if(status.pres_flag == 1)
113-
// {
114-
// mySensor.getPresenceValue(&presenceVal);
115-
// Serial.println(presenceVal);
116-
// }
117-
// }
118-
119-
// }

examples/Example2_Interrupts/Example2_Interrupts.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ void isr1()
2020

2121
void setup()
2222
{
23-
// Begin I2C transactions
2423
Serial.begin(115200);
2524
Serial.println("STHS34PF80 Example 2: Interrupts");
2625

examples/Example5_ArduinoPlotterOutput/Example5_ArduinoPlotterOutput.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ void setup()
2727

2828
Serial.println("Open the Serial Plotter for graphical viewing");
2929

30-
// Default ODR: 1Hz
31-
3230
delay(1000);
3331
}
3432

src/SparkFun_STHS34PF80_Arduino_Library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "SparkFun_STHS34PF80_Arduino_Library.h"
22

3-
int32_t STHS34PF80_I2C::begin(uint8_t devAddr)
3+
int32_t STHS34PF80_I2C::begin(uint8_t devAddr, TwoWire& wirePort)
44
{
55
bus.init(devAddr, Wire);
66
sensor.read_reg = STHS34PF80_I2C::read;

src/SparkFun_STHS34PF80_Arduino_Library.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Distributed as-is; no warranty is given.
2828
class STHS34PF80_I2C : public STHS34PF80
2929
{
3030
public:
31-
int32_t begin(uint8_t devAddr = STHS34PF80_I2C_ADD >> 1);
31+
int32_t begin(uint8_t devAddr = STHS34PF80_I2C_ADD >> 1, TwoWire& wirePort = Wire);
3232
static int32_t read(void *, uint8_t, uint8_t *, uint16_t);
3333
static int32_t write(void *, uint8_t, const uint8_t *, uint16_t);
3434
static void delayMS(uint32_t millisec);

src/sths34pf80_class.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ int32_t STHS34PF80::begin()
2626
// Set ambient temperature average (AVG_TAMB = 8)
2727
int32_t tAmbErr = setAverageTAmbientNumber(STHS34PF80_AVG_T_8);
2828

29-
// Block data rate update (BDU) to 1Hz
30-
int32_t blockErr = setBlockDataUpdate(STHS34PF80_TMOS_ODR_AT_1Hz);
29+
// Set block data rate update to true
30+
int32_t blockErr = setBlockDataUpdate(true);
3131

3232
// Set the data rate (ODR) to 1Hz
3333
int32_t odrErr = setTmosODR(STHS34PF80_TMOS_ODR_AT_1Hz);
@@ -71,13 +71,9 @@ int32_t STHS34PF80::isConnected()
7171

7272
/// @brief Checks to see if the data ready flag is high
7373
/// @return Data ready code (0 for not ready, 1 for ready)
74-
bool STHS34PF80::getDataReady()
74+
int32_t STHS34PF80::getDataReady(sths34pf80_tmos_drdy_status_t *drdy)
7575
{
76-
sths34pf80_tmos_drdy_status_t dataReady;
77-
78-
sths34pf80_tmos_drdy_status_get(&sensor, &dataReady);
79-
80-
return dataReady.drdy;
76+
return sths34pf80_tmos_drdy_status_get(&sensor, drdy);
8177
}
8278

8379
/// @brief This function checks the status of the of the device if
@@ -146,7 +142,7 @@ int32_t STHS34PF80::getTemperatureData(float *tempVal)
146142
int32_t retVal = sths34pf80_tobject_raw_get(&sensor, &tempValFill);
147143

148144
// Divide the raw value by the sensitivity
149-
*tempVal = tempValFill / sensitivity;
145+
*tempVal = (float)tempValFill / sensitivity;
150146

151147
return retVal;
152148
}
@@ -231,7 +227,7 @@ int32_t STHS34PF80::getTmosSensitivity(float *sense)
231227
uint16_t res1 = 2048;
232228
float res2 = 16;
233229

234-
*sense = (senseFill - res1) / res2;
230+
*sense = (float)(senseFill - res1) / res2;
235231
return err;
236232
}
237233

@@ -292,17 +288,17 @@ int32_t STHS34PF80::setTmosODR(sths34pf80_tmos_odr_t val)
292288
/// for output registers TOBJECT (26h - 27h) and TAMBIENT (28h - 29h).
293289
/// @param val Block data update bit (0 disabled, 1 enabled), -1 for error
294290
/// @return Error code (0 no error)
295-
int32_t STHS34PF80::getBlockDataUpdate(uint8_t *val)
291+
int32_t STHS34PF80::getBlockDataUpdate(bool *val)
296292
{
297-
return sths34pf80_block_data_update_get(&sensor, val);
293+
return sths34pf80_block_data_update_get(&sensor, (uint8_t*)val);
298294
}
299295

300296
/// @brief This function sets the block data update feature
301297
/// for output registeres TOBJECT (26h - 27h) and TAMBIENT (28h - 29h).
302298
/// Block data update bit (0 disabled, 1 enabled)
303299
/// @param val Value to set the block data update bit
304300
/// @return Error code (0 no error)
305-
int32_t STHS34PF80::setBlockDataUpdate(uint8_t val)
301+
int32_t STHS34PF80::setBlockDataUpdate(bool val)
306302
{
307303
return sths34pf80_block_data_update_set(&sensor, val);
308304
}

src/sths34pf80_class.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class STHS34PF80
99
public:
1010
int32_t begin(); // Resets the device and sets the values needed for sensor use
1111
int32_t isConnected(); // Determines connection to device
12-
bool getDataReady(); // Returns if the data is ready to be read or not
12+
int32_t getDataReady(sths34pf80_tmos_drdy_status_t *drdy); // Returns if the data is ready to be read or not
1313
int32_t getStatus(sths34pf80_tmos_func_status_t *statusVal); // Returns the status of the device
1414
int32_t reset(); // Set the boot bit, wait 3ms (as per the datasheet), then resets the algorithm
1515

@@ -34,8 +34,8 @@ class STHS34PF80
3434
int32_t getTmosODR(sths34pf80_tmos_odr_t *val); // Returns the block data update feature for output registers
3535
int32_t setTmosODR(sths34pf80_tmos_odr_t val); // Sets the block data update feature
3636

37-
int32_t getBlockDataUpdate(uint8_t *val); // Enables the block data update feature
38-
int32_t setBlockDataUpdate(uint8_t val); // Sets the block data
37+
int32_t getBlockDataUpdate(bool *val); // Enables the block data update feature
38+
int32_t setBlockDataUpdate(bool val); // Sets the block data
3939

4040
int32_t getTmosOneShot(sths34pf80_tmos_one_shot_t *val); // Returns the state of the trigger one-shot acquisition
4141
int32_t setTmosOneShot(sths34pf80_tmos_one_shot_t val); // Sets the trigger one-shot acquisiton

0 commit comments

Comments
 (0)