Skip to content

Commit bf140b8

Browse files
committed
updates to a) provide some level of backward compatablity with lib v1.0; b) update example 2
1 parent 3db2d39 commit bf140b8

File tree

4 files changed

+155
-61
lines changed

4 files changed

+155
-61
lines changed

examples/Example2_changeSettings/Example2_changeSettings.ino

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,88 +5,88 @@
55
* Paul Clark
66
* SparkFun Electronics
77
* November 4th 2021
8-
*
8+
*
99
* This example demonstrates how to change the VEML7700's sensitivity (gain) and integration time settings.
10-
*
10+
*
1111
* Want to support open source hardware? Buy a board from SparkFun!
1212
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
13-
*
13+
*
1414
* Please see LICENSE.md for the license information
15-
*
15+
*
1616
*/
1717

1818
#include <SparkFun_VEML7700_Arduino_Library.h> // Click here to get the library: http://librarymanager/All#SparkFun_VEML7700
1919

20-
VEML7700 mySensor; // Create a VEML7700 object
20+
SparkFunVEML7700 mySensor; // Create a VEML7700 object
2121

2222
void setup()
2323
{
24-
Serial.begin(115200);
25-
Serial.println(F("SparkFun VEML7700 Example"));
24+
Serial.begin(115200);
25+
Serial.println(F("SparkFun VEML7700 Example"));
2626

27-
Wire.begin();
27+
Wire.begin();
2828

29-
//mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
29+
// mySensor.enableDebugging(); // Uncomment this line to enable helpful debug messages on Serial
3030

31-
// Begin the VEML7700 using the Wire I2C port
32-
// .begin will return true on success, or false on failure to communicate
33-
if (mySensor.begin() == false)
34-
{
35-
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
36-
while (1)
37-
;
38-
}
31+
// Begin the VEML7700 using the Wire I2C port
32+
// .begin will return true on success, or false on failure to communicate
33+
if (mySensor.begin() == false)
34+
{
35+
Serial.println("Unable to communicate with the VEML7700. Please check the wiring. Freezing...");
36+
while (1)
37+
;
38+
}
3939

40-
//The default integration time is 100ms.
41-
//Possible values are:
42-
//VEML7700_INTEGRATION_25ms
43-
//VEML7700_INTEGRATION_50ms
44-
//VEML7700_INTEGRATION_100ms
45-
//VEML7700_INTEGRATION_200ms
46-
//VEML7700_INTEGRATION_400ms
47-
//VEML7700_INTEGRATION_800ms
48-
//Let's change the integration time to 50ms:
49-
mySensor.setIntegrationTime(VEML7700_INTEGRATION_50ms);
40+
// The default integration time is 100ms.
41+
// Possible values are:
42+
// VEML7700_INTEGRATION_25ms
43+
// VEML7700_INTEGRATION_50ms
44+
// VEML7700_INTEGRATION_100ms
45+
// VEML7700_INTEGRATION_200ms
46+
// VEML7700_INTEGRATION_400ms
47+
// VEML7700_INTEGRATION_800ms
48+
// Let's change the integration time to 50ms:
49+
mySensor.setIntegrationTime(VEML7700_INTEGRATION_50ms);
5050

51-
//Confirm the integration time was set correctly
52-
Serial.print(F("The sensor integration time is: "));
53-
Serial.println(mySensor.getIntegrationTimeStr());
51+
// Confirm the integration time was set correctly
52+
Serial.print(F("The sensor integration time is: "));
53+
Serial.println(mySensor.integrationTimeString());
5454

55-
//The default gain (sensitivity mode) is x1
56-
//Possible values are:
57-
//VEML7700_SENSITIVITY_x1
58-
//VEML7700_SENSITIVITY_x2
59-
//VEML7700_SENSITIVITY_x1_8
60-
//VEML7700_SENSITIVITY_x1_4
61-
//Let's change the sensitivity to x2:
62-
mySensor.setSensitivityMode(VEML7700_SENSITIVITY_x2);
55+
// The default gain (sensitivity mode) is x1
56+
// Possible values are:
57+
// VEML7700_SENSITIVITY_x1
58+
// VEML7700_SENSITIVITY_x2
59+
// VEML7700_SENSITIVITY_x1_8
60+
// VEML7700_SENSITIVITY_x1_4
61+
// Let's change the sensitivity to x2:
62+
mySensor.setSensitivityMode(VEML7700_SENSITIVITY_x2);
6363

64-
//Confirm that the sensitivity mode was set correctly
65-
Serial.print(F("The sensor gain (sensitivity mode) is: "));
66-
Serial.println(mySensor.getSensitivityModeStr());
64+
// Confirm that the sensitivity mode was set correctly
65+
Serial.print(F("The sensor gain (sensitivity mode) is: "));
66+
Serial.println(mySensor.sensitivityModeString());
6767

68-
//We can also change the persistence ptotect number. Default is 1.
69-
//Possible values are:
70-
//VEML7700_PERSISTENCE_1
71-
//VEML7700_PERSISTENCE_2
72-
//VEML7700_PERSISTENCE_4
73-
//VEML7700_PERSISTENCE_8
74-
//Let's change the persistence protect to 4:
75-
mySensor.setPersistenceProtect(VEML7700_PERSISTENCE_4);
68+
// We can also change the persistence ptotect number. Default is 1.
69+
// Possible values are:
70+
// VEML7700_PERSISTENCE_1
71+
// VEML7700_PERSISTENCE_2
72+
// VEML7700_PERSISTENCE_4
73+
// VEML7700_PERSISTENCE_8
74+
// Let's change the persistence protect to 4:
75+
mySensor.setPersistenceProtect(VEML7700_PERSISTENCE_4);
7676

77-
//Confirm that the persistence protect was set correctly
78-
Serial.print(F("The sensor persistence protect setting is: "));
79-
Serial.println(mySensor.getPersistenceProtectStr());
77+
// Confirm that the persistence protect was set correctly
78+
Serial.print(F("The sensor persistence protect setting is: "));
79+
Serial.println(mySensor.persistenceProtectString());
8080

81-
Serial.println(F("Lux:\tAmbient:\tWhite Level:"));
81+
Serial.println(F("Lux:\tAmbient:\tWhite Level:"));
8282
}
8383

