|
| 1 | +/** |
| 2 | + * @file APDS9999.h |
| 3 | + * @brief A class for interfacing with the Adafruit APDS9999 sensor. |
| 4 | + * |
| 5 | + * This file defines the APDS9999 class, which provides functionality for detecting proximity, |
| 6 | + * brightness, and determining if the sensor is "booped" (close proximity detection). |
| 7 | + * |
| 8 | + * @date 1/9/2026 |
| 9 | + * @author Coela Can't, AxionQC |
| 10 | + */ |
| 11 | + |
| 12 | +#pragma once |
| 13 | + |
| 14 | +#include <Arduino.h> // Include for Arduino compatibility. |
| 15 | +#include <Wire.h> // Include for I2C communication. |
| 16 | +#include <Adafruit_APDS9999.h> // Include for Adafruit APDS9999 sensor library. |
| 17 | +#include "../../Utils/Filter/MinFilter.h" // Include for minimum filtering. |
| 18 | +#include "../../Utils/Time/TimeStep.h" // Include for timing utilities. |
| 19 | + |
| 20 | +/** |
| 21 | + * @class APDS9999 |
| 22 | + * @brief A class for managing the Adafruit APDS9999 sensor. |
| 23 | + * |
| 24 | + * The APDS9999 class provides methods for initializing the sensor, detecting proximity and brightness, |
| 25 | + * and determining if the sensor is close enough to trigger a "boop" detection. |
| 26 | + */ |
| 27 | +class APDS9999 { |
| 28 | +private: |
| 29 | + static Adafruit_APDS9999 apds; ///< Instance of the Adafruit APDS9999 sensor. |
| 30 | + static uint16_t proximity; ///< Current proximity value. |
| 31 | + static uint16_t threshold; ///< Threshold value for proximity detection. |
| 32 | + static MinFilter<10> minF; ///< Minimum filter for smoothing proximity values. |
| 33 | + static TimeStep timeStep; ///< Time utility for managing timing intervals. |
| 34 | + static float minimum; ///< Minimum detected value. |
| 35 | + static bool didBegin; ///< Flag indicating if the sensor has been initialized. |
| 36 | + static bool isBright; ///< Flag indicating if brightness detection is enabled. |
| 37 | + static bool isProx; ///< Flag indicating if proximity detection is enabled. |
| 38 | + |
| 39 | +public: |
| 40 | + /** |
| 41 | + * @brief Initializes the APDS9999 sensor. |
| 42 | + * |
| 43 | + * @param threshold The threshold for proximity detection. |
| 44 | + * @return True if initialization is successful, false otherwise. |
| 45 | + */ |
| 46 | + static bool Initialize(uint8_t threshold); |
| 47 | + |
| 48 | + /** |
| 49 | + * @brief Checks if the sensor is "booped" (close proximity detected). |
| 50 | + * |
| 51 | + * @return True if the sensor is booped, false otherwise. |
| 52 | + */ |
| 53 | + static bool isBooped(); |
| 54 | + |
| 55 | + /** |
| 56 | + * @brief Resets the I2C bus in case of communication issues. |
| 57 | + */ |
| 58 | + static void ResetI2CBus(); |
| 59 | + |
| 60 | + /** |
| 61 | + * @brief Retrieves the current proximity value. |
| 62 | + * |
| 63 | + * @return The current proximity value as an 8-bit integer. |
| 64 | + */ |
| 65 | + static uint8_t GetValue(); |
| 66 | + |
| 67 | + /** |
| 68 | + * @brief Retrieves the current brightness value. |
| 69 | + * |
| 70 | + * @return The current brightness value as a 16-bit integer. |
| 71 | + */ |
| 72 | + static uint16_t GetBrightness(); |
| 73 | +}; |
0 commit comments