Skip to content

Commit 9ed57f8

Browse files
committed
sfe toolkit back in
-using SFE toolkit for I2C begin stuff again -removed some un-used code
1 parent f6463f9 commit 9ed57f8

File tree

4 files changed

+76
-95
lines changed

4 files changed

+76
-95
lines changed

examples/Example_01_BasicReadings/Example_01_BasicReadings.ino

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,38 @@
2929
#include <Wire.h>
3030
#include "SparkFun_BMV080_Arduino_Library.h" // CTRL+Click here to get the library: http://librarymanager/All#SparkFun_BMV080
3131

32-
Bmv080 bmv080;
33-
#define BMV080_IRQ 14 // The BMV080 interrupt pin
32+
Bmv080 bmv080; // Create an instance of the BMV080 class
3433
#define BMV080_ADDR 0x57 // SparkFun BMV080 Breakout defaults to 0x57
3534

36-
i2c_device_t i2c_device = {};
37-
38-
#define IRQ_Pin 14
39-
40-
bool int_flag = false;
35+
i2c_device_t i2c_device = {}; // I2C device struct instance for Bosch API
4136

4237
void setup()
4338
{
44-
// // Start serial
45-
// Serial.begin(115200);
39+
Serial.begin(115200);
4640

47-
// while(!Serial) delay(10); // Wait for Serial to become available.
48-
// // Necessary for boards with native USB (like the SAMD51 Thing+).
49-
// // For a final version of a project that does not need serial debug (or a USB cable plugged in),
50-
// // Comment out this while loop, or it will prevent the remaining code from running.
41+
while(!Serial) delay(10); // Wait for Serial to become available.
42+
// Necessary for boards with native USB (like the SAMD51 Thing+).
43+
// For a final version of a project that does not need serial debug (or a USB cable plugged in),
44+
// Comment out this while loop, or it will prevent the remaining code from running.
5145

52-
// Serial.println();
53-
// Serial.println("BMV080 Example 1 - Basic Readings");
46+
Serial.println();
47+
Serial.println("BMV080 Example 1 - Basic Readings");
5448

55-
// Wire.begin();
49+
Wire.begin();
5650

57-
// if (bmv080.begin(BMV080_ADDR, Wire, BMV080_IRQ) == false) {
58-
// Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
59-
// while (1)
60-
// ;
61-
// }
62-
// Serial.println("BMV080 found!");
51+
if (bmv080.begin(BMV080_ADDR, Wire) == false) {
52+
Serial.println("BMV080 not detected at default I2C address. Check your jumpers and the hookup guide. Freezing...");
53+
while (1)
54+
;
55+
}
56+
Serial.println("BMV080 found!");
6357

6458
// Wire.setClock(400000); //Increase I2C data rate to 400kHz
65-
66-
Serial.begin(115200);
67-
Serial.println("Starting BMV080 example...");
6859

6960
/* Communication interface initialization */
70-
7161
i2c_init(&i2c_device);
7262

63+
/* Initialize the Sensor (read driver, open, reset, id etc.)*/
7364
bmv080.init(&i2c_device);
7465

7566
/* Set the sensor mode to continuous mode */

src/SparkFun_BMV080_Arduino_Library.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
// TODO: Add includes as needed (e.g. #include <Wire.h>, #include <SPI.h>)
2929
#include "sfeBmv080.h"
30-
//#include <SparkFun_Toolkit.h>
30+
#include <SparkFun_Toolkit.h>
3131

3232
// #include "Arduino.h"
3333
#include <bmv080.h>
@@ -41,26 +41,26 @@ SET_LOOP_TASK_STACK_SIZE(60 * 1024); // 60KB
4141
class Bmv080 : public sfeBmv080
4242
{
4343
public:
44-
// /// @brief Begins the Device
45-
// /// @param address I2C device address to use for the sensor
46-
// /// @param wirePort Wire port to use for I2C communication
47-
// /// @return True if successful, false otherwise
48-
// bool begin(const uint8_t address = SFE_BMV080_DEFAULT_ADDRESS, TwoWire &wirePort = Wire, const uint8_t irqPin = SFE_BMV080_DEFAULT_IRQ_PIN)
49-
// {
50-
// // Setup Arudino I2C bus
51-
// _theI2CBus.init(wirePort, address);
44+
/// @brief Begins the Device
45+
/// @param address I2C device address to use for the sensor
46+
/// @param wirePort Wire port to use for I2C communication
47+
/// @return True if successful, false otherwise
48+
bool begin(const uint8_t address = SFE_BMV080_DEFAULT_ADDRESS, TwoWire &wirePort = Wire)
49+
{
50+
// Setup Arudino I2C bus
51+
_theI2CBus.init(wirePort, address);
5252

53-
// // Begin the sensor
54-
// return sfeBmv080::begin(&_theI2CBus) == kSTkErrOk;
55-
// }
53+
// Begin the sensor
54+
return sfeBmv080::begin(&_theI2CBus) == kSTkErrOk;
55+
}
5656

57-
// /// @brief Checks if the Device is connected
58-
// /// @return True if the sensor is connected, false otherwise
59-
// bool isConnected()
60-
// {
61-
// return sfeBmv080::isConnected() == kSTkErrOk;
62-
// }
57+
/// @brief Checks if the Device is connected
58+
/// @return True if the sensor is connected, false otherwise
59+
bool isConnected()
60+
{
61+
return sfeBmv080::isConnected() == kSTkErrOk;
62+
}
6363

64-
// private:
65-
// sfeTkArdI2C _theI2CBus;
64+
private:
65+
sfeTkArdI2C _theI2CBus;
6666
};

src/sfeBmv080.cpp

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,35 @@ void bmv080_service_routine(const bmv080_handle_t handle, void* callback_paramet
7575
#endif
7676

7777

78-
// sfeTkError_t sfeBmv080::begin(sfeTkII2C *theBus)
79-
// {
80-
// // Nullptr check
81-
// if (theBus == nullptr)
82-
// return kSTkErrFail;
83-
84-
// // Set bus pointer
85-
// _theBus = theBus;
86-
87-
// sfeTkError_t err;
88-
// err = isConnected();
89-
// // Check whether the ping was successful
90-
// if (err != kSTkErrOk)
91-
// return err;
92-
93-
// // Done!
94-
// return kSTkErrOk;
95-
// }
96-
97-
// sfeTkError_t sfeBmv080::isConnected()
98-
// {
99-
// // Just ping the device address
100-
// return _theBus->ping();
101-
// }
78+
sfeTkError_t sfeBmv080::begin(sfeTkII2C *theBus)
79+
{
80+
// Nullptr check
81+
if (theBus == nullptr)
82+
return kSTkErrFail;
83+
84+
// Set bus pointer
85+
_theBus = theBus;
86+
87+
// Set the bus pointer for the I2C device struct instance member
88+
//_i2c_device.instance = theBus;
89+
90+
i2c_init(&_i2c_device);
91+
92+
sfeTkError_t err;
93+
err = isConnected();
94+
// Check whether the ping was successful
95+
if (err != kSTkErrOk)
96+
return err;
97+
98+
// Done!
99+
return kSTkErrOk;
100+
}
101+
102+
sfeTkError_t sfeBmv080::isConnected()
103+
{
104+
// Just ping the device address
105+
return _theBus->ping();
106+
}
102107

103108
float sfeBmv080::getPM25()
104109
{
@@ -143,18 +148,6 @@ bool sfeBmv080::setMode(uint8_t mode)
143148
}
144149
}
145150

146-
// void print_to_serial(const char *format, ...)
147-
// {
148-
// char print_buffer[1024];
149-
// va_list args;
150-
// va_start(args, format);
151-
// vsnprintf(print_buffer, sizeof(print_buffer), format, args);
152-
// va_end(args);
153-
// Serial.print(print_buffer);
154-
// }
155-
156-
//print_function_t print_handle = (const print_function_t)print_to_serial;
157-
158151
bool sfeBmv080::dataAvailable()
159152
{
160153
bmv080_service_routine(bmv080_handle_class, this);

src/sfeBmv080.h

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,18 @@ class sfeBmv080
4040
{
4141
public:
4242
/// @brief Default constructor
43-
sfeBmv080()// : _theBus{nullptr}
43+
sfeBmv080() : _theBus{nullptr}
4444
{
4545
}
4646

47-
// /// @brief Begins the Device
48-
// /// @param theBus I2C bus to use for communication
49-
// /// @return 0 for succuss, negative for errors, positive for warnings
50-
// sfeTkError_t begin(sfeTkII2C *theBus = nullptr);
47+
/// @brief Begins the Device
48+
/// @param theBus I2C bus to use for communication
49+
/// @return 0 for succuss, negative for errors, positive for warnings
50+
sfeTkError_t begin(sfeTkII2C *theBus = nullptr);
5151

52-
// /// @brief Checks if the Device is connected
53-
// /// @return 0 for succuss, negative for errors, positive for warnings
54-
// sfeTkError_t isConnected();
52+
/// @brief Checks if the Device is connected
53+
/// @return 0 for succuss, negative for errors, positive for warnings
54+
sfeTkError_t isConnected();
5555

5656
/// @brief Initialize the sensor
5757
/// @details This function initializes the sensor and should be called
@@ -99,14 +99,11 @@ class sfeBmv080
9999
/// @return True if new data is available, false otherwise
100100
bool dataAvailable();
101101

102-
103-
104-
105102
private:
106103
bmv080_handle_t bmv080_handle_class = NULL;
107104
bool _dataAvailable = false;
108105
bmv080_output_t _sensorValue;
109106

110-
// protected:
111-
// sfeTkII2C *_theBus;
107+
protected:
108+
sfeTkII2C *_theBus;
112109
};

0 commit comments

Comments
 (0)