8484
void loop()
8585
{
86-
Serial.print(mySensor.getLux(), 4); // Read the lux from the sensor and print it
87-
Serial.print("\t");
88-
Serial.print(mySensor.getAmbientLight()); // Read the ambient light level
89-
Serial.print("\t");
90-
Serial.println(mySensor.getWhiteLevel()); // Read the white channel level
91-
delay(250);
86+
Serial.print(mySensor.getLux(), 4); // Read the lux from the sensor and print it
87+
Serial.print("\t");
88+
Serial.print(mySensor.getAmbientLight()); // Read the ambient light level
89+
Serial.print("\t");
90+
Serial.println(mySensor.getWhiteLevel()); // Read the white channel level
91+
delay(250);
9292
}

src/SparkFun_VEML7700_Arduino_Library.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
#include "sfTk/sfDevVEML7700.h"
2323
// clang-format on
2424

25+
// For backwards compatibility - with the SparkX (v1.0.0) library, remap error codes
26+
// to the toolkit error codes
27+
typedef enum : sfTkError_t
28+
{
29+
VEML7700_ERROR_READ = ksfTkErrFail,
30+
VEML7700_ERROR_WRITE = ksfTkErrFail,
31+
VEML7700_ERROR_INVALID_ADDRESS = ksfTkErrInvalidParam,
32+
VEML7700_ERROR_UNDEFINED = ksfTkErrInvalidParam,
33+
VEML7700_ERROR_SUCCESS = ksfTkErrOk
34+
} VEML7700_error_t;
35+
const VEML7700_error_t VEML7700_SUCCESS = VEML7700_ERROR_SUCCESS;
2536
/**
2637
* @brief Class for interfacing with the VMEL7700 sensor using I2C communication
2738
*
@@ -58,3 +69,8 @@ class SparkFunVEML7700 : public sfDevVEML7700
5869
private:
5970
sfTkArdI2C _theI2CBus;
6071
};
72+
73+
// for backwards compatibility
74+
class VEML7700 : public SparkFunVEML7700
75+
{
76+
};

src/sfTk/sfDevVEML7700.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ sfTkError_t sfDevVEML7700::enableInterrupt(bool bEnable)
205205
// Get the interrupt enable setting.
206206
//
207207

208-
bool sfDevVEML7700::interruptEnabled(void)
208+
bool sfDevVEML7700::isInterruptEnabled(void)
209209
{
210210

211211
sfDevVEML7700Config_t config;

src/sfTk/sfDevVEML7700.h

Lines changed: 79 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,13 @@ class sfDevVEML7700
189189
* @return sfTkError_t Error code indicating success or failure of the operation.
190190
*/
191191
sfTkError_t enableInterrupt(bool);
192+
192193
/**
193194
* @brief Checks if the interrupt feature is enabled on the VEML7700 device.
194195
*
195196
* @return true if the interrupt is enabled, false otherwise.
196197
*/
197-
bool interruptEnabled(void);
198+
bool isInterruptEnabled(void);
198199

