7 #include "AnalogChannel.h"
8 #include "AnalogModule.h"
9 #include "NetworkCommunication/UsageReporting.h"
11 #include "WPIErrors.h"
12 #include "LiveWindow/LiveWindow.h"
16 const uint8_t AnalogChannel::kAccumulatorModuleNumber;
17 const uint32_t AnalogChannel::kAccumulatorNumChannels;
18 const uint32_t AnalogChannel::kAccumulatorChannels[] = {1, 2};
23 void AnalogChannel::InitChannel(uint8_t moduleNumber, uint32_t channel)
30 snprintf(buf, 64,
"Analog Module %d", moduleNumber);
31 wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf);
36 snprintf(buf, 64,
"Analog Channel %d", channel);
37 wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf);
41 snprintf(buf, 64,
"Analog Input %d (Module: %d)", channel, moduleNumber);
42 if (channels->
Allocate((moduleNumber - 1) * kAnalogChannels + channel - 1, buf) == ~0ul)
51 tRioStatusCode localStatus = NiFpga_Status_Success;
52 m_accumulator = tAccumulator::create(channel - 1, &localStatus);
53 wpi_setError(localStatus);
54 m_accumulatorOffset=0;
60 m_shouldUseVoltageForPID =
false;
62 nUsageReporting::report(nUsageReporting::kResourceType_AnalogChannel, channel,
GetModuleNumber() - 1);
73 InitChannel(moduleNumber, channel);
83 InitChannel(GetDefaultAnalogModule(), channel);
91 channels->
Free((m_module->GetNumber() - 1) * kAnalogChannels + m_channel - 1);
113 return m_module->
GetValue(m_channel);
202 return m_module->GetNumber();
267 if(m_module->GetNumber() != kAccumulatorModuleNumber)
return false;
268 for (uint32_t i=0; i<kAccumulatorNumChannels; i++)
270 if (m_channel == kAccumulatorChannels[i])
return true;
281 m_accumulatorOffset = 0;
296 m_accumulatorOffset = initialValue;
305 if (m_accumulator == NULL)
307 wpi_setWPIError(NullParameter);
310 tRioStatusCode localStatus = NiFpga_Status_Success;
311 m_accumulator->strobeReset(&localStatus);
312 wpi_setError(localStatus);
328 if (m_accumulator == NULL)
330 wpi_setWPIError(NullParameter);
333 tRioStatusCode localStatus = NiFpga_Status_Success;
334 m_accumulator->writeCenter(center, &localStatus);
335 wpi_setError(localStatus);
344 if (m_accumulator == NULL)
346 wpi_setWPIError(NullParameter);
349 tRioStatusCode localStatus = NiFpga_Status_Success;
350 m_accumulator->writeDeadband(deadband, &localStatus);
351 wpi_setError(localStatus);
365 if (m_accumulator == NULL)
367 wpi_setWPIError(NullParameter);
370 tRioStatusCode localStatus = NiFpga_Status_Success;
371 INT64 value = m_accumulator->readOutput_Value(&localStatus) + m_accumulatorOffset;
372 wpi_setError(localStatus);
386 if (m_accumulator == NULL)
388 wpi_setWPIError(NullParameter);
391 tRioStatusCode localStatus = NiFpga_Status_Success;
392 uint32_t count = m_accumulator->readOutput_Count(&localStatus);
393 wpi_setError(localStatus);
410 if (m_accumulator == NULL)
412 wpi_setWPIError(NullParameter);
415 if (value == NULL || count == NULL)
417 wpi_setWPIError(NullParameter);
421 tRioStatusCode localStatus = NiFpga_Status_Success;
422 tAccumulator::tOutput output = m_accumulator->readOutput(&localStatus);
423 *value = output.Value + m_accumulatorOffset;
424 *count = output.Count;
425 wpi_setError(localStatus);
437 m_shouldUseVoltageForPID = shouldUseVoltageForPID;
448 if (m_shouldUseVoltageForPID) {
456 if (m_table != NULL) {
470 return "Analog Input";
void StartLiveWindowMode()
int32_t GetAverageValue()
void GetAccumulatorOutput(INT64 *value, uint32_t *count)
void InitTable(ITable *subTable)
static bool CheckAnalogModule(uint8_t moduleNumber)
int32_t GetOffset(uint32_t channel)
void StopLiveWindowMode()
virtual void PutNumber(std::string key, double value)=0
AnalogChannel(uint8_t moduleNumber, uint32_t channel)
void SetAccumulatorDeadband(int32_t deadband)
void SetAccumulatorInitialValue(INT64 value)
uint8_t GetModuleNumber()
uint32_t GetOversampleBits()
static AnalogModule * GetInstance(uint8_t moduleNumber)
INT64 GetAccumulatorValue()
void SetVoltageForPID(bool shouldUseVoltageForPID)
void SetOversampleBits(uint32_t channel, uint32_t bits)
void AddSensor(const char *subsystem, const char *name, LiveWindowSendable *component)
int16_t GetValue(uint32_t channel)
float GetAverageVoltage()
float GetAverageVoltage(uint32_t channel)
AnalogModule * GetModule()
bool IsAccumulatorChannel()
uint32_t GetAccumulatorCount()
void Free(uint32_t index)
std::string GetSmartDashboardType()
uint32_t Allocate(const char *resourceDesc)
uint32_t GetLSBWeight(uint32_t channel)
static LiveWindow * GetInstance()
uint32_t GetOversampleBits(uint32_t channel)
void SetAverageBits(uint32_t channel, uint32_t bits)
uint32_t GetAverageBits()
virtual bool StatusIsFatal() const
Check if the current error code represents a fatal error.
void SetAccumulatorCenter(int32_t center)
static void CreateResourceObject(Resource **r, uint32_t elements)
void SetAverageBits(uint32_t bits)
int32_t GetAverageValue(uint32_t channel)
uint32_t GetAverageBits(uint32_t channel)
float GetVoltage(uint32_t channel)
static bool CheckAnalogChannel(uint32_t channel)
void SetOversampleBits(uint32_t bits)