WPILib  2014.0
WPIRoboticsLibraryforFRC
 All Classes Functions Variables Pages
AnalogModule.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5 /*----------------------------------------------------------------------------*/
6 
7 #ifndef ANALOG_MODULE_H_
8 #define ANALOG_MODULE_H_
9 
10 #include "ChipObject.h"
11 #include "Module.h"
12 
20 class AnalogModule: public Module
21 {
22  friend class Module;
23 
24 public:
25  static const long kTimebase = 40000000;
26  static const long kDefaultOversampleBits = 0;
27  static const long kDefaultAverageBits = 7;
28  static constexpr float kDefaultSampleRate = 50000.0;
29 
30  void SetSampleRate(float samplesPerSecond);
31  float GetSampleRate();
32  void SetAverageBits(uint32_t channel, uint32_t bits);
33  uint32_t GetAverageBits(uint32_t channel);
34  void SetOversampleBits(uint32_t channel, uint32_t bits);
35  uint32_t GetOversampleBits(uint32_t channel);
36  int16_t GetValue(uint32_t channel);
37  int32_t GetAverageValue(uint32_t channel);
38  float GetAverageVoltage(uint32_t channel);
39  float GetVoltage(uint32_t channel);
40  uint32_t GetLSBWeight(uint32_t channel);
41  int32_t GetOffset(uint32_t channel);
42  int32_t VoltsToValue(int32_t channel, float voltage);
43 
44  static AnalogModule* GetInstance(uint8_t moduleNumber);
45 
46 protected:
47  explicit AnalogModule(uint8_t moduleNumber);
48  virtual ~AnalogModule();
49 
50 private:
51  static SEM_ID m_registerWindowSemaphore;
52 
53  uint32_t GetNumActiveChannels();
54  uint32_t GetNumChannelsToActivate();
55  void SetNumChannelsToActivate(uint32_t channels);
56 
57  tAI *m_module;
58  bool m_sampleRateSet;
59  uint32_t m_numChannelsToActivate;
60 };
61 
62 #endif
int32_t VoltsToValue(int32_t channel, float voltage)
Definition: AnalogModule.cpp:332
Definition: AnalogModule.h:20
float GetAverageVoltage(uint32_t channel)
Definition: AnalogModule.cpp:377
int32_t GetOffset(uint32_t channel)
Definition: AnalogModule.cpp:415
AnalogModule(uint8_t moduleNumber)
Definition: AnalogModule.cpp:54
virtual ~AnalogModule()
Definition: AnalogModule.cpp:85
float GetSampleRate()
Definition: AnalogModule.cpp:134
static const long kTimebase
40 MHz clock
Definition: AnalogModule.h:25
float GetVoltage(uint32_t channel)
Definition: AnalogModule.cpp:358
int32_t GetAverageValue(uint32_t channel)
Definition: AnalogModule.cpp:298
void SetOversampleBits(uint32_t channel, uint32_t bits)
Definition: AnalogModule.cpp:232
Definition: Module.h:15
void SetAverageBits(uint32_t channel, uint32_t bits)
Definition: AnalogModule.cpp:198
void SetSampleRate(float samplesPerSecond)
Definition: AnalogModule.cpp:97
uint32_t GetAverageBits(uint32_t channel)
Definition: AnalogModule.cpp:214
static AnalogModule * GetInstance(uint8_t moduleNumber)
Definition: AnalogModule.cpp:28
int16_t GetValue(uint32_t channel)
Definition: AnalogModule.cpp:264
uint32_t GetOversampleBits(uint32_t channel)
Definition: AnalogModule.cpp:248
uint32_t GetLSBWeight(uint32_t channel)
Definition: AnalogModule.cpp:397