199200
/**
200201
* @brief Sets the persistence protection mode for the VEML7700 sensor.
@@ -243,6 +244,17 @@ class sfDevVEML7700
243244
*/
244245
const char *persistenceProtectString(void);
245246

247+
/**
248+
* @brief Get the Persistence Protect object - this is for backward compatibility.
249+
*
250+
* @deprecated since version 2.0.0, use persistenceProtect() instead.
251+
* @return VEML7700_persistence_protect_t
252+
*/
253+
const char *getPersistenceProtectStr(void)
254+
{
255+
return persistenceProtectString();
256+
}
257+
246258
/**
247259
* @brief Sets the integration time for the VEML7700 sensor.
248260
*
@@ -275,6 +287,17 @@ class sfDevVEML7700
275287
*/
276288
VEML7700_integration_time_t integrationTime(void);
277289

290+
/**
291+
* @brief Get the Integration Time object - this is for backward compatibility.
292+
*
293+
* @deprecated since version 2.0.0, use integrationTime() instead.
294+
* @return VEML7700_integration_time_t
295+
*/
296+
297+
VEML7700_integration_time_t getIntegrationTime(void)
298+
{
299+
return integrationTime();
300+
}
278301
/**
279302
* @brief Returns a string representation of the current integration time setting.
280303
*
@@ -284,6 +307,17 @@ class sfDevVEML7700
284307
*/
285308
const char *integrationTimeString(void);
286309

310+
/**
311+
* @brief Get the Integration Time string - this is for backward compatibility.
312+
*
313+
* @deprecated since version 2.0.0, use integrationTimeString() instead.
314+
* @return const char* A string representing the integration time setting.
315+
*/
316+
const char *getIntegrationTimeStr(void)
317+
{
318+
return integrationTimeString();
319+
}
320+
287321
/**
288322
* @brief Sets the sensitivity mode for the VEML7700 sensor.
289323
*
@@ -315,6 +349,17 @@ class sfDevVEML7700
315349
*/
316350
VEML7700_sensitivity_mode_t sensitivityMode(void);
317351

352+
/**
353+
* @brief Get the Sensitivity Mode object - this is for backward compatibility.
354+
*
355+
* @deprecated since version 2.0.0, use sensitivityMode() instead.
356+
* @return VEML7700_sensitivity_mode_t
357+
*/
358+
VEML7700_sensitivity_mode_t getSensitivityMode(void)
359+
{
360+
return sensitivityMode();
361+
}
362+
318363
/**
319364
* @brief Returns a string representation of the current sensitivity mode setting.
320365
*
@@ -324,6 +369,17 @@ class sfDevVEML7700
324369
*/
325370
const char *sensitivityModeString(void);
326371

372+
/**
373+
* @brief Get the Sensitivity Mode string - this is for backward compatibility.
374+
*
375+
* @deprecated since version 2.0.0, use sensitivityModeString() instead.
376+
* @return const char* A string representing the sensitivity mode setting.
377+
*/
378+
const char *getSensitivityModeStr(void)
379+
{
380+
return sensitivityModeString();
381+
}
382+
327383
/**
328384
* @brief Sets the high threshold value for the VEML7700 sensor.
329385
*
@@ -354,6 +410,17 @@ class sfDevVEML7700
354410
*/
355411
uint16_t highThreshold(void);
356412

413+
/**
414+
* @brief Get the High Threshold object - this is for backward compatibility.
415+
*
416+
* @deprecated since version 2.0.0, use highThreshold() instead.
417+
* @return uint16_t The current high threshold value (16-bit unsigned integer): 0x0000 to 0xFFFF
418+
*/
419+
uint16_t getHighThreshold(void)
420+
{
421+
return highThreshold();
422+
}
423+
357424
/**
358425
* @brief Sets the low threshold value for the VEML7700 sensor.
359426
*
@@ -384,6 +451,17 @@ class sfDevVEML7700
384451
*/
385452
uint16_t lowThreshold(void);
386453

454+
/**
455+
* @brief Get the Low Threshold object - this is for backward compatibility.
456+
*
457+
* @deprecated since version 2.0.0, use lowThreshold() instead.
458+
* @return uint16_t The current low threshold value (16-bit unsigned integer): 0x0000 to 0xFFFF
459+
*/
460+
uint16_t getLowThreshold(void)
461+
{
462+
return lowThreshold();
463+
} // Get the Low Threshold object - this is for backward compatibility
464+
387465
/** Read the sensor data */
388466

389467
/**

0 commit comments

Comments
 (0)