SparkFun Ambient Light Sensor - VEML7700  v2.0.0-1-g1693613
Library for the SparkFun Ambient Light Sensor - VEML7700
Loading...
Searching...
No Matches
sfDevVEML7700.h
Go to the documentation of this file.
1
22#pragma once
23
24#include <stdint.h>
25
26// include the sparkfun toolkit headers
27#include <sfTk/sfToolkit.h>
28
29// Bus interfaces
30#include <sfTk/sfTkII2C.h>
31
32typedef uint16_t VEML7700_t;
33
35#define SF_VEML7700_DEFAULT_ADDRESS 0x10 // Default I2C address for the VEML7700 sensor
36
38typedef enum
39{
46
50typedef enum
51{
60
62typedef enum
63{
70
72typedef enum
73{
79typedef enum
80{
87
89typedef enum
90{
95
96const uint16_t kVEML7700ValueError = 0xFFFF; // Value returned when the VEML7700 is not connected or an error occurs
97
115{
116 public:
117 sfDevVEML7700() : _theBus{nullptr}
118 {
119 }
120
130 sfTkError_t begin(sfTkIBus *theBus = nullptr);
131
137 bool isConnected();
138
150 sfTkError_t setShutdown(bool);
158 sfTkError_t powerOn(void)
159 {
160 return setShutdown(false);
161 };
169 sfTkError_t shutdown(void)
170 {
171 return setShutdown(true);
172 };
181 bool isShutdown(void);
182
191 sfTkError_t enableInterrupt(bool);
192
198 bool isInterruptEnabled(void);
199
215
228
238
246 {
247 return persistenceProtect();
248 }
249
257 const char *persistenceProtectString(void);
258
265 const char *getPersistenceProtectStr(void)
266 {
268 }
269
282
292
301
310 {
311 return integrationTime();
312 }
320 const char *integrationTimeString(void);
321
328 const char *getIntegrationTimeStr(void)
329 {
330 return integrationTimeString();
331 }
332
344
354
363
371 {
372 return sensitivityMode();
373 }
374
382 const char *sensitivityModeString(void);
383
390 const char *getSensitivityModeStr(void)
391 {
392 return sensitivityModeString();
393 }
394
404 sfTkError_t setHighThreshold(uint16_t threshold);
405
414 sfTkError_t getHighThreshold(uint16_t &threshold);
415
423 uint16_t highThreshold(void);
424
431 uint16_t getHighThreshold(void)
432 {
433 return highThreshold();
434 }
435
445 sfTkError_t setLowThreshold(uint16_t threshold);
446
455 sfTkError_t getLowThreshold(uint16_t &threshold);
456
464 uint16_t lowThreshold(void);
465
472 uint16_t getLowThreshold(void)
473 {
474 return lowThreshold();
475 } // Get the Low Threshold object - this is for backward compatibility
476
487 sfTkError_t getAmbientLight(uint16_t &ambient);
495 uint16_t getAmbientLight(void);
496
505 sfTkError_t getWhiteLevel(uint16_t &whiteLevel);
513 uint16_t getWhiteLevel(void);
514
524 sfTkError_t getLux(float &lux);
525
533 float getLux(void);
534
550
558 {
559 return interruptStatus();
560 } // Get the Interrupt Status object - this is for backward compatibility
561
562 private:
564 typedef struct
565 {
566 union {
567 VEML7700_t all;
568 struct
569 {
570 VEML7700_t CONFIG_REG_SD : 1; // ALS shut down
571 VEML7700_t CONFIG_REG_INT_EN : 1; // ALS interrupt enable
572 VEML7700_t CONFIG_REG_RES1 : 2; // Reserved
573 VEML7700_t CONFIG_REG_PERS : 2; // ALS persistence protect number
574 VEML7700_t CONFIG_REG_IT : 4; // ALS integration time
575 VEML7700_t CONFIG_REG_RES2 : 1; // Reserved
576 VEML7700_t CONFIG_REG_SM : 2; // ALS sensitivity mode
577 VEML7700_t CONFIG_REG_RES3 : 3; // Reserved
578 };
579 };
580 } sfDevVEML7700Config_t;
581
585 typedef struct
586 {
587 union {
588 VEML7700_t all;
589 struct
590 {
591 VEML7700_t INT_STATUS_REG_RES : 14; // Reserved
592 // Bit 14 indicates if the high threshold was exceeded
593 // Bit 15 indicates if the low threshold was exceeded
594 VEML7700_t INT_STATUS_REG_INT_FLAGS : 2;
595 };
596 };
597 } VEML7700_INTERRUPT_STATUS_REGISTER_t;
598
599 // VEML7700 Registers - note types are uint8_t to match the I2C register size
600
601 static constexpr uint8_t VEML7700_CONFIGURATION_REGISTER = 0;
602 static constexpr uint8_t VEML7700_HIGH_THRESHOLD = 1;
603 static constexpr uint8_t VEML7700_LOW_THRESHOLD = 2;
604 static constexpr uint8_t VEML7700_ALS_OUTPUT = 4;
605 static constexpr uint8_t VEML7700_WHITE_OUTPUT = 5;
606 static constexpr uint8_t VEML7700_INTERRUPT_STATUS = 6;
607
608 // ALS integration time setting
609 typedef enum
610 {
611 VEML7700_CONFIG_INTEGRATION_25ms = 0b1100,
612 VEML7700_CONFIG_INTEGRATION_50ms = 0b1000,
613 VEML7700_CONFIG_INTEGRATION_100ms = 0b0000,
614 VEML7700_CONFIG_INTEGRATION_200ms = 0b0001,
615 VEML7700_CONFIG_INTEGRATION_400ms = 0b0010,
616 VEML7700_CONFIG_INTEGRATION_800ms = 0b0011,
617 VEML7700_CONFIG_INTEGRATION_INVALID
618 } VEML7700_config_integration_time_t;
619
633 sfTkError_t updateConfiguration(sfDevVEML7700Config_t &config);
634
639 VEML7700_config_integration_time_t integrationTimeConfig(VEML7700_integration_time_t it);
640
645 VEML7700_integration_time_t integrationTimeFromConfig(VEML7700_config_integration_time_t it);
646
650 sfTkIBus *_theBus;
651};
Driver class for the VEML7700 ambient light sensor.
Definition: sfDevVEML7700.h:115
VEML7700_sensitivity_mode_t sensitivityMode(void)
Gets the current sensitivity mode setting of the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:369
VEML7700_interrupt_status_t interruptStatus(void)
Retrieves the current interrupt status from the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:542
sfTkError_t powerOn(void)
Powers on the VEML7700 device by clearing the shutdown mode.
Definition: sfDevVEML7700.h:158
VEML7700_integration_time_t integrationTime(void)
Gets the current integration time setting of the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:313
uint16_t lowThreshold(void)
Gets the current low threshold value of the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:438
VEML7700_sensitivity_mode_t getSensitivityMode(void)
Get the Sensitivity Mode object - this is for backward compatibility.
Definition: sfDevVEML7700.h:370
uint16_t getHighThreshold(void)
Get the High Threshold object - this is for backward compatibility.
Definition: sfDevVEML7700.h:431
sfTkError_t shutdown(void)
Puts the VEML7700 device into shutdown mode.
Definition: sfDevVEML7700.h:169
const char * integrationTimeString(void)
Returns a string representation of the current integration time setting.
Definition: sfDevVEML7700.cpp:324
VEML7700_persistence_protect_t getPersistenceProtect(void)
Get the Persistence Protect object - this is for backward compatibility.
Definition: sfDevVEML7700.h:245
bool isConnected()
Checks if the VEML7700 sensor is connected and responding.
Definition: sfDevVEML7700.cpp:147
sfTkError_t enableInterrupt(bool)
Enables or disables the interrupt functionality of the VEML7700 device.
Definition: sfDevVEML7700.cpp:188
const char * sensitivityModeString(void)
Returns a string representation of the current sensitivity mode setting.
Definition: sfDevVEML7700.cpp:382
float getLux(void)
Reads the current ambient light level in lux.
Definition: sfDevVEML7700.cpp:528
sfDevVEML7700()
Definition: sfDevVEML7700.h:117
const char * getIntegrationTimeStr(void)
Get the Integration Time string - this is for backward compatibility.
Definition: sfDevVEML7700.h:328
sfTkError_t setPersistenceProtect(VEML7700_persistence_protect_t pp)
Sets the persistence protection mode for the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:221
uint16_t getWhiteLevel(void)
Reads the current white light level from the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:477
sfTkError_t setIntegrationTime(VEML7700_integration_time_t it)
Sets the integration time for the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:278
VEML7700_interrupt_status_t getInterruptStatus(void)
Gets the interrupt status of the VEML7700 sensor.
Definition: sfDevVEML7700.h:557
bool isShutdown(void)
Checks if the VEML7700 device is currently in shutdown mode.
Definition: sfDevVEML7700.cpp:174
uint16_t highThreshold(void)
Gets the current high threshold value of the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:411
VEML7700_integration_time_t getIntegrationTime(void)
Get the Integration Time object - this is for backward compatibility.
Definition: sfDevVEML7700.h:309
sfTkError_t setHighThreshold(uint16_t threshold)
Sets the high threshold value for the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:395
const char * getSensitivityModeStr(void)
Get the Sensitivity Mode string - this is for backward compatibility.
Definition: sfDevVEML7700.h:390
bool isInterruptEnabled(void)
Checks if the interrupt feature is enabled on the VEML7700 device.
Definition: sfDevVEML7700.cpp:205
VEML7700_persistence_protect_t persistenceProtect(void)
Gets the current persistence protection setting of the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:256
uint16_t getLowThreshold(void)
Get the Low Threshold object - this is for backward compatibility.
Definition: sfDevVEML7700.h:472
sfTkError_t setSensitivityMode(VEML7700_sensitivity_mode_t sm)
Sets the sensitivity mode for the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:337
const char * persistenceProtectString(void)
Returns a string representation of the current persistence protection setting.
Definition: sfDevVEML7700.cpp:265
sfTkError_t setLowThreshold(uint16_t threshold)
Sets the low threshold value for the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:422
sfTkError_t begin(sfTkIBus *theBus=nullptr)
Initializes the VEML7700 device on the specified bus.
Definition: sfDevVEML7700.cpp:121
const char * getPersistenceProtectStr(void)
Get the Persistence Protect object - this is for backward compatibility.
Definition: sfDevVEML7700.h:265
uint16_t getAmbientLight(void)
Reads the ambient light measurement from the VEML7700 sensor.
Definition: sfDevVEML7700.cpp:457
sfTkError_t setShutdown(bool)
Sets the shutdown mode of the VEML7700 device.
Definition: sfDevVEML7700.cpp:156
VEML7700_interrupt_enable_t
Definition: sfDevVEML7700.h:73
@ VEML7700_INT_INVALID
Definition: sfDevVEML7700.h:76
@ VEML7700_INT_ENABLE
Definition: sfDevVEML7700.h:75
@ VEML7700_INT_DISABLE
Definition: sfDevVEML7700.h:74
VEML7700_integration_time_t
Definition: sfDevVEML7700.h:51
@ VEML7700_INTEGRATION_50ms
Definition: sfDevVEML7700.h:53
@ VEML7700_INTEGRATION_100ms
Definition: sfDevVEML7700.h:54
@ VEML7700_INTEGRATION_200ms
Definition: sfDevVEML7700.h:55
@ VEML7700_INTEGRATION_400ms
Definition: sfDevVEML7700.h:56
@ VEML7700_INTEGRATION_25ms
Definition: sfDevVEML7700.h:52
@ VEML7700_INTEGRATION_800ms
Definition: sfDevVEML7700.h:57
@ VEML7700_INTEGRATION_INVALID
Definition: sfDevVEML7700.h:58
const uint16_t kVEML7700ValueError
Definition: sfDevVEML7700.h:96
VEML7700_shutdown_t
Definition: sfDevVEML7700.h:90
@ VEML7700_SHUT_DOWN
Definition: sfDevVEML7700.h:92
@ VEML7700_SHUTDOWN_INVALID
Definition: sfDevVEML7700.h:93
@ VEML7700_POWER_ON
Definition: sfDevVEML7700.h:91
VEML7700_interrupt_status_t
Definition: sfDevVEML7700.h:80
@ VEML7700_INT_STATUS_HIGH
Definition: sfDevVEML7700.h:82
@ VEML7700_INT_STATUS_BOTH
Definition: sfDevVEML7700.h:84
@ VEML7700_INT_STATUS_LOW
Definition: sfDevVEML7700.h:83
@ VEML7700_INT_STATUS_INVALID
Definition: sfDevVEML7700.h:85
@ VEML7700_INT_STATUS_NONE
Definition: sfDevVEML7700.h:81
uint16_t VEML7700_t
Definition: sfDevVEML7700.h:32
VEML7700_sensitivity_mode_t
Definition: sfDevVEML7700.h:39
@ VEML7700_SENSITIVITY_x2
Definition: sfDevVEML7700.h:41
@ VEML7700_SENSITIVITY_INVALID
Definition: sfDevVEML7700.h:44
@ VEML7700_SENSITIVITY_x1
Definition: sfDevVEML7700.h:40
@ VEML7700_SENSITIVITY_x1_8
Definition: sfDevVEML7700.h:42
@ VEML7700_SENSITIVITY_x1_4
Definition: sfDevVEML7700.h:43
VEML7700_persistence_protect_t
Definition: sfDevVEML7700.h:63
@ VEML7700_PERSISTENCE_8
Definition: sfDevVEML7700.h:67
@ VEML7700_PERSISTENCE_4
Definition: sfDevVEML7700.h:66
@ VEML7700_PERSISTENCE_2
Definition: sfDevVEML7700.h:65
@ VEML7700_PERSISTENCE_1
Definition: sfDevVEML7700.h:64
@ VEML7700_PERSISTENCE_INVALID
Definition: sfDevVEML7700.h:68