Treehopper C++ API
Vcnl4010Registers.h
Go to the documentation of this file.
1 #pragma once
3 #include "SMBusDevice.h"
6 #include "Libraries/Register.h"
7 
8 using namespace Treehopper::Libraries;
9 
10 namespace Treehopper { namespace Libraries { namespace Sensors { namespace Optical {
11 
12  enum class Rates
13  {
14  Hz_1_95 = 0,
15  Hz_3_90625 = 1,
16  Hz_7_8125 = 2,
17  Hz_16_625 = 3,
18  Hz_31_25 = 4,
19  Hz_62_5 = 5,
20  Hz_125 = 6,
21  Hz_250 = 7
22  };
23 
24  enum class AlsRates
25  {
26  Hz_1 = 0,
27  Hz_2 = 1,
28  Hz_3 = 2,
29  Hz_4 = 3,
30  Hz_5 = 4,
31  Hz_6 = 5,
32  Hz_8 = 6,
33  Hz_10 = 7
34  };
35 
36  enum class IntCountExceeds
37  {
38  count_1 = 0,
39  count_2 = 1,
40  count_4 = 2,
41  count_8 = 3,
42  count_16 = 4,
43  count_32 = 5,
44  count_64 = 6,
45  count_128 = 7
46  };
47 
48 
49  class Vcnl4010Registers : public RegisterManager
50  {
51  public:
52  class CommandRegister : public Register
53  {
54  public:
55  CommandRegister(RegisterManager& regManager) : Register(regManager,0x80, 1, false) { }
56  int selfTimedEnable;
57  int proxPeriodicEnable;
58  int alsPeriodicEnable;
59  int proxOnDemandStart;
60  int alsOnDemandStart;
61  int proxDataReady;
62  int alsDataReady;
63  int configLock;
64 
65  long getValue() { return ((selfTimedEnable & 0x1) << 0) | ((proxPeriodicEnable & 0x1) << 1) | ((alsPeriodicEnable & 0x1) << 2) | ((proxOnDemandStart & 0x1) << 3) | ((alsOnDemandStart & 0x1) << 4) | ((proxDataReady & 0x1) << 5) | ((alsDataReady & 0x1) << 6) | ((configLock & 0x1) << 7); }
66  void setValue(long val)
67  {
68  selfTimedEnable = (int)((val >> 0) & 0x1);
69  proxPeriodicEnable = (int)((val >> 1) & 0x1);
70  alsPeriodicEnable = (int)((val >> 2) & 0x1);
71  proxOnDemandStart = (int)((val >> 3) & 0x1);
72  alsOnDemandStart = (int)((val >> 4) & 0x1);
73  proxDataReady = (int)((val >> 5) & 0x1);
74  alsDataReady = (int)((val >> 6) & 0x1);
75  configLock = (int)((val >> 7) & 0x1);
76  }
77  };
78 
79  class ProductIdRegister : public Register
80  {
81  public:
82  ProductIdRegister(RegisterManager& regManager) : Register(regManager,0x82, 1, false) { }
83  int revisionId;
84  int productId;
85 
86  long getValue() { return ((revisionId & 0xF) << 0) | ((productId & 0xF) << 4); }
87  void setValue(long val)
88  {
89  revisionId = (int)((val >> 0) & 0xF);
90  productId = (int)((val >> 4) & 0xF);
91  }
92  };
93 
94  class ProximityRateRegister : public Register
95  {
96  public:
97  ProximityRateRegister(RegisterManager& regManager) : Register(regManager,0x82, 1, false) { }
98  int rate;
99  Rates getRate() { return (Rates)rate; }
100  void setRate(Rates enumVal) { rate = (int)enumVal; }
101 
102  long getValue() { return ((rate & 0xF) << 0); }
103  void setValue(long val)
104  {
105  rate = (int)((val >> 0) & 0xF);
106  }
107  };
108 
109  class LedCurrentRegister : public Register
110  {
111  public:
112  LedCurrentRegister(RegisterManager& regManager) : Register(regManager,0x83, 1, false) { }
113  int irLedCurrentValue;
114  int fuseProgId;
115 
116  long getValue() { return ((irLedCurrentValue & 0x3F) << 0) | ((fuseProgId & 0x3) << 6); }
117  void setValue(long val)
118  {
119  irLedCurrentValue = (int)((val >> 0) & 0x3F);
120  fuseProgId = (int)((val >> 6) & 0x3);
121  }
122  };
123 
124  class AmbientLightParametersRegister : public Register
125  {
126  public:
127  AmbientLightParametersRegister(RegisterManager& regManager) : Register(regManager,0x84, 1, false) { }
128  int averagingSamples;
129  int autoOffsetCompensation;
130  int alsRate;
131  int continuousConversionMode;
132  AlsRates getAlsRate() { return (AlsRates)alsRate; }
133  void setAlsRate(AlsRates enumVal) { alsRate = (int)enumVal; }
134 
135  long getValue() { return ((averagingSamples & 0x7) << 0) | ((autoOffsetCompensation & 0x1) << 3) | ((alsRate & 0x7) << 4) | ((continuousConversionMode & 0x1) << 7); }
136  void setValue(long val)
137  {
138  averagingSamples = (int)((val >> 0) & 0x7);
139  autoOffsetCompensation = (int)((val >> 3) & 0x1);
140  alsRate = (int)((val >> 4) & 0x7);
141  continuousConversionMode = (int)((val >> 7) & 0x1);
142  }
143  };
144 
145  class AmbientLightResultRegister : public Register
146  {
147  public:
148  AmbientLightResultRegister(RegisterManager& regManager) : Register(regManager,0x85, 2, false) { }
149  int value;
150 
151  long getValue() { return ((value & 0xFFFF) << 0); }
152  void setValue(long val)
153  {
154  value = (int)((val >> 0) & 0xFFFF);
155  }
156  };
157 
158  class ProximityResultRegister : public Register
159  {
160  public:
161  ProximityResultRegister(RegisterManager& regManager) : Register(regManager,0x87, 2, true) { }
162  int value;
163 
164  long getValue() { return ((value & 0xFFFF) << 0); }
165  void setValue(long val)
166  {
167  value = (int)((val >> 0) & 0xFFFF);
168  }
169  };
170 
171  class InterruptControlRegister : public Register
172  {
173  public:
174  InterruptControlRegister(RegisterManager& regManager) : Register(regManager,0x89, 1, false) { }
175  int interruptThresholdSelect;
176  int interruptThresholdEnable;
177  int interruptAlsReadyEnable;
178  int intCountExceed;
179  IntCountExceeds getIntCountExceed() { return (IntCountExceeds)intCountExceed; }
180  void setIntCountExceed(IntCountExceeds enumVal) { intCountExceed = (int)enumVal; }
181 
182  long getValue() { return ((interruptThresholdSelect & 0x1) << 0) | ((interruptThresholdEnable & 0x1) << 1) | ((interruptAlsReadyEnable & 0x1) << 2) | ((intCountExceed & 0x7) << 5); }
183  void setValue(long val)
184  {
185  interruptThresholdSelect = (int)((val >> 0) & 0x1);
186  interruptThresholdEnable = (int)((val >> 1) & 0x1);
187  interruptAlsReadyEnable = (int)((val >> 2) & 0x1);
188  intCountExceed = (int)((val >> 5) & 0x7);
189  }
190  };
191 
192  class LowThresholdRegister : public Register
193  {
194  public:
195  LowThresholdRegister(RegisterManager& regManager) : Register(regManager,0x8A, 2, true) { }
196  int value;
197 
198  long getValue() { return ((value & 0xFFFF) << 0); }
199  void setValue(long val)
200  {
201  value = (int)((val >> 0) & 0xFFFF);
202  }
203  };
204 
205  class HighThresholdRegister : public Register
206  {
207  public:
208  HighThresholdRegister(RegisterManager& regManager) : Register(regManager,0x8C, 2, true) { }
209  int value;
210 
211  long getValue() { return ((value & 0xFFFF) << 0); }
212  void setValue(long val)
213  {
214  value = (int)((val >> 0) & 0xFFFF);
215  }
216  };
217 
218  class InterruptStatusRegister : public Register
219  {
220  public:
221  InterruptStatusRegister(RegisterManager& regManager) : Register(regManager,0x8E, 1, false) { }
222  int intThresholdHighExceeded;
223  int intThresholdLowExceeded;
224  int intAlsReady;
225  int intProxReady;
226 
227  long getValue() { return ((intThresholdHighExceeded & 0x1) << 0) | ((intThresholdLowExceeded & 0x1) << 1) | ((intAlsReady & 0x1) << 2) | ((intProxReady & 0x1) << 3); }
228  void setValue(long val)
229  {
230  intThresholdHighExceeded = (int)((val >> 0) & 0x1);
231  intThresholdLowExceeded = (int)((val >> 1) & 0x1);
232  intAlsReady = (int)((val >> 2) & 0x1);
233  intProxReady = (int)((val >> 3) & 0x1);
234  }
235  };
236 
237  class ProxModulatorTimingAdustmentRegister : public Register
238  {
239  public:
240  ProxModulatorTimingAdustmentRegister(RegisterManager& regManager) : Register(regManager,0x8F, 1, false) { }
241  int modulationDeadTime;
242  int proximityFrequency;
243  int modulationDelayTime;
244 
245  long getValue() { return ((modulationDeadTime & 0x7) << 0) | ((proximityFrequency & 0x3) << 3) | ((modulationDelayTime & 0x7) << 5); }
246  void setValue(long val)
247  {
248  modulationDeadTime = (int)((val >> 0) & 0x7);
249  proximityFrequency = (int)((val >> 3) & 0x3);
250  modulationDelayTime = (int)((val >> 5) & 0x7);
251  }
252  };
253 
254  CommandRegister command;
255  ProductIdRegister productId;
256  ProximityRateRegister proximityRate;
257  LedCurrentRegister ledCurrent;
258  AmbientLightParametersRegister ambientLightParameters;
259  AmbientLightResultRegister ambientLightResult;
260  ProximityResultRegister proximityResult;
261  InterruptControlRegister interruptControl;
262  LowThresholdRegister lowThreshold;
263  HighThresholdRegister highThreshold;
264  InterruptStatusRegister interruptStatus;
265  ProxModulatorTimingAdustmentRegister proxModulatorTimingAdustment;
266 
267  Vcnl4010Registers(SMBusDevice& device) : RegisterManager(device, true), command(*this), productId(*this), proximityRate(*this), ledCurrent(*this), ambientLightParameters(*this), ambientLightResult(*this), proximityResult(*this), interruptControl(*this), lowThreshold(*this), highThreshold(*this), interruptStatus(*this), proxModulatorTimingAdustment(*this)
268  {
269  registers.push_back(&command);
270  registers.push_back(&productId);
271  registers.push_back(&proximityRate);
272  registers.push_back(&ledCurrent);
273  registers.push_back(&ambientLightParameters);
274  registers.push_back(&ambientLightResult);
275  registers.push_back(&proximityResult);
276  registers.push_back(&interruptControl);
277  registers.push_back(&lowThreshold);
278  registers.push_back(&highThreshold);
279  registers.push_back(&interruptStatus);
280  registers.push_back(&proxModulatorTimingAdustment);
281  }
282  };
283  } } } }
IntCountExceeds
Definition: Vcnl4010Registers.h:36
AlsRates
Definition: Vcnl4010Registers.h:24
Definition: Dm632.h:9
Definition: Register.h:11
Rates
Definition: Vcnl4010Registers.h:12
Definition: RegisterManager.h:10
Definition: AdcPin.h:3