mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-26 01:51:41 +00:00
Switches HAL to fixed length signed integers, and adds our own HAL_Bool Type (#155)
* Switches HAL to fixed length signed integers, and adds our own HAL_Bool type * Replaces HAL Floats with Doubles Doubles are just as fast as floats with optimizations turned on, so switches to all doubles. All made doubles for consistency. * Prepends HAL/ to HAL include files. Also fixes some range errors
This commit is contained in:
committed by
Peter Johnson
parent
4a98e68815
commit
b51e85ae26
@@ -7,6 +7,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HAL/Types.h"
|
||||
|
||||
enum HAL_AccelerometerRange {
|
||||
HAL_AccelerometerRange_k2G = 0,
|
||||
HAL_AccelerometerRange_k4G = 1,
|
||||
@@ -14,7 +16,7 @@ enum HAL_AccelerometerRange {
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
void HAL_SetAccelerometerActive(bool);
|
||||
void HAL_SetAccelerometerActive(HAL_Bool);
|
||||
void HAL_SetAccelerometerRange(HAL_AccelerometerRange);
|
||||
double HAL_GetAccelerometerX();
|
||||
double HAL_GetAccelerometerY();
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
void HAL_InitAccumulator(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
void HAL_ResetAccumulator(HAL_AnalogInputHandle analog_port_handle,
|
||||
@@ -24,8 +24,8 @@ void HAL_SetAccumulatorDeadband(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t deadband, int32_t* status);
|
||||
int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
uint32_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analog_port_handle,
|
||||
int64_t* value, uint32_t* count, int32_t* status);
|
||||
int64_t* value, int64_t* count, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle handle,
|
||||
@@ -17,17 +17,17 @@ HAL_GyroHandle HAL_InitializeAnalogGyro(HAL_AnalogInputHandle handle,
|
||||
void HAL_SetupAnalogGyro(HAL_GyroHandle handle, int32_t* status);
|
||||
void HAL_FreeAnalogGyro(HAL_GyroHandle handle);
|
||||
void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle,
|
||||
float voltsPerDegreePerSecond, float offset,
|
||||
uint32_t center, int32_t* status);
|
||||
double voltsPerDegreePerSecond, double offset,
|
||||
int32_t center, int32_t* status);
|
||||
void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle,
|
||||
float voltsPerDegreePerSecond,
|
||||
double voltsPerDegreePerSecond,
|
||||
int32_t* status);
|
||||
void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status);
|
||||
void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status);
|
||||
void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, float volts,
|
||||
void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, double volts,
|
||||
int32_t* status);
|
||||
float HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status);
|
||||
double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status);
|
||||
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status);
|
||||
float HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status);
|
||||
uint32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status);
|
||||
double HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status);
|
||||
int32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,38 +9,37 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
// Analog input functions
|
||||
HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle port_handle,
|
||||
int32_t* status);
|
||||
void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analog_port_handle);
|
||||
bool HAL_CheckAnalogModule(uint8_t module);
|
||||
bool HAL_CheckAnalogInputChannel(uint32_t pin);
|
||||
HAL_Bool HAL_CheckAnalogModule(int32_t module);
|
||||
HAL_Bool HAL_CheckAnalogInputChannel(int32_t pin);
|
||||
|
||||
void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status);
|
||||
float HAL_GetAnalogSampleRate(int32_t* status);
|
||||
double HAL_GetAnalogSampleRate(int32_t* status);
|
||||
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
uint32_t bits, int32_t* status);
|
||||
uint32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int32_t bits, int32_t* status);
|
||||
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
uint32_t bits, int32_t* status);
|
||||
uint32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int16_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t bits, int32_t* status);
|
||||
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
double voltage, int32_t* status);
|
||||
float HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
float HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
uint32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetAnalogOffset(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_AnalogOutputHandle HAL_InitializeAnalogOutputPort(
|
||||
@@ -19,5 +19,5 @@ void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
|
||||
double voltage, int32_t* status);
|
||||
double HAL_GetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
|
||||
int32_t* status);
|
||||
bool HAL_CheckAnalogOutputChannel(uint32_t pin);
|
||||
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t pin);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
enum HAL_AnalogTriggerType {
|
||||
HAL_Trigger_kInWindow = 0,
|
||||
@@ -20,7 +20,7 @@ enum HAL_AnalogTriggerType {
|
||||
|
||||
extern "C" {
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
HAL_AnalogInputHandle port_handle, uint32_t* index, int32_t* status);
|
||||
HAL_AnalogInputHandle port_handle, int32_t* index, int32_t* status);
|
||||
void HAL_CleanAnalogTrigger(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetAnalogTriggerLimitsRaw(
|
||||
@@ -30,13 +30,14 @@ void HAL_SetAnalogTriggerLimitsVoltage(
|
||||
HAL_AnalogTriggerHandle analog_trigger_handle, double lower, double upper,
|
||||
int32_t* status);
|
||||
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
bool useAveragedValue, int32_t* status);
|
||||
HAL_Bool useAveragedValue, int32_t* status);
|
||||
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
bool useFilteredValue, int32_t* status);
|
||||
bool HAL_GetAnalogTriggerInWindow(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
int32_t* status);
|
||||
bool HAL_GetAnalogTriggerTriggerState(
|
||||
HAL_Bool useFilteredValue, int32_t* status);
|
||||
HAL_Bool HAL_GetAnalogTriggerInWindow(
|
||||
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status);
|
||||
bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
HAL_AnalogTriggerType type, int32_t* status);
|
||||
HAL_Bool HAL_GetAnalogTriggerTriggerState(
|
||||
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetAnalogTriggerOutput(
|
||||
HAL_AnalogTriggerHandle analog_trigger_handle, HAL_AnalogTriggerType type,
|
||||
int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,34 +9,35 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_CompressorHandle HAL_InitializeCompressor(uint8_t module, int32_t* status);
|
||||
bool HAL_CheckCompressorModule(uint8_t module);
|
||||
HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status);
|
||||
HAL_Bool HAL_CheckCompressorModule(int32_t module);
|
||||
|
||||
bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
|
||||
void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
|
||||
bool value, int32_t* status);
|
||||
bool HAL_GetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
|
||||
bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
float HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
|
||||
bool HAL_GetCompressorCurrentTooHighFault(
|
||||
HAL_Bool value, int32_t* status);
|
||||
HAL_Bool HAL_GetCompressorClosedLoopControl(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
bool HAL_GetCompressorCurrentTooHighStickyFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
bool HAL_GetCompressorShortedStickyFault(HAL_CompressorHandle compressor_handle,
|
||||
|
||||
HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
bool HAL_GetCompressorNotConnectedStickyFault(
|
||||
double HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
|
||||
HAL_Bool HAL_GetCompressorCurrentTooHighFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetCompressorCurrentTooHighStickyFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetCompressorShortedStickyFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetCompressorNotConnectedStickyFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetCompressorNotConnectedFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status);
|
||||
bool HAL_GetCompressorNotConnectedFault(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
enum HAL_Counter_Mode {
|
||||
HAL_Counter_kTwoPulse = 0,
|
||||
@@ -30,7 +30,7 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
int32_t* status);
|
||||
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
|
||||
bool risingEdge, bool fallingEdge,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status);
|
||||
void HAL_ClearCounterUpSource(HAL_CounterHandle counter_handle,
|
||||
int32_t* status);
|
||||
@@ -39,7 +39,7 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
int32_t* status);
|
||||
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
|
||||
bool risingEdge, bool fallingEdge,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status);
|
||||
void HAL_ClearCounterDownSource(HAL_CounterHandle counter_handle,
|
||||
int32_t* status);
|
||||
@@ -48,7 +48,7 @@ void HAL_SetCounterUpDownMode(HAL_CounterHandle counter_handle,
|
||||
void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
|
||||
bool highSemiPeriod, int32_t* status);
|
||||
HAL_Bool highSemiPeriod, int32_t* status);
|
||||
void HAL_SetCounterPulseLengthMode(HAL_CounterHandle counter_handle,
|
||||
double threshold, int32_t* status);
|
||||
int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
|
||||
@@ -61,9 +61,11 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status);
|
||||
void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, double maxPeriod,
|
||||
int32_t* status);
|
||||
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
|
||||
bool enabled, int32_t* status);
|
||||
bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle, int32_t* status);
|
||||
bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle, int32_t* status);
|
||||
HAL_Bool enabled, int32_t* status);
|
||||
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
|
||||
bool reverseDirection, int32_t* status);
|
||||
HAL_Bool reverseDirection, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
|
||||
uint8_t input, int32_t* status);
|
||||
int32_t input, int32_t* status);
|
||||
void HAL_FreeDIOPort(HAL_DigitalHandle dio_port_handle);
|
||||
|
||||
HAL_DigitalPWMHandle HAL_AllocateDigitalPWM(int32_t* status);
|
||||
@@ -22,21 +22,20 @@ void HAL_SetDigitalPWMRate(double rate, int32_t* status);
|
||||
void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
||||
double dutyCycle, int32_t* status);
|
||||
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
|
||||
uint32_t pin, int32_t* status);
|
||||
|
||||
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, int16_t value,
|
||||
int32_t pin, int32_t* status);
|
||||
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, HAL_Bool value,
|
||||
int32_t* status);
|
||||
bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status);
|
||||
bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status);
|
||||
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle,
|
||||
int32_t* status);
|
||||
void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
|
||||
int32_t* status);
|
||||
bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status);
|
||||
bool HAL_IsAnyPulsing(int32_t* status);
|
||||
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status);
|
||||
HAL_Bool HAL_IsAnyPulsing(int32_t* status);
|
||||
|
||||
void HAL_SetFilterSelect(HAL_DigitalHandle dio_port_handle, int filter_index,
|
||||
int32_t* status);
|
||||
int HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status);
|
||||
|
||||
void HAL_SetFilterPeriod(int filter_index, uint32_t value, int32_t* status);
|
||||
uint32_t HAL_GetFilterPeriod(int filter_index, int32_t* status);
|
||||
void HAL_SetFilterSelect(HAL_DigitalHandle dio_port_handle,
|
||||
int32_t filter_index, int32_t* status);
|
||||
int32_t HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status);
|
||||
void HAL_SetFilterPeriod(int32_t filter_index, int64_t value, int32_t* status);
|
||||
int64_t HAL_GetFilterPeriod(int32_t filter_index, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
enum HAL_EncoderIndexingType {
|
||||
@@ -28,7 +28,7 @@ enum HAL_EncoderEncodingType {
|
||||
HAL_EncoderHandle HAL_InitializeEncoder(
|
||||
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
|
||||
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection, HAL_EncoderEncodingType encodingType,
|
||||
HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType,
|
||||
int32_t* status);
|
||||
void HAL_FreeEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
|
||||
int32_t HAL_GetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
|
||||
@@ -36,13 +36,13 @@ int32_t HAL_GetEncoderRaw(HAL_EncoderHandle encoder_handle, int32_t* status);
|
||||
int32_t HAL_GetEncoderEncodingScale(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status);
|
||||
void HAL_ResetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status);
|
||||
int32_t HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle, int32_t* status);
|
||||
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle, int32_t* status);
|
||||
void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoder_handle, double maxPeriod,
|
||||
int32_t* status);
|
||||
uint8_t HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status);
|
||||
uint8_t HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status);
|
||||
double HAL_GetEncoderDistance(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status);
|
||||
double HAL_GetEncoderRate(HAL_EncoderHandle encoder_handle, int32_t* status);
|
||||
@@ -51,7 +51,7 @@ void HAL_SetEncoderMinRate(HAL_EncoderHandle encoder_handle, double minRate,
|
||||
void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
|
||||
double distancePerPulse, int32_t* status);
|
||||
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoder_handle,
|
||||
uint8_t reverseDirection, int32_t* status);
|
||||
HAL_Bool reverseDirection, int32_t* status);
|
||||
void HAL_SetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
|
||||
int32_t samplesToAverage, int32_t* status);
|
||||
int32_t HAL_GetEncoderSamplesToAverage(HAL_EncoderHandle encoder_handle,
|
||||
|
||||
@@ -9,31 +9,31 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Accelerometer.h"
|
||||
#include "AnalogAccumulator.h"
|
||||
#include "AnalogGyro.h"
|
||||
#include "AnalogInput.h"
|
||||
#include "AnalogOutput.h"
|
||||
#include "AnalogTrigger.h"
|
||||
#include "Compressor.h"
|
||||
#include "Constants.h"
|
||||
#include "Counter.h"
|
||||
#include "DIO.h"
|
||||
#include "Errors.h"
|
||||
#include "FRC_NetworkCommunication/UsageReporting.h"
|
||||
#include "Handles.h"
|
||||
#include "I2C.h"
|
||||
#include "Interrupts.h"
|
||||
#include "Notifier.h"
|
||||
#include "PDP.h"
|
||||
#include "PWM.h"
|
||||
#include "Ports.h"
|
||||
#include "Power.h"
|
||||
#include "Relay.h"
|
||||
#include "SPI.h"
|
||||
#include "SerialPort.h"
|
||||
#include "Solenoid.h"
|
||||
#include "Task.h"
|
||||
#include "HAL/Accelerometer.h"
|
||||
#include "HAL/AnalogAccumulator.h"
|
||||
#include "HAL/AnalogGyro.h"
|
||||
#include "HAL/AnalogInput.h"
|
||||
#include "HAL/AnalogOutput.h"
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Compressor.h"
|
||||
#include "HAL/Constants.h"
|
||||
#include "HAL/Counter.h"
|
||||
#include "HAL/DIO.h"
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/I2C.h"
|
||||
#include "HAL/Interrupts.h"
|
||||
#include "HAL/Notifier.h"
|
||||
#include "HAL/PDP.h"
|
||||
#include "HAL/PWM.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "HAL/Power.h"
|
||||
#include "HAL/Relay.h"
|
||||
#include "HAL/SPI.h"
|
||||
#include "HAL/SerialPort.h"
|
||||
#include "HAL/Solenoid.h"
|
||||
#include "HAL/Task.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
namespace HALUsageReporting = nUsageReporting;
|
||||
|
||||
@@ -104,48 +104,50 @@ struct HAL_JoystickDescriptor {
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
HAL_PortHandle HAL_GetPort(uint8_t pin);
|
||||
HAL_PortHandle HAL_GetPortWithModule(uint8_t module, uint8_t pin);
|
||||
HAL_PortHandle HAL_GetPort(int32_t pin);
|
||||
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t pin);
|
||||
const char* HAL_GetErrorMessage(int32_t code);
|
||||
|
||||
uint16_t HAL_GetFPGAVersion(int32_t* status);
|
||||
uint32_t HAL_GetFPGARevision(int32_t* status);
|
||||
int32_t HAL_GetFPGAVersion(int32_t* status);
|
||||
int64_t HAL_GetFPGARevision(int32_t* status);
|
||||
uint64_t HAL_GetFPGATime(int32_t* status);
|
||||
|
||||
bool HAL_GetFPGAButton(int32_t* status);
|
||||
HAL_Bool HAL_GetFPGAButton(int32_t* status);
|
||||
|
||||
int HAL_SetErrorData(const char* errors, int errorsLength, int wait_ms);
|
||||
int HAL_SendError(int isError, int32_t errorCode, int isLVCode,
|
||||
const char* details, const char* location,
|
||||
const char* callStack, int printMsg);
|
||||
int32_t HAL_SetErrorData(const char* errors, int32_t errorsLength,
|
||||
int32_t wait_ms);
|
||||
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
const char* details, const char* location,
|
||||
const char* callStack, HAL_Bool printMsg);
|
||||
|
||||
int HAL_GetControlWord(HAL_ControlWord* controlWord);
|
||||
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord);
|
||||
HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status);
|
||||
int HAL_GetJoystickAxes(uint8_t joystickNum, HAL_JoystickAxes* axes);
|
||||
int HAL_GetJoystickPOVs(uint8_t joystickNum, HAL_JoystickPOVs* povs);
|
||||
int HAL_GetJoystickButtons(uint8_t joystickNum, HAL_JoystickButtons* buttons);
|
||||
int HAL_GetJoystickDescriptor(uint8_t joystickNum,
|
||||
HAL_JoystickDescriptor* desc);
|
||||
int HAL_GetJoystickIsXbox(uint8_t joystickNum);
|
||||
int HAL_GetJoystickType(uint8_t joystickNum);
|
||||
char* HAL_GetJoystickName(uint8_t joystickNum);
|
||||
int HAL_GetJoystickAxisType(uint8_t joystickNum, uint8_t axis);
|
||||
int HAL_SetJoystickOutputs(uint8_t joystickNum, uint32_t outputs,
|
||||
uint16_t leftRumble, uint16_t rightRumble);
|
||||
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes);
|
||||
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs);
|
||||
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons);
|
||||
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_JoystickDescriptor* desc);
|
||||
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum);
|
||||
int32_t HAL_GetJoystickType(int32_t joystickNum);
|
||||
char* HAL_GetJoystickName(int32_t joystickNum);
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis);
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble);
|
||||
float HAL_GetMatchTime(int32_t* status);
|
||||
|
||||
void HAL_WaitForDSData();
|
||||
|
||||
bool HAL_GetSystemActive(int32_t* status);
|
||||
bool HAL_GetBrownedOut(int32_t* status);
|
||||
HAL_Bool HAL_GetSystemActive(int32_t* status);
|
||||
HAL_Bool HAL_GetBrownedOut(int32_t* status);
|
||||
|
||||
int HAL_Initialize(int mode = 0);
|
||||
int32_t HAL_Initialize(int32_t mode = 0);
|
||||
void HAL_ObserveUserProgramStarting();
|
||||
void HAL_ObserveUserProgramDisabled();
|
||||
void HAL_ObserveUserProgramAutonomous();
|
||||
void HAL_ObserveUserProgramTeleop();
|
||||
void HAL_ObserveUserProgramTest();
|
||||
|
||||
uint32_t HAL_Report(uint8_t resource, uint8_t instanceNumber,
|
||||
uint8_t context = 0, const char* feature = nullptr);
|
||||
int64_t HAL_Report(int32_t resource, int32_t instanceNumber,
|
||||
int32_t context = 0, const char* feature = nullptr);
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
void HAL_InitializeI2C(uint8_t port, int32_t* status);
|
||||
int32_t HAL_TransactionI2C(uint8_t port, uint8_t deviceAddress,
|
||||
uint8_t* dataToSend, uint8_t sendSize,
|
||||
uint8_t* dataReceived, uint8_t receiveSize);
|
||||
int32_t HAL_WriteI2C(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
|
||||
uint8_t sendSize);
|
||||
int32_t HAL_ReadI2C(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
|
||||
uint8_t count);
|
||||
void HAL_CloseI2C(uint8_t port);
|
||||
void HAL_InitializeI2C(int32_t port, int32_t* status);
|
||||
int32_t HAL_TransactionI2C(int32_t port, int32_t deviceAddress,
|
||||
uint8_t* dataToSend, int32_t sendSize,
|
||||
uint8_t* dataReceived, int32_t receiveSize);
|
||||
int32_t HAL_WriteI2C(int32_t port, int32_t deviceAddress, uint8_t* dataToSend,
|
||||
int32_t sendSize);
|
||||
int32_t HAL_ReadI2C(int32_t port, int32_t deviceAddress, uint8_t* buffer,
|
||||
int32_t count);
|
||||
void HAL_CloseI2C(int32_t port);
|
||||
}
|
||||
|
||||
@@ -10,18 +10,18 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
typedef void (*InterruptHandlerFunction)(uint32_t interruptAssertedMask,
|
||||
void* param);
|
||||
|
||||
HAL_InterruptHandle HAL_InitializeInterrupts(bool watcher, int32_t* status);
|
||||
HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher, int32_t* status);
|
||||
void HAL_CleanInterrupts(HAL_InterruptHandle interrupt_handle, int32_t* status);
|
||||
|
||||
uint32_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
|
||||
double timeout, bool ignorePrevious,
|
||||
int32_t* status);
|
||||
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
|
||||
double timeout, HAL_Bool ignorePrevious,
|
||||
int32_t* status);
|
||||
void HAL_EnableInterrupts(HAL_InterruptHandle interrupt_handle,
|
||||
int32_t* status);
|
||||
void HAL_DisableInterrupts(HAL_InterruptHandle interrupt_handle,
|
||||
@@ -38,6 +38,6 @@ void HAL_AttachInterruptHandler(HAL_InterruptHandle interrupt_handle,
|
||||
InterruptHandlerFunction handler, void* param,
|
||||
int32_t* status);
|
||||
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interrupt_handle,
|
||||
bool risingEdge, bool fallingEdge,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_NotifierHandle HAL_InitializeNotifier(void (*process)(uint64_t, void*),
|
||||
|
||||
@@ -9,15 +9,18 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
void HAL_InitializePDP(uint8_t module);
|
||||
double HAL_GetPDPTemperature(uint8_t module, int32_t* status);
|
||||
double HAL_GetPDPVoltage(uint8_t module, int32_t* status);
|
||||
double HAL_GetPDPChannelCurrent(uint8_t module, uint8_t channel,
|
||||
void HAL_InitializePDP(int32_t module, int32_t* status);
|
||||
HAL_Bool HAL_CheckPDPModule(int32_t module);
|
||||
double HAL_GetPDPTemperature(int32_t module, int32_t* status);
|
||||
double HAL_GetPDPVoltage(int32_t module, int32_t* status);
|
||||
double HAL_GetPDPChannelCurrent(int32_t module, int32_t channel,
|
||||
int32_t* status);
|
||||
double HAL_GetPDPTotalCurrent(uint8_t module, int32_t* status);
|
||||
double HAL_GetPDPTotalPower(uint8_t module, int32_t* status);
|
||||
double HAL_GetPDPTotalEnergy(uint8_t module, int32_t* status);
|
||||
void HAL_ResetPDPTotalEnergy(uint8_t module, int32_t* status);
|
||||
void HAL_ClearPDPStickyFaults(uint8_t module, int32_t* status);
|
||||
double HAL_GetPDPTotalCurrent(int32_t module, int32_t* status);
|
||||
double HAL_GetPDPTotalPower(int32_t module, int32_t* status);
|
||||
double HAL_GetPDPTotalEnergy(int32_t module, int32_t* status);
|
||||
void HAL_ResetPDPTotalEnergy(int32_t module, int32_t* status);
|
||||
void HAL_ClearPDPStickyFaults(int32_t module, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
|
||||
int32_t* status);
|
||||
void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
|
||||
bool HAL_CheckPWMChannel(uint8_t pin);
|
||||
HAL_Bool HAL_CheckPWMChannel(int32_t pin);
|
||||
|
||||
void HAL_SetPWMConfig(HAL_DigitalHandle pwm_port_handle, double maxPwm,
|
||||
double deadbandMaxPwm, double centerPwm,
|
||||
@@ -30,21 +30,21 @@ void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t* maxPwm,
|
||||
int32_t* deadbandMinPwm, int32_t* minPwm,
|
||||
int32_t* status);
|
||||
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
uint8_t eliminateDeadband, int32_t* status);
|
||||
uint8_t HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, uint16_t value,
|
||||
HAL_Bool eliminateDeadband, int32_t* status);
|
||||
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t value,
|
||||
int32_t* status);
|
||||
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, float speed,
|
||||
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, double speed,
|
||||
int32_t* status);
|
||||
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, float position,
|
||||
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, double position,
|
||||
int32_t* status);
|
||||
void HAL_SetPWMDisabled(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
uint16_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
float HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
float HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
double HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
double HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
void HAL_LatchPWMZero(HAL_DigitalHandle pwm_port_handle, int32_t* status);
|
||||
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwm_port_handle,
|
||||
uint32_t squelchMask, int32_t* status);
|
||||
uint16_t HAL_GetLoopTiming(int32_t* status);
|
||||
int32_t squelchMask, int32_t* status);
|
||||
int32_t HAL_GetLoopTiming(int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,19 +9,21 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
float HAL_GetVinVoltage(int32_t* status);
|
||||
float HAL_GetVinCurrent(int32_t* status);
|
||||
float HAL_GetUserVoltage6V(int32_t* status);
|
||||
float HAL_GetUserCurrent6V(int32_t* status);
|
||||
bool HAL_GetUserActive6V(int32_t* status);
|
||||
int HAL_GetUserCurrentFaults6V(int32_t* status);
|
||||
float HAL_GetUserVoltage5V(int32_t* status);
|
||||
float HAL_GetUserCurrent5V(int32_t* status);
|
||||
bool HAL_GetUserActive5V(int32_t* status);
|
||||
int HAL_GetUserCurrentFaults5V(int32_t* status);
|
||||
float HAL_GetUserVoltage3V3(int32_t* status);
|
||||
float HAL_GetUserCurrent3V3(int32_t* status);
|
||||
bool HAL_GetUserActive3V3(int32_t* status);
|
||||
int HAL_GetUserCurrentFaults3V3(int32_t* status);
|
||||
double HAL_GetVinVoltage(int32_t* status);
|
||||
double HAL_GetVinCurrent(int32_t* status);
|
||||
double HAL_GetUserVoltage6V(int32_t* status);
|
||||
double HAL_GetUserCurrent6V(int32_t* status);
|
||||
HAL_Bool HAL_GetUserActive6V(int32_t* status);
|
||||
int32_t HAL_GetUserCurrentFaults6V(int32_t* status);
|
||||
double HAL_GetUserVoltage5V(int32_t* status);
|
||||
double HAL_GetUserCurrent5V(int32_t* status);
|
||||
HAL_Bool HAL_GetUserActive5V(int32_t* status);
|
||||
int32_t HAL_GetUserCurrentFaults5V(int32_t* status);
|
||||
double HAL_GetUserVoltage3V3(int32_t* status);
|
||||
double HAL_GetUserCurrent3V3(int32_t* status);
|
||||
HAL_Bool HAL_GetUserActive3V3(int32_t* status);
|
||||
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,15 +9,16 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle, uint8_t fwd,
|
||||
int32_t* status);
|
||||
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle,
|
||||
HAL_Bool fwd, int32_t* status);
|
||||
void HAL_FreeRelayPort(HAL_RelayHandle relay_port_handle);
|
||||
|
||||
bool HAL_CheckRelayChannel(uint8_t pin);
|
||||
HAL_Bool HAL_CheckRelayChannel(int32_t pin);
|
||||
|
||||
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, bool on, int32_t* status);
|
||||
bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status);
|
||||
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,35 +9,37 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
void HAL_InitializeSPI(uint8_t port, int32_t* status);
|
||||
int32_t HAL_TransactionSPI(uint8_t port, uint8_t* dataToSend,
|
||||
uint8_t* dataReceived, uint8_t size);
|
||||
int32_t HAL_WriteSPI(uint8_t port, uint8_t* dataToSend, uint8_t sendSize);
|
||||
int32_t HAL_ReadSPI(uint8_t port, uint8_t* buffer, uint8_t count);
|
||||
void HAL_CloseSPI(uint8_t port);
|
||||
void HAL_SetSPISpeed(uint8_t port, uint32_t speed);
|
||||
void HAL_SetSPIOpts(uint8_t port, int msb_first, int sample_on_trailing,
|
||||
int clk_idle_high);
|
||||
void HAL_SetSPIChipSelectActiveHigh(uint8_t port, int32_t* status);
|
||||
void HAL_SetSPIChipSelectActiveLow(uint8_t port, int32_t* status);
|
||||
int32_t HAL_GetSPIHandle(uint8_t port);
|
||||
void HAL_SetSPIHandle(uint8_t port, int32_t handle);
|
||||
#include "HAL/Types.h"
|
||||
|
||||
void HAL_InitSPIAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
|
||||
uint8_t xfer_size, uint32_t valid_mask,
|
||||
uint32_t valid_value, uint8_t data_shift,
|
||||
uint8_t data_size, bool is_signed, bool big_endian,
|
||||
int32_t* status);
|
||||
void HAL_FreeSPIAccumulator(uint8_t port, int32_t* status);
|
||||
void HAL_ResetSPIAccumulator(uint8_t port, int32_t* status);
|
||||
void HAL_SetSPIAccumulatorCenter(uint8_t port, int32_t center, int32_t* status);
|
||||
void HAL_SetSPIAccumulatorDeadband(uint8_t port, int32_t deadband,
|
||||
extern "C" {
|
||||
void HAL_InitializeSPI(int32_t port, int32_t* status);
|
||||
int32_t HAL_TransactionSPI(int32_t port, uint8_t* dataToSend,
|
||||
uint8_t* dataReceived, int32_t size);
|
||||
int32_t HAL_WriteSPI(int32_t port, uint8_t* dataToSend, int32_t sendSize);
|
||||
int32_t HAL_ReadSPI(int32_t port, uint8_t* buffer, int32_t count);
|
||||
void HAL_CloseSPI(int32_t port);
|
||||
void HAL_SetSPISpeed(int32_t port, int32_t speed);
|
||||
void HAL_SetSPIOpts(int32_t port, HAL_Bool msb_first,
|
||||
HAL_Bool sample_on_trailing, HAL_Bool clk_idle_high);
|
||||
void HAL_SetSPIChipSelectActiveHigh(int32_t port, int32_t* status);
|
||||
void HAL_SetSPIChipSelectActiveLow(int32_t port, int32_t* status);
|
||||
int32_t HAL_GetSPIHandle(int32_t port);
|
||||
void HAL_SetSPIHandle(int32_t port, int32_t handle);
|
||||
|
||||
void HAL_InitSPIAccumulator(int32_t port, int32_t period, int32_t cmd,
|
||||
int32_t xfer_size, int32_t valid_mask,
|
||||
int32_t valid_value, int32_t data_shift,
|
||||
int32_t data_size, HAL_Bool is_signed,
|
||||
HAL_Bool big_endian, int32_t* status);
|
||||
void HAL_FreeSPIAccumulator(int32_t port, int32_t* status);
|
||||
void HAL_ResetSPIAccumulator(int32_t port, int32_t* status);
|
||||
void HAL_SetSPIAccumulatorCenter(int32_t port, int32_t center, int32_t* status);
|
||||
void HAL_SetSPIAccumulatorDeadband(int32_t port, int32_t deadband,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetSPIAccumulatorLastValue(uint8_t port, int32_t* status);
|
||||
int64_t HAL_GetSPIAccumulatorValue(uint8_t port, int32_t* status);
|
||||
uint32_t HAL_GetSPIAccumulatorCount(uint8_t port, int32_t* status);
|
||||
double HAL_GetSPIAccumulatorAverage(uint8_t port, int32_t* status);
|
||||
void HAL_GetSPIAccumulatorOutput(uint8_t port, int64_t* value, uint32_t* count,
|
||||
int32_t HAL_GetSPIAccumulatorLastValue(int32_t port, int32_t* status);
|
||||
int64_t HAL_GetSPIAccumulatorValue(int32_t port, int32_t* status);
|
||||
int64_t HAL_GetSPIAccumulatorCount(int32_t port, int32_t* status);
|
||||
double HAL_GetSPIAccumulatorAverage(int32_t port, int32_t* status);
|
||||
void HAL_GetSPIAccumulatorOutput(int32_t port, int64_t* value, int64_t* count,
|
||||
int32_t* status);
|
||||
}
|
||||
|
||||
@@ -10,25 +10,25 @@
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
void HAL_InitializeSerialPort(uint8_t port, int32_t* status);
|
||||
void HAL_SetSerialBaudRate(uint8_t port, uint32_t baud, int32_t* status);
|
||||
void HAL_SetSerialDataBits(uint8_t port, uint8_t bits, int32_t* status);
|
||||
void HAL_SetSerialParity(uint8_t port, uint8_t parity, int32_t* status);
|
||||
void HAL_SetSerialStopBits(uint8_t port, uint8_t stopBits, int32_t* status);
|
||||
void HAL_SetSerialWriteMode(uint8_t port, uint8_t mode, int32_t* status);
|
||||
void HAL_SetSerialFlowControl(uint8_t port, uint8_t flow, int32_t* status);
|
||||
void HAL_SetSerialTimeout(uint8_t port, float timeout, int32_t* status);
|
||||
void HAL_EnableSerialTermination(uint8_t port, char terminator,
|
||||
void HAL_InitializeSerialPort(int32_t port, int32_t* status);
|
||||
void HAL_SetSerialBaudRate(int32_t port, int32_t baud, int32_t* status);
|
||||
void HAL_SetSerialDataBits(int32_t port, int32_t bits, int32_t* status);
|
||||
void HAL_SetSerialParity(int32_t port, int32_t parity, int32_t* status);
|
||||
void HAL_SetSerialStopBits(int32_t port, int32_t stopBits, int32_t* status);
|
||||
void HAL_SetSerialWriteMode(int32_t port, int32_t mode, int32_t* status);
|
||||
void HAL_SetSerialFlowControl(int32_t port, int32_t flow, int32_t* status);
|
||||
void HAL_SetSerialTimeout(int32_t port, double timeout, int32_t* status);
|
||||
void HAL_EnableSerialTermination(int32_t port, char terminator,
|
||||
int32_t* status);
|
||||
void HAL_DisableSerialTermination(uint8_t port, int32_t* status);
|
||||
void HAL_SetSerialReadBufferSize(uint8_t port, uint32_t size, int32_t* status);
|
||||
void HAL_SetSerialWriteBufferSize(uint8_t port, uint32_t size, int32_t* status);
|
||||
int32_t HAL_GetSerialBytesReceived(uint8_t port, int32_t* status);
|
||||
uint32_t HAL_ReadSerial(uint8_t port, char* buffer, int32_t count,
|
||||
void HAL_DisableSerialTermination(int32_t port, int32_t* status);
|
||||
void HAL_SetSerialReadBufferSize(int32_t port, int32_t size, int32_t* status);
|
||||
void HAL_SetSerialWriteBufferSize(int32_t port, int32_t size, int32_t* status);
|
||||
int32_t HAL_GetSerialBytesReceived(int32_t port, int32_t* status);
|
||||
int32_t HAL_ReadSerial(int32_t port, char* buffer, int32_t count,
|
||||
int32_t* status);
|
||||
int32_t HAL_WriteSerial(int32_t port, const char* buffer, int32_t count,
|
||||
int32_t* status);
|
||||
uint32_t HAL_WriteSerial(uint8_t port, const char* buffer, int32_t count,
|
||||
int32_t* status);
|
||||
void HAL_FlushSerial(uint8_t port, int32_t* status);
|
||||
void HAL_ClearSerial(uint8_t port, int32_t* status);
|
||||
void HAL_CloseSerial(uint8_t port, int32_t* status);
|
||||
void HAL_FlushSerial(int32_t port, int32_t* status);
|
||||
void HAL_ClearSerial(int32_t port, int32_t* status);
|
||||
void HAL_CloseSerial(int32_t port, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -9,21 +9,21 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle port_handle,
|
||||
int32_t* status);
|
||||
void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoid_port_handle);
|
||||
bool HAL_CheckSolenoidModule(uint8_t module);
|
||||
|
||||
bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle, int32_t* status);
|
||||
uint8_t HAL_GetAllSolenoids(uint8_t module, int32_t* status);
|
||||
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, bool value,
|
||||
HAL_Bool HAL_CheckSolenoidModule(int32_t module);
|
||||
HAL_Bool HAL_CheckSolenoidPin(int32_t pin);
|
||||
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle,
|
||||
int32_t* status);
|
||||
int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status);
|
||||
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, HAL_Bool value,
|
||||
int32_t* status);
|
||||
|
||||
int HAL_GetPCMSolenoidBlackList(uint8_t module, int32_t* status);
|
||||
bool HAL_GetPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status);
|
||||
bool HAL_GetPCMSolenoidVoltageFault(uint8_t module, int32_t* status);
|
||||
void HAL_ClearAllPCMStickyFaults(uint8_t module, int32_t* status);
|
||||
int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status);
|
||||
HAL_Bool HAL_GetPCMSolenoidVoltageStickyFault(int32_t module, int32_t* status);
|
||||
HAL_Bool HAL_GetPCMSolenoidVoltageFault(int32_t module, int32_t* status);
|
||||
void HAL_ClearAllPCMStickyFaults(int32_t module, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -42,3 +42,5 @@ typedef HAL_Handle HAL_FPGAEncoderHandle;
|
||||
typedef HAL_Handle HAL_EncoderHandle;
|
||||
|
||||
typedef HAL_Handle HAL_GyroHandle;
|
||||
|
||||
typedef int32_t HAL_Bool;
|
||||
@@ -99,7 +99,7 @@ static void initializeAccelerometer() {
|
||||
|
||||
static void writeRegister(Register reg, uint8_t data) {
|
||||
int32_t status = 0;
|
||||
uint32_t initialTime;
|
||||
uint64_t initialTime;
|
||||
|
||||
accel->writeADDR(kSendAddress, &status);
|
||||
|
||||
@@ -130,7 +130,7 @@ static void writeRegister(Register reg, uint8_t data) {
|
||||
|
||||
static uint8_t readRegister(Register reg) {
|
||||
int32_t status = 0;
|
||||
uint32_t initialTime;
|
||||
uint64_t initialTime;
|
||||
|
||||
// Send a start transmit/receive message with the register address
|
||||
accel->writeADDR(kSendAddress, &status);
|
||||
@@ -189,7 +189,7 @@ extern "C" {
|
||||
* Set the accelerometer to active or standby mode. It must be in standby
|
||||
* mode to change any configuration.
|
||||
*/
|
||||
void HAL_SetAccelerometerActive(bool active) {
|
||||
void HAL_SetAccelerometerActive(HAL_Bool active) {
|
||||
initializeAccelerometer();
|
||||
|
||||
uint8_t ctrlReg1 = readRegister(kReg_CtrlReg1);
|
||||
|
||||
@@ -18,8 +18,8 @@ extern "C" {
|
||||
*
|
||||
*@return The analog channel is attached to an accumulator.
|
||||
*/
|
||||
bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_IsAccumulatorChannel(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -131,8 +131,8 @@ int64_t HAL_GetAccumulatorValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
*
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
uint32_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
int64_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -155,8 +155,7 @@ uint32_t HAL_GetAccumulatorCount(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @param count Pointer to the number of accumulation cycles.
|
||||
*/
|
||||
void HAL_GetAccumulatorOutput(HAL_AnalogInputHandle analog_port_handle,
|
||||
int64_t* value, uint32_t* count,
|
||||
int32_t* status) {
|
||||
int64_t* value, int64_t* count, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
|
||||
@@ -18,17 +18,17 @@
|
||||
namespace {
|
||||
struct AnalogGyro {
|
||||
HAL_AnalogInputHandle handle;
|
||||
float voltsPerDegreePerSecond;
|
||||
float offset;
|
||||
uint32_t center;
|
||||
double voltsPerDegreePerSecond;
|
||||
double offset;
|
||||
int32_t center;
|
||||
};
|
||||
}
|
||||
|
||||
static constexpr uint32_t kOversampleBits = 10;
|
||||
static constexpr uint32_t kAverageBits = 0;
|
||||
static constexpr float kSamplesPerSecond = 50.0;
|
||||
static constexpr float kCalibrationSampleTime = 5.0;
|
||||
static constexpr float kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
static constexpr double kSamplesPerSecond = 50.0;
|
||||
static constexpr double kCalibrationSampleTime = 5.0;
|
||||
static constexpr double kDefaultVoltsPerDegreePerSecond = 0.007;
|
||||
|
||||
using namespace hal;
|
||||
|
||||
@@ -102,8 +102,8 @@ void HAL_FreeAnalogGyro(HAL_GyroHandle handle) {
|
||||
}
|
||||
|
||||
void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle,
|
||||
float voltsPerDegreePerSecond, float offset,
|
||||
uint32_t center, int32_t* status) {
|
||||
double voltsPerDegreePerSecond, double offset,
|
||||
int32_t center, int32_t* status) {
|
||||
auto gyro = analogGyroHandles.Get(handle);
|
||||
if (gyro == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -117,7 +117,7 @@ void HAL_SetAnalogGyroParameters(HAL_GyroHandle handle,
|
||||
}
|
||||
|
||||
void HAL_SetAnalogGyroVoltsPerDegreePerSecond(HAL_GyroHandle handle,
|
||||
float voltsPerDegreePerSecond,
|
||||
double voltsPerDegreePerSecond,
|
||||
int32_t* status) {
|
||||
auto gyro = analogGyroHandles.Get(handle);
|
||||
if (gyro == nullptr) {
|
||||
@@ -137,10 +137,10 @@ void HAL_ResetAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
||||
HAL_ResetAccumulator(gyro->handle, status);
|
||||
if (*status != 0) return;
|
||||
|
||||
const float sampleTime = 1.0f / HAL_GetAnalogSampleRate(status);
|
||||
const float overSamples =
|
||||
const double sampleTime = 1.0 / HAL_GetAnalogSampleRate(status);
|
||||
const double overSamples =
|
||||
1 << HAL_GetAnalogOversampleBits(gyro->handle, status);
|
||||
const float averageSamples =
|
||||
const double averageSamples =
|
||||
1 << HAL_GetAnalogAverageBits(gyro->handle, status);
|
||||
if (*status != 0) return;
|
||||
Wait(sampleTime * overSamples * averageSamples);
|
||||
@@ -158,46 +158,46 @@ void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
|
||||
Wait(kCalibrationSampleTime);
|
||||
|
||||
int64_t value;
|
||||
uint32_t count;
|
||||
int64_t count;
|
||||
HAL_GetAccumulatorOutput(gyro->handle, &value, &count, status);
|
||||
if (*status != 0) return;
|
||||
|
||||
gyro->center = static_cast<uint32_t>(
|
||||
static_cast<float>(value) / static_cast<float>(count) + .5);
|
||||
gyro->center = static_cast<int32_t>(
|
||||
static_cast<double>(value) / static_cast<double>(count) + .5);
|
||||
|
||||
gyro->offset = static_cast<float>(value) / static_cast<float>(count) -
|
||||
static_cast<float>(gyro->center);
|
||||
gyro->offset = static_cast<double>(value) / static_cast<double>(count) -
|
||||
static_cast<double>(gyro->center);
|
||||
HAL_SetAccumulatorCenter(gyro->handle, gyro->center, status);
|
||||
if (*status != 0) return;
|
||||
HAL_ResetAnalogGyro(handle, status);
|
||||
}
|
||||
|
||||
void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, float volts,
|
||||
void HAL_SetAnalogGyroDeadband(HAL_GyroHandle handle, double volts,
|
||||
int32_t* status) {
|
||||
auto gyro = analogGyroHandles.Get(handle);
|
||||
if (gyro == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
int32_t deadband = volts * 1e9 /
|
||||
HAL_GetAnalogLSBWeight(gyro->handle, status) *
|
||||
(1 << HAL_GetAnalogOversampleBits(gyro->handle, status));
|
||||
int32_t deadband = static_cast<int32_t>(
|
||||
volts * 1e9 / HAL_GetAnalogLSBWeight(gyro->handle, status) *
|
||||
(1 << HAL_GetAnalogOversampleBits(gyro->handle, status)));
|
||||
if (*status != 0) return;
|
||||
HAL_SetAccumulatorDeadband(gyro->handle, deadband, status);
|
||||
}
|
||||
|
||||
float HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
|
||||
double HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
|
||||
auto gyro = analogGyroHandles.Get(handle);
|
||||
if (gyro == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return 0;
|
||||
}
|
||||
int64_t rawValue = 0;
|
||||
uint32_t count = 0;
|
||||
int64_t count = 0;
|
||||
HAL_GetAccumulatorOutput(gyro->handle, &rawValue, &count, status);
|
||||
|
||||
int64_t value =
|
||||
rawValue - static_cast<int64_t>(static_cast<float>(count) * gyro->offset);
|
||||
int64_t value = rawValue - static_cast<int64_t>(static_cast<double>(count) *
|
||||
gyro->offset);
|
||||
|
||||
double scaledValue =
|
||||
value * 1e-9 *
|
||||
@@ -222,7 +222,7 @@ double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
|
||||
gyro->voltsPerDegreePerSecond);
|
||||
}
|
||||
|
||||
float HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status) {
|
||||
double HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status) {
|
||||
auto gyro = analogGyroHandles.Get(handle);
|
||||
if (gyro == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -231,7 +231,7 @@ float HAL_GetAnalogGyroOffset(HAL_GyroHandle handle, int32_t* status) {
|
||||
return gyro->offset;
|
||||
}
|
||||
|
||||
uint32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status) {
|
||||
int32_t HAL_GetAnalogGyroCenter(HAL_GyroHandle handle, int32_t* status) {
|
||||
auto gyro = analogGyroHandles.Get(handle);
|
||||
if (gyro == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
|
||||
@@ -75,7 +75,7 @@ void HAL_FreeAnalogInputPort(HAL_AnalogInputHandle analog_port_handle) {
|
||||
*
|
||||
* @return Analog module is valid and present
|
||||
*/
|
||||
bool HAL_CheckAnalogModule(uint8_t module) { return module == 1; }
|
||||
HAL_Bool HAL_CheckAnalogModule(int32_t module) { return module == 1; }
|
||||
|
||||
/**
|
||||
* Check that the analog output channel number is value.
|
||||
@@ -84,9 +84,8 @@ bool HAL_CheckAnalogModule(uint8_t module) { return module == 1; }
|
||||
*
|
||||
* @return Analog channel is valid
|
||||
*/
|
||||
bool HAL_CheckAnalogInputChannel(uint32_t pin) {
|
||||
if (pin < kNumAnalogInputs) return true;
|
||||
return false;
|
||||
HAL_Bool HAL_CheckAnalogInputChannel(int32_t pin) {
|
||||
return (pin < kNumAnalogInputs) && (pin >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,7 +103,7 @@ void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
|
||||
|
||||
// Compute the convert rate
|
||||
uint32_t ticksPerSample =
|
||||
static_cast<uint32_t>(static_cast<float>(kTimebase) / samplesPerSecond);
|
||||
static_cast<uint32_t>(static_cast<double>(kTimebase) / samplesPerSecond);
|
||||
uint32_t ticksPerConversion =
|
||||
ticksPerSample / getAnalogNumChannelsToActivate(status);
|
||||
// ticksPerConversion must be at least 80
|
||||
@@ -132,11 +131,11 @@ void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
|
||||
*
|
||||
* @return Sample rate.
|
||||
*/
|
||||
float HAL_GetAnalogSampleRate(int32_t* status) {
|
||||
double HAL_GetAnalogSampleRate(int32_t* status) {
|
||||
uint32_t ticksPerConversion = analogInputSystem->readLoopTiming(status);
|
||||
uint32_t ticksPerSample =
|
||||
ticksPerConversion * getAnalogNumActiveChannels(status);
|
||||
return static_cast<float>(kTimebase) / static_cast<float>(ticksPerSample);
|
||||
return static_cast<double>(kTimebase) / static_cast<double>(ticksPerSample);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,13 +149,14 @@ float HAL_GetAnalogSampleRate(int32_t* status) {
|
||||
* @param bits Number of bits to average.
|
||||
*/
|
||||
void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
uint32_t bits, int32_t* status) {
|
||||
int32_t bits, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
analogInputSystem->writeAverageBits(port->pin, bits, status);
|
||||
analogInputSystem->writeAverageBits(port->pin, static_cast<uint8_t>(bits),
|
||||
status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -168,14 +168,14 @@ void HAL_SetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @param analog_port_pointer Pointer to the analog port to use.
|
||||
* @return Bits to average.
|
||||
*/
|
||||
uint32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
int32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return kDefaultAverageBits;
|
||||
}
|
||||
uint32_t result = analogInputSystem->readAverageBits(port->pin, status);
|
||||
uint8_t result = analogInputSystem->readAverageBits(port->pin, status);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -191,13 +191,14 @@ uint32_t HAL_GetAnalogAverageBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @param bits Number of bits to oversample.
|
||||
*/
|
||||
void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
uint32_t bits, int32_t* status) {
|
||||
int32_t bits, int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
analogInputSystem->writeOversampleBits(port->pin, bits, status);
|
||||
analogInputSystem->writeOversampleBits(port->pin, static_cast<uint8_t>(bits),
|
||||
status);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,14 +211,14 @@ void HAL_SetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @param analog_port_pointer Pointer to the analog port to use.
|
||||
* @return Bits to oversample.
|
||||
*/
|
||||
uint32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
int32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return kDefaultOversampleBits;
|
||||
}
|
||||
uint32_t result = analogInputSystem->readOversampleBits(port->pin, status);
|
||||
uint8_t result = analogInputSystem->readOversampleBits(port->pin, status);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -231,7 +232,7 @@ uint32_t HAL_GetAnalogOversampleBits(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @param analog_port_pointer Pointer to the analog port to use.
|
||||
* @return A sample straight from the channel on this module.
|
||||
*/
|
||||
int16_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t HAL_GetAnalogValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
@@ -289,12 +290,12 @@ int32_t HAL_GetAnalogAverageValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @param analog_port_pointer Pointer to the analog port to use.
|
||||
* @return A scaled sample straight from the channel on this module.
|
||||
*/
|
||||
float HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
int16_t value = HAL_GetAnalogValue(analog_port_handle, status);
|
||||
uint32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
|
||||
double HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
int32_t value = HAL_GetAnalogValue(analog_port_handle, status);
|
||||
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
|
||||
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
|
||||
float voltage = LSBWeight * 1.0e-9 * value - offset * 1.0e-9;
|
||||
double voltage = LSBWeight * 1.0e-9 * value - offset * 1.0e-9;
|
||||
return voltage;
|
||||
}
|
||||
|
||||
@@ -311,15 +312,15 @@ float HAL_GetAnalogVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @return A scaled sample from the output of the oversample and average engine
|
||||
* for the channel.
|
||||
*/
|
||||
float HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
double HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
int32_t value = HAL_GetAnalogAverageValue(analog_port_handle, status);
|
||||
uint32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
|
||||
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
|
||||
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
|
||||
uint32_t oversampleBits =
|
||||
int32_t oversampleBits =
|
||||
HAL_GetAnalogOversampleBits(analog_port_handle, status);
|
||||
float voltage =
|
||||
LSBWeight * 1.0e-9 * value / static_cast<float>(1 << oversampleBits) -
|
||||
double voltage =
|
||||
LSBWeight * 1.0e-9 * value / static_cast<double>(1 << oversampleBits) -
|
||||
offset * 1.0e-9;
|
||||
return voltage;
|
||||
}
|
||||
@@ -346,9 +347,10 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
voltage = 0.0;
|
||||
*status = VOLTAGE_OUT_OF_RANGE;
|
||||
}
|
||||
uint32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
|
||||
int32_t LSBWeight = HAL_GetAnalogLSBWeight(analog_port_handle, status);
|
||||
int32_t offset = HAL_GetAnalogOffset(analog_port_handle, status);
|
||||
int32_t value = (int32_t)((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9));
|
||||
int32_t value =
|
||||
static_cast<int32_t>((voltage + offset * 1.0e-9) / (LSBWeight * 1.0e-9));
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -362,8 +364,8 @@ int32_t HAL_GetAnalogVoltsToValue(HAL_AnalogInputHandle analog_port_handle,
|
||||
* @param analog_port_pointer Pointer to the analog port to use.
|
||||
* @return Least significant bit weight.
|
||||
*/
|
||||
uint32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
int32_t HAL_GetAnalogLSBWeight(HAL_AnalogInputHandle analog_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = analogInputHandles.Get(analog_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace hal {
|
||||
constexpr int32_t kTimebase = 40000000; ///< 40 MHz clock
|
||||
constexpr int32_t kDefaultOversampleBits = 0;
|
||||
constexpr int32_t kDefaultAverageBits = 7;
|
||||
constexpr float kDefaultSampleRate = 50000.0;
|
||||
constexpr double kDefaultSampleRate = 50000.0;
|
||||
static const uint32_t kAccumulatorChannels[] = {0, 1};
|
||||
|
||||
extern tAI* analogInputSystem;
|
||||
|
||||
@@ -69,9 +69,8 @@ void HAL_FreeAnalogOutputPort(HAL_AnalogOutputHandle analog_output_handle) {
|
||||
*
|
||||
* @return Analog channel is valid
|
||||
*/
|
||||
bool HAL_CheckAnalogOutputChannel(uint32_t pin) {
|
||||
if (pin < kNumAnalogOutputs) return true;
|
||||
return false;
|
||||
HAL_Bool HAL_CheckAnalogOutputChannel(int32_t pin) {
|
||||
return (pin < kNumAnalogOutputs) && (pin >= 0);
|
||||
}
|
||||
|
||||
void HAL_SetAnalogOutput(HAL_AnalogOutputHandle analog_output_handle,
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace {
|
||||
struct AnalogTrigger {
|
||||
tAnalogTrigger* trigger;
|
||||
HAL_AnalogInputHandle analogHandle;
|
||||
uint32_t index;
|
||||
uint8_t index;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ static LimitedHandleResource<HAL_AnalogTriggerHandle, AnalogTrigger,
|
||||
extern "C" {
|
||||
|
||||
HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
HAL_AnalogInputHandle port_handle, uint32_t* index, int32_t* status) {
|
||||
HAL_AnalogInputHandle port_handle, int32_t* index, int32_t* status) {
|
||||
if (port_handle == HAL_kInvalidHandle) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
@@ -49,8 +49,8 @@ HAL_AnalogTriggerHandle HAL_InitializeAnalogTrigger(
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
*index = static_cast<uint32_t>(getHandleIndex(handle));
|
||||
trigger->index = *index;
|
||||
trigger->index = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
*index = trigger->index;
|
||||
// TODO: if (index == ~0ul) { CloneError(triggers); return; }
|
||||
|
||||
trigger->trigger = tAnalogTrigger::create(trigger->index, status);
|
||||
@@ -114,7 +114,7 @@ void HAL_SetAnalogTriggerLimitsVoltage(
|
||||
* trigger, otherwise the immediate value is used.
|
||||
*/
|
||||
void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
bool useAveragedValue, int32_t* status) {
|
||||
HAL_Bool useAveragedValue, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -135,7 +135,7 @@ void HAL_SetAnalogTriggerAveraged(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
* pot crosses through zero.
|
||||
*/
|
||||
void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
bool useFilteredValue, int32_t* status) {
|
||||
HAL_Bool useFilteredValue, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -154,8 +154,8 @@ void HAL_SetAnalogTriggerFiltered(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
* True if the analog input is between the upper and lower limits.
|
||||
* @return The InWindow output of the analog trigger.
|
||||
*/
|
||||
bool HAL_GetAnalogTriggerInWindow(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetAnalogTriggerInWindow(
|
||||
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -171,7 +171,7 @@ bool HAL_GetAnalogTriggerInWindow(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
* If in Hysteresis, maintain previous state.
|
||||
* @return The TriggerState output of the analog trigger.
|
||||
*/
|
||||
bool HAL_GetAnalogTriggerTriggerState(
|
||||
HAL_Bool HAL_GetAnalogTriggerTriggerState(
|
||||
HAL_AnalogTriggerHandle analog_trigger_handle, int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
@@ -185,8 +185,9 @@ bool HAL_GetAnalogTriggerTriggerState(
|
||||
* Get the state of the analog trigger output.
|
||||
* @return The state of the analog trigger output.
|
||||
*/
|
||||
bool HAL_GetAnalogTriggerOutput(HAL_AnalogTriggerHandle analog_trigger_handle,
|
||||
HAL_AnalogTriggerType type, int32_t* status) {
|
||||
HAL_Bool HAL_GetAnalogTriggerOutput(
|
||||
HAL_AnalogTriggerHandle analog_trigger_handle, HAL_AnalogTriggerType type,
|
||||
int32_t* status) {
|
||||
auto trigger = analogTriggerHandles.Get(analog_trigger_handle);
|
||||
if (trigger == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
|
||||
@@ -17,27 +17,26 @@ using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_CompressorHandle HAL_InitializeCompressor(uint8_t module, int32_t* status) {
|
||||
// fail on invalid index;
|
||||
if (!HAL_CheckCompressorModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
HAL_CompressorHandle HAL_InitializeCompressor(int32_t module, int32_t* status) {
|
||||
// Use status to check for invalid index
|
||||
initializePCM(module, status);
|
||||
if (*status != 0) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
initializePCM(module);
|
||||
|
||||
// As compressors can have unlimited objects, just create a
|
||||
// handle with the module number as the index.
|
||||
|
||||
return (HAL_CompressorHandle)createHandle(module, HAL_HandleEnum::Compressor);
|
||||
return (HAL_CompressorHandle)createHandle(static_cast<int16_t>(module),
|
||||
HAL_HandleEnum::Compressor);
|
||||
}
|
||||
|
||||
bool HAL_CheckCompressorModule(uint8_t module) {
|
||||
return module < kNumPCMModules;
|
||||
HAL_Bool HAL_CheckCompressorModule(int32_t module) {
|
||||
return (module < kNumPCMModules) && (module >= 0);
|
||||
}
|
||||
|
||||
bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
@@ -53,7 +52,7 @@ bool HAL_GetCompressor(HAL_CompressorHandle compressor_handle,
|
||||
}
|
||||
|
||||
void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
|
||||
bool value, int32_t* status) {
|
||||
HAL_Bool value, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
@@ -65,8 +64,8 @@ void HAL_SetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
|
||||
*status = module->SetClosedLoopControl(value);
|
||||
}
|
||||
|
||||
bool HAL_GetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetCompressorClosedLoopControl(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
@@ -81,8 +80,8 @@ bool HAL_GetCompressorClosedLoopControl(HAL_CompressorHandle compressor_handle,
|
||||
return value;
|
||||
}
|
||||
|
||||
bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
@@ -97,8 +96,8 @@ bool HAL_GetCompressorPressureSwitch(HAL_CompressorHandle compressor_handle,
|
||||
return value;
|
||||
}
|
||||
|
||||
float HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
double HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
@@ -112,7 +111,7 @@ float HAL_GetCompressorCurrent(HAL_CompressorHandle compressor_handle,
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetCompressorCurrentTooHighFault(
|
||||
HAL_Bool HAL_GetCompressorCurrentTooHighFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
@@ -127,7 +126,7 @@ bool HAL_GetCompressorCurrentTooHighFault(
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetCompressorCurrentTooHighStickyFault(
|
||||
HAL_Bool HAL_GetCompressorCurrentTooHighStickyFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
@@ -142,8 +141,8 @@ bool HAL_GetCompressorCurrentTooHighStickyFault(
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetCompressorShortedStickyFault(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetCompressorShortedStickyFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
@@ -157,8 +156,8 @@ bool HAL_GetCompressorShortedStickyFault(HAL_CompressorHandle compressor_handle,
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
@@ -172,7 +171,7 @@ bool HAL_GetCompressorShortedFault(HAL_CompressorHandle compressor_handle,
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetCompressorNotConnectedStickyFault(
|
||||
HAL_Bool HAL_GetCompressorNotConnectedStickyFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
@@ -187,8 +186,8 @@ bool HAL_GetCompressorNotConnectedStickyFault(
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetCompressorNotConnectedFault(HAL_CompressorHandle compressor_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetCompressorNotConnectedFault(
|
||||
HAL_CompressorHandle compressor_handle, int32_t* status) {
|
||||
int16_t index =
|
||||
getHandleTypedIndex(compressor_handle, HAL_HandleEnum::Compressor);
|
||||
if (index == InvalidHandleIndex) {
|
||||
|
||||
@@ -18,7 +18,7 @@ using namespace hal;
|
||||
namespace {
|
||||
struct Counter {
|
||||
tCounter* counter;
|
||||
uint32_t index;
|
||||
uint8_t index;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -39,12 +39,12 @@ HAL_CounterHandle HAL_InitializeCounter(HAL_Counter_Mode mode, int32_t* index,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
*index = static_cast<uint32_t>(getHandleIndex(handle));
|
||||
counter->index = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
*index = counter->index;
|
||||
|
||||
counter->counter = tCounter::create(*index, status);
|
||||
counter->counter = tCounter::create(counter->index, status);
|
||||
counter->counter->writeConfig_Mode(mode, status);
|
||||
counter->counter->writeTimerConfig_AverageSize(1, status);
|
||||
counter->index = *index;
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
|
||||
}
|
||||
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
@@ -110,7 +110,7 @@ void HAL_SetCounterUpSource(HAL_CounterHandle counter_handle,
|
||||
* Set the up source to either detect rising edges or falling edges.
|
||||
*/
|
||||
void HAL_SetCounterUpSourceEdge(HAL_CounterHandle counter_handle,
|
||||
bool risingEdge, bool fallingEdge,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
@@ -151,7 +151,7 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
unsigned char mode = counter->counter->readConfig_Mode(status);
|
||||
uint8_t mode = counter->counter->readConfig_Mode(status);
|
||||
if (mode != HAL_Counter_kTwoPulse && mode != HAL_Counter_kExternalDirection) {
|
||||
// TODO: wpi_setWPIErrorWithContext(ParameterOutOfRange, "Counter only
|
||||
// supports DownSource in TwoPulse and ExternalDirection modes.");
|
||||
@@ -160,7 +160,7 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
|
||||
}
|
||||
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
@@ -184,7 +184,7 @@ void HAL_SetCounterDownSource(HAL_CounterHandle counter_handle,
|
||||
* Set the down source to either detect rising edges or falling edges.
|
||||
*/
|
||||
void HAL_SetCounterDownSourceEdge(HAL_CounterHandle counter_handle,
|
||||
bool risingEdge, bool fallingEdge,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
@@ -246,7 +246,7 @@ void HAL_SetCounterExternalDirectionMode(HAL_CounterHandle counter_handle,
|
||||
* Counts up on both rising and falling edges.
|
||||
*/
|
||||
void HAL_SetCounterSemiPeriodMode(HAL_CounterHandle counter_handle,
|
||||
bool highSemiPeriod, int32_t* status) {
|
||||
HAL_Bool highSemiPeriod, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -300,7 +300,7 @@ int32_t HAL_GetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
|
||||
* @param samplesToAverage The number of samples to average from 1 to 127.
|
||||
*/
|
||||
void HAL_SetCounterSamplesToAverage(HAL_CounterHandle counter_handle,
|
||||
int samplesToAverage, int32_t* status) {
|
||||
int32_t samplesToAverage, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -365,7 +365,8 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status) {
|
||||
period = static_cast<double>(output.Period << 1) /
|
||||
static_cast<double>(output.Count);
|
||||
}
|
||||
return period * 2.5e-8; // result * timebase (currently 40ns)
|
||||
return static_cast<double>(period *
|
||||
2.5e-8); // result * timebase (currently 25ns)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -401,7 +402,7 @@ void HAL_SetCounterMaxPeriod(HAL_CounterHandle counter_handle, double maxPeriod,
|
||||
* at the end of an average and there are no samples to average).
|
||||
*/
|
||||
void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
|
||||
bool enabled, int32_t* status) {
|
||||
HAL_Bool enabled, int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -418,7 +419,8 @@ void HAL_SetCounterUpdateWhenEmpty(HAL_CounterHandle counter_handle,
|
||||
* @return Returns true if the most recent counter period exceeds the MaxPeriod
|
||||
* value set by SetMaxPeriod.
|
||||
*/
|
||||
bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle, int32_t* status) {
|
||||
HAL_Bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -431,8 +433,8 @@ bool HAL_GetCounterStopped(HAL_CounterHandle counter_handle, int32_t* status) {
|
||||
* The last direction the counter value changed.
|
||||
* @return The last direction the counter value changed.
|
||||
*/
|
||||
bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -449,7 +451,8 @@ bool HAL_GetCounterDirection(HAL_CounterHandle counter_handle,
|
||||
* @param reverseDirection true if the value counted should be negated.
|
||||
*/
|
||||
void HAL_SetCounterReverseDirection(HAL_CounterHandle counter_handle,
|
||||
bool reverseDirection, int32_t* status) {
|
||||
HAL_Bool reverseDirection,
|
||||
int32_t* status) {
|
||||
auto counter = counterHandles.Get(counter_handle);
|
||||
if (counter == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
|
||||
@@ -29,7 +29,7 @@ extern "C" {
|
||||
* Create a new instance of a digital port.
|
||||
*/
|
||||
HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
|
||||
uint8_t input, int32_t* status) {
|
||||
int32_t input, int32_t* status) {
|
||||
initializeDigital(status);
|
||||
|
||||
if (*status != 0) return HAL_kInvalidHandle;
|
||||
@@ -58,7 +58,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
|
||||
tDIO::tOutputEnable outputEnable = digitalSystem->readOutputEnable(status);
|
||||
|
||||
if (port->pin < kNumDigitalHeaders) {
|
||||
uint32_t bitToSet = 1 << port->pin;
|
||||
uint32_t bitToSet = 1u << port->pin;
|
||||
if (input) {
|
||||
outputEnable.Headers =
|
||||
outputEnable.Headers & (~bitToSet); // clear the bit for read
|
||||
@@ -67,10 +67,9 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
|
||||
outputEnable.Headers | bitToSet; // set the bit for write
|
||||
}
|
||||
} else {
|
||||
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
|
||||
uint32_t bitToSet = 1u << remapMXPChannel(port->pin);
|
||||
|
||||
// Disable special functions on this pin
|
||||
int16_t specialFunctions =
|
||||
uint16_t specialFunctions =
|
||||
digitalSystem->readEnableMXPSpecialFunction(status);
|
||||
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
|
||||
status);
|
||||
@@ -158,23 +157,25 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
uint32_t id = *port;
|
||||
int32_t id = *port;
|
||||
if (dutyCycle > 1.0) dutyCycle = 1.0;
|
||||
if (dutyCycle < 0.0) dutyCycle = 0.0;
|
||||
float rawDutyCycle = 256.0 * dutyCycle;
|
||||
double rawDutyCycle = 256.0 * dutyCycle;
|
||||
if (rawDutyCycle > 255.5) rawDutyCycle = 255.5;
|
||||
{
|
||||
std::lock_guard<priority_recursive_mutex> sync(digitalPwmMutex);
|
||||
uint8_t pwmPeriodPower = digitalSystem->readPWMPeriodPower(status);
|
||||
uint16_t pwmPeriodPower = digitalSystem->readPWMPeriodPower(status);
|
||||
if (pwmPeriodPower < 4) {
|
||||
// The resolution of the duty cycle drops close to the highest
|
||||
// frequencies.
|
||||
rawDutyCycle = rawDutyCycle / std::pow(2.0, 4 - pwmPeriodPower);
|
||||
}
|
||||
if (id < 4)
|
||||
digitalSystem->writePWMDutyCycleA(id, (uint8_t)rawDutyCycle, status);
|
||||
digitalSystem->writePWMDutyCycleA(id, static_cast<uint8_t>(rawDutyCycle),
|
||||
status);
|
||||
else
|
||||
digitalSystem->writePWMDutyCycleB(id - 4, (uint8_t)rawDutyCycle, status);
|
||||
digitalSystem->writePWMDutyCycleB(
|
||||
id - 4, static_cast<uint8_t>(rawDutyCycle), status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,13 +186,13 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
|
||||
* @param channel The Digital Output channel to output on
|
||||
*/
|
||||
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
|
||||
uint32_t pin, int32_t* status) {
|
||||
int32_t pin, int32_t* status) {
|
||||
auto port = digitalPWMHandles.Get(pwmGenerator);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return;
|
||||
}
|
||||
uint32_t id = *port;
|
||||
int32_t id = *port;
|
||||
if (pin >= kNumDigitalHeaders) { // if it is on the MXP
|
||||
pin += kMXPDigitalPWMOffset; // then to write as a digital PWM pin requires
|
||||
// an offset to write on the correct pin
|
||||
@@ -207,7 +208,7 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
|
||||
* @param value The state to set the digital channel (if it is configured as an
|
||||
* output)
|
||||
*/
|
||||
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, int16_t value,
|
||||
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, HAL_Bool value,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
@@ -223,19 +224,19 @@ void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, int16_t value,
|
||||
|
||||
if (port->pin < kNumDigitalHeaders) {
|
||||
if (value == 0) {
|
||||
currentDIO.Headers = currentDIO.Headers & ~(1 << port->pin);
|
||||
currentDIO.Headers = currentDIO.Headers & ~(1u << port->pin);
|
||||
} else if (value == 1) {
|
||||
currentDIO.Headers = currentDIO.Headers | (1 << port->pin);
|
||||
currentDIO.Headers = currentDIO.Headers | (1u << port->pin);
|
||||
}
|
||||
} else {
|
||||
if (value == 0) {
|
||||
currentDIO.MXP = currentDIO.MXP & ~(1 << remapMXPChannel(port->pin));
|
||||
currentDIO.MXP = currentDIO.MXP & ~(1u << remapMXPChannel(port->pin));
|
||||
} else if (value == 1) {
|
||||
currentDIO.MXP = currentDIO.MXP | (1 << remapMXPChannel(port->pin));
|
||||
currentDIO.MXP = currentDIO.MXP | (1u << remapMXPChannel(port->pin));
|
||||
}
|
||||
|
||||
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
|
||||
int16_t specialFunctions =
|
||||
int32_t bitToSet = 1 << remapMXPChannel(port->pin);
|
||||
uint16_t specialFunctions =
|
||||
digitalSystem->readEnableMXPSpecialFunction(status);
|
||||
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
|
||||
status);
|
||||
@@ -251,7 +252,7 @@ void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, int16_t value,
|
||||
* @param channel The digital I/O channel
|
||||
* @return The state of the specified channel
|
||||
*/
|
||||
bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
HAL_Bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -267,8 +268,8 @@ bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
return ((currentDIO.Headers >> port->pin) & 1) != 0;
|
||||
} else {
|
||||
// Disable special functions
|
||||
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
|
||||
int16_t specialFunctions =
|
||||
int32_t bitToSet = 1 << remapMXPChannel(port->pin);
|
||||
uint16_t specialFunctions =
|
||||
digitalSystem->readEnableMXPSpecialFunction(status);
|
||||
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
|
||||
status);
|
||||
@@ -284,7 +285,8 @@ bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
* @param channel The digital I/O channel
|
||||
* @return The direction of the specified channel
|
||||
*/
|
||||
bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
HAL_Bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -322,13 +324,14 @@ void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
|
||||
tDIO::tPulse pulse;
|
||||
|
||||
if (port->pin < kNumDigitalHeaders) {
|
||||
pulse.Headers = 1 << port->pin;
|
||||
pulse.Headers = 1u << port->pin;
|
||||
} else {
|
||||
pulse.MXP = 1 << remapMXPChannel(port->pin);
|
||||
pulse.MXP = 1u << remapMXPChannel(port->pin);
|
||||
}
|
||||
|
||||
digitalSystem->writePulseLength(
|
||||
(uint8_t)(1.0e9 * pulseLength / (pwmSystem->readLoopTiming(status) * 25)),
|
||||
static_cast<uint8_t>(1.0e9 * pulseLength /
|
||||
(pwmSystem->readLoopTiming(status) * 25)),
|
||||
status);
|
||||
digitalSystem->writePulse(pulse, status);
|
||||
}
|
||||
@@ -338,7 +341,7 @@ void HAL_Pulse(HAL_DigitalHandle dio_port_handle, double pulseLength,
|
||||
*
|
||||
* @return A pulse is in progress
|
||||
*/
|
||||
bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
HAL_Bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -358,7 +361,7 @@ bool HAL_IsPulsing(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
*
|
||||
* @return A pulse on some line is in progress
|
||||
*/
|
||||
bool HAL_IsAnyPulsing(int32_t* status) {
|
||||
HAL_Bool HAL_IsAnyPulsing(int32_t* status) {
|
||||
tDIO::tPulse pulseRegister = digitalSystem->readPulse(status);
|
||||
return pulseRegister.Headers != 0 && pulseRegister.MXP != 0;
|
||||
}
|
||||
@@ -423,7 +426,7 @@ int HAL_GetFilterSelect(HAL_DigitalHandle dio_port_handle, int32_t* status) {
|
||||
* @param value The number of cycles that the signal must not transition to be
|
||||
* counted as a transition.
|
||||
*/
|
||||
void HAL_SetFilterPeriod(int filter_index, uint32_t value, int32_t* status) {
|
||||
void HAL_SetFilterPeriod(int32_t filter_index, int64_t value, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(digitalDIOMutex);
|
||||
digitalSystem->writeFilterPeriodHdr(filter_index, value, status);
|
||||
if (*status == 0) {
|
||||
@@ -443,7 +446,7 @@ void HAL_SetFilterPeriod(int filter_index, uint32_t value, int32_t* status) {
|
||||
* @param value The number of cycles that the signal must not transition to be
|
||||
* counted as a transition.
|
||||
*/
|
||||
uint32_t HAL_GetFilterPeriod(int filter_index, int32_t* status) {
|
||||
int64_t HAL_GetFilterPeriod(int32_t filter_index, int32_t* status) {
|
||||
uint32_t hdr_period = 0;
|
||||
uint32_t mxp_period = 0;
|
||||
{
|
||||
|
||||
@@ -69,7 +69,7 @@ void initializeDigital(int32_t* status) {
|
||||
(kDefaultPwmCenter - kDefaultPwmStepsDown * loopTime) / loopTime + .5);
|
||||
pwmSystem->writeConfig_MinHigh(minHigh, status);
|
||||
// Ensure that PWM output values are set to OFF
|
||||
for (uint32_t pwm_index = 0; pwm_index < kNumPWMPins; pwm_index++) {
|
||||
for (uint8_t pwm_index = 0; pwm_index < kNumPWMPins; pwm_index++) {
|
||||
// Copy of SetPWM
|
||||
if (pwm_index < tPWM::kNumHdrRegisters) {
|
||||
pwmSystem->writeHdr(pwm_index, kPwmDisabled, status);
|
||||
@@ -94,9 +94,9 @@ void initializeDigital(int32_t* status) {
|
||||
* Map DIO pin numbers from their physical number (10 to 26) to their position
|
||||
* in the bit field.
|
||||
*/
|
||||
uint32_t remapMXPChannel(uint32_t pin) { return pin - 10; }
|
||||
int32_t remapMXPChannel(int32_t pin) { return pin - 10; }
|
||||
|
||||
uint32_t remapMXPPWMChannel(uint32_t pin) {
|
||||
int32_t remapMXPPWMChannel(int32_t pin) {
|
||||
if (pin < 14) {
|
||||
return pin - 10; // first block of 4 pwms (MXP 0-3)
|
||||
} else {
|
||||
@@ -110,17 +110,17 @@ uint32_t remapMXPPWMChannel(uint32_t pin) {
|
||||
* channel else do normal digital input remapping based on pin number (MXP)
|
||||
*/
|
||||
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType, uint32_t& pin,
|
||||
HAL_AnalogTriggerType analogTriggerType, uint8_t& pin,
|
||||
uint8_t& module, bool& analogTrigger) {
|
||||
if (isHandleType(digitalSourceHandle, HAL_HandleEnum::AnalogTrigger)) {
|
||||
// If handle passed, index is not negative
|
||||
uint32_t index = getHandleIndex(digitalSourceHandle);
|
||||
int32_t index = getHandleIndex(digitalSourceHandle);
|
||||
pin = (index << 2) + analogTriggerType;
|
||||
module = pin >> 4;
|
||||
analogTrigger = true;
|
||||
return true;
|
||||
} else if (isHandleType(digitalSourceHandle, HAL_HandleEnum::DIO)) {
|
||||
uint32_t index = getHandleIndex(digitalSourceHandle);
|
||||
int32_t index = getHandleIndex(digitalSourceHandle);
|
||||
if (index >= kNumDigitalHeaders) {
|
||||
pin = remapMXPChannel(index);
|
||||
module = 1;
|
||||
|
||||
@@ -11,8 +11,8 @@
|
||||
|
||||
#include "ChipObject.h"
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "handles/DigitalHandleResource.h"
|
||||
#include "handles/HandlesInternal.h"
|
||||
@@ -78,8 +78,8 @@ extern DigitalHandleResource<HAL_DigitalHandle, DigitalPort,
|
||||
|
||||
void initializeDigital(int32_t* status);
|
||||
bool remapDigitalSource(HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType, uint32_t& pin,
|
||||
HAL_AnalogTriggerType analogTriggerType, uint8_t& pin,
|
||||
uint8_t& module, bool& analogTrigger);
|
||||
uint32_t remapMXPPWMChannel(uint32_t pin);
|
||||
uint32_t remapMXPChannel(uint32_t pin);
|
||||
int32_t remapMXPPWMChannel(int32_t pin);
|
||||
int32_t remapMXPChannel(int32_t pin);
|
||||
} // namespace hal
|
||||
|
||||
@@ -230,7 +230,7 @@ extern "C" {
|
||||
HAL_EncoderHandle HAL_InitializeEncoder(
|
||||
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
|
||||
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection, HAL_EncoderEncodingType encodingType,
|
||||
HAL_Bool reverseDirection, HAL_EncoderEncodingType encodingType,
|
||||
int32_t* status) {
|
||||
auto encoder = std::make_shared<Encoder>(
|
||||
digitalSourceHandleA, analogTriggerTypeA, digitalSourceHandleB,
|
||||
@@ -285,8 +285,7 @@ void HAL_ResetEncoder(HAL_EncoderHandle encoder_handle, int32_t* status) {
|
||||
encoder->Reset(status);
|
||||
}
|
||||
|
||||
int32_t HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
double HAL_GetEncoderPeriod(HAL_EncoderHandle encoder_handle, int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -305,8 +304,8 @@ void HAL_SetEncoderMaxPeriod(HAL_EncoderHandle encoder_handle, double maxPeriod,
|
||||
encoder->SetMaxPeriod(maxPeriod, status);
|
||||
}
|
||||
|
||||
uint8_t HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -315,8 +314,8 @@ uint8_t HAL_GetEncoderStopped(HAL_EncoderHandle encoder_handle,
|
||||
return encoder->GetStopped(status);
|
||||
}
|
||||
|
||||
uint8_t HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetEncoderDirection(HAL_EncoderHandle encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -365,7 +364,8 @@ void HAL_SetEncoderDistancePerPulse(HAL_EncoderHandle encoder_handle,
|
||||
}
|
||||
|
||||
void HAL_SetEncoderReverseDirection(HAL_EncoderHandle encoder_handle,
|
||||
uint8_t reverseDirection, int32_t* status) {
|
||||
HAL_Bool reverseDirection,
|
||||
int32_t* status) {
|
||||
auto encoder = encoderHandles.Get(encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
|
||||
@@ -16,7 +16,7 @@ using namespace hal;
|
||||
namespace {
|
||||
struct Encoder {
|
||||
tEncoder* encoder;
|
||||
uint32_t index;
|
||||
uint8_t index;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -30,15 +30,15 @@ extern "C" {
|
||||
HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
|
||||
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
|
||||
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection, int32_t* index, int32_t* status) {
|
||||
HAL_Bool reverseDirection, int32_t* index, int32_t* status) {
|
||||
bool routingAnalogTriggerA = false;
|
||||
uint32_t routingPinA = 0;
|
||||
uint8_t routingPinA = 0;
|
||||
uint8_t routingModuleA = 0;
|
||||
bool successA =
|
||||
remapDigitalSource(digitalSourceHandleA, analogTriggerTypeA, routingPinA,
|
||||
routingModuleA, routingAnalogTriggerA);
|
||||
bool routingAnalogTriggerB = false;
|
||||
uint32_t routingPinB = 0;
|
||||
uint8_t routingPinB = 0;
|
||||
uint8_t routingModuleB = 0;
|
||||
bool successB =
|
||||
remapDigitalSource(digitalSourceHandleB, analogTriggerTypeB, routingPinB,
|
||||
@@ -61,8 +61,7 @@ HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
encoder->index = static_cast<uint32_t>(getHandleIndex(handle));
|
||||
|
||||
encoder->index = static_cast<uint8_t>(getHandleIndex(handle));
|
||||
*index = encoder->index;
|
||||
// TODO: if (index == ~0ul) { CloneError(quadEncoders); return; }
|
||||
encoder->encoder = tEncoder::create(encoder->index, status);
|
||||
@@ -187,8 +186,8 @@ void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
* one where the most recent pulse width exceeds the MaxPeriod.
|
||||
* @return True if the encoder is considered stopped.
|
||||
*/
|
||||
bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -201,8 +200,8 @@ bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
* The last direction the encoder value changed.
|
||||
* @return The last direction the encoder value changed.
|
||||
*/
|
||||
bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -218,7 +217,7 @@ bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
* @param reverseDirection true if the encoder direction should be reversed
|
||||
*/
|
||||
void HAL_SetFPGAEncoderReverseDirection(
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, bool reverseDirection,
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, HAL_Bool reverseDirection,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
@@ -235,7 +234,7 @@ void HAL_SetFPGAEncoderReverseDirection(
|
||||
* @param samplesToAverage The number of samples to average from 1 to 127.
|
||||
*/
|
||||
void HAL_SetFPGAEncoderSamplesToAverage(
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, uint32_t samplesToAverage,
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t samplesToAverage,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
@@ -254,7 +253,7 @@ void HAL_SetFPGAEncoderSamplesToAverage(
|
||||
* mechanical imperfections or as oversampling to increase resolution.
|
||||
* @return SamplesToAverage The number of samples being averaged (from 1 to 127)
|
||||
*/
|
||||
uint32_t HAL_GetFPGAEncoderSamplesToAverage(
|
||||
int32_t HAL_GetFPGAEncoderSamplesToAverage(
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
@@ -271,7 +270,7 @@ uint32_t HAL_GetFPGAEncoderSamplesToAverage(
|
||||
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
bool activeHigh, bool edgeSensitive,
|
||||
HAL_Bool activeHigh, HAL_Bool edgeSensitive,
|
||||
int32_t* status) {
|
||||
auto encoder = fpgaEncoderHandles.Get(fpga_encoder_handle);
|
||||
if (encoder == nullptr) {
|
||||
@@ -280,7 +279,7 @@ void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
}
|
||||
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/AnalogTrigger.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
extern "C" {
|
||||
HAL_FPGAEncoderHandle HAL_InitializeFPGAEncoder(
|
||||
HAL_Handle digitalSourceHandleA, HAL_AnalogTriggerType analogTriggerTypeA,
|
||||
HAL_Handle digitalSourceHandleB, HAL_AnalogTriggerType analogTriggerTypeB,
|
||||
bool reverseDirection, int32_t* index, int32_t* status);
|
||||
HAL_Bool reverseDirection, int32_t* index, int32_t* status);
|
||||
void HAL_FreeFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status);
|
||||
void HAL_ResetFPGAEncoder(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
@@ -27,21 +27,21 @@ double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetFPGAEncoderMaxPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
double maxPeriod, int32_t* status);
|
||||
bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status);
|
||||
bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetFPGAEncoderStopped(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status);
|
||||
HAL_Bool HAL_GetFPGAEncoderDirection(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
int32_t* status);
|
||||
void HAL_SetFPGAEncoderReverseDirection(
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, bool reverseDirection,
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, HAL_Bool reverseDirection,
|
||||
int32_t* status);
|
||||
void HAL_SetFPGAEncoderSamplesToAverage(
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, uint32_t samplesToAverage,
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t samplesToAverage,
|
||||
int32_t* status);
|
||||
uint32_t HAL_GetFPGAEncoderSamplesToAverage(
|
||||
int32_t HAL_GetFPGAEncoderSamplesToAverage(
|
||||
HAL_FPGAEncoderHandle fpga_encoder_handle, int32_t* status);
|
||||
void HAL_SetFPGAEncoderIndexSource(HAL_FPGAEncoderHandle fpga_encoder_handle,
|
||||
HAL_Handle digitalSourceHandle,
|
||||
HAL_AnalogTriggerType analogTriggerType,
|
||||
bool activeHigh, bool edgeSensitive,
|
||||
HAL_Bool activeHigh, HAL_Bool edgeSensitive,
|
||||
int32_t* status);
|
||||
}
|
||||
|
||||
@@ -45,12 +45,19 @@ using namespace hal;
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_PortHandle HAL_GetPort(uint8_t pin) { return createPortHandle(pin, 1); }
|
||||
HAL_PortHandle HAL_GetPort(int32_t pin) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (pin < 0 || pin >= 255) return HAL_kInvalidHandle;
|
||||
return createPortHandle(pin, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Uses module numbers
|
||||
*/
|
||||
HAL_PortHandle HAL_GetPortWithModule(uint8_t module, uint8_t pin) {
|
||||
HAL_PortHandle HAL_GetPortWithModule(int32_t module, int32_t pin) {
|
||||
// Dont allow a number that wouldn't fit in a uint8_t
|
||||
if (pin < 0 || pin >= 255) return HAL_kInvalidHandle;
|
||||
if (module < 0 || module >= 255) return HAL_kInvalidHandle;
|
||||
return createPortHandle(pin, module);
|
||||
}
|
||||
|
||||
@@ -164,7 +171,7 @@ const char* HAL_GetErrorMessage(int32_t code) {
|
||||
* For now, expect this to be competition year.
|
||||
* @return FPGA Version number.
|
||||
*/
|
||||
uint16_t HAL_GetFPGAVersion(int32_t* status) {
|
||||
int32_t HAL_GetFPGAVersion(int32_t* status) {
|
||||
if (!global) {
|
||||
*status = NiFpga_Status_ResourceNotInitialized;
|
||||
return 0;
|
||||
@@ -180,7 +187,7 @@ uint16_t HAL_GetFPGAVersion(int32_t* status) {
|
||||
* The 12 least significant bits are the Build Number.
|
||||
* @return FPGA Revision number.
|
||||
*/
|
||||
uint32_t HAL_GetFPGARevision(int32_t* status) {
|
||||
int64_t HAL_GetFPGARevision(int32_t* status) {
|
||||
if (!global) {
|
||||
*status = NiFpga_Status_ResourceNotInitialized;
|
||||
return 0;
|
||||
@@ -212,7 +219,7 @@ uint64_t HAL_GetFPGATime(int32_t* status) {
|
||||
* Get the state of the "USER" button on the roboRIO
|
||||
* @return true if the button is currently pressed down
|
||||
*/
|
||||
bool HAL_GetFPGAButton(int32_t* status) {
|
||||
HAL_Bool HAL_GetFPGAButton(int32_t* status) {
|
||||
if (!global) {
|
||||
*status = NiFpga_Status_ResourceNotInitialized;
|
||||
return false;
|
||||
@@ -220,13 +227,14 @@ bool HAL_GetFPGAButton(int32_t* status) {
|
||||
return global->readUserButton(status);
|
||||
}
|
||||
|
||||
int HAL_SetErrorData(const char* errors, int errorsLength, int wait_ms) {
|
||||
int32_t HAL_SetErrorData(const char* errors, int32_t errorsLength,
|
||||
int32_t wait_ms) {
|
||||
return setErrorData(errors, errorsLength, wait_ms);
|
||||
}
|
||||
|
||||
int HAL_SendError(int isError, int32_t errorCode, int isLVCode,
|
||||
const char* details, const char* location,
|
||||
const char* callStack, int printMsg) {
|
||||
int32_t HAL_SendError(HAL_Bool isError, int32_t errorCode, HAL_Bool isLVCode,
|
||||
const char* details, const char* location,
|
||||
const char* callStack, HAL_Bool printMsg) {
|
||||
// Avoid flooding console by keeping track of previous 5 error
|
||||
// messages and only printing again if they're longer than 1 second old.
|
||||
static constexpr int KEEP_MSGS = 5;
|
||||
@@ -270,7 +278,7 @@ int HAL_SendError(int isError, int32_t errorCode, int isLVCode,
|
||||
return retval;
|
||||
}
|
||||
|
||||
bool HAL_GetSystemActive(int32_t* status) {
|
||||
HAL_Bool HAL_GetSystemActive(int32_t* status) {
|
||||
if (!watchdog) {
|
||||
*status = NiFpga_Status_ResourceNotInitialized;
|
||||
return false;
|
||||
@@ -278,7 +286,7 @@ bool HAL_GetSystemActive(int32_t* status) {
|
||||
return watchdog->readStatus_SystemActive(status);
|
||||
}
|
||||
|
||||
bool HAL_GetBrownedOut(int32_t* status) {
|
||||
HAL_Bool HAL_GetBrownedOut(int32_t* status) {
|
||||
if (!watchdog) {
|
||||
*status = NiFpga_Status_ResourceNotInitialized;
|
||||
return false;
|
||||
@@ -312,7 +320,7 @@ void HAL_WaitForDSData() {
|
||||
/**
|
||||
* Call this to start up HAL. This is required for robot programs.
|
||||
*/
|
||||
int HAL_Initialize(int mode) {
|
||||
int32_t HAL_Initialize(int32_t mode) {
|
||||
setlinebuf(stdin);
|
||||
setlinebuf(stdout);
|
||||
|
||||
@@ -382,8 +390,8 @@ int HAL_Initialize(int mode) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t HAL_Report(uint8_t resource, uint8_t instanceNumber, uint8_t context,
|
||||
const char* feature) {
|
||||
int64_t HAL_Report(int32_t resource, int32_t instanceNumber, int32_t context,
|
||||
const char* feature) {
|
||||
if (feature == nullptr) {
|
||||
feature = "";
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ extern "C" {
|
||||
* If opening the MXP port, also sets up the pin functions appropriately
|
||||
* @param port The port to open, 0 for the on-board, 1 for the MXP.
|
||||
*/
|
||||
void HAL_InitializeI2C(uint8_t port, int32_t* status) {
|
||||
void HAL_InitializeI2C(int32_t port, int32_t* status) {
|
||||
initializeDigital(status);
|
||||
if (*status != 0) return;
|
||||
|
||||
@@ -80,9 +80,9 @@ void HAL_InitializeI2C(uint8_t port, int32_t* status) {
|
||||
* @param receiveSize Number of bytes to read from the device.
|
||||
* @return The number of bytes read (>= 0) or -1 on transfer abort.
|
||||
*/
|
||||
int32_t HAL_TransactionI2C(uint8_t port, uint8_t deviceAddress,
|
||||
uint8_t* dataToSend, uint8_t sendSize,
|
||||
uint8_t* dataReceived, uint8_t receiveSize) {
|
||||
int32_t HAL_TransactionI2C(int32_t port, int32_t deviceAddress,
|
||||
uint8_t* dataToSend, int32_t sendSize,
|
||||
uint8_t* dataReceived, int32_t receiveSize) {
|
||||
if (port > 1) {
|
||||
// Set port out of range error here
|
||||
return -1;
|
||||
@@ -112,8 +112,8 @@ int32_t HAL_TransactionI2C(uint8_t port, uint8_t deviceAddress,
|
||||
* @param data The byte to write to the register on the device.
|
||||
* @return The number of bytes written (>= 0) or -1 on transfer abort.
|
||||
*/
|
||||
int32_t HAL_WriteI2C(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
|
||||
uint8_t sendSize) {
|
||||
int32_t HAL_WriteI2C(int32_t port, int32_t deviceAddress, uint8_t* dataToSend,
|
||||
int32_t sendSize) {
|
||||
if (port > 1) {
|
||||
// Set port out of range error here
|
||||
return -1;
|
||||
@@ -142,8 +142,8 @@ int32_t HAL_WriteI2C(uint8_t port, uint8_t deviceAddress, uint8_t* dataToSend,
|
||||
* device.
|
||||
* @return The number of bytes read (>= 0) or -1 on transfer abort.
|
||||
*/
|
||||
int32_t HAL_ReadI2C(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
|
||||
uint8_t count) {
|
||||
int32_t HAL_ReadI2C(int32_t port, int32_t deviceAddress, uint8_t* buffer,
|
||||
int32_t count) {
|
||||
if (port > 1) {
|
||||
// Set port out of range error here
|
||||
return -1;
|
||||
@@ -159,7 +159,7 @@ int32_t HAL_ReadI2C(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_CloseI2C(uint8_t port) {
|
||||
void HAL_CloseI2C(int32_t port) {
|
||||
if (port > 1) {
|
||||
// Set port out of range error here
|
||||
return;
|
||||
|
||||
@@ -33,7 +33,8 @@ static LimitedHandleResource<HAL_InterruptHandle, Interrupt, kNumInterrupts,
|
||||
|
||||
extern "C" {
|
||||
|
||||
HAL_InterruptHandle HAL_InitializeInterrupts(bool watcher, int32_t* status) {
|
||||
HAL_InterruptHandle HAL_InitializeInterrupts(HAL_Bool watcher,
|
||||
int32_t* status) {
|
||||
HAL_InterruptHandle handle = interruptHandles.Allocate();
|
||||
if (handle == HAL_kInvalidHandle) {
|
||||
*status = NO_AVAILABLE_RESOURCES;
|
||||
@@ -45,7 +46,7 @@ HAL_InterruptHandle HAL_InitializeInterrupts(bool watcher, int32_t* status) {
|
||||
anInterrupt->anInterrupt = tInterrupt::create(interruptIndex, status);
|
||||
anInterrupt->anInterrupt->writeConfig_WaitForAck(false, status);
|
||||
anInterrupt->manager = new tInterruptManager(
|
||||
(1 << interruptIndex) | (1 << (interruptIndex + 8)), watcher, status);
|
||||
(1u << interruptIndex) | (1u << (interruptIndex + 8u)), watcher, status);
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -68,9 +69,9 @@ void HAL_CleanInterrupts(HAL_InterruptHandle interrupt_handle,
|
||||
* waitForInterrupt was called.
|
||||
* @return The mask of interrupts that fired.
|
||||
*/
|
||||
uint32_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
|
||||
double timeout, bool ignorePrevious,
|
||||
int32_t* status) {
|
||||
int64_t HAL_WaitForInterrupt(HAL_InterruptHandle interrupt_handle,
|
||||
double timeout, HAL_Bool ignorePrevious,
|
||||
int32_t* status) {
|
||||
uint32_t result;
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
@@ -162,7 +163,7 @@ void HAL_RequestInterrupts(HAL_InterruptHandle interrupt_handle,
|
||||
}
|
||||
anInterrupt->anInterrupt->writeConfig_WaitForAck(false, status);
|
||||
bool routingAnalogTrigger = false;
|
||||
uint32_t routingPin = 0;
|
||||
uint8_t routingPin = 0;
|
||||
uint8_t routingModule = 0;
|
||||
bool success =
|
||||
remapDigitalSource(digitalSourceHandle, analogTriggerType, routingPin,
|
||||
@@ -189,7 +190,7 @@ void HAL_AttachInterruptHandler(HAL_InterruptHandle interrupt_handle,
|
||||
}
|
||||
|
||||
void HAL_SetInterruptUpSourceEdge(HAL_InterruptHandle interrupt_handle,
|
||||
bool risingEdge, bool fallingEdge,
|
||||
HAL_Bool risingEdge, HAL_Bool fallingEdge,
|
||||
int32_t* status) {
|
||||
auto anInterrupt = interruptHandles.Get(interrupt_handle);
|
||||
if (anInterrupt == nullptr) {
|
||||
|
||||
@@ -7,12 +7,18 @@
|
||||
|
||||
#include "PCMInternal.h"
|
||||
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/Solenoid.h"
|
||||
#include "PortsInternal.h"
|
||||
|
||||
namespace hal {
|
||||
PCM* PCM_modules[kNumPCMModules] = {nullptr};
|
||||
|
||||
void initializePCM(int module) {
|
||||
void initializePCM(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckSolenoidModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
if (!PCM_modules[module]) {
|
||||
PCM_modules[module] = new PCM(module);
|
||||
}
|
||||
|
||||
@@ -16,5 +16,5 @@
|
||||
namespace hal {
|
||||
extern PCM* PCM_modules[kNumPCMModules];
|
||||
|
||||
void initializePCM(int module);
|
||||
void initializePCM(int32_t module, int32_t* status);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include "HAL/PDP.h"
|
||||
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/Ports.h"
|
||||
#include "PortsInternal.h"
|
||||
#include "ctre/PDP.h"
|
||||
@@ -17,13 +18,26 @@ static PDP* pdp[kNumPDPModules] = {nullptr};
|
||||
|
||||
extern "C" {
|
||||
|
||||
void HAL_InitializePDP(uint8_t module) {
|
||||
void HAL_InitializePDP(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
if (!pdp[module]) {
|
||||
pdp[module] = new PDP(module);
|
||||
}
|
||||
}
|
||||
|
||||
double HAL_GetPDPTemperature(uint8_t module, int32_t* status) {
|
||||
HAL_Bool HAL_CheckPDPModule(int32_t module) {
|
||||
return (module < kNumPDPModules) && (module >= 0);
|
||||
}
|
||||
|
||||
double HAL_GetPDPTemperature(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double temperature;
|
||||
|
||||
*status = pdp[module]->GetTemperature(temperature);
|
||||
@@ -31,7 +45,12 @@ double HAL_GetPDPTemperature(uint8_t module, int32_t* status) {
|
||||
return temperature;
|
||||
}
|
||||
|
||||
double HAL_GetPDPVoltage(uint8_t module, int32_t* status) {
|
||||
double HAL_GetPDPVoltage(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double voltage;
|
||||
|
||||
*status = pdp[module]->GetVoltage(voltage);
|
||||
@@ -39,8 +58,13 @@ double HAL_GetPDPVoltage(uint8_t module, int32_t* status) {
|
||||
return voltage;
|
||||
}
|
||||
|
||||
double HAL_GetPDPChannelCurrent(uint8_t module, uint8_t channel,
|
||||
double HAL_GetPDPChannelCurrent(int32_t module, int32_t channel,
|
||||
int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double current;
|
||||
|
||||
*status = pdp[module]->GetChannelCurrent(channel, current);
|
||||
@@ -48,7 +72,12 @@ double HAL_GetPDPChannelCurrent(uint8_t module, uint8_t channel,
|
||||
return current;
|
||||
}
|
||||
|
||||
double HAL_GetPDPTotalCurrent(uint8_t module, int32_t* status) {
|
||||
double HAL_GetPDPTotalCurrent(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double current;
|
||||
|
||||
*status = pdp[module]->GetTotalCurrent(current);
|
||||
@@ -56,7 +85,12 @@ double HAL_GetPDPTotalCurrent(uint8_t module, int32_t* status) {
|
||||
return current;
|
||||
}
|
||||
|
||||
double HAL_GetPDPTotalPower(uint8_t module, int32_t* status) {
|
||||
double HAL_GetPDPTotalPower(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double power;
|
||||
|
||||
*status = pdp[module]->GetTotalPower(power);
|
||||
@@ -64,7 +98,12 @@ double HAL_GetPDPTotalPower(uint8_t module, int32_t* status) {
|
||||
return power;
|
||||
}
|
||||
|
||||
double HAL_GetPDPTotalEnergy(uint8_t module, int32_t* status) {
|
||||
double HAL_GetPDPTotalEnergy(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
double energy;
|
||||
|
||||
*status = pdp[module]->GetTotalEnergy(energy);
|
||||
@@ -72,11 +111,21 @@ double HAL_GetPDPTotalEnergy(uint8_t module, int32_t* status) {
|
||||
return energy;
|
||||
}
|
||||
|
||||
void HAL_ResetPDPTotalEnergy(uint8_t module, int32_t* status) {
|
||||
void HAL_ResetPDPTotalEnergy(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
|
||||
*status = pdp[module]->ResetEnergy();
|
||||
}
|
||||
|
||||
void HAL_ClearPDPStickyFaults(uint8_t module, int32_t* status) {
|
||||
void HAL_ClearPDPStickyFaults(int32_t module, int32_t* status) {
|
||||
if (!HAL_CheckPDPModule(module)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
}
|
||||
|
||||
*status = pdp[module]->ClearStickyFaults();
|
||||
}
|
||||
|
||||
|
||||
@@ -74,8 +74,8 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
|
||||
|
||||
port->pin = origPin;
|
||||
|
||||
uint32_t bitToSet = 1 << remapMXPPWMChannel(port->pin);
|
||||
int16_t specialFunctions =
|
||||
int32_t bitToSet = 1 << remapMXPPWMChannel(port->pin);
|
||||
unsigned short specialFunctions =
|
||||
digitalSystem->readEnableMXPSpecialFunction(status);
|
||||
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions | bitToSet,
|
||||
status);
|
||||
@@ -90,8 +90,8 @@ void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
}
|
||||
|
||||
if (port->pin > tPWM::kNumHdrRegisters - 1) {
|
||||
uint32_t bitToUnset = 1 << remapMXPPWMChannel(port->pin);
|
||||
int16_t specialFunctions =
|
||||
int32_t bitToUnset = 1 << remapMXPPWMChannel(port->pin);
|
||||
unsigned short specialFunctions =
|
||||
digitalSystem->readEnableMXPSpecialFunction(status);
|
||||
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToUnset,
|
||||
status);
|
||||
@@ -100,7 +100,9 @@ void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
digitalPinHandles.Free(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
}
|
||||
|
||||
bool HAL_CheckPWMChannel(uint8_t pin) { return pin < kNumPWMPins; }
|
||||
HAL_Bool HAL_CheckPWMChannel(int32_t pin) {
|
||||
return (pin < kNumPWMPins) && (pin >= 0);
|
||||
}
|
||||
|
||||
void HAL_SetPWMConfig(HAL_DigitalHandle pwm_port_handle, double max,
|
||||
double deadbandMax, double center, double deadbandMin,
|
||||
@@ -169,7 +171,7 @@ void HAL_GetPWMConfigRaw(HAL_DigitalHandle pwm_port_handle, int32_t* maxPwm,
|
||||
}
|
||||
|
||||
void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
uint8_t eliminateDeadband, int32_t* status) {
|
||||
HAL_Bool eliminateDeadband, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -178,8 +180,8 @@ void HAL_SetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
port->eliminateDeadband = eliminateDeadband;
|
||||
}
|
||||
|
||||
uint8_t HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
int32_t* status) {
|
||||
HAL_Bool HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -196,7 +198,7 @@ uint8_t HAL_GetPWMEliminateDeadband(HAL_DigitalHandle pwm_port_handle,
|
||||
* @param channel The PWM channel to set.
|
||||
* @param value The PWM value to set.
|
||||
*/
|
||||
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, uint16_t value,
|
||||
void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t value,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
@@ -220,7 +222,7 @@ void HAL_SetPWMRaw(HAL_DigitalHandle pwm_port_handle, uint16_t value,
|
||||
* @param channel The PWM channel to set.
|
||||
* @param value The scaled PWM value to set.
|
||||
*/
|
||||
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, float speed,
|
||||
void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, double speed,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
@@ -246,12 +248,12 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, float speed,
|
||||
rawValue = GetCenterPwm(dPort);
|
||||
} else if (speed > 0.0) {
|
||||
rawValue = static_cast<int32_t>(
|
||||
speed * static_cast<float>(GetPositiveScaleFactor(dPort)) +
|
||||
static_cast<float>(GetMinPositivePwm(dPort)) + 0.5);
|
||||
speed * static_cast<double>(GetPositiveScaleFactor(dPort)) +
|
||||
static_cast<double>(GetMinPositivePwm(dPort)) + 0.5);
|
||||
} else {
|
||||
rawValue = static_cast<int32_t>(
|
||||
speed * static_cast<float>(GetNegativeScaleFactor(dPort)) +
|
||||
static_cast<float>(GetMaxNegativePwm(dPort)) + 0.5);
|
||||
speed * static_cast<double>(GetNegativeScaleFactor(dPort)) +
|
||||
static_cast<double>(GetMaxNegativePwm(dPort)) + 0.5);
|
||||
}
|
||||
|
||||
if (!((rawValue >= GetMinNegativePwm(dPort)) &&
|
||||
@@ -273,7 +275,7 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, float speed,
|
||||
* @param channel The PWM channel to set.
|
||||
* @param value The scaled PWM value to set.
|
||||
*/
|
||||
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, float pos,
|
||||
void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, double pos,
|
||||
int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
@@ -294,8 +296,8 @@ void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, float pos,
|
||||
|
||||
// note, need to perform the multiplication below as floating point before
|
||||
// converting to int
|
||||
uint16_t rawValue = static_cast<int32_t>(
|
||||
(pos * static_cast<float>(GetFullRangeScaleFactor(dPort))) +
|
||||
int32_t rawValue = static_cast<int32_t>(
|
||||
(pos * static_cast<double>(GetFullRangeScaleFactor(dPort))) +
|
||||
GetMinNegativePwm(dPort));
|
||||
|
||||
if (rawValue == kPwmDisabled) {
|
||||
@@ -316,7 +318,7 @@ void HAL_SetPWMDisabled(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
* @param channel The PWM channel to read from.
|
||||
* @return The raw PWM value.
|
||||
*/
|
||||
uint16_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
int32_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -336,7 +338,7 @@ uint16_t HAL_GetPWMRaw(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
* @param channel The PWM channel to read from.
|
||||
* @return The scaled PWM value.
|
||||
*/
|
||||
float HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
double HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -358,11 +360,11 @@ float HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
} else if (value < GetMinNegativePwm(dPort)) {
|
||||
return -1.0;
|
||||
} else if (value > GetMinPositivePwm(dPort)) {
|
||||
return static_cast<float>(value - GetMinPositivePwm(dPort)) /
|
||||
static_cast<float>(GetPositiveScaleFactor(dPort));
|
||||
return static_cast<double>(value - GetMinPositivePwm(dPort)) /
|
||||
static_cast<double>(GetPositiveScaleFactor(dPort));
|
||||
} else if (value < GetMaxNegativePwm(dPort)) {
|
||||
return static_cast<float>(value - GetMaxNegativePwm(dPort)) /
|
||||
static_cast<float>(GetNegativeScaleFactor(dPort));
|
||||
return static_cast<double>(value - GetMaxNegativePwm(dPort)) /
|
||||
static_cast<double>(GetNegativeScaleFactor(dPort));
|
||||
} else {
|
||||
return 0.0;
|
||||
}
|
||||
@@ -374,7 +376,7 @@ float HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
* @param channel The PWM channel to read from.
|
||||
* @return The scaled PWM value.
|
||||
*/
|
||||
float HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
double HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -394,8 +396,8 @@ float HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
} else if (value > GetMaxPositivePwm(dPort)) {
|
||||
return 1.0;
|
||||
} else {
|
||||
return static_cast<float>(value - GetMinNegativePwm(dPort)) /
|
||||
static_cast<float>(GetFullRangeScaleFactor(dPort));
|
||||
return static_cast<double>(value - GetMinNegativePwm(dPort)) /
|
||||
static_cast<double>(GetFullRangeScaleFactor(dPort));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +419,7 @@ void HAL_LatchPWMZero(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
|
||||
* @param squelchMask The 2-bit mask of outputs to squelch.
|
||||
*/
|
||||
void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwm_port_handle,
|
||||
uint32_t squelchMask, int32_t* status) {
|
||||
int32_t squelchMask, int32_t* status) {
|
||||
auto port = digitalPinHandles.Get(pwm_port_handle, HAL_HandleEnum::PWM);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -437,7 +439,7 @@ void HAL_SetPWMPeriodScale(HAL_DigitalHandle pwm_port_handle,
|
||||
*
|
||||
* @return The loop time
|
||||
*/
|
||||
uint16_t HAL_GetLoopTiming(int32_t* status) {
|
||||
int32_t HAL_GetLoopTiming(int32_t* status) {
|
||||
return pwmSystem->readLoopTiming(status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,39 +22,39 @@ extern "C" {
|
||||
/**
|
||||
* Get the roboRIO input voltage
|
||||
*/
|
||||
float HAL_GetVinVoltage(int32_t* status) {
|
||||
double HAL_GetVinVoltage(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readVinVoltage(status) / 4.096f * 0.025733f - 0.029f;
|
||||
return power->readVinVoltage(status) / 4.096 * 0.025733 - 0.029;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the roboRIO input current
|
||||
*/
|
||||
float HAL_GetVinCurrent(int32_t* status) {
|
||||
double HAL_GetVinCurrent(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readVinCurrent(status) / 4.096f * 0.017042 - 0.071f;
|
||||
return power->readVinCurrent(status) / 4.096 * 0.017042 - 0.071;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 6V rail voltage
|
||||
*/
|
||||
float HAL_GetUserVoltage6V(int32_t* status) {
|
||||
double HAL_GetUserVoltage6V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage6V(status) / 4.096f * 0.007019f - 0.014f;
|
||||
return power->readUserVoltage6V(status) / 4.096 * 0.007019 - 0.014;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 6V rail current
|
||||
*/
|
||||
float HAL_GetUserCurrent6V(int32_t* status) {
|
||||
double HAL_GetUserCurrent6V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserCurrent6V(status) / 4.096f * 0.005566f - 0.009f;
|
||||
return power->readUserCurrent6V(status) / 4.096 * 0.005566 - 0.009;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active state of the 6V rail
|
||||
*/
|
||||
bool HAL_GetUserActive6V(int32_t* status) {
|
||||
HAL_Bool HAL_GetUserActive6V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readStatus_User6V(status) == 4;
|
||||
}
|
||||
@@ -62,32 +62,32 @@ bool HAL_GetUserActive6V(int32_t* status) {
|
||||
/**
|
||||
* Get the fault count for the 6V rail
|
||||
*/
|
||||
int HAL_GetUserCurrentFaults6V(int32_t* status) {
|
||||
int32_t HAL_GetUserCurrentFaults6V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return static_cast<int>(
|
||||
return static_cast<int32_t>(
|
||||
power->readFaultCounts_OverCurrentFaultCount6V(status));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 5V rail voltage
|
||||
*/
|
||||
float HAL_GetUserVoltage5V(int32_t* status) {
|
||||
double HAL_GetUserVoltage5V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage5V(status) / 4.096f * 0.005962f - 0.013f;
|
||||
return power->readUserVoltage5V(status) / 4.096 * 0.005962 - 0.013;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 5V rail current
|
||||
*/
|
||||
float HAL_GetUserCurrent5V(int32_t* status) {
|
||||
double HAL_GetUserCurrent5V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserCurrent5V(status) / 4.096f * 0.001996f - 0.002f;
|
||||
return power->readUserCurrent5V(status) / 4.096 * 0.001996 - 0.002;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active state of the 5V rail
|
||||
*/
|
||||
bool HAL_GetUserActive5V(int32_t* status) {
|
||||
HAL_Bool HAL_GetUserActive5V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readStatus_User5V(status) == 4;
|
||||
}
|
||||
@@ -95,13 +95,13 @@ bool HAL_GetUserActive5V(int32_t* status) {
|
||||
/**
|
||||
* Get the fault count for the 5V rail
|
||||
*/
|
||||
int HAL_GetUserCurrentFaults5V(int32_t* status) {
|
||||
int32_t HAL_GetUserCurrentFaults5V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return static_cast<int>(
|
||||
return static_cast<int32_t>(
|
||||
power->readFaultCounts_OverCurrentFaultCount5V(status));
|
||||
}
|
||||
|
||||
unsigned char HAL_GetUserStatus5V(int32_t* status) {
|
||||
uint8_t HAL_GetUserStatus5V(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readStatus_User5V(status);
|
||||
}
|
||||
@@ -109,23 +109,23 @@ unsigned char HAL_GetUserStatus5V(int32_t* status) {
|
||||
/**
|
||||
* Get the 3.3V rail voltage
|
||||
*/
|
||||
float HAL_GetUserVoltage3V3(int32_t* status) {
|
||||
double HAL_GetUserVoltage3V3(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserVoltage3V3(status) / 4.096f * 0.004902f - 0.01f;
|
||||
return power->readUserVoltage3V3(status) / 4.096 * 0.004902 - 0.01;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the 3.3V rail current
|
||||
*/
|
||||
float HAL_GetUserCurrent3V3(int32_t* status) {
|
||||
double HAL_GetUserCurrent3V3(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readUserCurrent3V3(status) / 4.096f * 0.002486f - 0.003f;
|
||||
return power->readUserCurrent3V3(status) / 4.096 * 0.002486 - 0.003;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active state of the 3.3V rail
|
||||
*/
|
||||
bool HAL_GetUserActive3V3(int32_t* status) {
|
||||
HAL_Bool HAL_GetUserActive3V3(int32_t* status) {
|
||||
initializePower(status);
|
||||
return power->readStatus_User3V3(status) == 4;
|
||||
}
|
||||
@@ -133,9 +133,9 @@ bool HAL_GetUserActive3V3(int32_t* status) {
|
||||
/**
|
||||
* Get the fault count for the 3.3V rail
|
||||
*/
|
||||
int HAL_GetUserCurrentFaults3V3(int32_t* status) {
|
||||
int32_t HAL_GetUserCurrentFaults3V3(int32_t* status) {
|
||||
initializePower(status);
|
||||
return static_cast<int>(
|
||||
return static_cast<int32_t>(
|
||||
power->readFaultCounts_OverCurrentFaultCount3V3(status));
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ static IndexedHandleResource<HAL_RelayHandle, Relay, kNumRelayPins,
|
||||
static priority_recursive_mutex digitalRelayMutex;
|
||||
|
||||
extern "C" {
|
||||
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle, uint8_t fwd,
|
||||
int32_t* status) {
|
||||
HAL_RelayHandle HAL_InitializeRelayPort(HAL_PortHandle port_handle,
|
||||
HAL_Bool fwd, int32_t* status) {
|
||||
initializeDigital(status);
|
||||
|
||||
if (*status != 0) return HAL_kInvalidHandle;
|
||||
@@ -69,18 +69,19 @@ void HAL_FreeRelayPort(HAL_RelayHandle relay_port_handle) {
|
||||
relayHandles.Free(relay_port_handle);
|
||||
}
|
||||
|
||||
bool HAL_CheckRelayChannel(uint8_t pin) {
|
||||
HAL_Bool HAL_CheckRelayChannel(int32_t pin) {
|
||||
// roboRIO only has 4 headers, and the FPGA has
|
||||
// seperate functions for forward and reverse,
|
||||
// instead of seperate pin IDs
|
||||
return pin < kNumRelayHeaders;
|
||||
return (pin < kNumRelayHeaders) && (pin >= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the state of a relay.
|
||||
* Set the state of a relay output.
|
||||
*/
|
||||
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, bool on, int32_t* status) {
|
||||
void HAL_SetRelay(HAL_RelayHandle relay_port_handle, HAL_Bool on,
|
||||
int32_t* status) {
|
||||
auto port = relayHandles.Get(relay_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -112,7 +113,7 @@ void HAL_SetRelay(HAL_RelayHandle relay_port_handle, bool on, int32_t* status) {
|
||||
/**
|
||||
* Get the current state of the relay channel
|
||||
*/
|
||||
bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status) {
|
||||
HAL_Bool HAL_GetRelay(HAL_RelayHandle relay_port_handle, int32_t* status) {
|
||||
auto port = relayHandles.Get(relay_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
|
||||
@@ -40,7 +40,7 @@ static HAL_DigitalHandle spiMXPDigitalHandle4 = HAL_kInvalidHandle;
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
* @return The semaphore for the SPI port.
|
||||
*/
|
||||
static priority_recursive_mutex& spiGetSemaphore(uint8_t port) {
|
||||
static priority_recursive_mutex& spiGetSemaphore(int32_t port) {
|
||||
if (port < 4)
|
||||
return spiOnboardSemaphore;
|
||||
else
|
||||
@@ -52,7 +52,7 @@ extern "C" {
|
||||
struct SPIAccumulator {
|
||||
std::atomic<HAL_NotifierHandle> notifier{0};
|
||||
uint64_t triggerTime;
|
||||
uint32_t period;
|
||||
int32_t period;
|
||||
|
||||
int64_t value = 0;
|
||||
uint32_t count = 0;
|
||||
@@ -62,8 +62,8 @@ struct SPIAccumulator {
|
||||
int32_t deadband = 0;
|
||||
|
||||
uint8_t cmd[4]; // command to send (up to 4 bytes)
|
||||
uint32_t valid_mask;
|
||||
uint32_t valid_value;
|
||||
int32_t valid_mask;
|
||||
int32_t valid_value;
|
||||
int32_t data_max; // one more than max data value
|
||||
int32_t data_msb_mask; // data field MSB mask (for signed)
|
||||
uint8_t data_shift; // data field shift right amount, in bits
|
||||
@@ -80,7 +80,7 @@ SPIAccumulator* spiAccumulators[5] = {nullptr, nullptr, nullptr, nullptr,
|
||||
* If opening the MXP port, also sets up the pin functions appropriately
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
*/
|
||||
void HAL_InitializeSPI(uint8_t port, int32_t* status) {
|
||||
void HAL_InitializeSPI(int32_t port, int32_t* status) {
|
||||
if (spiSystem == nullptr) spiSystem = tSPI::create(status);
|
||||
if (HAL_GetSPIHandle(port) != 0) return;
|
||||
switch (port) {
|
||||
@@ -132,6 +132,7 @@ void HAL_InitializeSPI(uint8_t port, int32_t* status) {
|
||||
HAL_SetSPIHandle(4, spilib_open("/dev/spidev1.0"));
|
||||
break;
|
||||
default:
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
@@ -149,8 +150,8 @@ void HAL_InitializeSPI(uint8_t port, int32_t* status) {
|
||||
* @param size Number of bytes to transfer. [0..7]
|
||||
* @return Number of bytes transferred, -1 for error
|
||||
*/
|
||||
int32_t HAL_TransactionSPI(uint8_t port, uint8_t* dataToSend,
|
||||
uint8_t* dataReceived, uint8_t size) {
|
||||
int32_t HAL_TransactionSPI(int32_t port, uint8_t* dataToSend,
|
||||
uint8_t* dataReceived, int32_t size) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
return spilib_writeread(
|
||||
HAL_GetSPIHandle(port), reinterpret_cast<const char*>(dataToSend),
|
||||
@@ -167,7 +168,7 @@ int32_t HAL_TransactionSPI(uint8_t port, uint8_t* dataToSend,
|
||||
* @param sendSize The number of bytes to be written
|
||||
* @return The number of bytes written. -1 for an error
|
||||
*/
|
||||
int32_t HAL_WriteSPI(uint8_t port, uint8_t* dataToSend, uint8_t sendSize) {
|
||||
int32_t HAL_WriteSPI(int32_t port, uint8_t* dataToSend, int32_t sendSize) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
return spilib_write(HAL_GetSPIHandle(port),
|
||||
reinterpret_cast<const char*>(dataToSend),
|
||||
@@ -187,7 +188,7 @@ int32_t HAL_WriteSPI(uint8_t port, uint8_t* dataToSend, uint8_t sendSize) {
|
||||
* @param count The number of bytes to read in the transaction. [1..7]
|
||||
* @return Number of bytes read. -1 for error.
|
||||
*/
|
||||
int32_t HAL_ReadSPI(uint8_t port, uint8_t* buffer, uint8_t count) {
|
||||
int32_t HAL_ReadSPI(int32_t port, uint8_t* buffer, int32_t count) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
return spilib_read(HAL_GetSPIHandle(port), reinterpret_cast<char*>(buffer),
|
||||
static_cast<int32_t>(count));
|
||||
@@ -198,7 +199,7 @@ int32_t HAL_ReadSPI(uint8_t port, uint8_t* buffer, uint8_t count) {
|
||||
*
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
*/
|
||||
void HAL_CloseSPI(uint8_t port) {
|
||||
void HAL_CloseSPI(int32_t port) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
if (spiAccumulators[port]) {
|
||||
int32_t status = 0;
|
||||
@@ -221,7 +222,7 @@ void HAL_CloseSPI(uint8_t port) {
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
* @param speed The speed in Hz (0-1MHz)
|
||||
*/
|
||||
void HAL_SetSPISpeed(uint8_t port, uint32_t speed) {
|
||||
void HAL_SetSPISpeed(int32_t port, int32_t speed) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
spilib_setspeed(HAL_GetSPIHandle(port), speed);
|
||||
}
|
||||
@@ -236,11 +237,11 @@ void HAL_SetSPISpeed(uint8_t port, uint32_t speed) {
|
||||
* @param clk_idle_high True to set the clock to active low, False to set the
|
||||
* clock active high
|
||||
*/
|
||||
void HAL_SetSPIOpts(uint8_t port, int msb_first, int sample_on_trailing,
|
||||
int clk_idle_high) {
|
||||
void HAL_SetSPIOpts(int32_t port, HAL_Bool msb_first,
|
||||
HAL_Bool sample_on_trailing, HAL_Bool clk_idle_high) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
spilib_setopts(HAL_GetSPIHandle(port), msb_first, sample_on_trailing,
|
||||
clk_idle_high);
|
||||
spilib_setopts(HAL_GetSPIHandle(port), (int)msb_first,
|
||||
(int)sample_on_trailing, (int)clk_idle_high);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -248,7 +249,7 @@ void HAL_SetSPIOpts(uint8_t port, int msb_first, int sample_on_trailing,
|
||||
*
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
*/
|
||||
void HAL_SetSPIChipSelectActiveHigh(uint8_t port, int32_t* status) {
|
||||
void HAL_SetSPIChipSelectActiveHigh(int32_t port, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
if (port < 4) {
|
||||
spiSystem->writeChipSelectActiveHigh_Hdr(
|
||||
@@ -263,7 +264,7 @@ void HAL_SetSPIChipSelectActiveHigh(uint8_t port, int32_t* status) {
|
||||
*
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
*/
|
||||
void HAL_SetSPIChipSelectActiveLow(uint8_t port, int32_t* status) {
|
||||
void HAL_SetSPIChipSelectActiveLow(int32_t port, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
if (port < 4) {
|
||||
spiSystem->writeChipSelectActiveHigh_Hdr(
|
||||
@@ -279,7 +280,7 @@ void HAL_SetSPIChipSelectActiveLow(uint8_t port, int32_t* status) {
|
||||
* @param port The number of the port to use. 0-3 for Onboard CS0-CS2, 4 for MXP
|
||||
* @return The stored handle for the SPI port. 0 represents no stored handle.
|
||||
*/
|
||||
int32_t HAL_GetSPIHandle(uint8_t port) {
|
||||
int32_t HAL_GetSPIHandle(int32_t port) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
switch (port) {
|
||||
case 0:
|
||||
@@ -304,7 +305,7 @@ int32_t HAL_GetSPIHandle(uint8_t port) {
|
||||
* MXP.
|
||||
* @param handle The value of the handle for the port.
|
||||
*/
|
||||
void HAL_SetSPIHandle(uint8_t port, int32_t handle) {
|
||||
void HAL_SetSPIHandle(int32_t port, int32_t handle) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
switch (port) {
|
||||
case 0:
|
||||
@@ -352,7 +353,7 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
|
||||
}
|
||||
|
||||
// process response
|
||||
if ((resp & accum->valid_mask) == accum->valid_value) {
|
||||
if ((resp & accum->valid_mask) == static_cast<uint32_t>(accum->valid_value)) {
|
||||
// valid sensor data; extract data field
|
||||
int32_t data = static_cast<int32_t>(resp >> accum->data_shift);
|
||||
data &= accum->data_max - 1;
|
||||
@@ -395,11 +396,11 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
|
||||
* @param is_signed Is data field signed?
|
||||
* @param big_endian Is device big endian?
|
||||
*/
|
||||
void HAL_InitSPIAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
|
||||
uint8_t xfer_size, uint32_t valid_mask,
|
||||
uint32_t valid_value, uint8_t data_shift,
|
||||
uint8_t data_size, bool is_signed, bool big_endian,
|
||||
int32_t* status) {
|
||||
void HAL_InitSPIAccumulator(int32_t port, int32_t period, int32_t cmd,
|
||||
int32_t xfer_size, int32_t valid_mask,
|
||||
int32_t valid_value, int32_t data_shift,
|
||||
int32_t data_size, HAL_Bool is_signed,
|
||||
HAL_Bool big_endian, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
if (port > 4) return;
|
||||
if (!spiAccumulators[port]) spiAccumulators[port] = new SPIAccumulator();
|
||||
@@ -439,7 +440,7 @@ void HAL_InitSPIAccumulator(uint8_t port, uint32_t period, uint32_t cmd,
|
||||
/**
|
||||
* Frees a SPI accumulator.
|
||||
*/
|
||||
void HAL_FreeSPIAccumulator(uint8_t port, int32_t* status) {
|
||||
void HAL_FreeSPIAccumulator(int32_t port, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
if (!accum) {
|
||||
@@ -455,7 +456,7 @@ void HAL_FreeSPIAccumulator(uint8_t port, int32_t* status) {
|
||||
/**
|
||||
* Resets the accumulator to zero.
|
||||
*/
|
||||
void HAL_ResetSPIAccumulator(uint8_t port, int32_t* status) {
|
||||
void HAL_ResetSPIAccumulator(int32_t port, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
if (!accum) {
|
||||
@@ -476,7 +477,7 @@ void HAL_ResetSPIAccumulator(uint8_t port, int32_t* status) {
|
||||
* integration work
|
||||
* and to take the device offset into account when integrating.
|
||||
*/
|
||||
void HAL_SetSPIAccumulatorCenter(uint8_t port, int32_t center,
|
||||
void HAL_SetSPIAccumulatorCenter(int32_t port, int32_t center,
|
||||
int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
@@ -490,7 +491,7 @@ void HAL_SetSPIAccumulatorCenter(uint8_t port, int32_t center,
|
||||
/**
|
||||
* Set the accumulator's deadband.
|
||||
*/
|
||||
void HAL_SetSPIAccumulatorDeadband(uint8_t port, int32_t deadband,
|
||||
void HAL_SetSPIAccumulatorDeadband(int32_t port, int32_t deadband,
|
||||
int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
@@ -504,7 +505,7 @@ void HAL_SetSPIAccumulatorDeadband(uint8_t port, int32_t deadband,
|
||||
/**
|
||||
* Read the last value read by the accumulator engine.
|
||||
*/
|
||||
int32_t HAL_GetSPIAccumulatorLastValue(uint8_t port, int32_t* status) {
|
||||
int32_t HAL_GetSPIAccumulatorLastValue(int32_t port, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
if (!accum) {
|
||||
@@ -519,7 +520,7 @@ int32_t HAL_GetSPIAccumulatorLastValue(uint8_t port, int32_t* status) {
|
||||
*
|
||||
* @return The 64-bit value accumulated since the last Reset().
|
||||
*/
|
||||
int64_t HAL_GetSPIAccumulatorValue(uint8_t port, int32_t* status) {
|
||||
int64_t HAL_GetSPIAccumulatorValue(int32_t port, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
if (!accum) {
|
||||
@@ -537,7 +538,7 @@ int64_t HAL_GetSPIAccumulatorValue(uint8_t port, int32_t* status) {
|
||||
*
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
uint32_t HAL_GetSPIAccumulatorCount(uint8_t port, int32_t* status) {
|
||||
int64_t HAL_GetSPIAccumulatorCount(int32_t port, int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
if (!accum) {
|
||||
@@ -552,9 +553,9 @@ uint32_t HAL_GetSPIAccumulatorCount(uint8_t port, int32_t* status) {
|
||||
*
|
||||
* @return The accumulated average value (value / count).
|
||||
*/
|
||||
double HAL_GetSPIAccumulatorAverage(uint8_t port, int32_t* status) {
|
||||
double HAL_GetSPIAccumulatorAverage(int32_t port, int32_t* status) {
|
||||
int64_t value;
|
||||
uint32_t count;
|
||||
int64_t count;
|
||||
HAL_GetAccumulatorOutput(port, &value, &count, status);
|
||||
if (count == 0) return 0.0;
|
||||
return static_cast<double>(value) / count;
|
||||
@@ -569,7 +570,7 @@ double HAL_GetSPIAccumulatorAverage(uint8_t port, int32_t* status) {
|
||||
* @param value Pointer to the 64-bit accumulated output.
|
||||
* @param count Pointer to the number of accumulation cycles.
|
||||
*/
|
||||
void HAL_GetSPIAccumulatorOutput(uint8_t port, int64_t* value, uint32_t* count,
|
||||
void HAL_GetSPIAccumulatorOutput(int32_t port, int64_t* value, int64_t* count,
|
||||
int32_t* status) {
|
||||
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
|
||||
SPIAccumulator* accum = spiAccumulators[port];
|
||||
|
||||
@@ -14,7 +14,7 @@ static uint32_t m_portHandle[2];
|
||||
|
||||
extern "C" {
|
||||
|
||||
void HAL_InitializeSerialPort(uint8_t port, int32_t* status) {
|
||||
void HAL_InitializeSerialPort(int32_t port, int32_t* status) {
|
||||
char const* portName;
|
||||
|
||||
if (m_resourceManagerHandle == 0)
|
||||
@@ -33,44 +33,44 @@ void HAL_InitializeSerialPort(uint8_t port, int32_t* status) {
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialBaudRate(uint8_t port, uint32_t baud, int32_t* status) {
|
||||
void HAL_SetSerialBaudRate(int32_t port, int32_t baud, int32_t* status) {
|
||||
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_BAUD, baud);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialDataBits(uint8_t port, uint8_t bits, int32_t* status) {
|
||||
void HAL_SetSerialDataBits(int32_t port, int32_t bits, int32_t* status) {
|
||||
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_DATA_BITS, bits);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialParity(uint8_t port, uint8_t parity, int32_t* status) {
|
||||
void HAL_SetSerialParity(int32_t port, int32_t parity, int32_t* status) {
|
||||
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_PARITY, parity);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialStopBits(uint8_t port, uint8_t stopBits, int32_t* status) {
|
||||
void HAL_SetSerialStopBits(int32_t port, int32_t stopBits, int32_t* status) {
|
||||
*status =
|
||||
viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_STOP_BITS, stopBits);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialWriteMode(uint8_t port, uint8_t mode, int32_t* status) {
|
||||
void HAL_SetSerialWriteMode(int32_t port, int32_t mode, int32_t* status) {
|
||||
*status = viSetAttribute(m_portHandle[port], VI_ATTR_WR_BUF_OPER_MODE, mode);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialFlowControl(uint8_t port, uint8_t flow, int32_t* status) {
|
||||
void HAL_SetSerialFlowControl(int32_t port, int32_t flow, int32_t* status) {
|
||||
*status = viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_FLOW_CNTRL, flow);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialTimeout(uint8_t port, float timeout, int32_t* status) {
|
||||
void HAL_SetSerialTimeout(int32_t port, double timeout, int32_t* status) {
|
||||
*status = viSetAttribute(m_portHandle[port], VI_ATTR_TMO_VALUE,
|
||||
(uint32_t)(timeout * 1e3));
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_EnableSerialTermination(uint8_t port, char terminator,
|
||||
void HAL_EnableSerialTermination(int32_t port, char terminator,
|
||||
int32_t* status) {
|
||||
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR_EN, VI_TRUE);
|
||||
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR, terminator);
|
||||
@@ -79,25 +79,24 @@ void HAL_EnableSerialTermination(uint8_t port, char terminator,
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_DisableSerialTermination(uint8_t port, int32_t* status) {
|
||||
void HAL_DisableSerialTermination(int32_t port, int32_t* status) {
|
||||
viSetAttribute(m_portHandle[port], VI_ATTR_TERMCHAR_EN, VI_FALSE);
|
||||
*status =
|
||||
viSetAttribute(m_portHandle[port], VI_ATTR_ASRL_END_IN, VI_ASRL_END_NONE);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialReadBufferSize(uint8_t port, uint32_t size, int32_t* status) {
|
||||
void HAL_SetSerialReadBufferSize(int32_t port, int32_t size, int32_t* status) {
|
||||
*status = viSetBuf(m_portHandle[port], VI_READ_BUF, size);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_SetSerialWriteBufferSize(uint8_t port, uint32_t size,
|
||||
int32_t* status) {
|
||||
void HAL_SetSerialWriteBufferSize(int32_t port, int32_t size, int32_t* status) {
|
||||
*status = viSetBuf(m_portHandle[port], VI_WRITE_BUF, size);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
int32_t HAL_GetSerialBytesReceived(uint8_t port, int32_t* status) {
|
||||
int32_t HAL_GetSerialBytesReceived(int32_t port, int32_t* status) {
|
||||
int32_t bytes = 0;
|
||||
|
||||
*status = viGetAttribute(m_portHandle[port], VI_ATTR_ASRL_AVAIL_NUM, &bytes);
|
||||
@@ -105,8 +104,8 @@ int32_t HAL_GetSerialBytesReceived(uint8_t port, int32_t* status) {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
uint32_t HAL_ReadSerial(uint8_t port, char* buffer, int32_t count,
|
||||
int32_t* status) {
|
||||
int32_t HAL_ReadSerial(int32_t port, char* buffer, int32_t count,
|
||||
int32_t* status) {
|
||||
uint32_t retCount = 0;
|
||||
|
||||
*status =
|
||||
@@ -119,31 +118,31 @@ uint32_t HAL_ReadSerial(uint8_t port, char* buffer, int32_t count,
|
||||
}
|
||||
|
||||
if (*status == VI_ERROR_TMO || *status > 0) *status = 0;
|
||||
return retCount;
|
||||
return static_cast<int32_t>(retCount);
|
||||
}
|
||||
|
||||
uint32_t HAL_WriteSerial(uint8_t port, const char* buffer, int32_t count,
|
||||
int32_t* status) {
|
||||
int32_t HAL_WriteSerial(int32_t port, const char* buffer, int32_t count,
|
||||
int32_t* status) {
|
||||
uint32_t retCount = 0;
|
||||
|
||||
*status =
|
||||
viWrite(m_portHandle[port], (ViPBuf)buffer, count, (ViPUInt32)&retCount);
|
||||
|
||||
if (*status > 0) *status = 0;
|
||||
return retCount;
|
||||
return static_cast<int32_t>(retCount);
|
||||
}
|
||||
|
||||
void HAL_FlushSerial(uint8_t port, int32_t* status) {
|
||||
void HAL_FlushSerial(int32_t port, int32_t* status) {
|
||||
*status = viFlush(m_portHandle[port], VI_WRITE_BUF);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_ClearSerial(uint8_t port, int32_t* status) {
|
||||
void HAL_ClearSerial(int32_t port, int32_t* status) {
|
||||
*status = viClear(m_portHandle[port]);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
void HAL_CloseSerial(uint8_t port, int32_t* status) {
|
||||
void HAL_CloseSerial(int32_t port, int32_t* status) {
|
||||
*status = viClose(m_portHandle[port]);
|
||||
if (*status > 0) *status = 0;
|
||||
}
|
||||
|
||||
@@ -38,16 +38,20 @@ HAL_SolenoidHandle HAL_InitializeSolenoidPort(HAL_PortHandle port_handle,
|
||||
int16_t pin = getPortHandlePin(port_handle);
|
||||
int16_t module = getPortHandleModule(port_handle);
|
||||
if (pin == InvalidHandleIndex) {
|
||||
*status = PARAMETER_OUT_OF_RANGE; // Change to Handle Error
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
if (module >= kNumPCMModules || pin >= kNumSolenoidPins) {
|
||||
// initializePCM will check the module
|
||||
if (!HAL_CheckSolenoidPin(pin)) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
initializePCM(module);
|
||||
initializePCM(module, status);
|
||||
if (*status != 0) {
|
||||
return HAL_kInvalidHandle;
|
||||
}
|
||||
|
||||
auto handle =
|
||||
solenoidHandles.Allocate(module * kNumSolenoidPins + pin, status);
|
||||
@@ -70,9 +74,16 @@ void HAL_FreeSolenoidPort(HAL_SolenoidHandle solenoid_port_handle) {
|
||||
solenoidHandles.Free(solenoid_port_handle);
|
||||
}
|
||||
|
||||
bool HAL_CheckSolenoidModule(uint8_t module) { return module < kNumPCMModules; }
|
||||
HAL_Bool HAL_CheckSolenoidModule(int32_t module) {
|
||||
return (module < kNumPCMModules) && (module >= 0);
|
||||
}
|
||||
|
||||
bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle, int32_t* status) {
|
||||
HAL_Bool HAL_CheckSolenoidPin(int32_t pin) {
|
||||
return (pin < kNumSolenoidPins) && (pin >= 0);
|
||||
}
|
||||
|
||||
HAL_Bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle,
|
||||
int32_t* status) {
|
||||
auto port = solenoidHandles.Get(solenoid_port_handle);
|
||||
if (port == nullptr) {
|
||||
*status = HAL_HANDLE_ERROR;
|
||||
@@ -85,7 +96,7 @@ bool HAL_GetSolenoid(HAL_SolenoidHandle solenoid_port_handle, int32_t* status) {
|
||||
return value;
|
||||
}
|
||||
|
||||
uint8_t HAL_GetAllSolenoids(uint8_t module, int32_t* status) {
|
||||
int32_t HAL_GetAllSolenoids(int32_t module, int32_t* status) {
|
||||
if (module >= kNumPCMModules) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0;
|
||||
@@ -97,7 +108,7 @@ uint8_t HAL_GetAllSolenoids(uint8_t module, int32_t* status) {
|
||||
return value;
|
||||
}
|
||||
|
||||
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, bool value,
|
||||
void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, HAL_Bool value,
|
||||
int32_t* status) {
|
||||
auto port = solenoidHandles.Get(solenoid_port_handle);
|
||||
if (port == nullptr) {
|
||||
@@ -108,7 +119,7 @@ void HAL_SetSolenoid(HAL_SolenoidHandle solenoid_port_handle, bool value,
|
||||
*status = PCM_modules[port->module]->SetSolenoid(port->pin, value);
|
||||
}
|
||||
|
||||
int HAL_GetPCMSolenoidBlackList(uint8_t module, int32_t* status) {
|
||||
int32_t HAL_GetPCMSolenoidBlackList(int32_t module, int32_t* status) {
|
||||
if (module >= kNumPCMModules) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return 0;
|
||||
@@ -119,7 +130,7 @@ int HAL_GetPCMSolenoidBlackList(uint8_t module, int32_t* status) {
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status) {
|
||||
HAL_Bool HAL_GetPCMSolenoidVoltageStickyFault(int32_t module, int32_t* status) {
|
||||
if (module >= kNumPCMModules) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return false;
|
||||
@@ -130,7 +141,7 @@ bool HAL_GetPCMSolenoidVoltageStickyFault(uint8_t module, int32_t* status) {
|
||||
|
||||
return value;
|
||||
}
|
||||
bool HAL_GetPCMSolenoidVoltageFault(uint8_t module, int32_t* status) {
|
||||
HAL_Bool HAL_GetPCMSolenoidVoltageFault(int32_t module, int32_t* status) {
|
||||
if (module >= kNumPCMModules) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return false;
|
||||
@@ -141,7 +152,7 @@ bool HAL_GetPCMSolenoidVoltageFault(uint8_t module, int32_t* status) {
|
||||
|
||||
return value;
|
||||
}
|
||||
void HAL_ClearAllPCMStickyFaults(uint8_t module, int32_t* status) {
|
||||
void HAL_ClearAllPCMStickyFaults(int32_t module, int32_t* status) {
|
||||
if (module >= kNumPCMModules) {
|
||||
*status = PARAMETER_OUT_OF_RANGE;
|
||||
return;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "HandlesInternal.h"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
/* General Handle Data Layout
|
||||
* Bits 0-15: Handle Index
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "HAL/Errors.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "HandlesInternal.h"
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "HandlesInternal.h"
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "HandlesInternal.h"
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "HAL/cpp/priority_mutex.h"
|
||||
#include "handles/HandlesInternal.h"
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
#include "FRC_NetworkCommunication/FRCComm.h"
|
||||
|
||||
@@ -19,7 +20,7 @@ struct HAL_JoystickAxesInt {
|
||||
|
||||
extern "C" {
|
||||
|
||||
int HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
||||
int32_t HAL_GetControlWord(HAL_ControlWord* controlWord) {
|
||||
std::memset(controlWord, 0, sizeof(HAL_ControlWord));
|
||||
return FRC_NetworkCommunication_getControlWord(
|
||||
reinterpret_cast<ControlWord_t*>(controlWord));
|
||||
@@ -32,7 +33,7 @@ HAL_AllianceStationID HAL_GetAllianceStation(int32_t* status) {
|
||||
return allianceStation;
|
||||
}
|
||||
|
||||
int HAL_GetJoystickAxes(uint8_t joystickNum, HAL_JoystickAxes* axes) {
|
||||
int32_t HAL_GetJoystickAxes(int32_t joystickNum, HAL_JoystickAxes* axes) {
|
||||
HAL_JoystickAxesInt axesInt;
|
||||
|
||||
int retVal = FRC_NetworkCommunication_getJoystickAxes(
|
||||
@@ -55,13 +56,14 @@ int HAL_GetJoystickAxes(uint8_t joystickNum, HAL_JoystickAxes* axes) {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int HAL_GetJoystickPOVs(uint8_t joystickNum, HAL_JoystickPOVs* povs) {
|
||||
int32_t HAL_GetJoystickPOVs(int32_t joystickNum, HAL_JoystickPOVs* povs) {
|
||||
return FRC_NetworkCommunication_getJoystickPOVs(
|
||||
joystickNum, reinterpret_cast<JoystickPOV_t*>(povs),
|
||||
HAL_kMaxJoystickPOVs);
|
||||
}
|
||||
|
||||
int HAL_GetJoystickButtons(uint8_t joystickNum, HAL_JoystickButtons* buttons) {
|
||||
int32_t HAL_GetJoystickButtons(int32_t joystickNum,
|
||||
HAL_JoystickButtons* buttons) {
|
||||
return FRC_NetworkCommunication_getJoystickButtons(
|
||||
joystickNum, &buttons->buttons, &buttons->count);
|
||||
}
|
||||
@@ -76,10 +78,10 @@ int HAL_GetJoystickButtons(uint8_t joystickNum, HAL_JoystickButtons* buttons) {
|
||||
* @return error code reported from Network Comm back-end. Zero is good,
|
||||
* nonzero is bad.
|
||||
*/
|
||||
int HAL_GetJoystickDescriptor(uint8_t joystickNum,
|
||||
HAL_JoystickDescriptor* desc) {
|
||||
int32_t HAL_GetJoystickDescriptor(int32_t joystickNum,
|
||||
HAL_JoystickDescriptor* desc) {
|
||||
desc->isXbox = 0;
|
||||
desc->type = -1;
|
||||
desc->type = std::numeric_limits<uint8_t>::max();
|
||||
desc->name[0] = '\0';
|
||||
desc->axisCount =
|
||||
HAL_kMaxJoystickAxes; /* set to the desc->axisTypes's capacity */
|
||||
@@ -99,7 +101,7 @@ int HAL_GetJoystickDescriptor(uint8_t joystickNum,
|
||||
return retval;
|
||||
}
|
||||
|
||||
int HAL_GetJoystickIsXbox(uint8_t joystickNum) {
|
||||
HAL_Bool HAL_GetJoystickIsXbox(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return 0;
|
||||
@@ -108,7 +110,7 @@ int HAL_GetJoystickIsXbox(uint8_t joystickNum) {
|
||||
}
|
||||
}
|
||||
|
||||
int HAL_GetJoystickType(uint8_t joystickNum) {
|
||||
int32_t HAL_GetJoystickType(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
@@ -117,7 +119,7 @@ int HAL_GetJoystickType(uint8_t joystickNum) {
|
||||
}
|
||||
}
|
||||
|
||||
char* HAL_GetJoystickName(uint8_t joystickNum) {
|
||||
char* HAL_GetJoystickName(int32_t joystickNum) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
char* name = static_cast<char*>(std::malloc(1));
|
||||
@@ -132,7 +134,7 @@ char* HAL_GetJoystickName(uint8_t joystickNum) {
|
||||
}
|
||||
}
|
||||
|
||||
int HAL_GetJoystickAxisType(uint8_t joystickNum, uint8_t axis) {
|
||||
int32_t HAL_GetJoystickAxisType(int32_t joystickNum, int32_t axis) {
|
||||
HAL_JoystickDescriptor joystickDesc;
|
||||
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
|
||||
return -1;
|
||||
@@ -141,8 +143,8 @@ int HAL_GetJoystickAxisType(uint8_t joystickNum, uint8_t axis) {
|
||||
}
|
||||
}
|
||||
|
||||
int HAL_SetJoystickOutputs(uint8_t joystickNum, uint32_t outputs,
|
||||
uint16_t leftRumble, uint16_t rightRumble) {
|
||||
int32_t HAL_SetJoystickOutputs(int32_t joystickNum, int64_t outputs,
|
||||
int32_t leftRumble, int32_t rightRumble) {
|
||||
return FRC_NetworkCommunication_setJoystickOutputs(joystickNum, outputs,
|
||||
leftRumble, rightRumble);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include "GyroBase.h"
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
|
||||
class AnalogInput;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "PIDSource.h"
|
||||
#include "SensorBase.h"
|
||||
@@ -40,7 +40,7 @@ class AnalogInput : public SensorBase,
|
||||
explicit AnalogInput(uint32_t channel);
|
||||
virtual ~AnalogInput();
|
||||
|
||||
int16_t GetValue() const;
|
||||
int32_t GetValue() const;
|
||||
int32_t GetAverageValue() const;
|
||||
|
||||
float GetVoltage() const;
|
||||
@@ -48,12 +48,12 @@ class AnalogInput : public SensorBase,
|
||||
|
||||
uint32_t GetChannel() const;
|
||||
|
||||
void SetAverageBits(uint32_t bits);
|
||||
uint32_t GetAverageBits() const;
|
||||
void SetOversampleBits(uint32_t bits);
|
||||
uint32_t GetOversampleBits() const;
|
||||
void SetAverageBits(int32_t bits);
|
||||
int32_t GetAverageBits() const;
|
||||
void SetOversampleBits(int32_t bits);
|
||||
int32_t GetOversampleBits() const;
|
||||
|
||||
uint32_t GetLSBWeight() const;
|
||||
int32_t GetLSBWeight() const;
|
||||
int32_t GetOffset() const;
|
||||
|
||||
bool IsAccumulatorChannel() const;
|
||||
@@ -63,8 +63,8 @@ class AnalogInput : public SensorBase,
|
||||
void SetAccumulatorCenter(int32_t center);
|
||||
void SetAccumulatorDeadband(int32_t deadband);
|
||||
int64_t GetAccumulatorValue() const;
|
||||
uint32_t GetAccumulatorCount() const;
|
||||
void GetAccumulatorOutput(int64_t& value, uint32_t& count) const;
|
||||
int64_t GetAccumulatorCount() const;
|
||||
void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
|
||||
|
||||
static void SetSampleRate(float samplesPerSecond);
|
||||
static float GetSampleRate();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "AnalogTriggerOutput.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
class AnalogInput;
|
||||
@@ -25,7 +25,7 @@ class AnalogTrigger : public SensorBase {
|
||||
void SetLimitsRaw(int32_t lower, int32_t upper);
|
||||
void SetAveraged(bool useAveragedValue);
|
||||
void SetFiltered(bool useFilteredValue);
|
||||
uint32_t GetIndex() const;
|
||||
int32_t GetIndex() const;
|
||||
bool GetInWindow();
|
||||
bool GetTriggerState();
|
||||
std::shared_ptr<AnalogTriggerOutput> CreateOutput(
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
|
||||
class ControllerPower {
|
||||
public:
|
||||
static double GetInputVoltage();
|
||||
static double GetInputCurrent();
|
||||
static double GetVoltage3V3();
|
||||
static double GetCurrent3V3();
|
||||
static float GetInputVoltage();
|
||||
static float GetInputCurrent();
|
||||
static float GetVoltage3V3();
|
||||
static float GetCurrent3V3();
|
||||
static bool GetEnabled3V3();
|
||||
static int GetFaultCount3V3();
|
||||
static double GetVoltage5V();
|
||||
static double GetCurrent5V();
|
||||
static float GetVoltage5V();
|
||||
static float GetCurrent5V();
|
||||
static bool GetEnabled5V();
|
||||
static int GetFaultCount5V();
|
||||
static double GetVoltage6V();
|
||||
static double GetCurrent6V();
|
||||
static float GetVoltage6V();
|
||||
static float GetCurrent6V();
|
||||
static bool GetEnabled6V();
|
||||
static int GetFaultCount6V();
|
||||
};
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "AnalogTrigger.h"
|
||||
#include "CounterBase.h"
|
||||
#include "HAL/Counter.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "DigitalSource.h"
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
@@ -26,7 +26,7 @@ class DigitalOutput : public DigitalSource,
|
||||
public:
|
||||
explicit DigitalOutput(uint32_t channel);
|
||||
virtual ~DigitalOutput();
|
||||
void Set(uint32_t value);
|
||||
void Set(bool value);
|
||||
uint32_t GetChannel() const override;
|
||||
void Pulse(float length);
|
||||
bool IsPulsing() const;
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "InterruptableSensorBase.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SolenoidBase.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
@@ -66,10 +66,10 @@ class Encoder : public SensorBase,
|
||||
bool GetStopped() const override;
|
||||
bool GetDirection() const override;
|
||||
|
||||
double GetDistance() const;
|
||||
double GetRate() const;
|
||||
void SetMinRate(double minRate);
|
||||
void SetDistancePerPulse(double distancePerPulse);
|
||||
float GetDistance() const;
|
||||
float GetRate() const;
|
||||
void SetMinRate(float minRate);
|
||||
void SetDistancePerPulse(float distancePerPulse);
|
||||
void SetReverseDirection(bool reverseDirection);
|
||||
void SetSamplesToAverage(int samplesToAverage);
|
||||
int GetSamplesToAverage() const;
|
||||
@@ -94,7 +94,7 @@ class Encoder : public SensorBase,
|
||||
private:
|
||||
void InitEncoder(bool reverseDirection, EncodingType encodingType);
|
||||
|
||||
double DecodingScaleFactor() const;
|
||||
float DecodingScaleFactor() const;
|
||||
|
||||
std::shared_ptr<DigitalSource> m_aSource; // the A phase of the quad encoder
|
||||
std::shared_ptr<DigitalSource> m_bSource; // the B phase of the quad encoder
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SensorBase.h"
|
||||
#include "tables/ITableListener.h"
|
||||
@@ -53,8 +53,8 @@ class PWM : public SensorBase,
|
||||
void SetPeriodMultiplier(PeriodMultiplier mult);
|
||||
void SetZeroLatch();
|
||||
void EnableDeadbandElimination(bool eliminateDeadband);
|
||||
void SetBounds(double max, double deadbandMax, double center,
|
||||
double deadbandMin, double min);
|
||||
void SetBounds(float max, float deadbandMax, float center, float deadbandMin,
|
||||
float min);
|
||||
void SetRawBounds(int32_t max, int32_t deadbandMax, int32_t center,
|
||||
int32_t deadbandMin, int32_t min);
|
||||
void GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
|
||||
|
||||
@@ -21,12 +21,12 @@ class PowerDistributionPanel : public SensorBase, public LiveWindowSendable {
|
||||
PowerDistributionPanel();
|
||||
explicit PowerDistributionPanel(uint8_t module);
|
||||
|
||||
double GetVoltage() const;
|
||||
double GetTemperature() const;
|
||||
double GetCurrent(uint8_t channel) const;
|
||||
double GetTotalCurrent() const;
|
||||
double GetTotalPower() const;
|
||||
double GetTotalEnergy() const;
|
||||
float GetVoltage() const;
|
||||
float GetTemperature() const;
|
||||
float GetCurrent(uint8_t channel) const;
|
||||
float GetTotalCurrent() const;
|
||||
float GetTotalPower() const;
|
||||
float GetTotalEnergy() const;
|
||||
void ResetTotalEnergy();
|
||||
void ClearStickyFaults();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "MotorSafety.h"
|
||||
#include "SensorBase.h"
|
||||
|
||||
@@ -57,9 +57,9 @@ class SPI : public SensorBase {
|
||||
void SetAccumulatorDeadband(int32_t deadband);
|
||||
int32_t GetAccumulatorLastValue() const;
|
||||
int64_t GetAccumulatorValue() const;
|
||||
uint32_t GetAccumulatorCount() const;
|
||||
int64_t GetAccumulatorCount() const;
|
||||
double GetAccumulatorAverage() const;
|
||||
void GetAccumulatorOutput(int64_t& value, uint32_t& count) const;
|
||||
void GetAccumulatorOutput(int64_t& value, int64_t& count) const;
|
||||
|
||||
protected:
|
||||
uint8_t m_port;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "HAL/Handles.h"
|
||||
#include "HAL/Types.h"
|
||||
#include "LiveWindow/LiveWindowSendable.h"
|
||||
#include "SolenoidBase.h"
|
||||
#include "tables/ITableListener.h"
|
||||
|
||||
@@ -65,10 +65,10 @@ AnalogInput::~AnalogInput() {
|
||||
*
|
||||
* @return A sample straight from this channel.
|
||||
*/
|
||||
int16_t AnalogInput::GetValue() const {
|
||||
int32_t AnalogInput::GetValue() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
int16_t value = HAL_GetAnalogValue(m_port, &status);
|
||||
int32_t value = HAL_GetAnalogValue(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return value;
|
||||
}
|
||||
@@ -140,7 +140,7 @@ float AnalogInput::GetAverageVoltage() const {
|
||||
*
|
||||
* @return Least significant bit weight.
|
||||
*/
|
||||
uint32_t AnalogInput::GetLSBWeight() const {
|
||||
int32_t AnalogInput::GetLSBWeight() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
int32_t lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
|
||||
@@ -184,7 +184,7 @@ uint32_t AnalogInput::GetChannel() const {
|
||||
*
|
||||
* @param bits Number of bits of averaging.
|
||||
*/
|
||||
void AnalogInput::SetAverageBits(uint32_t bits) {
|
||||
void AnalogInput::SetAverageBits(int32_t bits) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogAverageBits(m_port, bits, &status);
|
||||
@@ -199,7 +199,7 @@ void AnalogInput::SetAverageBits(uint32_t bits) {
|
||||
*
|
||||
* @return Number of bits of averaging previously configured.
|
||||
*/
|
||||
uint32_t AnalogInput::GetAverageBits() const {
|
||||
int32_t AnalogInput::GetAverageBits() const {
|
||||
int32_t status = 0;
|
||||
int32_t averageBits = HAL_GetAnalogAverageBits(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
@@ -216,7 +216,7 @@ uint32_t AnalogInput::GetAverageBits() const {
|
||||
*
|
||||
* @param bits Number of bits of oversampling.
|
||||
*/
|
||||
void AnalogInput::SetOversampleBits(uint32_t bits) {
|
||||
void AnalogInput::SetOversampleBits(int32_t bits) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
HAL_SetAnalogOversampleBits(m_port, bits, &status);
|
||||
@@ -232,7 +232,7 @@ void AnalogInput::SetOversampleBits(uint32_t bits) {
|
||||
*
|
||||
* @return Number of bits of oversampling previously configured.
|
||||
*/
|
||||
uint32_t AnalogInput::GetOversampleBits() const {
|
||||
int32_t AnalogInput::GetOversampleBits() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
int32_t oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status);
|
||||
@@ -348,10 +348,10 @@ int64_t AnalogInput::GetAccumulatorValue() const {
|
||||
*
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
uint32_t AnalogInput::GetAccumulatorCount() const {
|
||||
int64_t AnalogInput::GetAccumulatorCount() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
uint32_t count = HAL_GetAccumulatorCount(m_port, &status);
|
||||
int64_t count = HAL_GetAccumulatorCount(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return count;
|
||||
}
|
||||
@@ -365,7 +365,7 @@ uint32_t AnalogInput::GetAccumulatorCount() const {
|
||||
* @param value Reference to the 64-bit accumulated output.
|
||||
* @param count Reference to the number of accumulation cycles.
|
||||
*/
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t& value, uint32_t& count) const {
|
||||
void AnalogInput::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
HAL_GetAccumulatorOutput(m_port, &value, &count, &status);
|
||||
|
||||
@@ -35,7 +35,7 @@ AnalogTrigger::AnalogTrigger(int32_t channel)
|
||||
AnalogTrigger::AnalogTrigger(AnalogInput* input) {
|
||||
m_analogInput = input;
|
||||
int32_t status = 0;
|
||||
uint32_t index = 0;
|
||||
int32_t index = 0;
|
||||
m_trigger = HAL_InitializeAnalogTrigger(input->m_port, &index, &status);
|
||||
if (status != 0) {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
@@ -128,8 +128,8 @@ void AnalogTrigger::SetFiltered(bool useFilteredValue) {
|
||||
*
|
||||
* @return The index of the analog trigger.
|
||||
*/
|
||||
uint32_t AnalogTrigger::GetIndex() const {
|
||||
if (StatusIsFatal()) return std::numeric_limits<uint32_t>::max();
|
||||
int32_t AnalogTrigger::GetIndex() const {
|
||||
if (StatusIsFatal()) return -1;
|
||||
return m_index;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@
|
||||
*
|
||||
* @return The controller input voltage value in Volts
|
||||
*/
|
||||
double ControllerPower::GetInputVoltage() {
|
||||
float ControllerPower::GetInputVoltage() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinVoltage(&status);
|
||||
float retVal = HAL_GetVinVoltage(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -30,9 +30,9 @@ double ControllerPower::GetInputVoltage() {
|
||||
*
|
||||
* @return The controller input current value in Amps
|
||||
*/
|
||||
double ControllerPower::GetInputCurrent() {
|
||||
float ControllerPower::GetInputCurrent() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetVinCurrent(&status);
|
||||
float retVal = HAL_GetVinCurrent(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -42,9 +42,9 @@ double ControllerPower::GetInputCurrent() {
|
||||
*
|
||||
* @return The controller 6V rail voltage value in Volts
|
||||
*/
|
||||
double ControllerPower::GetVoltage6V() {
|
||||
float ControllerPower::GetVoltage6V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage6V(&status);
|
||||
float retVal = HAL_GetUserVoltage6V(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -54,9 +54,9 @@ double ControllerPower::GetVoltage6V() {
|
||||
*
|
||||
* @return The controller 6V rail output current value in Amps
|
||||
*/
|
||||
double ControllerPower::GetCurrent6V() {
|
||||
float ControllerPower::GetCurrent6V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent6V(&status);
|
||||
float retVal = HAL_GetUserCurrent6V(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -92,9 +92,9 @@ int ControllerPower::GetFaultCount6V() {
|
||||
*
|
||||
* @return The controller 5V rail voltage value in Volts
|
||||
*/
|
||||
double ControllerPower::GetVoltage5V() {
|
||||
float ControllerPower::GetVoltage5V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage5V(&status);
|
||||
float retVal = HAL_GetUserVoltage5V(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -104,9 +104,9 @@ double ControllerPower::GetVoltage5V() {
|
||||
*
|
||||
* @return The controller 5V rail output current value in Amps
|
||||
*/
|
||||
double ControllerPower::GetCurrent5V() {
|
||||
float ControllerPower::GetCurrent5V() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent5V(&status);
|
||||
float retVal = HAL_GetUserCurrent5V(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -142,9 +142,9 @@ int ControllerPower::GetFaultCount5V() {
|
||||
*
|
||||
* @return The controller 3.3V rail voltage value in Volts
|
||||
*/
|
||||
double ControllerPower::GetVoltage3V3() {
|
||||
float ControllerPower::GetVoltage3V3() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserVoltage3V3(&status);
|
||||
float retVal = HAL_GetUserVoltage3V3(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -154,9 +154,9 @@ double ControllerPower::GetVoltage3V3() {
|
||||
*
|
||||
* @return The controller 3.3V rail output current value in Amps
|
||||
*/
|
||||
double ControllerPower::GetCurrent3V3() {
|
||||
float ControllerPower::GetCurrent3V3() {
|
||||
int32_t status = 0;
|
||||
double retVal = HAL_GetUserCurrent3V3(&status);
|
||||
float retVal = HAL_GetUserCurrent3V3(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ DigitalOutput::~DigitalOutput() {
|
||||
*
|
||||
* @param value 1 (true) for high, 0 (false) for disabled
|
||||
*/
|
||||
void DigitalOutput::Set(uint32_t value) {
|
||||
void DigitalOutput::Set(bool value) {
|
||||
if (StatusIsFatal()) return;
|
||||
|
||||
int32_t status = 0;
|
||||
|
||||
@@ -293,10 +293,10 @@ bool Encoder::GetDirection() const {
|
||||
* The scale needed to convert a raw counter value into a number of encoder
|
||||
* pulses.
|
||||
*/
|
||||
double Encoder::DecodingScaleFactor() const {
|
||||
float Encoder::DecodingScaleFactor() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
int32_t status = 0;
|
||||
double val = HAL_GetEncoderDecodingScaleFactor(m_encoder, &status);
|
||||
float val = HAL_GetEncoderDecodingScaleFactor(m_encoder, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return val;
|
||||
}
|
||||
@@ -307,10 +307,10 @@ double Encoder::DecodingScaleFactor() const {
|
||||
* @return The distance driven since the last reset as scaled by the value from
|
||||
* SetDistancePerPulse().
|
||||
*/
|
||||
double Encoder::GetDistance() const {
|
||||
float Encoder::GetDistance() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderDistance(m_encoder, &status);
|
||||
float value = HAL_GetEncoderDistance(m_encoder, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return value;
|
||||
}
|
||||
@@ -323,10 +323,10 @@ double Encoder::GetDistance() const {
|
||||
*
|
||||
* @return The current rate of the encoder.
|
||||
*/
|
||||
double Encoder::GetRate() const {
|
||||
float Encoder::GetRate() const {
|
||||
if (StatusIsFatal()) return 0.0;
|
||||
int32_t status = 0;
|
||||
double value = HAL_GetEncoderRate(m_encoder, &status);
|
||||
float value = HAL_GetEncoderRate(m_encoder, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return value;
|
||||
}
|
||||
@@ -337,7 +337,7 @@ double Encoder::GetRate() const {
|
||||
* @param minRate The minimum rate. The units are in distance per second as
|
||||
* scaled by the value from SetDistancePerPulse().
|
||||
*/
|
||||
void Encoder::SetMinRate(double minRate) {
|
||||
void Encoder::SetMinRate(float minRate) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderMinRate(m_encoder, minRate, &status);
|
||||
@@ -361,7 +361,7 @@ void Encoder::SetMinRate(double minRate) {
|
||||
* @param distancePerPulse The scale factor that will be used to convert pulses
|
||||
* to useful units.
|
||||
*/
|
||||
void Encoder::SetDistancePerPulse(double distancePerPulse) {
|
||||
void Encoder::SetDistancePerPulse(float distancePerPulse) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
HAL_SetEncoderDistancePerPulse(m_encoder, distancePerPulse, &status);
|
||||
|
||||
@@ -97,8 +97,8 @@ void PWM::EnableDeadbandElimination(bool eliminateDeadband) {
|
||||
* @param deadbandMin The low end of the deadband pulse width in ms
|
||||
* @param min The minimum pulse width in ms
|
||||
*/
|
||||
void PWM::SetBounds(double max, double deadbandMax, double center,
|
||||
double deadbandMin, double min) {
|
||||
void PWM::SetBounds(float max, float deadbandMax, float center,
|
||||
float deadbandMin, float min) {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
HAL_SetPWMConfig(m_handle, max, deadbandMax, center, deadbandMin, min,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "PowerDistributionPanel.h"
|
||||
#include "HAL/PDP.h"
|
||||
#include "HAL/HAL.h"
|
||||
#include "LiveWindow/LiveWindow.h"
|
||||
#include "WPIErrors.h"
|
||||
|
||||
@@ -19,7 +19,13 @@ PowerDistributionPanel::PowerDistributionPanel() : PowerDistributionPanel(0) {}
|
||||
*/
|
||||
PowerDistributionPanel::PowerDistributionPanel(uint8_t module)
|
||||
: m_module(module) {
|
||||
HAL_InitializePDP(m_module);
|
||||
int32_t status = 0;
|
||||
HAL_InitializePDP(m_module, &status);
|
||||
if (status != 0) {
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
m_module = -1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,10 +33,11 @@ PowerDistributionPanel::PowerDistributionPanel(uint8_t module)
|
||||
*
|
||||
* @return The voltage of the PDP in volts
|
||||
*/
|
||||
double PowerDistributionPanel::GetVoltage() const {
|
||||
float PowerDistributionPanel::GetVoltage() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
double voltage = HAL_GetPDPVoltage(m_module, &status);
|
||||
float voltage = HAL_GetPDPVoltage(m_module, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
@@ -44,10 +51,11 @@ double PowerDistributionPanel::GetVoltage() const {
|
||||
*
|
||||
* @return The temperature of the PDP in degrees Celsius
|
||||
*/
|
||||
double PowerDistributionPanel::GetTemperature() const {
|
||||
float PowerDistributionPanel::GetTemperature() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
double temperature = HAL_GetPDPTemperature(m_module, &status);
|
||||
float temperature = HAL_GetPDPTemperature(m_module, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
@@ -61,7 +69,8 @@ double PowerDistributionPanel::GetTemperature() const {
|
||||
*
|
||||
* @return The current of one of the PDP channels (channels 0-15) in Amperes
|
||||
*/
|
||||
double PowerDistributionPanel::GetCurrent(uint8_t channel) const {
|
||||
float PowerDistributionPanel::GetCurrent(uint8_t channel) const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
if (!CheckPDPChannel(channel)) {
|
||||
@@ -70,7 +79,7 @@ double PowerDistributionPanel::GetCurrent(uint8_t channel) const {
|
||||
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
|
||||
}
|
||||
|
||||
double current = HAL_GetPDPChannelCurrent(m_module, channel, &status);
|
||||
float current = HAL_GetPDPChannelCurrent(m_module, channel, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
@@ -84,10 +93,11 @@ double PowerDistributionPanel::GetCurrent(uint8_t channel) const {
|
||||
*
|
||||
* @return The the total current drawn from the PDP channels in Amperes
|
||||
*/
|
||||
double PowerDistributionPanel::GetTotalCurrent() const {
|
||||
float PowerDistributionPanel::GetTotalCurrent() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
double current = HAL_GetPDPTotalCurrent(m_module, &status);
|
||||
float current = HAL_GetPDPTotalCurrent(m_module, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
@@ -101,10 +111,11 @@ double PowerDistributionPanel::GetTotalCurrent() const {
|
||||
*
|
||||
* @return The the total power drawn from the PDP channels in Watts
|
||||
*/
|
||||
double PowerDistributionPanel::GetTotalPower() const {
|
||||
float PowerDistributionPanel::GetTotalPower() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
double power = HAL_GetPDPTotalPower(m_module, &status);
|
||||
float power = HAL_GetPDPTotalPower(m_module, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
@@ -118,10 +129,11 @@ double PowerDistributionPanel::GetTotalPower() const {
|
||||
*
|
||||
* @return The the total energy drawn from the PDP channels in Joules
|
||||
*/
|
||||
double PowerDistributionPanel::GetTotalEnergy() const {
|
||||
float PowerDistributionPanel::GetTotalEnergy() const {
|
||||
if (StatusIsFatal()) return 0;
|
||||
int32_t status = 0;
|
||||
|
||||
double energy = HAL_GetPDPTotalEnergy(m_module, &status);
|
||||
float energy = HAL_GetPDPTotalEnergy(m_module, &status);
|
||||
|
||||
if (status) {
|
||||
wpi_setWPIErrorWithContext(Timeout, "");
|
||||
@@ -136,6 +148,7 @@ double PowerDistributionPanel::GetTotalEnergy() const {
|
||||
* @see PowerDistributionPanel#GetTotalEnergy
|
||||
*/
|
||||
void PowerDistributionPanel::ResetTotalEnergy() {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_ResetPDPTotalEnergy(m_module, &status);
|
||||
@@ -149,6 +162,7 @@ void PowerDistributionPanel::ResetTotalEnergy() {
|
||||
* Remove all of the fault flags on the PDP.
|
||||
*/
|
||||
void PowerDistributionPanel::ClearStickyFaults() {
|
||||
if (StatusIsFatal()) return;
|
||||
int32_t status = 0;
|
||||
|
||||
HAL_ClearPDPStickyFaults(m_module, &status);
|
||||
|
||||
@@ -49,9 +49,7 @@ void SPI::SetClockRate(double hz) { HAL_SetSPISpeed(m_port, hz); }
|
||||
*/
|
||||
void SPI::SetMSBFirst() {
|
||||
m_msbFirst = true;
|
||||
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
|
||||
static_cast<int>(m_sampleOnTrailing),
|
||||
static_cast<int>(m_clk_idle_high));
|
||||
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +58,7 @@ void SPI::SetMSBFirst() {
|
||||
*/
|
||||
void SPI::SetLSBFirst() {
|
||||
m_msbFirst = false;
|
||||
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
|
||||
static_cast<int>(m_sampleOnTrailing),
|
||||
static_cast<int>(m_clk_idle_high));
|
||||
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,9 +67,7 @@ void SPI::SetLSBFirst() {
|
||||
*/
|
||||
void SPI::SetSampleDataOnFalling() {
|
||||
m_sampleOnTrailing = true;
|
||||
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
|
||||
static_cast<int>(m_sampleOnTrailing),
|
||||
static_cast<int>(m_clk_idle_high));
|
||||
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,9 +76,7 @@ void SPI::SetSampleDataOnFalling() {
|
||||
*/
|
||||
void SPI::SetSampleDataOnRising() {
|
||||
m_sampleOnTrailing = false;
|
||||
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
|
||||
static_cast<int>(m_sampleOnTrailing),
|
||||
static_cast<int>(m_clk_idle_high));
|
||||
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,9 +85,7 @@ void SPI::SetSampleDataOnRising() {
|
||||
*/
|
||||
void SPI::SetClockActiveLow() {
|
||||
m_clk_idle_high = true;
|
||||
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
|
||||
static_cast<int>(m_sampleOnTrailing),
|
||||
static_cast<int>(m_clk_idle_high));
|
||||
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,9 +94,7 @@ void SPI::SetClockActiveLow() {
|
||||
*/
|
||||
void SPI::SetClockActiveHigh() {
|
||||
m_clk_idle_high = false;
|
||||
HAL_SetSPIOpts(m_port, static_cast<int>(m_msbFirst),
|
||||
static_cast<int>(m_sampleOnTrailing),
|
||||
static_cast<int>(m_clk_idle_high));
|
||||
HAL_SetSPIOpts(m_port, m_msbFirst, m_sampleOnTrailing, m_clk_idle_high);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -276,9 +264,9 @@ int64_t SPI::GetAccumulatorValue() const {
|
||||
*
|
||||
* @return The number of times samples from the channel were accumulated.
|
||||
*/
|
||||
uint32_t SPI::GetAccumulatorCount() const {
|
||||
int64_t SPI::GetAccumulatorCount() const {
|
||||
int32_t status = 0;
|
||||
uint32_t retVal = HAL_GetSPIAccumulatorCount(m_port, &status);
|
||||
int64_t retVal = HAL_GetSPIAccumulatorCount(m_port, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return retVal;
|
||||
}
|
||||
@@ -304,7 +292,7 @@ double SPI::GetAccumulatorAverage() const {
|
||||
* @param value Pointer to the 64-bit accumulated output.
|
||||
* @param count Pointer to the number of accumulation cycles.
|
||||
*/
|
||||
void SPI::GetAccumulatorOutput(int64_t& value, uint32_t& count) const {
|
||||
void SPI::GetAccumulatorOutput(int64_t& value, int64_t& count) const {
|
||||
int32_t status = 0;
|
||||
HAL_GetSPIAccumulatorOutput(m_port, &value, &count, &status);
|
||||
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
|
||||
@@ -125,9 +125,9 @@ bool wpi_assertNotEqual_impl(int valueA, int valueB, const char* valueAString,
|
||||
* For now, expect this to be competition year.
|
||||
* @return FPGA Version number.
|
||||
*/
|
||||
uint16_t GetFPGAVersion() {
|
||||
int32_t GetFPGAVersion() {
|
||||
int32_t status = 0;
|
||||
uint16_t version = HAL_GetFPGAVersion(&status);
|
||||
int32_t version = HAL_GetFPGAVersion(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return version;
|
||||
}
|
||||
@@ -140,9 +140,9 @@ uint16_t GetFPGAVersion() {
|
||||
* The 12 least significant bits are the Build Number.
|
||||
* @return FPGA Revision number.
|
||||
*/
|
||||
uint32_t GetFPGARevision() {
|
||||
int64_t GetFPGARevision() {
|
||||
int32_t status = 0;
|
||||
uint32_t revision = HAL_GetFPGARevision(&status);
|
||||
int64_t revision = HAL_GetFPGARevision(&status);
|
||||
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
|
||||
return revision;
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ bool wpi_assertNotEqual_impl(int valueA, int valueB, const char* valueAString,
|
||||
|
||||
void wpi_suspendOnAssertEnabled(bool enabled);
|
||||
|
||||
uint16_t GetFPGAVersion();
|
||||
uint32_t GetFPGARevision();
|
||||
int32_t GetFPGAVersion();
|
||||
int64_t GetFPGARevision();
|
||||
uint64_t GetFPGATime();
|
||||
bool GetUserButton();
|
||||
std::string GetStackTrace(uint32_t offset);
|
||||
|
||||
@@ -494,7 +494,7 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorCount(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_AnalogJNI
|
||||
* Method: getAccumulatorOutput
|
||||
* Signature: (ILjava/nio/LongBuffer;Ljava/nio/IntBuffer;)V
|
||||
* Signature: (ILjava/nio/LongBuffer;Ljava/nio/LongBuffer;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput(
|
||||
@@ -502,7 +502,7 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_getAccumulatorOutput(
|
||||
ANALOGJNI_LOG(logDEBUG) << "Analog Handle = " << (HAL_AnalogInputHandle)id;
|
||||
int32_t status = 0;
|
||||
jlong *valuePtr = (jlong *)env->GetDirectBufferAddress(value);
|
||||
uint32_t *countPtr = (uint32_t *)env->GetDirectBufferAddress(count);
|
||||
jlong *countPtr = (jlong *)env->GetDirectBufferAddress(count);
|
||||
HAL_GetAccumulatorOutput((HAL_AnalogInputHandle)id, valuePtr, countPtr, &status);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Value = " << *valuePtr;
|
||||
ANALOGJNI_LOG(logDEBUG) << "Count = " << *countPtr;
|
||||
@@ -523,7 +523,7 @@ Java_edu_wpi_first_wpilibj_hal_AnalogJNI_initializeAnalogTrigger(
|
||||
ANALOGJNI_LOG(logDEBUG) << "Index Ptr = " << indexHandle;
|
||||
int32_t status = 0;
|
||||
HAL_AnalogTriggerHandle analogTrigger =
|
||||
HAL_InitializeAnalogTrigger((HAL_AnalogInputHandle)id, (uint32_t *)indexHandle, &status);
|
||||
HAL_InitializeAnalogTrigger((HAL_AnalogInputHandle)id, (int32_t *)indexHandle, &status);
|
||||
ANALOGJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
ANALOGJNI_LOG(logDEBUG) << "AnalogTrigger Handle = " << analogTrigger;
|
||||
CheckStatus(env, status);
|
||||
|
||||
@@ -17,8 +17,10 @@ extern "C" {
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_edu_wpi_first_wpilibj_hal_PDPJNI_initializePDP(
|
||||
JNIEnv *, jclass, jint module) {
|
||||
HAL_InitializePDP(module);
|
||||
JNIEnv *env, jclass, jint module) {
|
||||
int32_t status = 0;
|
||||
HAL_InitializePDP(module, &status);
|
||||
CheckStatus(env, status);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -342,7 +342,7 @@ Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorAverage(
|
||||
/*
|
||||
* Class: edu_wpi_first_wpilibj_hal_SPIJNI
|
||||
* Method: spiGetAccumulatorOutput
|
||||
* Signature: (BLjava/nio/LongBuffer;Ljava/nio/IntBuffer;)V
|
||||
* Signature: (BLjava/nio/LongBuffer;Ljava/nio/LongBuffer;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorOutput(
|
||||
@@ -352,7 +352,7 @@ Java_edu_wpi_first_wpilibj_hal_SPIJNI_spiGetAccumulatorOutput(
|
||||
int32_t status = 0;
|
||||
|
||||
jlong *valuePtr = (jlong *)env->GetDirectBufferAddress(value);
|
||||
uint32_t *countPtr = (uint32_t *)env->GetDirectBufferAddress(count);
|
||||
jlong *countPtr = (jlong *)env->GetDirectBufferAddress(count);
|
||||
|
||||
HAL_GetSPIAccumulatorOutput(port, valuePtr, countPtr, &status);
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialRead(
|
||||
jbyte* dataReceivedPtr = nullptr;
|
||||
dataReceivedPtr = (jbyte*)env->GetDirectBufferAddress(dataReceived);
|
||||
int32_t status = 0;
|
||||
jint retVal = HAL_ReadSerial(port, (char*)dataReceivedPtr, size, &status);
|
||||
jint retVal = HAL_ReadSerial(port, reinterpret_cast<char*>(dataReceivedPtr), size, &status);
|
||||
SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
|
||||
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
@@ -263,7 +263,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_hal_SerialPortJNI_serialWrite(
|
||||
dataToSendPtr = (jbyte*)env->GetDirectBufferAddress(dataToSend);
|
||||
}
|
||||
int32_t status = 0;
|
||||
jint retVal = HAL_WriteSerial(port, (const char*)dataToSendPtr, size, &status);
|
||||
jint retVal = HAL_WriteSerial(port, reinterpret_cast<char*>(dataToSendPtr), size, &status);
|
||||
SERIALJNI_LOG(logDEBUG) << "ReturnValue = " << retVal;
|
||||
SERIALJNI_LOG(logDEBUG) << "Status = " << status;
|
||||
CheckStatus(env, status);
|
||||
|
||||
@@ -295,12 +295,12 @@ public class AnalogInput extends SensorBase implements PIDSource, LiveWindowSend
|
||||
ByteBuffer value = ByteBuffer.allocateDirect(8);
|
||||
// set the byte order
|
||||
value.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer count = ByteBuffer.allocateDirect(4);
|
||||
ByteBuffer count = ByteBuffer.allocateDirect(8);
|
||||
// set the byte order
|
||||
count.order(ByteOrder.LITTLE_ENDIAN);
|
||||
AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asIntBuffer());
|
||||
AnalogJNI.getAccumulatorOutput(m_port, value.asLongBuffer(), count.asLongBuffer());
|
||||
result.value = value.asLongBuffer().get(0) + m_accumulatorOffset;
|
||||
result.count = count.asIntBuffer().get(0);
|
||||
result.count = count.asLongBuffer().get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -365,11 +365,11 @@ public class SPI extends SensorBase {
|
||||
ByteBuffer value = ByteBuffer.allocateDirect(8);
|
||||
// set the byte order
|
||||
value.order(ByteOrder.LITTLE_ENDIAN);
|
||||
ByteBuffer count = ByteBuffer.allocateDirect(4);
|
||||
ByteBuffer count = ByteBuffer.allocateDirect(8);
|
||||
// set the byte order
|
||||
count.order(ByteOrder.LITTLE_ENDIAN);
|
||||
SPIJNI.spiGetAccumulatorOutput(m_port, value.asLongBuffer(), count.asIntBuffer());
|
||||
SPIJNI.spiGetAccumulatorOutput(m_port, value.asLongBuffer(), count.asLongBuffer());
|
||||
result.value = value.asLongBuffer().get(0);
|
||||
result.count = count.asIntBuffer().get(0);
|
||||
result.count = count.asLongBuffer().get(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class AnalogJNI extends JNIWrapper {
|
||||
public static native int getAccumulatorCount(int analogPortHandle);
|
||||
|
||||
public static native void getAccumulatorOutput(int analogPortHandle, LongBuffer value,
|
||||
IntBuffer count);
|
||||
LongBuffer count);
|
||||
|
||||
public static native int initializeAnalogTrigger(int analogInputHandle, IntBuffer index);
|
||||
|
||||
|
||||
@@ -54,5 +54,5 @@ public class SPIJNI extends JNIWrapper {
|
||||
public static native double spiGetAccumulatorAverage(byte port);
|
||||
|
||||
public static native void spiGetAccumulatorOutput(byte port, LongBuffer value,
|
||||
IntBuffer count);
|
||||
LongBuffer count);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user