libPlayingWithFusion  2020.02.24
Playing With Fusion driver library for FRC roboRIO
TMD37003.h
1 #pragma once
2 #include <algorithm>
3 #include <chrono>
4 #include <cstdint>
5 #include "frc/I2C.h"
6 
7 #define inline
8 #include <frc/util/Color.h>
9 #undef inline
10 
11 
12 namespace frc {
13 
14 class TMD37003 {
15  public:
21  TMD37003(I2C::Port i2cPort);
22 
23 
32  void ConfigureColorSense(double alsIntegrationTime, int alsGain);
33 
34 
48  void ConfigureProximitySense(double proximitySampleTime, double proximityPulseLength, int numProximityPulses,
49  int proximityGain, int proximityLedCurrent);
50 
51 
70  void SetGain(double r, double g, double b, double c, double gamma);
71 
72 
78  Color GetColor();
79 
80 
86  double GetHue();
87 
88 
94  double GetSaturation();
95 
96 
101  double GetRed();
102 
103 
108  double GetGreen();
109 
110 
115  double GetBlue();
116 
121  double GetAmbientLightLevel();
122 
123 
128  double GetProximity();
129 
130 
131  private:
132  const uint8_t m_deviceAddress = 0x39;
133  I2C m_port;
134  std::chrono::steady_clock::time_point lastRx;
135 
136  bool m_alsSaturated;
137  bool m_proximitySaturated;
138  double m_r;
139  double m_g;
140  double m_b;
141  double m_c;
142  double m_proximity;
143 
144  double m_alsIntegrationTime = 80;
145  double m_alsWaitTime = 0;
146  int m_alsGain = 4;
147  double m_proximitySampleTime = 20;
148  double m_proximityPulseLength = 0.008;
149  int m_numProximityPulses = 2;
150  int m_proximityGain = 2;
151  int m_proximityLedCurrent = 90;
152 
153  double m_gamma = 1.0 / 2.2;
154  double m_rGain = 1.0 / 0.197;
155  double m_gGain = 1.0 / 0.126;
156  double m_bGain = 1.0 / 0.071;
157  double m_cGain = 1.0 / 0.340;
158 
159  enum Reg {
160  ENABLE = 0x80,
161  ATIME = 0x81,
162  PRATE = 0x82,
163  WTIME = 0x83,
164  AILTL = 0x84,
165  AILTH = 0x85,
166  AIHTL = 0x86,
167  AIHTH = 0x87,
168  PILT = 0x88,
169  PIHT = 0x8A,
170  PERS = 0x8C,
171  CFG0 = 0x8D,
172  PCFG0 = 0x8E,
173  PCFG1 = 0x8F,
174  CFG1 = 0x90,
175  REVID = 0x91,
176  ID = 0x92,
177  STATUS = 0x93,
178  CDATAL = 0x94,
179  CDATAH = 0x95,
180  RDATAL = 0x96,
181  RDATAH = 0x97,
182  GDATAL = 0x98,
183  GDATAH = 0x99,
184  BDATAL = 0x9A,
185  BDATAH = 0x9B,
186  PDATA = 0x9C,
187  CFG2 = 0x9F,
188  CFG3 = 0xAB,
189  POFFSET_L = 0xC0,
190  POFFSET_H = 0xC1,
191  CALIB = 0xD7,
192  CALIBCFG = 0xD9,
193  CALIBSTAT = 0xDC,
194  INTENAB = 0xDD
195  };
196 
197  void PushConfiguration();
198 
199  void Read();
200 };
201 
202 }
frc::TMD37003::GetAmbientLightLevel
double GetAmbientLightLevel()
Definition: TMD37003.cpp:203
frc::TMD37003::GetBlue
double GetBlue()
Definition: TMD37003.cpp:194
frc::TMD37003::GetGreen
double GetGreen()
Definition: TMD37003.cpp:184
frc::TMD37003
Definition: TMD37003.h:14
frc::TMD37003::GetColor
Color GetColor()
Definition: TMD37003.cpp:110
frc::TMD37003::TMD37003
TMD37003(I2C::Port i2cPort)
Definition: TMD37003.cpp:12
frc::TMD37003::ConfigureColorSense
void ConfigureColorSense(double alsIntegrationTime, int alsGain)
Definition: TMD37003.cpp:41
frc::TMD37003::GetSaturation
double GetSaturation()
Definition: TMD37003.cpp:155
frc::TMD37003::SetGain
void SetGain(double r, double g, double b, double c, double gamma)
Definition: TMD37003.cpp:94
frc::TMD37003::GetRed
double GetRed()
Definition: TMD37003.cpp:174
frc::TMD37003::ConfigureProximitySense
void ConfigureProximitySense(double proximitySampleTime, double proximityPulseLength, int numProximityPulses, int proximityGain, int proximityLedCurrent)
Definition: TMD37003.cpp:64
frc::TMD37003::GetHue
double GetHue()
Definition: TMD37003.cpp:120
frc::TMD37003::GetProximity
double GetProximity()
Definition: TMD37003.cpp:213