ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
APDS9999.cpp
Go to the documentation of this file.
1#include "APDS9999.h"
2
3Adafruit_APDS9999 APDS9999::apds;
6
9float APDS9999::minimum = 0.0f;
10bool APDS9999::didBegin = false;
11bool APDS9999::isBright = false;
12bool APDS9999::isProx = false;
13
14bool APDS9999::Initialize(uint8_t threshold)
15{
17
18 Wire.setClock(100000); // for longer-range transmissions
19 Wire.begin();
20
21#ifdef WS35
22 Wire.setSDA(19);
23 Wire.setSCL(18);
24#else
25 Wire.setSDA(18);
26 Wire.setSCL(19);
27#endif
28
29 Wire.beginTransmission(0x39);
30 uint8_t error = Wire.endTransmission();
31
32 if (error == 0)
33 { // SSD1306 Found
34 didBegin = apds.begin();
35
36 // apds.setLED(APDS9960_LEDDRIVE_12MA, APDS9960_LEDBOOST_100PCNT);
37 // apds.setProxGain(APDS9960_PGAIN_1X);
38 }
39 else
40 {
41 didBegin = false;
42 }
43
44 return didBegin;
45}
46
48{
49 GetValue();
50
51 if (timeStep.IsReady())
52 {
54 }
55
56 return proximity > minimum + threshold;
57}
58
60{
61 Wire.end(); // Disable the I2C hardware
62 delay(10); // Wait a bit
63 Wire.begin(); // Re-enable the I2C hardware
64}
65
67{
68 unsigned long cmdTime = millis();
69
70 if (didBegin)
71 {
72 if (!isProx)
73 {
74 apds.enableProximitySensor(true);
75 isProx = true;
76 }
77 uint16_t proxVal = 0;
78 apds.readProximity(&proxVal);
79 proximity = proxVal;
80 }
81
82 if (millis() - cmdTime > 100)
83 {
84 // Timeout occurred
86 }
87
88 return proximity;
89}
90
92{
93 uint16_t brightness;
94
95 if (didBegin)
96 {
97 if (!isBright)
98 {
99 apds.lightSensorEnabled();
100 isBright = true;
101 }
102
103 brightness = apds.getLightGain();
104 }
105 else
106 {
107 brightness = 0;
108 }
109
110 return brightness;
111}
A class for interfacing with the Adafruit APDS9999 sensor.
static bool isProx
Flag indicating if proximity detection is enabled.
Definition APDS9999.h:37
static uint16_t GetBrightness()
Retrieves the current brightness value.
Definition APDS9999.cpp:91
static float minimum
Minimum detected value.
Definition APDS9999.h:34
static MinFilter< 10 > minF
Minimum filter for smoothing proximity values.
Definition APDS9999.h:32
static bool isBright
Flag indicating if brightness detection is enabled.
Definition APDS9999.h:36
static bool Initialize(uint8_t threshold)
Initializes the APDS9999 sensor.
Definition APDS9999.cpp:14
static bool isBooped()
Checks if the sensor is "booped" (close proximity detected).
Definition APDS9999.cpp:47
static TimeStep timeStep
Time utility for managing timing intervals.
Definition APDS9999.h:33
static uint8_t GetValue()
Retrieves the current proximity value.
Definition APDS9999.cpp:66
static uint16_t proximity
Current proximity value.
Definition APDS9999.h:30
static uint16_t threshold
Threshold value for proximity detection.
Definition APDS9999.h:31
static void ResetI2CBus()
Resets the I2C bus in case of communication issues.
Definition APDS9999.cpp:59
static bool didBegin
Flag indicating if the sensor has been initialized.
Definition APDS9999.h:35
static Adafruit_APDS9999 apds
Instance of the Adafruit APDS9999 sensor.
Definition APDS9999.h:29
Implements a minimum filter over a sliding window.
Definition MinFilter.h:28
float Filter(float value)
Filters the given value, updating the minimum value within the memory window.
Provides a mechanism to trigger actions at a specified frequency.
Definition TimeStep.h:18
bool IsReady()
Checks if the specified time interval has elapsed.
Definition TimeStep.cpp:11