ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
APDS9960.h
Go to the documentation of this file.
1/**
2 * @file APDS9960.h
3 * @brief A class for interfacing with the Adafruit APDS9960 sensor.
4 *
5 * This file defines the APDS9960 class, which provides functionality for detecting proximity,
6 * brightness, and determining if the sensor is "booped" (close proximity detection).
7 *
8 * @date 22/12/2024
9 * @author Coela Can't
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_APDS9960.h> // Include for Adafruit APDS9960 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 APDS9960
22 * @brief A class for managing the Adafruit APDS9960 sensor.
23 *
24 * The APDS9960 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 */
27class APDS9960 {
28private:
29 static Adafruit_APDS9960 apds; ///< Instance of the Adafruit APDS9960 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
39public:
40 /**
41 * @brief Initializes the APDS9960 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};
A class for managing the Adafruit APDS9960 sensor.
Definition APDS9960.h:27
static bool isProx
Flag indicating if proximity detection is enabled.
Definition APDS9960.h:37
static uint16_t GetBrightness()
Retrieves the current brightness value.
Definition APDS9960.cpp:78
static float minimum
Minimum detected value.
Definition APDS9960.h:34
static MinFilter< 10 > minF
Minimum filter for smoothing proximity values.
Definition APDS9960.h:32
static bool isBright
Flag indicating if brightness detection is enabled.
Definition APDS9960.h:36
static bool Initialize(uint8_t threshold)
Initializes the APDS9960 sensor.
Definition APDS9960.cpp:14
static bool isBooped()
Checks if the sensor is "booped" (close proximity detected).
Definition APDS9960.cpp:43
static TimeStep timeStep
Time utility for managing timing intervals.
Definition APDS9960.h:33
static uint8_t GetValue()
Retrieves the current proximity value.
Definition APDS9960.cpp:59
static uint16_t proximity
Current proximity value.
Definition APDS9960.h:30
static Adafruit_APDS9960 apds
Instance of the Adafruit APDS9960 sensor.
Definition APDS9960.h:29
static uint16_t threshold
Threshold value for proximity detection.
Definition APDS9960.h:31
static void ResetI2CBus()
Resets the I2C bus in case of communication issues.
Definition APDS9960.cpp:53
static bool didBegin
Flag indicating if the sensor has been initialized.
Definition APDS9960.h:35
Implements a minimum filter over a sliding window.
Definition MinFilter.h:28
Provides a mechanism to trigger actions at a specified frequency.
Definition TimeStep.h:18