Skip to content

Commit eec243e

Browse files
committed
initial refactor of the library - not tested, not even compiled
1 parent dd7d8fd commit eec243e

File tree

3 files changed

+480
-860
lines changed

3 files changed

+480
-860
lines changed
Lines changed: 46 additions & 239 deletions
Original file line numberDiff line numberDiff line change
@@ -1,252 +1,59 @@
1-
/*!
1+
/******************************************************************************
22
* @file SparkFun_VEML7700_Arduino_Library.h
3+
* @brief SparkFun VEML7700 Library header file
34
*
4-
* SparkFun VEML7700 Ambient Light Sensor Arduino Library
5+
* This file implements the SparkFunVEML7700 class
6+
* for use with the SparkFun VEML7700 sensor qwiic breakout board
57
*
6-
* This library facilitates communication with the VEML7700 over I<sup>2</sup>C.
8+
* @author SparkFUn Electronics
9+
* @date 2021-2025
10+
* @version 2.0.0
11+
* @copyright (c) 2021=2025 SparkFun Electronics Inc. This project is released under the MIT License.
712
*
8-
* Want to support open source hardware? Buy a board from SparkFun!
9-
* <br>SparkX smôl Environmental Peripheral Board (SPX-18976): https://www.sparkfun.com/products/18976
13+
* SPDX-License-Identifier: MIT
1014
*
11-
* This library was written by:
12-
* Paul Clark
13-
* SparkFun Electronics
14-
* November 4th 2021
15-
*
16-
* Please see LICENSE.md for the license information
17-
*
18-
*/
19-
20-
#ifndef __SFE_SMOL_POWER_BOARD__
21-
#define __SFE_SMOL_POWER_BOARD__
22-
23-
#include <Arduino.h>
24-
#include <Wire.h>
25-
26-
typedef uint16_t VEML7700_t;
27-
28-
/** VEML7700 I2C address */
29-
#define VEML7700_I2C_ADDRESS 0x10
30-
31-
/** VEML7700 error code returns */
32-
typedef enum
33-
{
34-
VEML7700_ERROR_READ = -4,
35-
VEML7700_ERROR_WRITE = -3,
36-
VEML7700_ERROR_INVALID_ADDRESS = -2,
37-
VEML7700_ERROR_UNDEFINED = -1,
38-
VEML7700_ERROR_SUCCESS = 1
39-
} VEML7700_error_t;
40-
const VEML7700_error_t VEML7700_SUCCESS = VEML7700_ERROR_SUCCESS;
41-
42-
/** Sensitivity mode selection */
43-
typedef enum
44-
{
45-
VEML7700_SENSITIVITY_x1,
46-
VEML7700_SENSITIVITY_x2,
47-
VEML7700_SENSITIVITY_x1_8,
48-
VEML7700_SENSITIVITY_x1_4,
49-
VEML7700_SENSITIVITY_INVALID
50-
} VEML7700_sensitivity_mode_t;
51-
52-
/** ALS integration time setting
53-
Note: these are defined here in simple sequential order.
54-
The actual register settings are defined in VEML7700_config_integration_time_t */
55-
typedef enum
56-
{
57-
VEML7700_INTEGRATION_25ms,
58-
VEML7700_INTEGRATION_50ms,
59-
VEML7700_INTEGRATION_100ms,
60-
VEML7700_INTEGRATION_200ms,
61-
VEML7700_INTEGRATION_400ms,
62-
VEML7700_INTEGRATION_800ms,
63-
VEML7700_INTEGRATION_INVALID
64-
} VEML7700_integration_time_t;
65-
66-
/** ALS persistence protect number setting */
67-
typedef enum
68-
{
69-
VEML7700_PERSISTENCE_1,
70-
VEML7700_PERSISTENCE_2,
71-
VEML7700_PERSISTENCE_4,
72-
VEML7700_PERSISTENCE_8,
73-
VEML7700_PERSISTENCE_INVALID
74-
} VEML7700_persistence_protect_t;
75-
76-
/** ALS interrupt enable setting */
77-
typedef enum
78-
{
79-
VEML7700_INT_DISABLE,
80-
VEML7700_INT_ENABLE,
81-
VEML7700_INT_INVALID
82-
} VEML7700_interrupt_enable_t;
83-
84-
/** ALS interrupt status, logical OR of the crossing low and high thrteshold INT triggers */
85-
typedef enum
86-
{
87-
VEML7700_INT_STATUS_NONE,
88-
VEML7700_INT_STATUS_HIGH,
89-
VEML7700_INT_STATUS_LOW,
90-
VEML7700_INT_STATUS_BOTH,
91-
VEML7700_INT_STATUS_INVALID
92-
} VEML7700_interrupt_status_t;
93-
94-
/** ALS shut down setting */
95-
typedef enum
96-
{
97-
VEML7700_POWER_ON,
98-
VEML7700_SHUT_DOWN,
99-
VEML7700_SHUTDOWN_INVALID
100-
} VEML7700_shutdown_t;
101-
102-
/** Communication interface for the VEML7700 */
103-
class VEML7700
104-
{
105-
public:
106-
/** @brief Class to communicate with the VEML7700 */
107-
VEML7700();
108-
109-
/** Begin the VEML7700. Default to Wire */
110-
bool begin(TwoWire &wirePort = Wire);
15+
******************************************************************************/
11116

112-
/** Enable debug messages. Default to Serial */
113-
void enableDebugging(Stream &debugPort = Serial);
114-
void disableDebugging();
17+
#pragma once
11518

116-
bool isConnected();
19+
// helps to keep the Toolkit header before the tk calls
20+
// clang-format off
21+
#include <SparkFun_Toolkit.h>
22+
#include "sfTk/sfDevVEML7700.h"
23+
// clang-format on
11724

118-
/** Configuration controls */
119-
120-
VEML7700_error_t setShutdown(VEML7700_shutdown_t);
121-
VEML7700_error_t powerOn() { return setShutdown(VEML7700_POWER_ON); };
122-
VEML7700_error_t shutdown() { return setShutdown(VEML7700_SHUT_DOWN); };
123-
VEML7700_shutdown_t getShutdown();
124-
125-
VEML7700_error_t setInterruptEnable(VEML7700_interrupt_enable_t ie);
126-
VEML7700_error_t getInterruptEnable(VEML7700_interrupt_enable_t *ie);
127-
VEML7700_interrupt_enable_t getInterruptEnable();
128-
129-
VEML7700_error_t setPersistenceProtect(VEML7700_persistence_protect_t pp);
130-
VEML7700_error_t getPersistenceProtect(VEML7700_persistence_protect_t *pp);
131-
VEML7700_persistence_protect_t getPersistenceProtect();
132-
const char * getPersistenceProtectStr();
133-
134-
VEML7700_error_t setIntegrationTime(VEML7700_integration_time_t it);
135-
VEML7700_error_t getIntegrationTime(VEML7700_integration_time_t *it);
136-
VEML7700_integration_time_t getIntegrationTime();
137-
const char * getIntegrationTimeStr();
138-
139-
VEML7700_error_t setSensitivityMode(VEML7700_sensitivity_mode_t sm);
140-
VEML7700_error_t getSensitivityMode(VEML7700_sensitivity_mode_t *sm);
141-
VEML7700_sensitivity_mode_t getSensitivityMode();
142-
const char * getSensitivityModeStr();
143-
144-
VEML7700_error_t setHighThreshold(uint16_t threshold);
145-
VEML7700_error_t getHighThreshold(uint16_t *threshold);
146-
uint16_t getHighThreshold();
147-
148-
VEML7700_error_t setLowThreshold(uint16_t threshold);
149-
VEML7700_error_t getLowThreshold(uint16_t *threshold);
150-
uint16_t getLowThreshold();
151-
152-
/** Read the sensor data */
153-
154-
VEML7700_error_t getAmbientLight(uint16_t *ambient);
155-
uint16_t getAmbientLight();
156-
157-
VEML7700_error_t getWhiteLevel(uint16_t *whiteLevel);
158-
uint16_t getWhiteLevel();
159-
160-
VEML7700_error_t getLux(float *lux);
161-
float getLux();
162-
163-
/** Note: reading the interrupt status register clears the interrupts.
164-
So, we need to check both interrupt flags in a single read. */
165-
VEML7700_error_t getInterruptStatus(VEML7700_interrupt_status_t *status);
166-
VEML7700_interrupt_status_t getInterruptStatus();
167-
168-
private:
169-
170-
/** Provide bit field access to the configuration register */
171-
typedef struct
172-
{
173-
union
174-
{
175-
VEML7700_t all;
176-
struct
177-
{
178-
VEML7700_t CONFIG_REG_SD : 1; // ALS shut down
179-
VEML7700_t CONFIG_REG_INT_EN : 1; // ALS interrupt enable
180-
VEML7700_t CONFIG_REG_RES1 : 2; // Reserved
181-
VEML7700_t CONFIG_REG_PERS : 2; // ALS persistence protect number
182-
VEML7700_t CONFIG_REG_IT : 4; // ALS integration time
183-
VEML7700_t CONFIG_REG_RES2 : 1; // Reserved
184-
VEML7700_t CONFIG_REG_SM : 2; // ALS sensitivity mode
185-
VEML7700_t CONFIG_REG_RES3 : 3; // Reserved
186-
};
187-
};
188-
} VEML7700_CONFIGURATION_REGISTER_t;
189-
VEML7700_CONFIGURATION_REGISTER_t _configurationRegister;
190-
191-
/** Provide bit field access to the interrupt status register
192-
Note: reading the interrupt status register clears the interrupts.
193-
So, we need to check both interrupt flags in a single read. */
194-
typedef struct
195-
{
196-
union
25+
/**
26+
* @brief Class for interfacing with the VMEL7700 sensor using I2C communication
27+
*
28+
* This class provides methods to initialize and communicate with the BMV080 sensor
29+
* over an I2C bus. It inherits from the sfDevVEML7700 class and uses the SparkFun
30+
* Toolkit for I2C communication.
31+
*
32+
* @see sfDevVEML7700
33+
*/
34+
class SparkFunVEML7700 : public sfDevVEML7700
35+
{
36+
public:
37+
/**
38+
* @brief Begins the Device with I2C as the communication bus
39+
*
40+
* This method initializes the I2C bus and sets up communication with the VEML7700 sensor.
41+
*
42+
* @param address I2C device address to use for the sensor
43+
* @param wirePort Wire port to use for I2C communication
44+
* @return True if successful, false otherwise
45+
*/
46+
bool begin(const uint8_t address = SF_VEML7700_DEFAULT_ADDRESS, TwoWire &wirePort = Wire)
19747
{
198-
VEML7700_t all;
199-
struct
200-
{
201-
VEML7700_t INT_STATUS_REG_RES : 14; // Reserved
202-
// Bit 14 indicates if the high threshold was exceeded
203-
// Bit 15 indicates if the low threshold was exceeded
204-
VEML7700_t INT_STATUS_REG_INT_FLAGS : 2;
205-
};
206-
};
207-
} VEML7700_INTERRUPT_STATUS_REGISTER_t;
208-
209-
/** VEML7700 Registers */
210-
typedef enum
211-
{
212-
VEML7700_CONFIGURATION_REGISTER,
213-
VEML7700_HIGH_THRESHOLD,
214-
VEML7700_LOW_THRESHOLD,
215-
VEML7700_ALS_OUTPUT = 4,
216-
VEML7700_WHITE_OUTPUT,
217-
VEML7700_INTERRUPT_STATUS
218-
} VEML7700_registers_t;
219-
220-
/** ALS integration time setting */
221-
typedef enum
222-
{
223-
VEML7700_CONFIG_INTEGRATION_25ms = 0b1100,
224-
VEML7700_CONFIG_INTEGRATION_50ms = 0b1000,
225-
VEML7700_CONFIG_INTEGRATION_100ms = 0b0000,
226-
VEML7700_CONFIG_INTEGRATION_200ms = 0b0001,
227-
VEML7700_CONFIG_INTEGRATION_400ms = 0b0010,
228-
VEML7700_CONFIG_INTEGRATION_800ms = 0b0011,
229-
VEML7700_CONFIG_INTEGRATION_INVALID
230-
} VEML7700_config_integration_time_t;
48+
// Setup Arduino I2C bus
49+
_theI2CBus.init(wirePort, address);
23150

232-
TwoWire *_i2cPort;
233-
Stream *_debugPort;
234-
uint8_t _deviceAddress;
235-
bool _debugEnabled;
51+
// Begin the sensor
52+
sfTkError_t rc = sfDevVEML7700::begin(&_theI2CBus);
23653

237-
VEML7700_error_t _connected(void);
238-
239-
/** I2C Read/Write */
240-
VEML7700_error_t readI2CBuffer(uint8_t *dest, VEML7700_registers_t startRegister, uint16_t len);
241-
VEML7700_error_t writeI2CBuffer(uint8_t *src, VEML7700_registers_t startRegister, uint16_t len);
242-
VEML7700_error_t readI2CRegister(VEML7700_t *dest, VEML7700_registers_t registerAddress);
243-
VEML7700_error_t writeI2CRegister(VEML7700_t data, VEML7700_registers_t registerAddress);
244-
245-
/** Convert the (sequential) integration time into the corresponding (non-sequential) configuration value */
246-
VEML7700_config_integration_time_t integrationTimeConfig(VEML7700_integration_time_t it);
247-
/** Convert the (non-sequential) integration time config into the corresponding (sequential) integration time */
248-
VEML7700_integration_time_t integrationTimeFromConfig(VEML7700_config_integration_time_t it);
54+
return rc == ksfTkErrOk ? isConnected() : false;
55+
}
24956

57+
private:
58+
sfTkArdI2C _theI2CBus;
25059
};
251-
252-
#endif

0 commit comments

Comments
 (0)