Treehopper C++ API
Ads1115Registers.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 IO { namespace Adc {
11 
12  enum class ComparatorQueues
13  {
18  };
19 
20  enum class DataRates
21  {
22  Sps_8 = 0,
23  Sps_16 = 1,
24  Sps_32 = 2,
25  Sps_64 = 3,
26  Sps_128 = 4,
27  Sps_250 = 5,
28  Sps_475 = 6,
29  Sps_860 = 7
30  };
31 
32  enum class Pgas
33  {
34  Fsr_6144 = 0,
35  Fsr_4096 = 1,
36  Fsr_2048 = 2,
37  Fsr_1024 = 3,
38  Fsr_512 = 4,
39  Fsr_256 = 5
40  };
41 
42  enum class Muxes
43  {
44  ain0_ain1 = 0,
45  ain0_ain3 = 1,
46  ain1_ain3 = 2,
47  ain2_ain3 = 3,
48  ain0_gnd = 4,
49  ain1_gnd = 5,
50  ain2_gnd = 6,
51  ain3_gnd = 7
52  };
53 
54 
55  class Ads1115Registers : public RegisterManager
56  {
57  public:
58  class ConversionRegister : public Register
59  {
60  public:
61  ConversionRegister(RegisterManager& regManager) : Register(regManager,0x00, 2, true) { }
62  int value;
63 
64  long getValue() { return ((value & 0xFFFF) << 0); }
65  void setValue(long val)
66  {
67  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
68  }
69  };
70 
71  class ConfigRegister : public Register
72  {
73  public:
74  ConfigRegister(RegisterManager& regManager) : Register(regManager,0x01, 2, false) { }
75  int comparatorQueue;
76  int latchingComparator;
77  int comparatorPolarity;
78  int comparatorMode;
79  int dataRate;
80  int operatingMode;
81  int pga;
82  int mux;
83  int operationalStatus;
84  ComparatorQueues getComparatorQueue() { return (ComparatorQueues)comparatorQueue; }
85  void setComparatorQueue(ComparatorQueues enumVal) { comparatorQueue = (int)enumVal; }
86  DataRates getDataRate() { return (DataRates)dataRate; }
87  void setDataRate(DataRates enumVal) { dataRate = (int)enumVal; }
88  Pgas getPga() { return (Pgas)pga; }
89  void setPga(Pgas enumVal) { pga = (int)enumVal; }
90  Muxes getMux() { return (Muxes)mux; }
91  void setMux(Muxes enumVal) { mux = (int)enumVal; }
92 
93  long getValue() { return ((comparatorQueue & 0x3) << 0) | ((latchingComparator & 0x1) << 2) | ((comparatorPolarity & 0x1) << 3) | ((comparatorMode & 0x1) << 4) | ((dataRate & 0x7) << 5) | ((operatingMode & 0x1) << 8) | ((pga & 0x7) << 9) | ((mux & 0x7) << 12) | ((operationalStatus & 0x1) << 15); }
94  void setValue(long val)
95  {
96  comparatorQueue = (int)((val >> 0) & 0x3);
97  latchingComparator = (int)((val >> 2) & 0x1);
98  comparatorPolarity = (int)((val >> 3) & 0x1);
99  comparatorMode = (int)((val >> 4) & 0x1);
100  dataRate = (int)((val >> 5) & 0x7);
101  operatingMode = (int)((val >> 8) & 0x1);
102  pga = (int)((val >> 9) & 0x7);
103  mux = (int)((val >> 12) & 0x7);
104  operationalStatus = (int)((val >> 15) & 0x1);
105  }
106  };
107 
108  class LowThresholdRegister : public Register
109  {
110  public:
111  LowThresholdRegister(RegisterManager& regManager) : Register(regManager,0x02, 2, true) { }
112  int value;
113 
114  long getValue() { return ((value & 0xFFFF) << 0); }
115  void setValue(long val)
116  {
117  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
118  }
119  };
120 
121  class HighThresholdRegister : public Register
122  {
123  public:
124  HighThresholdRegister(RegisterManager& regManager) : Register(regManager,0x03, 2, true) { }
125  int value;
126 
127  long getValue() { return ((value & 0xFFFF) << 0); }
128  void setValue(long val)
129  {
130  value = (int)(((val >> 0) & 0xFFFF) << (32 - 16)) >> (32 - 16);
131  }
132  };
133 
134  ConversionRegister conversion;
135  ConfigRegister config;
136  LowThresholdRegister lowThreshold;
137  HighThresholdRegister highThreshold;
138 
139  Ads1115Registers(SMBusDevice& device) : RegisterManager(device, true), conversion(*this), config(*this), lowThreshold(*this), highThreshold(*this)
140  {
141  registers.push_back(&conversion);
142  registers.push_back(&config);
143  registers.push_back(&lowThreshold);
144  registers.push_back(&highThreshold);
145  }
146  };
147  } } } }
Definition: Dm632.h:9
Definition: Register.h:11
Muxes
Definition: Ads1115Registers.h:42
Definition: RegisterManager.h:10
ComparatorQueues
Definition: Ads1115Registers.h:12
Definition: AdcPin.h:3
DataRates
Definition: Ads1115Registers.h:20
Pgas
Definition: Ads1115Registers.h:32