Cleaned up integer type usage in wpilibc (#92)

Replaced all unsigned types to signed and int32_t with int in wpilibc
This commit is contained in:
Tyler Veness
2016-09-06 00:01:45 -07:00
committed by Peter Johnson
parent ff93050b31
commit 0cd05d1a42
169 changed files with 914 additions and 943 deletions

View File

@@ -10,10 +10,10 @@
#include "I2C.h"
#include "LiveWindow/LiveWindow.h"
const uint8_t ADXL345_I2C::kAddress;
const uint8_t ADXL345_I2C::kPowerCtlRegister;
const uint8_t ADXL345_I2C::kDataFormatRegister;
const uint8_t ADXL345_I2C::kDataRegister;
const int ADXL345_I2C::kAddress;
const int ADXL345_I2C::kPowerCtlRegister;
const int ADXL345_I2C::kDataFormatRegister;
const int ADXL345_I2C::kDataRegister;
constexpr double ADXL345_I2C::kGsPerLSB;
/**
@@ -54,7 +54,7 @@ double ADXL345_I2C::GetZ() { return GetAcceleration(kAxis_Z); }
*/
double ADXL345_I2C::GetAcceleration(ADXL345_I2C::Axes axis) {
int16_t rawAccel = 0;
m_i2c.Read(kDataRegister + static_cast<uint8_t>(axis), sizeof(rawAccel),
m_i2c.Read(kDataRegister + static_cast<int>(axis), sizeof(rawAccel),
reinterpret_cast<uint8_t*>(&rawAccel));
return rawAccel * kGsPerLSB;
}

View File

@@ -11,9 +11,9 @@
#include "HAL/HAL.h"
#include "LiveWindow/LiveWindow.h"
const uint8_t ADXL345_SPI::kPowerCtlRegister;
const uint8_t ADXL345_SPI::kDataFormatRegister;
const uint8_t ADXL345_SPI::kDataRegister;
const int ADXL345_SPI::kPowerCtlRegister;
const int ADXL345_SPI::kDataFormatRegister;
const int ADXL345_SPI::kDataRegister;
constexpr double ADXL345_SPI::kGsPerLSB;
/**
@@ -92,7 +92,7 @@ ADXL345_SPI::AllAxes ADXL345_SPI::GetAccelerations() {
dataBuffer[0] = (kAddress_Read | kAddress_MultiByte | kDataRegister);
m_spi.Transaction(dataBuffer, dataBuffer, 7);
for (int32_t i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
// Sensor is little endian... swap bytes
rawData[i] = dataBuffer[i * 2 + 2] << 8 | dataBuffer[i * 2 + 1];
}

View File

@@ -12,22 +12,22 @@
#include "HAL/HAL.h"
#include "LiveWindow/LiveWindow.h"
static uint8_t kRegWrite = 0x0A;
static uint8_t kRegRead = 0x0B;
static int kRegWrite = 0x0A;
static int kRegRead = 0x0B;
static uint8_t kPartIdRegister = 0x02;
static uint8_t kDataRegister = 0x0E;
static uint8_t kFilterCtlRegister = 0x2C;
static uint8_t kPowerCtlRegister = 0x2D;
static int kPartIdRegister = 0x02;
static int kDataRegister = 0x0E;
static int kFilterCtlRegister = 0x2C;
static int kPowerCtlRegister = 0x2D;
// static uint8_t kFilterCtl_Range2G = 0x00;
// static uint8_t kFilterCtl_Range4G = 0x40;
// static uint8_t kFilterCtl_Range8G = 0x80;
static uint8_t kFilterCtl_ODR_100Hz = 0x03;
// static int kFilterCtl_Range2G = 0x00;
// static int kFilterCtl_Range4G = 0x40;
// static int kFilterCtl_Range8G = 0x80;
static int kFilterCtl_ODR_100Hz = 0x03;
static uint8_t kPowerCtl_UltraLowNoise = 0x20;
// static uint8_t kPowerCtl_AutoSleep = 0x04;
static uint8_t kPowerCtl_Measure = 0x02;
static int kPowerCtl_UltraLowNoise = 0x20;
// static int kPowerCtl_AutoSleep = 0x04;
static int kPowerCtl_Measure = 0x02;
/**
* Constructor. Uses the onboard CS1.
@@ -147,7 +147,7 @@ ADXL362::AllAxes ADXL362::GetAccelerations() {
dataBuffer[1] = kDataRegister;
m_spi.Transaction(dataBuffer, dataBuffer, 8);
for (int32_t i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
// Sensor is little endian... swap bytes
rawData[i] = dataBuffer[i * 2 + 3] << 8 | dataBuffer[i * 2 + 2];
}

View File

@@ -14,15 +14,15 @@ static constexpr double kSamplePeriod = 0.001;
static constexpr double kCalibrationSampleTime = 5.0;
static constexpr double kDegreePerSecondPerLSB = 0.0125;
static constexpr uint8_t kRateRegister = 0x00;
static constexpr uint8_t kTemRegister = 0x02;
static constexpr uint8_t kLoCSTRegister = 0x04;
static constexpr uint8_t kHiCSTRegister = 0x06;
static constexpr uint8_t kQuadRegister = 0x08;
static constexpr uint8_t kFaultRegister = 0x0A;
static constexpr uint8_t kPIDRegister = 0x0C;
static constexpr uint8_t kSNHighRegister = 0x0E;
static constexpr uint8_t kSNLowRegister = 0x10;
static constexpr int kRateRegister = 0x00;
static constexpr int kTemRegister = 0x02;
static constexpr int kLoCSTRegister = 0x04;
static constexpr int kHiCSTRegister = 0x06;
static constexpr int kQuadRegister = 0x08;
static constexpr int kFaultRegister = 0x0A;
static constexpr int kPIDRegister = 0x0C;
static constexpr int kSNHighRegister = 0x0E;
static constexpr int kSNLowRegister = 0x10;
/**
* Initialize the gyro.
@@ -43,8 +43,7 @@ void ADXRS450_Gyro::Calibrate() {
Wait(kCalibrationSampleTime);
m_spi.SetAccumulatorCenter(
static_cast<int32_t>(m_spi.GetAccumulatorAverage()));
m_spi.SetAccumulatorCenter(static_cast<int>(m_spi.GetAccumulatorAverage()));
m_spi.ResetAccumulator();
}
@@ -80,7 +79,7 @@ ADXRS450_Gyro::ADXRS450_Gyro(SPI::Port port) : m_spi(port) {
LiveWindow::GetInstance()->AddSensor("ADXRS450_Gyro", port, this);
}
static bool CalcParity(uint32_t v) {
static bool CalcParity(int v) {
bool parity = false;
while (v != 0) {
parity = !parity;
@@ -89,16 +88,16 @@ static bool CalcParity(uint32_t v) {
return parity;
}
static inline uint32_t BytesToIntBE(uint8_t* buf) {
uint32_t result = static_cast<uint32_t>(buf[0]) << 24;
result |= static_cast<uint32_t>(buf[1]) << 16;
result |= static_cast<uint32_t>(buf[2]) << 8;
result |= static_cast<uint32_t>(buf[3]);
static inline int BytesToIntBE(uint8_t* buf) {
int result = static_cast<int>(buf[0]) << 24;
result |= static_cast<int>(buf[1]) << 16;
result |= static_cast<int>(buf[2]) << 8;
result |= static_cast<int>(buf[3]);
return result;
}
uint16_t ADXRS450_Gyro::ReadRegister(uint8_t reg) {
uint32_t cmd = 0x80000000 | static_cast<uint32_t>(reg) << 17;
uint16_t ADXRS450_Gyro::ReadRegister(int reg) {
int cmd = 0x80000000 | static_cast<int>(reg) << 17;
if (!CalcParity(cmd)) cmd |= 1u;
// big endian

View File

@@ -28,7 +28,7 @@ void AnalogAccelerometer::InitAccelerometer() {
* @param channel The channel number for the analog input the accelerometer is
* connected to
*/
AnalogAccelerometer::AnalogAccelerometer(int32_t channel) {
AnalogAccelerometer::AnalogAccelerometer(int channel) {
m_analogInput = std::make_shared<AnalogInput>(channel);
InitAccelerometer();
}

View File

@@ -15,8 +15,8 @@
#include "Timer.h"
#include "WPIErrors.h"
const uint32_t AnalogGyro::kOversampleBits;
const uint32_t AnalogGyro::kAverageBits;
const int AnalogGyro::kOversampleBits;
const int AnalogGyro::kAverageBits;
constexpr float AnalogGyro::kSamplesPerSecond;
constexpr float AnalogGyro::kCalibrationSampleTime;
constexpr float AnalogGyro::kDefaultVoltsPerDegreePerSecond;
@@ -27,7 +27,7 @@ constexpr float AnalogGyro::kDefaultVoltsPerDegreePerSecond;
* @param channel The analog channel the gyro is connected to. Gyros can only
* be used on on-board Analog Inputs 0-1.
*/
AnalogGyro::AnalogGyro(int32_t channel)
AnalogGyro::AnalogGyro(int channel)
: AnalogGyro(std::make_shared<AnalogInput>(channel)) {}
/**
@@ -76,7 +76,7 @@ AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel)
* value.
* @param offset Preset uncalibrated value to use as the gyro offset.
*/
AnalogGyro::AnalogGyro(int32_t channel, uint32_t center, float offset) {
AnalogGyro::AnalogGyro(int channel, int center, float offset) {
m_analog = std::make_shared<AnalogInput>(channel);
InitGyro();
int32_t status = 0;
@@ -101,7 +101,7 @@ AnalogGyro::AnalogGyro(int32_t channel, uint32_t center, float offset) {
* @param channel A pointer to the AnalogInput object that the gyro is
* connected to.
*/
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, uint32_t center,
AnalogGyro::AnalogGyro(std::shared_ptr<AnalogInput> channel, int center,
float offset)
: m_analog(channel) {
if (channel == nullptr) {
@@ -239,10 +239,10 @@ float AnalogGyro::GetOffset() const {
*
* @return the current center value
*/
uint32_t AnalogGyro::GetCenter() const {
int AnalogGyro::GetCenter() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
uint32_t value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
int value = HAL_GetAnalogGyroCenter(m_gyroHandle, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}

View File

@@ -14,9 +14,9 @@
#include "Timer.h"
#include "WPIErrors.h"
const uint8_t AnalogInput::kAccumulatorModuleNumber;
const uint32_t AnalogInput::kAccumulatorNumChannels;
const uint32_t AnalogInput::kAccumulatorChannels[] = {0, 1};
const int AnalogInput::kAccumulatorModuleNumber;
const int AnalogInput::kAccumulatorNumChannels;
const int AnalogInput::kAccumulatorChannels[] = {0, 1};
/**
* Construct an analog input.
@@ -24,7 +24,7 @@ const uint32_t AnalogInput::kAccumulatorChannels[] = {0, 1};
* @param channel The channel number on the roboRIO to represent. 0-3 are
* on-board 4-7 are on the MXP port.
*/
AnalogInput::AnalogInput(uint32_t channel) {
AnalogInput::AnalogInput(int channel) {
std::stringstream buf;
buf << "Analog Input " << channel;
@@ -41,7 +41,7 @@ AnalogInput::AnalogInput(uint32_t channel) {
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumAnalogInputs(), channel,
HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
m_port = HAL_kInvalidHandle;
return;
}
@@ -67,10 +67,10 @@ AnalogInput::~AnalogInput() {
*
* @return A sample straight from this channel.
*/
int32_t AnalogInput::GetValue() const {
int AnalogInput::GetValue() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t value = HAL_GetAnalogValue(m_port, &status);
int value = HAL_GetAnalogValue(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -89,10 +89,10 @@ int32_t AnalogInput::GetValue() const {
*
* @return A sample from the oversample and average engine for this channel.
*/
int32_t AnalogInput::GetAverageValue() const {
int AnalogInput::GetAverageValue() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t value = HAL_GetAnalogAverageValue(m_port, &status);
int value = HAL_GetAnalogAverageValue(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -142,10 +142,10 @@ float AnalogInput::GetAverageVoltage() const {
*
* @return Least significant bit weight.
*/
int32_t AnalogInput::GetLSBWeight() const {
int AnalogInput::GetLSBWeight() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
int lsbWeight = HAL_GetAnalogLSBWeight(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return lsbWeight;
}
@@ -157,10 +157,10 @@ int32_t AnalogInput::GetLSBWeight() const {
*
* @return Offset constant.
*/
int32_t AnalogInput::GetOffset() const {
int AnalogInput::GetOffset() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t offset = HAL_GetAnalogOffset(m_port, &status);
int offset = HAL_GetAnalogOffset(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return offset;
}
@@ -170,7 +170,7 @@ int32_t AnalogInput::GetOffset() const {
*
* @return The channel number.
*/
uint32_t AnalogInput::GetChannel() const {
int AnalogInput::GetChannel() const {
if (StatusIsFatal()) return 0;
return m_channel;
}
@@ -186,7 +186,7 @@ uint32_t AnalogInput::GetChannel() const {
*
* @param bits Number of bits of averaging.
*/
void AnalogInput::SetAverageBits(int32_t bits) {
void AnalogInput::SetAverageBits(int bits) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetAnalogAverageBits(m_port, bits, &status);
@@ -201,9 +201,9 @@ void AnalogInput::SetAverageBits(int32_t bits) {
*
* @return Number of bits of averaging previously configured.
*/
int32_t AnalogInput::GetAverageBits() const {
int AnalogInput::GetAverageBits() const {
int32_t status = 0;
int32_t averageBits = HAL_GetAnalogAverageBits(m_port, &status);
int averageBits = HAL_GetAnalogAverageBits(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return averageBits;
}
@@ -218,7 +218,7 @@ int32_t AnalogInput::GetAverageBits() const {
*
* @param bits Number of bits of oversampling.
*/
void AnalogInput::SetOversampleBits(int32_t bits) {
void AnalogInput::SetOversampleBits(int bits) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetAnalogOversampleBits(m_port, bits, &status);
@@ -234,10 +234,10 @@ void AnalogInput::SetOversampleBits(int32_t bits) {
*
* @return Number of bits of oversampling previously configured.
*/
int32_t AnalogInput::GetOversampleBits() const {
int AnalogInput::GetOversampleBits() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status);
int oversampleBits = HAL_GetAnalogOversampleBits(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return oversampleBits;
}
@@ -309,7 +309,7 @@ void AnalogInput::ResetAccumulator() {
* source from the accumulator channel. Because of this, any non-zero
* oversample bits will affect the size of the value for this field.
*/
void AnalogInput::SetAccumulatorCenter(int32_t center) {
void AnalogInput::SetAccumulatorCenter(int center) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetAccumulatorCenter(m_port, center, &status);
@@ -319,7 +319,7 @@ void AnalogInput::SetAccumulatorCenter(int32_t center) {
/**
* Set the accumulator's deadband.
*/
void AnalogInput::SetAccumulatorDeadband(int32_t deadband) {
void AnalogInput::SetAccumulatorDeadband(int deadband) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetAccumulatorDeadband(m_port, deadband, &status);

View File

@@ -21,13 +21,13 @@
*
* @param channel The channel number on the roboRIO to represent.
*/
AnalogOutput::AnalogOutput(uint32_t channel) {
AnalogOutput::AnalogOutput(int channel) {
std::stringstream buf;
buf << "analog input " << channel;
if (!SensorBase::CheckAnalogOutputChannel(channel)) {
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
m_port = HAL_kInvalidHandle;
return;
}
@@ -40,7 +40,7 @@ AnalogOutput::AnalogOutput(uint32_t channel) {
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumAnalogOutputs(), channel,
HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
m_port = HAL_kInvalidHandle;
return;
}

View File

@@ -19,7 +19,7 @@
* @param channel The channel number on the roboRIO to represent. 0-3 are
* on-board 4-7 are on the MXP port.
*/
AnalogTrigger::AnalogTrigger(int32_t channel)
AnalogTrigger::AnalogTrigger(int channel)
: AnalogTrigger(new AnalogInput(channel)) {
m_ownsAnalog = true;
}
@@ -35,11 +35,11 @@ AnalogTrigger::AnalogTrigger(int32_t channel)
AnalogTrigger::AnalogTrigger(AnalogInput* input) {
m_analogInput = input;
int32_t status = 0;
int32_t index = 0;
int index = 0;
m_trigger = HAL_InitializeAnalogTrigger(input->m_port, &index, &status);
if (status != 0) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
m_index = std::numeric_limits<uint8_t>::max();
m_index = std::numeric_limits<int>::max();
m_trigger = HAL_kInvalidHandle;
return;
}
@@ -66,7 +66,7 @@ AnalogTrigger::~AnalogTrigger() {
* @param lower The lower limit of the trigger in ADC codes (12-bit values).
* @param upper The upper limit of the trigger in ADC codes (12-bit values).
*/
void AnalogTrigger::SetLimitsRaw(int32_t lower, int32_t upper) {
void AnalogTrigger::SetLimitsRaw(int lower, int upper) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetAnalogTriggerLimitsRaw(m_trigger, lower, upper, &status);
@@ -128,7 +128,7 @@ void AnalogTrigger::SetFiltered(bool useFilteredValue) {
*
* @return The index of the analog trigger.
*/
int32_t AnalogTrigger::GetIndex() const {
int AnalogTrigger::GetIndex() const {
if (StatusIsFatal()) return -1;
return m_index;
}

View File

@@ -73,4 +73,4 @@ AnalogTriggerType AnalogTriggerOutput::GetAnalogTriggerTypeForRouting() const {
/**
* @return The channel of the source.
*/
uint32_t AnalogTriggerOutput::GetChannel() const { return m_trigger.m_index; }
int AnalogTriggerOutput::GetChannel() const { return m_trigger.m_index; }

View File

@@ -12,6 +12,7 @@
#include "FRC_NetworkCommunication/CANSessionMux.h"
#include "HAL/HAL.h"
#include "LiveWindow/LiveWindow.h"
#include "Resource.h"
#include "Timer.h"
#include "WPIErrors.h"
@@ -27,20 +28,20 @@
#define FXP16_EQ(a, b) \
(static_cast<int32_t>((a)*65536.0) == static_cast<int32_t>((b)*65536.0))
const int32_t CANJaguar::kControllerRate;
const int CANJaguar::kControllerRate;
constexpr double CANJaguar::kApproxBusVoltage;
static const int32_t kSendMessagePeriod = 20;
static const uint32_t kFullMessageIDMask =
static const int kSendMessagePeriod = 20;
static const int kFullMessageIDMask =
(CAN_MSGID_API_M | CAN_MSGID_MFR_M | CAN_MSGID_DTYPE_M);
static const int32_t kReceiveStatusAttempts = 50;
static const int kReceiveStatusAttempts = 50;
static std::unique_ptr<Resource> allocated;
static int32_t sendMessageHelper(uint32_t messageID, const uint8_t* data,
uint8_t dataSize, int32_t period) {
static const uint32_t kTrustedMessages[] = {
static int sendMessageHelper(int messageID, const uint8_t* data,
uint8_t dataSize, int period) {
static const int kTrustedMessages[] = {
LM_API_VOLT_T_EN, LM_API_VOLT_T_SET, LM_API_SPD_T_EN, LM_API_SPD_T_SET,
LM_API_VCOMP_T_EN, LM_API_VCOMP_T_SET, LM_API_POS_T_EN, LM_API_POS_T_SET,
LM_API_ICTRL_T_EN, LM_API_ICTRL_T_SET};
@@ -56,7 +57,7 @@ static int32_t sendMessageHelper(uint32_t messageID, const uint8_t* data,
// Make sure the data will still fit after adjusting for the token.
assert(dataSize <= 6);
for (uint8_t j = 0; j < dataSize; j++) {
for (int j = 0; j < dataSize; j++) {
dataBuffer[j + 2] = data[j];
}
@@ -97,7 +98,7 @@ void CANJaguar::InitCANJaguar() {
if (!receivedFirmwareVersion &&
getMessage(CAN_MSGID_API_FIRMVER, CAN_MSGID_FULL_M, dataBuffer,
&dataSize)) {
m_firmwareVersion = unpackint32_t(dataBuffer);
m_firmwareVersion = unpackInt32(dataBuffer);
receivedFirmwareVersion = true;
}
@@ -180,7 +181,7 @@ void CANJaguar::InitCANJaguar() {
* @see CANJaguar#SetVoltageMode(EncoderTag, int)
* @see CANJaguar#SetVoltageMode(QuadEncoderTag, int)
*/
CANJaguar::CANJaguar(uint8_t deviceNumber) : m_deviceNumber(deviceNumber) {
CANJaguar::CANJaguar(int deviceNumber) : m_deviceNumber(deviceNumber) {
std::stringstream buf;
buf << "CANJaguar device number " << m_deviceNumber;
Resource::CreateResourceObject(allocated, 63);
@@ -229,7 +230,7 @@ CANJaguar::~CANJaguar() {
/**
* @return The CAN ID passed in the constructor
*/
uint8_t CANJaguar::getDeviceNumber() const { return m_deviceNumber; }
int CANJaguar::getDeviceNumber() const { return m_deviceNumber; }
/**
* Sets the output set-point value.
@@ -246,8 +247,8 @@ uint8_t CANJaguar::getDeviceNumber() const { return m_deviceNumber; }
* @param syncGroup The update group to add this Set() to, pending
* UpdateSyncGroup(). If 0, update immediately.
*/
void CANJaguar::Set(float outputValue, uint8_t syncGroup) {
uint32_t messageID;
void CANJaguar::Set(float outputValue, int syncGroup) {
int messageID;
uint8_t dataBuffer[8];
uint8_t dataSize;
@@ -344,30 +345,30 @@ void CANJaguar::PIDWrite(float output) {
}
}
uint8_t CANJaguar::packPercentage(uint8_t* buffer, double value) {
int CANJaguar::packPercentage(uint8_t* buffer, double value) {
int16_t intValue = static_cast<int16_t>(value * 32767.0);
*reinterpret_cast<int16_t*>(buffer) = swap16(intValue);
return sizeof(int16_t);
}
uint8_t CANJaguar::packFXP8_8(uint8_t* buffer, double value) {
int CANJaguar::packFXP8_8(uint8_t* buffer, double value) {
int16_t intValue = static_cast<int16_t>(value * 256.0);
*reinterpret_cast<int16_t*>(buffer) = swap16(intValue);
return sizeof(int16_t);
}
uint8_t CANJaguar::packFXP16_16(uint8_t* buffer, double value) {
int32_t intValue = static_cast<int32_t>(value * 65536.0);
int CANJaguar::packFXP16_16(uint8_t* buffer, double value) {
int intValue = static_cast<int>(value * 65536.0);
*reinterpret_cast<int32_t*>(buffer) = swap32(intValue);
return sizeof(int32_t);
}
uint8_t CANJaguar::packint16_t(uint8_t* buffer, int16_t value) {
int CANJaguar::packInt16(uint8_t* buffer, int16_t value) {
*reinterpret_cast<int16_t*>(buffer) = swap16(value);
return sizeof(int16_t);
}
uint8_t CANJaguar::packint32_t(uint8_t* buffer, int32_t value) {
int CANJaguar::packInt32(uint8_t* buffer, int32_t value) {
*reinterpret_cast<int32_t*>(buffer) = swap32(value);
return sizeof(int32_t);
}
@@ -385,17 +386,17 @@ double CANJaguar::unpackFXP8_8(uint8_t* buffer) const {
}
double CANJaguar::unpackFXP16_16(uint8_t* buffer) const {
int32_t value = *reinterpret_cast<int32_t*>(buffer);
int value = *reinterpret_cast<int*>(buffer);
value = swap32(value);
return value / 65536.0;
}
int16_t CANJaguar::unpackint16_t(uint8_t* buffer) const {
int16_t CANJaguar::unpackInt16(uint8_t* buffer) const {
int16_t value = *reinterpret_cast<int16_t*>(buffer);
return swap16(value);
}
int32_t CANJaguar::unpackint32_t(uint8_t* buffer) const {
int32_t CANJaguar::unpackInt32(uint8_t* buffer) const {
int32_t value = *reinterpret_cast<int32_t*>(buffer);
return swap32(value);
}
@@ -410,9 +411,9 @@ int32_t CANJaguar::unpackint32_t(uint8_t* buffer) const {
* @param periodic If positive, tell Network Communications to send the
* message every "period" milliseconds.
*/
void CANJaguar::sendMessage(uint32_t messageID, const uint8_t* data,
uint8_t dataSize, int32_t period) {
int32_t localStatus =
void CANJaguar::sendMessage(int messageID, const uint8_t* data,
uint8_t dataSize, int period) {
int localStatus =
sendMessageHelper(messageID | m_deviceNumber, data, dataSize, period);
if (localStatus < 0) {
@@ -427,7 +428,7 @@ void CANJaguar::sendMessage(uint32_t messageID, const uint8_t* data,
* @param periodic If positive, tell Network Communications to send the
* message every "period" milliseconds.
*/
void CANJaguar::requestMessage(uint32_t messageID, int32_t period) {
void CANJaguar::requestMessage(int messageID, int period) {
sendMessageHelper(messageID | m_deviceNumber, nullptr, 0, period);
}
@@ -444,8 +445,8 @@ void CANJaguar::requestMessage(uint32_t messageID, int32_t period) {
* @return true if the message was found. Otherwise, no new message is
* available.
*/
bool CANJaguar::getMessage(uint32_t messageID, uint32_t messageMask,
uint8_t* data, uint8_t* dataSize) const {
bool CANJaguar::getMessage(int messageID, uint32_t messageMask, uint8_t* data,
uint8_t* dataSize) const {
uint32_t targetedMessageID = messageID | m_deviceNumber;
int32_t status = 0;
uint32_t timeStamp;
@@ -490,7 +491,7 @@ void CANJaguar::setupPeriodicStatus() {
static const uint8_t kMessage2Data[] = {LM_PSTAT_LIMIT_CLR, LM_PSTAT_FAULT,
LM_PSTAT_END};
dataSize = packint16_t(data, kSendMessagePeriod);
dataSize = packInt16(data, kSendMessagePeriod);
sendMessage(LM_API_PSTAT_PER_EN_S0, data, dataSize);
sendMessage(LM_API_PSTAT_PER_EN_S1, data, dataSize);
sendMessage(LM_API_PSTAT_PER_EN_S2, data, dataSize);
@@ -638,7 +639,7 @@ void CANJaguar::verify() {
if (!m_speedRefVerified) {
if (getMessage(LM_API_SPD_REF, CAN_MSGID_FULL_M, dataBuffer, &dataSize)) {
uint8_t speedRef = dataBuffer[0];
int speedRef = dataBuffer[0];
if (m_speedReference == speedRef)
m_speedRefVerified = true;
@@ -653,7 +654,7 @@ void CANJaguar::verify() {
if (!m_posRefVerified) {
if (getMessage(LM_API_POS_REF, CAN_MSGID_FULL_M, dataBuffer, &dataSize)) {
uint8_t posRef = dataBuffer[0];
int posRef = dataBuffer[0];
if (m_positionReference == posRef)
m_posRefVerified = true;
@@ -667,7 +668,7 @@ void CANJaguar::verify() {
}
if (!m_pVerified) {
uint32_t message = 0;
int message = 0;
if (m_controlMode == kSpeed) {
message = LM_API_SPD_PC;
@@ -697,7 +698,7 @@ void CANJaguar::verify() {
}
if (!m_iVerified) {
uint32_t message = 0;
int message = 0;
if (m_controlMode == kSpeed) {
message = LM_API_SPD_IC;
@@ -727,7 +728,7 @@ void CANJaguar::verify() {
}
if (!m_dVerified) {
uint32_t message = 0;
int message = 0;
if (m_controlMode == kSpeed) {
message = LM_API_SPD_DC;
@@ -775,7 +776,7 @@ void CANJaguar::verify() {
if (!m_encoderCodesPerRevVerified) {
if (getMessage(LM_API_CFG_ENC_LINES, CAN_MSGID_FULL_M, dataBuffer,
&dataSize)) {
uint16_t codes = unpackint16_t(dataBuffer);
uint16_t codes = unpackInt16(dataBuffer);
if (codes == m_encoderCodesPerRev)
m_encoderCodesPerRevVerified = true;
@@ -791,7 +792,7 @@ void CANJaguar::verify() {
if (!m_potentiometerTurnsVerified) {
if (getMessage(LM_API_CFG_POT_TURNS, CAN_MSGID_FULL_M, dataBuffer,
&dataSize)) {
uint16_t turns = unpackint16_t(dataBuffer);
uint16_t turns = unpackInt16(dataBuffer);
if (turns == m_potentiometerTurns)
m_potentiometerTurnsVerified = true;
@@ -912,7 +913,7 @@ void CANJaguar::verify() {
if (!m_faultTimeVerified) {
if (getMessage(LM_API_CFG_FAULT_TIME, CAN_MSGID_FULL_M, dataBuffer,
&dataSize)) {
uint16_t faultTime = unpackint16_t(dataBuffer);
uint16_t faultTime = unpackInt16(dataBuffer);
if (static_cast<uint16_t>(m_faultTime * 1000.0) == faultTime) {
m_faultTimeVerified = true;
@@ -945,7 +946,7 @@ void CANJaguar::verify() {
*
* @param reference Specify a speed reference.
*/
void CANJaguar::SetSpeedReference(uint8_t reference) {
void CANJaguar::SetSpeedReference(int reference) {
uint8_t dataBuffer[8];
// Send the speed reference parameter
@@ -962,7 +963,7 @@ void CANJaguar::SetSpeedReference(uint8_t reference) {
* @return A speed reference indicating the currently selected reference device
* for speed controller mode.
*/
uint8_t CANJaguar::GetSpeedReference() const { return m_speedReference; }
int CANJaguar::GetSpeedReference() const { return m_speedReference; }
/**
* Set the reference source device for position controller mode.
@@ -972,7 +973,7 @@ uint8_t CANJaguar::GetSpeedReference() const { return m_speedReference; }
*
* @param reference Specify a PositionReference.
*/
void CANJaguar::SetPositionReference(uint8_t reference) {
void CANJaguar::SetPositionReference(int reference) {
uint8_t dataBuffer[8];
// Send the position reference parameter
@@ -989,7 +990,7 @@ void CANJaguar::SetPositionReference(uint8_t reference) {
* @return A PositionReference indicating the currently selected reference
* device for position controller mode.
*/
uint8_t CANJaguar::GetPositionReference() const { return m_positionReference; }
int CANJaguar::GetPositionReference() const { return m_positionReference; }
/**
* Set the P, I, and D constants for the closed loop modes.
@@ -1711,7 +1712,7 @@ uint16_t CANJaguar::GetFaults() const {
void CANJaguar::SetVoltageRampRate(double rampRate) {
uint8_t dataBuffer[8];
uint8_t dataSize;
uint32_t message;
int message;
switch (m_controlMode) {
case kPercentVbus:
@@ -1741,14 +1742,14 @@ void CANJaguar::SetVoltageRampRate(double rampRate) {
*
* @return The firmware version. 0 if the device did not respond.
*/
uint32_t CANJaguar::GetFirmwareVersion() const { return m_firmwareVersion; }
int CANJaguar::GetFirmwareVersion() const { return m_firmwareVersion; }
/**
* Get the version of the Jaguar hardware.
*
* @return The hardware version. 1: Jaguar, 2: Black Jaguar
*/
uint8_t CANJaguar::GetHardwareVersion() const { return m_hardwareVersion; }
int CANJaguar::GetHardwareVersion() const { return m_hardwareVersion; }
/**
* Configure what the controller does to the H-Bridge when neutral (not driving
@@ -1778,7 +1779,7 @@ void CANJaguar::ConfigEncoderCodesPerRev(uint16_t codesPerRev) {
uint8_t dataBuffer[8];
// Set the codes per revolution mode
packint16_t(dataBuffer, codesPerRev);
packInt16(dataBuffer, codesPerRev);
sendMessage(LM_API_CFG_ENC_LINES, dataBuffer, sizeof(uint16_t));
m_encoderCodesPerRev = codesPerRev;
@@ -1798,7 +1799,7 @@ void CANJaguar::ConfigPotentiometerTurns(uint16_t turns) {
uint8_t dataSize;
// Set the pot turns
dataSize = packint16_t(dataBuffer, turns);
dataSize = packInt16(dataBuffer, turns);
sendMessage(LM_API_CFG_POT_TURNS, dataBuffer, dataSize);
m_potentiometerTurns = turns;
@@ -1921,7 +1922,7 @@ void CANJaguar::ConfigFaultTime(float faultTime) {
faultTime = 3.0;
// Message takes ms
dataSize = packint16_t(dataBuffer, static_cast<int16_t>(faultTime * 1000.0));
dataSize = packInt16(dataBuffer, static_cast<int16_t>(faultTime * 1000.0));
sendMessage(LM_API_CFG_FAULT_TIME, dataBuffer, dataSize);
m_faultTime = faultTime;
@@ -1965,7 +1966,7 @@ void CANJaguar::GetDescription(std::ostringstream& desc) const {
desc << "CANJaguar ID " << m_deviceNumber;
}
uint8_t CANJaguar::GetDeviceID() const { return m_deviceNumber; }
int CANJaguar::GetDeviceID() const { return m_deviceNumber; }
/**
* Common interface for stopping the motor until the next Set() command

View File

@@ -31,7 +31,7 @@ const double kNativePwdUnitsPerRotation = 4096.0;
*/
const double kMinutesPer100msUnit = 1.0 / 600.0;
constexpr unsigned int CANTalon::kDelayForSolicitedSignalsUs;
constexpr int CANTalon::kDelayForSolicitedSignalsUs;
/**
* Constructor for the CANTalon device.
@@ -299,7 +299,7 @@ void CANTalon::SetF(double f) {
*
* @see SelectProfileSlot to choose between the two sets of gains.
*/
void CANTalon::SetIzone(unsigned iz) {
void CANTalon::SetIzone(int iz) {
CTR_Code status = m_impl->SetIzone(m_profile, iz);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -562,7 +562,7 @@ float CANTalon::GetTemperature() const {
* portion of the postion based on overflows).
*/
void CANTalon::SetPosition(double pos) {
int32_t nativePos = ScaleRotationsToNativeUnits(m_feedbackDevice, pos);
int nativePos = ScaleRotationsToNativeUnits(m_feedbackDevice, pos);
CTR_Code status = m_impl->SetSensorPosition(nativePos);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -580,7 +580,7 @@ void CANTalon::SetPosition(double pos) {
* When using quadrature, each unit is a quadrature edge (4X) mode.
*/
double CANTalon::GetPosition() const {
int32_t position;
int position;
CTR_Code status = m_impl->GetSensorPosition(position);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -642,7 +642,7 @@ int CANTalon::GetClosedLoopError() const {
* Units: mA for Curent closed loop.
* Talon Native Units for position and velocity.
*/
void CANTalon::SetAllowableClosedLoopErr(uint32_t allowableCloseLoopError) {
void CANTalon::SetAllowableClosedLoopErr(int allowableCloseLoopError) {
/* grab param enum */
CanTalonSRX::param_t param;
if (m_profile == 1) {
@@ -669,7 +669,7 @@ void CANTalon::SetAllowableClosedLoopErr(uint32_t allowableCloseLoopError) {
* would then equate to 20% of a rotation per 100ms, or 10 rotations per second.
*/
double CANTalon::GetSpeed() const {
int32_t speed;
int speed;
CTR_Code status = m_impl->GetSensorVelocity(speed);
if (status != CTR_OKAY) {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -1124,7 +1124,7 @@ void CANTalon::SetCloseLoopRampRate(double rampRate) {
/**
* @return The version of the firmware running on the Talon
*/
uint32_t CANTalon::GetFirmwareVersion() const {
int CANTalon::GetFirmwareVersion() const {
int firmwareVersion;
CTR_Code status = m_impl->RequestParam(CanTalonSRX::eFirmVers);
if (status != CTR_OKAY) {
@@ -1378,7 +1378,7 @@ void CANTalon::ConfigLimitMode(LimitMode mode) {
*/
void CANTalon::ConfigForwardLimit(double forwardLimitPosition) {
CTR_Code status = CTR_OKAY;
int32_t nativeLimitPos =
int nativeLimitPos =
ScaleRotationsToNativeUnits(m_feedbackDevice, forwardLimitPosition);
status = m_impl->SetForwardSoftLimit(nativeLimitPos);
if (status != CTR_OKAY) {
@@ -1459,7 +1459,7 @@ void CANTalon::ConfigRevLimitSwitchNormallyOpen(bool normallyOpen) {
*/
void CANTalon::ConfigReverseLimit(double reverseLimitPosition) {
CTR_Code status = CTR_OKAY;
int32_t nativeLimitPos =
int nativeLimitPos =
ScaleRotationsToNativeUnits(m_feedbackDevice, reverseLimitPosition);
status = m_impl->SetReverseSoftLimit(nativeLimitPos);
if (status != CTR_OKAY) {
@@ -1514,7 +1514,7 @@ void CANTalon::ConfigNominalOutputVoltage(double forwardVoltage,
* General set frame. Since the parameter is a general integral type, this can
* be used for testing future features.
*/
void CANTalon::ConfigSetParameter(uint32_t paramEnum, double value) {
void CANTalon::ConfigSetParameter(int paramEnum, double value) {
CTR_Code status;
/* config peak throttle when in closed-loop mode in the positive direction. */
status = m_impl->SetParam((CanTalonSRX::param_t)paramEnum, value);
@@ -1527,7 +1527,7 @@ void CANTalon::ConfigSetParameter(uint32_t paramEnum, double value) {
* General get frame. Since the parameter is a general integral type, this can
* be used for testing future features.
*/
bool CANTalon::GetParameter(uint32_t paramEnum, double& dvalue) const {
bool CANTalon::GetParameter(int paramEnum, double& dvalue) const {
bool retval = true;
/* send the request frame */
CTR_Code status = m_impl->RequestParam((CanTalonSRX::param_t)paramEnum);
@@ -1658,7 +1658,7 @@ double CANTalon::GetNativeUnitsPerRotationScalar(
* that the calling app does not require knowing the CPR at all. So do
* both checks here.
*/
int32_t qeiPulsePerCount = 4; /* default to 4x */
int qeiPulsePerCount = 4; /* default to 4x */
switch (m_feedbackDevice) {
case CtreMagEncoder_Relative:
case CtreMagEncoder_Absolute:
@@ -1747,14 +1747,14 @@ double CANTalon::GetNativeUnitsPerRotationScalar(
* @see ConfigEncoderCodesPerRev
* @return fullRotations in native engineering units of the Talon SRX firmware.
*/
int32_t CANTalon::ScaleRotationsToNativeUnits(FeedbackDevice devToLookup,
double fullRotations) const {
int CANTalon::ScaleRotationsToNativeUnits(FeedbackDevice devToLookup,
double fullRotations) const {
/* first assume we don't have config info, prep the default return */
int32_t retval = static_cast<int32_t>(fullRotations);
int retval = static_cast<int>(fullRotations);
/* retrieve scaling info */
double scalar = GetNativeUnitsPerRotationScalar(devToLookup);
/* apply scalar if its available */
if (scalar > 0) retval = static_cast<int32_t>(fullRotations * scalar);
if (scalar > 0) retval = static_cast<int>(fullRotations * scalar);
return retval;
}
@@ -1769,15 +1769,15 @@ int32_t CANTalon::ScaleRotationsToNativeUnits(FeedbackDevice devToLookup,
* @return sensor velocity in native engineering units of the Talon SRX
* firmware.
*/
int32_t CANTalon::ScaleVelocityToNativeUnits(FeedbackDevice devToLookup,
double rpm) const {
int CANTalon::ScaleVelocityToNativeUnits(FeedbackDevice devToLookup,
double rpm) const {
/* first assume we don't have config info, prep the default return */
int32_t retval = static_cast<int32_t>(rpm);
int retval = static_cast<int>(rpm);
/* retrieve scaling info */
double scalar = GetNativeUnitsPerRotationScalar(devToLookup);
/* apply scalar if its available */
if (scalar > 0) {
retval = static_cast<int32_t>(rpm * kMinutesPer100msUnit * scalar);
retval = static_cast<int>(rpm * kMinutesPer100msUnit * scalar);
}
return retval;
}
@@ -1793,7 +1793,7 @@ int32_t CANTalon::ScaleVelocityToNativeUnits(FeedbackDevice devToLookup,
* performed.
*/
double CANTalon::ScaleNativeUnitsToRotations(FeedbackDevice devToLookup,
int32_t nativePos) const {
int nativePos) const {
/* first assume we don't have config info, prep the default return */
double retval = static_cast<double>(nativePos);
/* retrieve scaling info */
@@ -1814,7 +1814,7 @@ double CANTalon::ScaleNativeUnitsToRotations(FeedbackDevice devToLookup,
* performed.
*/
double CANTalon::ScaleNativeUnitsToRpm(FeedbackDevice devToLookup,
int32_t nativeVel) const {
int nativeVel) const {
/* first assume we don't have config info, prep the default return */
double retval = static_cast<double>(nativeVel);
/* retrieve scaling info */
@@ -1891,15 +1891,13 @@ int CANTalon::GetMotionProfileTopLevelBufferCount() {
*/
bool CANTalon::PushMotionProfileTrajectory(const TrajectoryPoint& trajPt) {
/* convert positiona and velocity to native units */
int32_t targPos =
ScaleRotationsToNativeUnits(m_feedbackDevice, trajPt.position);
int32_t targVel =
ScaleVelocityToNativeUnits(m_feedbackDevice, trajPt.velocity);
int targPos = ScaleRotationsToNativeUnits(m_feedbackDevice, trajPt.position);
int targVel = ScaleVelocityToNativeUnits(m_feedbackDevice, trajPt.velocity);
/* bounds check signals that require it */
uint32_t profileSlotSelect = (trajPt.profileSlotSelect) ? 1 : 0;
uint8_t timeDurMs = (trajPt.timeDurMs >= 255)
? 255
: trajPt.timeDurMs; /* cap time to 255ms */
int profileSlotSelect = (trajPt.profileSlotSelect) ? 1 : 0;
int timeDurMs = (trajPt.timeDurMs >= 255)
? 255
: trajPt.timeDurMs; /* cap time to 255ms */
/* send it to the top level buffer */
CTR_Code status = m_impl->PushMotionProfileTrajectory(
targPos, targVel, profileSlotSelect, timeDurMs, trajPt.velocityOnly,
@@ -1939,7 +1937,7 @@ void CANTalon::GetMotionProfileStatus(
MotionProfileStatus& motionProfileStatus) {
uint32_t flags;
uint32_t profileSlotSelect;
int32_t targPos, targVel;
int targPos, targVel;
uint32_t topBufferRem, topBufferCnt, btmBufferCnt;
uint32_t outputEnable;
/* retrieve all motion profile signals from status frame */

View File

@@ -40,7 +40,7 @@ CameraServer::CameraServer()
}
void CameraServer::FreeImageData(
std::tuple<uint8_t*, unsigned int, unsigned int, bool> imageData) {
std::tuple<uint8_t*, int, int, bool> imageData) {
if (std::get<3>(imageData)) {
imaqDispose(std::get<0>(imageData));
} else if (std::get<0>(imageData) != nullptr) {
@@ -49,8 +49,8 @@ void CameraServer::FreeImageData(
}
}
void CameraServer::SetImageData(uint8_t* data, unsigned int size,
unsigned int start, bool imaqData) {
void CameraServer::SetImageData(uint8_t* data, int size, int start,
bool imaqData) {
std::lock_guard<priority_recursive_mutex> lock(m_imageMutex);
FreeImageData(m_imageData);
m_imageData = std::make_tuple(data, size, start, imaqData);
@@ -58,7 +58,7 @@ void CameraServer::SetImageData(uint8_t* data, unsigned int size,
}
void CameraServer::SetImage(Image const* image) {
unsigned int dataSize = 0;
uint32_t dataSize = 0;
uint8_t* data = reinterpret_cast<uint8_t*>(
imaqFlatten(image, IMAQ_FLATTEN_IMAGE, IMAQ_COMPRESSION_JPEG,
10 * m_quality, &dataSize));
@@ -70,7 +70,7 @@ void CameraServer::SetImage(Image const* image) {
std::lock_guard<priority_recursive_mutex> lock(m_imageMutex);
hwClient = m_hwClient;
}
unsigned int start = 0;
uint32_t start = 0;
if (hwClient) {
while (start < dataSize - 1) {
if (data[start] == 0xFF && data[start + 1] == 0xD8)
@@ -101,7 +101,7 @@ void CameraServer::AutoCapture() {
}
if (hwClient) {
unsigned int size = m_camera->GetImageData(data, kMaxImageSize);
int size = m_camera->GetImageData(data, kMaxImageSize);
SetImageData(data, size);
} else {
m_camera->GetImage(frame);
@@ -134,7 +134,7 @@ bool CameraServer::IsAutoCaptureStarted() {
return m_autoCaptureStarted;
}
void CameraServer::SetSize(unsigned int size) {
void CameraServer::SetSize(int size) {
std::lock_guard<priority_recursive_mutex> lock(m_imageMutex);
if (!m_camera) return;
if (size == kSize160x120)
@@ -145,12 +145,12 @@ void CameraServer::SetSize(unsigned int size) {
m_camera->SetSize(640, 480);
}
void CameraServer::SetQuality(unsigned int quality) {
void CameraServer::SetQuality(int quality) {
std::lock_guard<priority_recursive_mutex> lock(m_imageMutex);
m_quality = quality > 100 ? 100 : quality;
}
unsigned int CameraServer::GetQuality() {
int CameraServer::GetQuality() {
std::lock_guard<priority_recursive_mutex> lock(m_imageMutex);
return m_quality;
}
@@ -238,7 +238,7 @@ void CameraServer::Serve() {
auto period = std::chrono::microseconds(1000000) / req.fps;
while (true) {
auto startTime = std::chrono::steady_clock::now();
std::tuple<uint8_t*, unsigned int, unsigned int, bool> imageData;
std::tuple<uint8_t*, int, int, bool> imageData;
{
std::unique_lock<priority_recursive_mutex> lock(m_imageMutex);
m_newImageVariable.wait(lock);
@@ -246,9 +246,9 @@ void CameraServer::Serve() {
m_imageData = std::make_tuple<uint8_t*>(nullptr, 0, 0, false);
}
unsigned int size = std::get<1>(imageData);
unsigned int netSize = htonl(size);
unsigned int start = std::get<2>(imageData);
int size = std::get<1>(imageData);
int netSize = htonl(size);
int start = std::get<2>(imageData);
uint8_t* data = std::get<0>(imageData);
if (data == nullptr) continue;

View File

@@ -15,7 +15,7 @@
*
* @param module The PCM ID to use (0-62)
*/
Compressor::Compressor(uint8_t pcmID) : m_module(pcmID) {
Compressor::Compressor(int pcmID) : m_module(pcmID) {
int32_t status = 0;
m_compressorHandle = HAL_InitializeCompressor(m_module, &status);
if (status != 0) {

View File

@@ -80,7 +80,7 @@ Counter::Counter(std::shared_ptr<DigitalSource> source) : Counter(kTwoPulse) {
* @param channel The DIO channel to use as the up source. 0-9 are on-board,
* 10-25 are on the MXP
*/
Counter::Counter(int32_t channel) : Counter(kTwoPulse) {
Counter::Counter(int channel) : Counter(kTwoPulse) {
SetUpSource(channel);
ClearDownSource();
}
@@ -190,7 +190,7 @@ Counter::~Counter() {
* @param channel The DIO channel to use as the up source. 0-9 are on-board,
* 10-25 are on the MXP
*/
void Counter::SetUpSource(int32_t channel) {
void Counter::SetUpSource(int channel) {
if (StatusIsFatal()) return;
SetUpSource(std::make_shared<DigitalInput>(channel));
}
@@ -296,7 +296,7 @@ void Counter::ClearUpSource() {
* @param channel The DIO channel to use as the up source. 0-9 are on-board,
* 10-25 are on the MXP
*/
void Counter::SetDownSource(int32_t channel) {
void Counter::SetDownSource(int channel) {
if (StatusIsFatal()) return;
SetDownSource(std::make_shared<DigitalInput>(channel));
}
@@ -462,7 +462,7 @@ void Counter::SetPulseLengthMode(float threshold) {
*/
int Counter::GetSamplesToAverage() const {
int32_t status = 0;
int32_t samples = HAL_GetCounterSamplesToAverage(m_counter, &status);
int samples = HAL_GetCounterSamplesToAverage(m_counter, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return samples;
}
@@ -491,10 +491,10 @@ void Counter::SetSamplesToAverage(int samplesToAverage) {
* Read the value at this instant. It may still be running, so it reflects the
* current value. Next time it is read, it might have a different value.
*/
int32_t Counter::Get() const {
int Counter::Get() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t value = HAL_GetCounter(m_counter, &status);
int value = HAL_GetCounter(m_counter, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}

View File

@@ -146,7 +146,7 @@ void DigitalGlitchFilter::Remove(Counter* input) {
*
* @param fpga_cycles The number of FPGA cycles.
*/
void DigitalGlitchFilter::SetPeriodCycles(uint32_t fpga_cycles) {
void DigitalGlitchFilter::SetPeriodCycles(int fpga_cycles) {
int32_t status = 0;
HAL_SetFilterPeriod(m_channelIndex, fpga_cycles, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -159,7 +159,7 @@ void DigitalGlitchFilter::SetPeriodCycles(uint32_t fpga_cycles) {
*/
void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) {
int32_t status = 0;
uint32_t fpga_cycles =
int fpga_cycles =
nanoseconds * HAL_GetSystemClockTicksPerMicrosecond() / 4 / 1000;
HAL_SetFilterPeriod(m_channelIndex, fpga_cycles, &status);
@@ -171,9 +171,9 @@ void DigitalGlitchFilter::SetPeriodNanoSeconds(uint64_t nanoseconds) {
*
* @return The number of cycles.
*/
uint32_t DigitalGlitchFilter::GetPeriodCycles() {
int DigitalGlitchFilter::GetPeriodCycles() {
int32_t status = 0;
uint32_t fpga_cycles = HAL_GetFilterPeriod(m_channelIndex, &status);
int fpga_cycles = HAL_GetFilterPeriod(m_channelIndex, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -187,7 +187,7 @@ uint32_t DigitalGlitchFilter::GetPeriodCycles() {
*/
uint64_t DigitalGlitchFilter::GetPeriodNanoSeconds() {
int32_t status = 0;
uint32_t fpga_cycles = HAL_GetFilterPeriod(m_channelIndex, &status);
int fpga_cycles = HAL_GetFilterPeriod(m_channelIndex, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));

View File

@@ -21,13 +21,13 @@
*
* @param channel The DIO channel 0-9 are on-board, 10-25 are on the MXP port
*/
DigitalInput::DigitalInput(uint32_t channel) {
DigitalInput::DigitalInput(int channel) {
std::stringstream buf;
if (!CheckDigitalChannel(channel)) {
buf << "Digital Channel " << channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
return;
}
m_channel = channel;
@@ -38,7 +38,7 @@ DigitalInput::DigitalInput(uint32_t channel) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumDigitalChannels(),
channel, HAL_GetErrorMessage(status));
m_handle = HAL_kInvalidHandle;
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
return;
}
@@ -77,7 +77,7 @@ bool DigitalInput::Get() const {
/**
* @return The GPIO channel number that this object represents.
*/
uint32_t DigitalInput::GetChannel() const { return m_channel; }
int DigitalInput::GetChannel() const { return m_channel; }
/**
* @return The HAL Handle to the specified source.

View File

@@ -21,14 +21,14 @@
* @param channel The digital channel 0-9 are on-board, 10-25 are on the MXP
* port
*/
DigitalOutput::DigitalOutput(uint32_t channel) {
DigitalOutput::DigitalOutput(int channel) {
std::stringstream buf;
m_pwmGenerator = HAL_kInvalidHandle;
if (!CheckDigitalChannel(channel)) {
buf << "Digital Channel " << channel;
wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf.str());
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
return;
}
m_channel = channel;
@@ -38,7 +38,7 @@ DigitalOutput::DigitalOutput(uint32_t channel) {
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumDigitalChannels(),
channel, HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
m_handle = HAL_kInvalidHandle;
return;
}
@@ -78,7 +78,7 @@ void DigitalOutput::Set(bool value) {
*
* @return the state of the digital output.
*/
bool DigitalOutput::Get() {
bool DigitalOutput::Get() const {
if (StatusIsFatal()) return false;
int32_t status = 0;
@@ -90,7 +90,7 @@ bool DigitalOutput::Get() {
/**
* @return The GPIO channel number that this object represents.
*/
uint32_t DigitalOutput::GetChannel() const { return m_channel; }
int DigitalOutput::GetChannel() const { return m_channel; }
/**
* Output a single pulse on the digital output line.

View File

@@ -21,7 +21,7 @@
* @param forwardChannel The forward channel number on the PCM (0..7).
* @param reverseChannel The reverse channel number on the PCM (0..7).
*/
DoubleSolenoid::DoubleSolenoid(uint32_t forwardChannel, uint32_t reverseChannel)
DoubleSolenoid::DoubleSolenoid(int forwardChannel, int reverseChannel)
: DoubleSolenoid(GetDefaultSolenoidModule(), forwardChannel,
reverseChannel) {}
@@ -32,8 +32,8 @@ DoubleSolenoid::DoubleSolenoid(uint32_t forwardChannel, uint32_t reverseChannel)
* @param forwardChannel The forward channel on the PCM to control (0..7).
* @param reverseChannel The reverse channel on the PCM to control (0..7).
*/
DoubleSolenoid::DoubleSolenoid(uint8_t moduleNumber, uint32_t forwardChannel,
uint32_t reverseChannel)
DoubleSolenoid::DoubleSolenoid(int moduleNumber, int forwardChannel,
int reverseChannel)
: SolenoidBase(moduleNumber),
m_forwardChannel(forwardChannel),
m_reverseChannel(reverseChannel) {
@@ -120,9 +120,9 @@ void DoubleSolenoid::Set(Value value) {
reverse = true;
break;
}
int32_t fstatus = 0;
int fstatus = 0;
HAL_SetSolenoid(m_forwardHandle, forward, &fstatus);
int32_t rstatus = 0;
int rstatus = 0;
HAL_SetSolenoid(m_reverseHandle, reverse, &rstatus);
wpi_setErrorWithContext(fstatus, HAL_GetErrorMessage(fstatus));
@@ -136,8 +136,8 @@ void DoubleSolenoid::Set(Value value) {
*/
DoubleSolenoid::Value DoubleSolenoid::Get() const {
if (StatusIsFatal()) return kOff;
int32_t fstatus = 0;
int32_t rstatus = 0;
int fstatus = 0;
int rstatus = 0;
bool valueForward = HAL_GetSolenoid(m_forwardHandle, &fstatus);
bool valueReverse = HAL_GetSolenoid(m_reverseHandle, &rstatus);

View File

@@ -17,7 +17,7 @@
const double JOYSTICK_UNPLUGGED_MESSAGE_INTERVAL = 1.0;
const uint32_t DriverStation::kJoystickPorts;
const int DriverStation::kJoystickPorts;
DriverStation::~DriverStation() {
m_isRunning = false;
@@ -74,7 +74,7 @@ void DriverStation::ReportError(bool is_error, int32_t code,
* @param axis The analog axis value to read from the joystick.
* @return The value of the axis on the joystick.
*/
float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis) {
float DriverStation::GetStickAxis(int stick, int axis) {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return 0;
@@ -100,7 +100,7 @@ float DriverStation::GetStickAxis(uint32_t stick, uint32_t axis) {
*
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
*/
int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
int DriverStation::GetStickPOV(int stick, int pov) {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return -1;
@@ -126,7 +126,7 @@ int DriverStation::GetStickPOV(uint32_t stick, uint32_t pov) {
* @param stick The joystick to read.
* @return The state of the buttons on the joystick.
*/
uint32_t DriverStation::GetStickButtons(uint32_t stick) const {
int DriverStation::GetStickButtons(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return 0;
@@ -142,7 +142,7 @@ uint32_t DriverStation::GetStickButtons(uint32_t stick) const {
* @param button The button index, beginning at 1.
* @return The state of the joystick button.
*/
bool DriverStation::GetStickButton(uint32_t stick, uint8_t button) {
bool DriverStation::GetStickButton(int stick, int button) {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return false;
@@ -171,7 +171,7 @@ bool DriverStation::GetStickButton(uint32_t stick, uint8_t button) {
* @param stick The joystick port number
* @return The number of axes on the indicated joystick
*/
int DriverStation::GetStickAxisCount(uint32_t stick) const {
int DriverStation::GetStickAxisCount(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return 0;
@@ -186,7 +186,7 @@ int DriverStation::GetStickAxisCount(uint32_t stick) const {
* @param stick The joystick port number
* @return The number of POVs on the indicated joystick
*/
int DriverStation::GetStickPOVCount(uint32_t stick) const {
int DriverStation::GetStickPOVCount(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return 0;
@@ -201,7 +201,7 @@ int DriverStation::GetStickPOVCount(uint32_t stick) const {
* @param stick The joystick port number
* @return The number of buttons on the indicated joystick
*/
int DriverStation::GetStickButtonCount(uint32_t stick) const {
int DriverStation::GetStickButtonCount(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return 0;
@@ -216,7 +216,7 @@ int DriverStation::GetStickButtonCount(uint32_t stick) const {
* @param stick The joystick port number
* @return A boolean that is true if the controller is an xbox controller.
*/
bool DriverStation::GetJoystickIsXbox(uint32_t stick) const {
bool DriverStation::GetJoystickIsXbox(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return false;
@@ -231,7 +231,7 @@ bool DriverStation::GetJoystickIsXbox(uint32_t stick) const {
* @param stick The joystick port number
* @return The HID type of joystick at the given port
*/
int DriverStation::GetJoystickType(uint32_t stick) const {
int DriverStation::GetJoystickType(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return -1;
@@ -246,7 +246,7 @@ int DriverStation::GetJoystickType(uint32_t stick) const {
* @param stick The joystick port number
* @return The name of the joystick at the given port
*/
std::string DriverStation::GetJoystickName(uint32_t stick) const {
std::string DriverStation::GetJoystickName(int stick) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
}
@@ -261,7 +261,7 @@ std::string DriverStation::GetJoystickName(uint32_t stick) const {
* @param stick The joystick port number and the target axis
* @return What type of axis the axis is reporting to be
*/
int DriverStation::GetJoystickAxisType(uint32_t stick, uint8_t axis) const {
int DriverStation::GetJoystickAxisType(int stick, int axis) const {
if (stick >= kJoystickPorts) {
wpi_setWPIError(BadJoystickIndex);
return -1;
@@ -419,7 +419,7 @@ DriverStation::Alliance DriverStation::GetAlliance() const {
*
* @return The location of the driver station (1-3, 0 for invalid)
*/
uint32_t DriverStation::GetLocation() const {
int DriverStation::GetLocation() const {
int32_t status = 0;
auto allianceStationID = HAL_GetAllianceStation(&status);
switch (allianceStationID) {

View File

@@ -68,7 +68,7 @@ void Encoder::InitEncoder(bool reverseDirection, EncodingType encodingType) {
* value will either exactly match the spec'd count or
* be double (2x) the spec'd count.
*/
Encoder::Encoder(uint32_t aChannel, uint32_t bChannel, bool reverseDirection,
Encoder::Encoder(int aChannel, int bChannel, bool reverseDirection,
EncodingType encodingType) {
m_aSource = std::make_shared<DigitalInput>(aChannel);
m_bSource = std::make_shared<DigitalInput>(bChannel);
@@ -164,9 +164,9 @@ Encoder::~Encoder() {
*
* Used to divide raw edge counts down to spec'd counts.
*/
int32_t Encoder::GetEncodingScale() const {
int Encoder::GetEncodingScale() const {
int32_t status = 0;
int32_t val = HAL_GetEncoderEncodingScale(m_encoder, &status);
int val = HAL_GetEncoderEncodingScale(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return val;
}
@@ -179,10 +179,10 @@ int32_t Encoder::GetEncodingScale() const {
*
* @return Current raw count from the encoder
*/
int32_t Encoder::GetRaw() const {
int Encoder::GetRaw() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t value = HAL_GetEncoderRaw(m_encoder, &status);
int value = HAL_GetEncoderRaw(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -196,10 +196,10 @@ int32_t Encoder::GetRaw() const {
* @return Current count from the Encoder adjusted for the 1x, 2x, or 4x scale
* factor.
*/
int32_t Encoder::Get() const {
int Encoder::Get() const {
if (StatusIsFatal()) return 0;
int32_t status = 0;
int32_t value = HAL_GetEncoder(m_encoder, &status);
int value = HAL_GetEncoder(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -445,7 +445,7 @@ double Encoder::PIDGet() {
* @param channel A DIO channel to set as the encoder index
* @param type The state that will cause the encoder to reset
*/
void Encoder::SetIndexSource(uint32_t channel, Encoder::IndexingType type) {
void Encoder::SetIndexSource(int channel, Encoder::IndexingType type) {
// Force digital input if just given an index
m_indexSource = std::make_unique<DigitalInput>(channel);
SetIndexSource(m_indexSource.get(), type);
@@ -483,9 +483,9 @@ void Encoder::SetIndexSource(const DigitalSource& source,
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
int32_t Encoder::GetFPGAIndex() const {
int Encoder::GetFPGAIndex() const {
int32_t status = 0;
int32_t val = HAL_GetEncoderFPGAIndex(m_encoder, &status);
int val = HAL_GetEncoderFPGAIndex(m_encoder, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return val;
}

View File

@@ -27,8 +27,7 @@ void GearTooth::EnableDirectionSensing(bool directionSensitive) {
* @param directionSensitive True to enable the pulse length decoding in
* hardware to specify count direction.
*/
GearTooth::GearTooth(uint32_t channel, bool directionSensitive)
: Counter(channel) {
GearTooth::GearTooth(int channel, bool directionSensitive) : Counter(channel) {
EnableDirectionSensing(directionSensitive);
LiveWindow::GetInstance()->AddSensor("GearTooth", channel, this);
}

View File

@@ -15,7 +15,7 @@
* @param port The I2C port to which the device is connected.
* @param deviceAddress The address of the device on the I2C bus.
*/
I2C::I2C(Port port, uint8_t deviceAddress)
I2C::I2C(Port port, int deviceAddress)
: m_port(port), m_deviceAddress(deviceAddress) {
int32_t status = 0;
HAL_InitializeI2C(m_port, &status);
@@ -41,8 +41,8 @@ I2C::~I2C() { HAL_CloseI2C(m_port); }
* @param receiveSize Number of bytes to read from the device.
* @return Transfer Aborted... false for success, true for aborted.
*/
bool I2C::Transaction(uint8_t* dataToSend, uint8_t sendSize,
uint8_t* dataReceived, uint8_t receiveSize) {
bool I2C::Transaction(uint8_t* dataToSend, int sendSize, uint8_t* dataReceived,
int receiveSize) {
int32_t status = 0;
status = HAL_TransactionI2C(m_port, m_deviceAddress, dataToSend, sendSize,
dataReceived, receiveSize);
@@ -71,13 +71,13 @@ bool I2C::AddressOnly() { return Transaction(nullptr, 0, nullptr, 0); }
* @param data The byte to write to the register on the device.
* @return Transfer Aborted... false for success, true for aborted.
*/
bool I2C::Write(uint8_t registerAddress, uint8_t data) {
bool I2C::Write(int registerAddress, uint8_t data) {
uint8_t buffer[2];
buffer[0] = registerAddress;
buffer[1] = data;
int32_t status = 0;
status = HAL_WriteI2C(m_port, m_deviceAddress, buffer, sizeof(buffer));
return status < static_cast<int32_t>(sizeof(buffer));
return status < static_cast<int>(sizeof(buffer));
}
/**
@@ -90,7 +90,7 @@ bool I2C::Write(uint8_t registerAddress, uint8_t data) {
* @param count The number of bytes to be written.
* @return Transfer Aborted... false for success, true for aborted.
*/
bool I2C::WriteBulk(uint8_t* data, uint8_t count) {
bool I2C::WriteBulk(uint8_t* data, int count) {
int32_t status = 0;
status = HAL_WriteI2C(m_port, m_deviceAddress, data, count);
return status < count;
@@ -109,7 +109,7 @@ bool I2C::WriteBulk(uint8_t* data, uint8_t count) {
* read from the device.
* @return Transfer Aborted... false for success, true for aborted.
*/
bool I2C::Read(uint8_t registerAddress, uint8_t count, uint8_t* buffer) {
bool I2C::Read(int registerAddress, int count, uint8_t* buffer) {
if (count < 1) {
wpi_setWPIErrorWithContext(ParameterOutOfRange, "count");
return true;
@@ -118,7 +118,8 @@ bool I2C::Read(uint8_t registerAddress, uint8_t count, uint8_t* buffer) {
wpi_setWPIErrorWithContext(NullParameter, "buffer");
return true;
}
return Transaction(&registerAddress, sizeof(registerAddress), buffer, count);
return Transaction(reinterpret_cast<uint8_t*>(&registerAddress),
sizeof(registerAddress), buffer, count);
}
/**
@@ -132,7 +133,7 @@ bool I2C::Read(uint8_t registerAddress, uint8_t count, uint8_t* buffer) {
* @param count The number of bytes to read in the transaction.
* @return Transfer Aborted... false for success, true for aborted.
*/
bool I2C::ReadOnly(uint8_t count, uint8_t* buffer) {
bool I2C::ReadOnly(int count, uint8_t* buffer) {
if (count < 1) {
wpi_setWPIErrorWithContext(ParameterOutOfRange, "count");
return true;
@@ -155,7 +156,7 @@ bool I2C::ReadOnly(uint8_t count, uint8_t* buffer) {
* @param data The value to write to the devices.
*/
[[gnu::warning("I2C::Broadcast() is not implemented.")]] void I2C::Broadcast(
uint8_t registerAddress, uint8_t data) {}
int registerAddress, uint8_t data) {}
/**
* Verify that a device's registers contain expected values.
@@ -172,17 +173,17 @@ bool I2C::ReadOnly(uint8_t count, uint8_t* buffer) {
* @param expected A buffer containing the values expected from the
* device.
*/
bool I2C::VerifySensor(uint8_t registerAddress, uint8_t count,
bool I2C::VerifySensor(int registerAddress, int count,
const uint8_t* expected) {
// TODO: Make use of all 7 read bytes
uint8_t deviceData[4];
for (uint8_t i = 0, curRegisterAddress = registerAddress; i < count;
for (int i = 0, curRegisterAddress = registerAddress; i < count;
i += 4, curRegisterAddress += 4) {
uint8_t toRead = count - i < 4 ? count - i : 4;
int toRead = count - i < 4 ? count - i : 4;
// Read the chunk of data. Return false if the sensor does not respond.
if (Read(curRegisterAddress, toRead, deviceData)) return false;
for (uint8_t j = 0; j < toRead; j++) {
for (int j = 0; j < toRead; j++) {
if (deviceData[j] != expected[i + j]) return false;
}
}

View File

@@ -101,7 +101,7 @@ InterruptableSensorBase::WaitResult InterruptableSensorBase::WaitForInterrupt(
if (StatusIsFatal()) return InterruptableSensorBase::kTimeout;
wpi_assert(m_interrupt != HAL_kInvalidHandle);
int32_t status = 0;
uint32_t result;
int result;
result = HAL_WaitForInterrupt(m_interrupt, timeout, ignorePrevious, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));

View File

@@ -15,7 +15,7 @@
* @param channel The PWM channel that the Jaguar is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
Jaguar::Jaguar(uint32_t channel) : PWMSpeedController(channel) {
Jaguar::Jaguar(int channel) : PWMSpeedController(channel) {
/**
* Input profile defined by Luminary Micro.
*

View File

@@ -11,13 +11,13 @@
#include "DriverStation.h"
#include "WPIErrors.h"
const uint32_t Joystick::kDefaultXAxis;
const uint32_t Joystick::kDefaultYAxis;
const uint32_t Joystick::kDefaultZAxis;
const uint32_t Joystick::kDefaultTwistAxis;
const uint32_t Joystick::kDefaultThrottleAxis;
const uint32_t Joystick::kDefaultTriggerButton;
const uint32_t Joystick::kDefaultTopButton;
const int Joystick::kDefaultXAxis;
const int Joystick::kDefaultYAxis;
const int Joystick::kDefaultZAxis;
const int Joystick::kDefaultTwistAxis;
const int Joystick::kDefaultThrottleAxis;
const int Joystick::kDefaultTriggerButton;
const int Joystick::kDefaultTopButton;
static Joystick* joysticks[DriverStation::kJoystickPorts];
static bool joySticksInitialized = false;
@@ -29,8 +29,7 @@ static bool joySticksInitialized = false;
* @param port The port on the driver station that the joystick is plugged into
* (0-5).
*/
Joystick::Joystick(uint32_t port)
: Joystick(port, kNumAxisTypes, kNumButtonTypes) {
Joystick::Joystick(int port) : Joystick(port, kNumAxisTypes, kNumButtonTypes) {
m_axes[kXAxis] = kDefaultXAxis;
m_axes[kYAxis] = kDefaultYAxis;
m_axes[kZAxis] = kDefaultZAxis;
@@ -54,8 +53,7 @@ Joystick::Joystick(uint32_t port)
* @param numAxisTypes The number of axis types in the enum.
* @param numButtonTypes The number of button types in the enum.
*/
Joystick::Joystick(uint32_t port, uint32_t numAxisTypes,
uint32_t numButtonTypes)
Joystick::Joystick(int port, int numAxisTypes, int numButtonTypes)
: m_ds(DriverStation::GetInstance()),
m_port(port),
m_axes(numAxisTypes),
@@ -71,7 +69,7 @@ Joystick::Joystick(uint32_t port, uint32_t numAxisTypes,
}
}
Joystick* Joystick::GetStickForPort(uint32_t port) {
Joystick* Joystick::GetStickForPort(int port) {
Joystick* stick = joysticks[port];
if (stick == nullptr) {
stick = new Joystick(port);
@@ -133,7 +131,7 @@ float Joystick::GetThrottle() const {
* @param axis The axis to read, starting at 0.
* @return The value of the axis.
*/
float Joystick::GetRawAxis(uint32_t axis) const {
float Joystick::GetRawAxis(int axis) const {
return m_ds.GetStickAxis(m_port, axis);
}
@@ -211,7 +209,7 @@ bool Joystick::GetBumper(JoystickHand hand) const {
* @param button The button number to be read (starting at 1)
* @return The state of the button.
**/
bool Joystick::GetRawButton(uint32_t button) const {
bool Joystick::GetRawButton(int button) const {
return m_ds.GetStickButton(m_port, button);
}
@@ -224,9 +222,7 @@ bool Joystick::GetRawButton(uint32_t button) const {
* @param pov The index of the POV to read (starting at 0)
* @return the angle of the POV in degrees, or -1 if the POV is not pressed.
*/
int Joystick::GetPOV(uint32_t pov) const {
return m_ds.GetStickPOV(m_port, pov);
}
int Joystick::GetPOV(int pov) const { return m_ds.GetStickPOV(m_port, pov); }
/**
* Get buttons based on an enumerated type.
@@ -315,7 +311,7 @@ int Joystick::GetPOVCount() const { return m_ds.GetStickPOVCount(m_port); }
* @param axis The axis to look up the channel for.
* @return The channel fr the axis.
*/
uint32_t Joystick::GetAxisChannel(AxisType axis) const { return m_axes[axis]; }
int Joystick::GetAxisChannel(AxisType axis) const { return m_axes[axis]; }
/**
* Set the channel associated with a specified axis.
@@ -323,7 +319,7 @@ uint32_t Joystick::GetAxisChannel(AxisType axis) const { return m_axes[axis]; }
* @param axis The axis to set the channel for.
* @param channel The channel to set the axis to.
*/
void Joystick::SetAxisChannel(AxisType axis, uint32_t channel) {
void Joystick::SetAxisChannel(AxisType axis, int channel) {
m_axes[axis] = channel;
}
@@ -385,7 +381,7 @@ void Joystick::SetRumble(RumbleType type, float value) {
* @param value The value to set the output to
*/
void Joystick::SetOutput(uint8_t outputNumber, bool value) {
void Joystick::SetOutput(int outputNumber, bool value) {
m_outputs =
(m_outputs & ~(1 << (outputNumber - 1))) | (value << (outputNumber - 1));
@@ -397,7 +393,7 @@ void Joystick::SetOutput(uint8_t outputNumber, bool value) {
*
* @param value The 32 bit output value (1 bit for each output)
*/
void Joystick::SetOutputs(uint32_t value) {
void Joystick::SetOutputs(int value) {
m_outputs = value;
HAL_SetJoystickOutputs(m_port, m_outputs, m_leftRumble, m_rightRumble);
}

View File

@@ -67,7 +67,7 @@ PIDController::PIDController(float Kp, float Ki, float Kd, float Kf,
m_controlLoop->StartPeriodic(m_period);
m_setpointTimer.Start();
static int32_t instances = 0;
static int instances = 0;
instances++;
HAL_Report(HALUsageReporting::kResourceType_PIDController, instances);
}
@@ -473,12 +473,12 @@ void PIDController::SetPercentTolerance(float percent) {
*
* @param bufLength Number of previous cycles to average. Defaults to 1.
*/
void PIDController::SetToleranceBuffer(unsigned bufLength) {
void PIDController::SetToleranceBuffer(int bufLength) {
std::lock_guard<priority_recursive_mutex> sync(m_mutex);
m_bufLength = bufLength;
// Cut the buffer down to size if needed.
while (m_buf.size() > bufLength) {
while (m_buf.size() > static_cast<uint32_t>(bufLength)) {
m_bufTotal -= m_buf.front();
m_buf.pop();
}

View File

@@ -23,7 +23,7 @@
* @param channel The PWM channel number. 0-9 are on-board, 10-19 are on the
* MXP port
*/
PWM::PWM(uint32_t channel) {
PWM::PWM(int channel) {
std::stringstream buf;
if (!CheckPWMChannel(channel)) {
@@ -37,7 +37,7 @@ PWM::PWM(uint32_t channel) {
if (status != 0) {
wpi_setErrorWithContextRange(status, 0, HAL_GetNumPWMChannels(), channel,
HAL_GetErrorMessage(status));
m_channel = std::numeric_limits<uint32_t>::max();
m_channel = std::numeric_limits<int>::max();
m_handle = HAL_kInvalidHandle;
return;
}
@@ -120,8 +120,8 @@ void PWM::SetBounds(float max, float deadbandMax, float center,
* @param deadbandMin The low end of the deadband range
* @param min The minimum pwm value
*/
void PWM::SetRawBounds(int32_t max, int32_t deadbandMax, int32_t center,
int32_t deadbandMin, int32_t min) {
void PWM::SetRawBounds(int max, int deadbandMax, int center, int deadbandMin,
int min) {
if (StatusIsFatal()) return;
int32_t status = 0;
HAL_SetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min,
@@ -142,8 +142,8 @@ void PWM::SetRawBounds(int32_t max, int32_t deadbandMax, int32_t center,
* @param deadbandMin The low end of the deadband range
* @param min The minimum pwm value
*/
void PWM::GetRawBounds(int32_t* max, int32_t* deadbandMax, int32_t* center,
int32_t* deadbandMin, int32_t* min) {
void PWM::GetRawBounds(int* max, int* deadbandMax, int* center,
int* deadbandMin, int* min) {
int32_t status = 0;
HAL_GetPWMConfigRaw(m_handle, max, deadbandMax, center, deadbandMin, min,
&status);

View File

@@ -13,7 +13,7 @@
* @param channel The PWM channel that the controller is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
PWMSpeedController::PWMSpeedController(uint32_t channel) : SafePWM(channel) {}
PWMSpeedController::PWMSpeedController(int channel) : SafePWM(channel) {}
/**
* Set the PWM value.

View File

@@ -18,8 +18,7 @@ PowerDistributionPanel::PowerDistributionPanel() : PowerDistributionPanel(0) {}
/**
* Initialize the PDP.
*/
PowerDistributionPanel::PowerDistributionPanel(uint8_t module)
: m_module(module) {
PowerDistributionPanel::PowerDistributionPanel(int module) : m_module(module) {
int32_t status = 0;
HAL_InitializePDP(m_module, &status);
if (status != 0) {
@@ -71,7 +70,7 @@ float PowerDistributionPanel::GetTemperature() const {
*
* @return The current of one of the PDP channels (channels 0-15) in Amperes
*/
float PowerDistributionPanel::GetCurrent(uint8_t channel) const {
float PowerDistributionPanel::GetCurrent(int channel) const {
if (StatusIsFatal()) return 0;
int32_t status = 0;

View File

@@ -20,7 +20,7 @@ void Preferences::Listener::ValueChanged(ITable* source, llvm::StringRef key,
bool isNew) {}
void Preferences::Listener::ValueChangedEx(ITable* source, llvm::StringRef key,
std::shared_ptr<nt::Value> value,
unsigned int flags) {
uint32_t flags) {
source->SetPersistent(key);
}

View File

@@ -23,7 +23,7 @@
* @param channel The channel number (0-3).
* @param direction The direction that the Relay object will control.
*/
Relay::Relay(uint32_t channel, Relay::Direction direction)
Relay::Relay(int channel, Relay::Direction direction)
: m_channel(channel), m_direction(direction) {
std::stringstream buf;
if (!SensorBase::CheckRelayChannel(m_channel)) {
@@ -206,7 +206,7 @@ Relay::Value Relay::Get() const {
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
}
uint32_t Relay::GetChannel() const { return m_channel; }
int Relay::GetChannel() const { return m_channel; }
/**
* Set the expiration time for the Relay object

View File

@@ -17,7 +17,7 @@
#include "Utility.h"
#include "WPIErrors.h"
const int32_t RobotDrive::kMaxNumberOfMotors;
const int RobotDrive::kMaxNumberOfMotors;
static auto make_shared_nodelete(SpeedController* ptr) {
return std::shared_ptr<SpeedController>(ptr, NullDeleter<SpeedController>());
@@ -55,7 +55,7 @@ void RobotDrive::InitRobotDrive() {
* @param rightMotorChannel The PWM channel number that drives the right motor.
* 0-9 are on-board, 10-19 are on the MXP port
*/
RobotDrive::RobotDrive(uint32_t leftMotorChannel, uint32_t rightMotorChannel) {
RobotDrive::RobotDrive(int leftMotorChannel, int rightMotorChannel) {
InitRobotDrive();
m_rearLeftMotor = std::make_shared<Talon>(leftMotorChannel);
m_rearRightMotor = std::make_shared<Talon>(rightMotorChannel);
@@ -78,8 +78,8 @@ RobotDrive::RobotDrive(uint32_t leftMotorChannel, uint32_t rightMotorChannel) {
* @param rearRightMotor Rear Right motor channel number. 0-9 are on-board,
* 10-19 are on the MXP port
*/
RobotDrive::RobotDrive(uint32_t frontLeftMotor, uint32_t rearLeftMotor,
uint32_t frontRightMotor, uint32_t rearRightMotor) {
RobotDrive::RobotDrive(int frontLeftMotor, int rearLeftMotor,
int frontRightMotor, int rearRightMotor) {
InitRobotDrive();
m_rearLeftMotor = std::make_shared<Talon>(rearLeftMotor);
m_rearRightMotor = std::make_shared<Talon>(rearRightMotor);
@@ -275,8 +275,8 @@ void RobotDrive::TankDrive(GenericHID& leftStick, GenericHID& rightStick,
* robot.
* @param rightAxis The axis to select on the right side Joystick object.
*/
void RobotDrive::TankDrive(GenericHID* leftStick, uint32_t leftAxis,
GenericHID* rightStick, uint32_t rightAxis,
void RobotDrive::TankDrive(GenericHID* leftStick, int leftAxis,
GenericHID* rightStick, int rightAxis,
bool squaredInputs) {
if (leftStick == nullptr || rightStick == nullptr) {
wpi_setWPIError(NullParameter);
@@ -286,8 +286,8 @@ void RobotDrive::TankDrive(GenericHID* leftStick, uint32_t leftAxis,
squaredInputs);
}
void RobotDrive::TankDrive(GenericHID& leftStick, uint32_t leftAxis,
GenericHID& rightStick, uint32_t rightAxis,
void RobotDrive::TankDrive(GenericHID& leftStick, int leftAxis,
GenericHID& rightStick, int rightAxis,
bool squaredInputs) {
TankDrive(leftStick.GetRawAxis(leftAxis), rightStick.GetRawAxis(rightAxis),
squaredInputs);
@@ -382,8 +382,8 @@ void RobotDrive::ArcadeDrive(GenericHID& stick, bool squaredInputs) {
* @param squaredInputs Setting this parameter to true increases the
* sensitivity at lower speeds
*/
void RobotDrive::ArcadeDrive(GenericHID* moveStick, uint32_t moveAxis,
GenericHID* rotateStick, uint32_t rotateAxis,
void RobotDrive::ArcadeDrive(GenericHID* moveStick, int moveAxis,
GenericHID* rotateStick, int rotateAxis,
bool squaredInputs) {
float moveValue = moveStick->GetRawAxis(moveAxis);
float rotateValue = rotateStick->GetRawAxis(rotateAxis);
@@ -407,8 +407,8 @@ void RobotDrive::ArcadeDrive(GenericHID* moveStick, uint32_t moveAxis,
* @param squaredInputs Setting this parameter to true increases the
* sensitivity at lower speeds
*/
void RobotDrive::ArcadeDrive(GenericHID& moveStick, uint32_t moveAxis,
GenericHID& rotateStick, uint32_t rotateAxis,
void RobotDrive::ArcadeDrive(GenericHID& moveStick, int moveAxis,
GenericHID& rotateStick, int rotateAxis,
bool squaredInputs) {
float moveValue = moveStick.GetRawAxis(moveAxis);
float rotateValue = rotateStick.GetRawAxis(rotateAxis);
@@ -637,7 +637,7 @@ float RobotDrive::Limit(float num) {
*/
void RobotDrive::Normalize(double* wheelSpeeds) {
double maxMagnitude = std::fabs(wheelSpeeds[0]);
int32_t i;
int i;
for (i = 1; i < kMaxNumberOfMotors; i++) {
double temp = std::fabs(wheelSpeeds[i]);
if (maxMagnitude < temp) maxMagnitude = temp;

View File

@@ -31,7 +31,7 @@
* @param channel The PWM channel that the SD540 is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
SD540::SD540(uint32_t channel) : PWMSpeedController(channel) {
SD540::SD540(int channel) : PWMSpeedController(channel) {
SetBounds(2.05, 1.55, 1.50, 1.44, .94);
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetSpeed(0.0);

View File

@@ -23,7 +23,7 @@ SPI::SPI(Port SPIport) {
HAL_InitializeSPI(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
static int32_t instances = 0;
static int instances = 0;
instances++;
HAL_Report(HALUsageReporting::kResourceType_SPI, instances);
}
@@ -122,8 +122,8 @@ void SPI::SetChipSelectActiveLow() {
* If not running in output only mode, also saves the data received
* on the MISO input during the transfer into the receive FIFO.
*/
int32_t SPI::Write(uint8_t* data, uint8_t size) {
int32_t retVal = 0;
int SPI::Write(uint8_t* data, int size) {
int retVal = 0;
retVal = HAL_WriteSPI(m_port, data, size);
return retVal;
}
@@ -141,8 +141,8 @@ int32_t SPI::Write(uint8_t* data, uint8_t size) {
* that data is already in the receive FIFO from a previous
* write.
*/
int32_t SPI::Read(bool initiate, uint8_t* dataReceived, uint8_t size) {
int32_t retVal = 0;
int SPI::Read(bool initiate, uint8_t* dataReceived, int size) {
int retVal = 0;
if (initiate) {
auto dataToSend = new uint8_t[size];
std::memset(dataToSend, 0, size);
@@ -160,9 +160,8 @@ int32_t SPI::Read(bool initiate, uint8_t* dataReceived, uint8_t size) {
* @param dataReceived Buffer to receive data from the device
* @param size The length of the transaction, in bytes
*/
int32_t SPI::Transaction(uint8_t* dataToSend, uint8_t* dataReceived,
uint8_t size) {
int32_t retVal = 0;
int SPI::Transaction(uint8_t* dataToSend, uint8_t* dataReceived, int size) {
int retVal = 0;
retVal = HAL_TransactionSPI(m_port, dataToSend, dataReceived, size);
return retVal;
}
@@ -182,12 +181,11 @@ int32_t SPI::Transaction(uint8_t* dataToSend, uint8_t* dataReceived,
* @param is_signed Is data field signed?
* @param big_endian Is device big endian?
*/
void SPI::InitAccumulator(double 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) {
void SPI::InitAccumulator(double period, int cmd, int xfer_size, int valid_mask,
int valid_value, int data_shift, int data_size,
bool is_signed, bool big_endian) {
int32_t status = 0;
HAL_InitSPIAccumulator(m_port, static_cast<uint32_t>(period * 1e6), cmd,
HAL_InitSPIAccumulator(m_port, static_cast<int32_t>(period * 1e6), cmd,
xfer_size, valid_mask, valid_value, data_shift,
data_size, is_signed, big_endian, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -219,7 +217,7 @@ void SPI::ResetAccumulator() {
* accelerometers to make integration work and to take the device offset into
* account when integrating.
*/
void SPI::SetAccumulatorCenter(int32_t center) {
void SPI::SetAccumulatorCenter(int center) {
int32_t status = 0;
HAL_SetSPIAccumulatorCenter(m_port, center, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -228,7 +226,7 @@ void SPI::SetAccumulatorCenter(int32_t center) {
/**
* Set the accumulator's deadband.
*/
void SPI::SetAccumulatorDeadband(int32_t deadband) {
void SPI::SetAccumulatorDeadband(int deadband) {
int32_t status = 0;
HAL_SetSPIAccumulatorDeadband(m_port, deadband, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -237,9 +235,9 @@ void SPI::SetAccumulatorDeadband(int32_t deadband) {
/**
* Read the last value read by the accumulator engine.
*/
int32_t SPI::GetAccumulatorLastValue() const {
int SPI::GetAccumulatorLastValue() const {
int32_t status = 0;
int32_t retVal = HAL_GetSPIAccumulatorLastValue(m_port, &status);
int retVal = HAL_GetSPIAccumulatorLastValue(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return retVal;
}

View File

@@ -13,7 +13,7 @@
* @param channel The PWM channel number 0-9 are on-board, 10-19 are on the MXP
* port
*/
SafePWM::SafePWM(uint32_t channel) : PWM(channel) {
SafePWM::SafePWM(int channel) : PWM(channel) {
m_safetyHelper = std::make_unique<MotorSafetyHelper>(this);
m_safetyHelper->SetSafetyEnabled(false);
}

View File

@@ -23,7 +23,7 @@
* @param stopBits The number of stop bits to use as defined by the enum
* StopBits.
*/
SerialPort::SerialPort(uint32_t baudRate, Port port, uint8_t dataBits,
SerialPort::SerialPort(int baudRate, Port port, int dataBits,
SerialPort::Parity parity,
SerialPort::StopBits stopBits) {
int32_t status = 0;
@@ -105,9 +105,9 @@ void SerialPort::DisableTermination() {
*
* @return The number of bytes available to read
*/
int32_t SerialPort::GetBytesReceived() {
int SerialPort::GetBytesReceived() {
int32_t status = 0;
int32_t retVal = HAL_GetSerialBytesReceived(m_port, &status);
int retVal = HAL_GetSerialBytesReceived(m_port, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return retVal;
}
@@ -119,9 +119,9 @@ int32_t SerialPort::GetBytesReceived() {
* @param count The maximum number of bytes to read.
* @return The number of bytes actually read into the buffer.
*/
uint32_t SerialPort::Read(char* buffer, int32_t count) {
int SerialPort::Read(char* buffer, int count) {
int32_t status = 0;
int32_t retVal = HAL_ReadSerial(m_port, buffer, count, &status);
int retVal = HAL_ReadSerial(m_port, buffer, count, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return retVal;
}
@@ -133,9 +133,9 @@ uint32_t SerialPort::Read(char* buffer, int32_t count) {
* @param count The maximum number of bytes to write.
* @return The number of bytes actually written into the port.
*/
uint32_t SerialPort::Write(const std::string& buffer, int32_t count) {
int SerialPort::Write(const std::string& buffer, int count) {
int32_t status = 0;
int32_t retVal = HAL_WriteSerial(m_port, buffer.c_str(), count, &status);
int retVal = HAL_WriteSerial(m_port, buffer.c_str(), count, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return retVal;
}
@@ -166,7 +166,7 @@ void SerialPort::SetTimeout(float timeout) {
*
* @param size The read buffer size.
*/
void SerialPort::SetReadBufferSize(uint32_t size) {
void SerialPort::SetReadBufferSize(int size) {
int32_t status = 0;
HAL_SetSerialReadBufferSize(m_port, size, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
@@ -180,7 +180,7 @@ void SerialPort::SetReadBufferSize(uint32_t size) {
*
* @param size The write buffer size.
*/
void SerialPort::SetWriteBufferSize(uint32_t size) {
void SerialPort::SetWriteBufferSize(int size) {
int32_t status = 0;
HAL_SetSerialWriteBufferSize(m_port, size, &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));

View File

@@ -19,7 +19,7 @@ constexpr float Servo::kDefaultMinServoPWM;
* @param channel The PWM channel to which the servo is attached. 0-9 are
* on-board, 10-19 are on the MXP port
*/
Servo::Servo(uint32_t channel) : SafePWM(channel) {
Servo::Servo(int channel) : SafePWM(channel) {
// Set minimum and maximum PWM values supported by the servo
SetBounds(kDefaultMaxServoPWM, 0.0, 0.0, 0.0, kDefaultMinServoPWM);

View File

@@ -18,7 +18,7 @@
*
* @param channel The channel on the PCM to control (0..7).
*/
Solenoid::Solenoid(uint32_t channel)
Solenoid::Solenoid(int channel)
: Solenoid(GetDefaultSolenoidModule(), channel) {}
/**
@@ -27,7 +27,7 @@ Solenoid::Solenoid(uint32_t channel)
* @param moduleNumber The CAN ID of the PCM the solenoid is attached to
* @param channel The channel on the PCM to control (0..7).
*/
Solenoid::Solenoid(uint8_t moduleNumber, uint32_t channel)
Solenoid::Solenoid(int moduleNumber, int channel)
: SolenoidBase(moduleNumber), m_channel(channel) {
std::stringstream buf;
if (!CheckSolenoidModule(m_moduleNumber)) {

View File

@@ -14,18 +14,17 @@
*
* @param moduleNumber The CAN PCM ID.
*/
SolenoidBase::SolenoidBase(uint8_t moduleNumber)
: m_moduleNumber(moduleNumber) {}
SolenoidBase::SolenoidBase(int moduleNumber) : m_moduleNumber(moduleNumber) {}
/**
* Read all 8 solenoids as a single byte
*
* @return The current value of all 8 solenoids on the module.
*/
uint8_t SolenoidBase::GetAll(int module) const {
uint8_t value = 0;
int SolenoidBase::GetAll(int module) const {
int value = 0;
int32_t status = 0;
value = HAL_GetAllSolenoids(static_cast<uint8_t>(module), &status);
value = HAL_GetAllSolenoids(static_cast<int>(module), &status);
wpi_setErrorWithContext(status, HAL_GetErrorMessage(status));
return value;
}
@@ -39,9 +38,9 @@ uint8_t SolenoidBase::GetAll(int module) const {
*
* @return The solenoid blacklist of all 8 solenoids on the module.
*/
uint8_t SolenoidBase::GetPCMSolenoidBlackList(int module) const {
int SolenoidBase::GetPCMSolenoidBlackList(int module) const {
int32_t status = 0;
return HAL_GetPCMSolenoidBlackList(static_cast<uint8_t>(module), &status);
return HAL_GetPCMSolenoidBlackList(static_cast<int>(module), &status);
}
/**
@@ -50,7 +49,7 @@ uint8_t SolenoidBase::GetPCMSolenoidBlackList(int module) const {
*/
bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) const {
int32_t status = 0;
return HAL_GetPCMSolenoidVoltageStickyFault(static_cast<uint8_t>(module),
return HAL_GetPCMSolenoidVoltageStickyFault(static_cast<int>(module),
&status);
}
@@ -60,7 +59,7 @@ bool SolenoidBase::GetPCMSolenoidVoltageStickyFault(int module) const {
*/
bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) const {
int32_t status = 0;
return HAL_GetPCMSolenoidVoltageFault(static_cast<uint8_t>(module), &status);
return HAL_GetPCMSolenoidVoltageFault(static_cast<int>(module), &status);
}
/**
@@ -75,5 +74,5 @@ bool SolenoidBase::GetPCMSolenoidVoltageFault(int module) const {
*/
void SolenoidBase::ClearAllPCMStickyFaults(int module) {
int32_t status = 0;
return HAL_ClearAllPCMStickyFaults(static_cast<uint8_t>(module), &status);
return HAL_ClearAllPCMStickyFaults(static_cast<int>(module), &status);
}

View File

@@ -31,7 +31,7 @@
* @param channel The PWM channel that the Spark is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
Spark::Spark(uint32_t channel) : PWMSpeedController(channel) {
Spark::Spark(int channel) : PWMSpeedController(channel) {
SetBounds(2.003, 1.55, 1.50, 1.46, .999);
SetPeriodMultiplier(kPeriodMultiplier_1X);
SetSpeed(0.0);

View File

@@ -16,7 +16,7 @@
* @param channel The PWM channel number that the Talon is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
Talon::Talon(uint32_t channel) : PWMSpeedController(channel) {
Talon::Talon(int channel) : PWMSpeedController(channel) {
/* Note that the Talon uses the following bounds for PWM values. These values
* should work reasonably well for most controllers, but if users experience
* issues such as asymmetric behavior around the deadband or inability to

View File

@@ -16,7 +16,7 @@
* @param channel The PWM channel that the TalonSRX is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
TalonSRX::TalonSRX(uint32_t channel) : PWMSpeedController(channel) {
TalonSRX::TalonSRX(int channel) : PWMSpeedController(channel) {
/* Note that the TalonSRX uses the following bounds for PWM values. These
* values should work reasonably well for most controllers, but if users
* experience issues such as asymmetric behavior around the deadband or

View File

@@ -18,7 +18,7 @@
#define ERROR (-1)
#endif /* ERROR */
const uint32_t Task::kDefaultPriority;
const int Task::kDefaultPriority;
Task& Task::operator=(Task&& task) {
m_thread.swap(task.m_thread);
@@ -60,7 +60,7 @@ bool Task::Verify() {
*
* @return task priority or 0 if an error occured
*/
int32_t Task::GetPriority() {
int Task::GetPriority() {
int priority;
auto id = m_thread.native_handle();
if (HandleError(HAL_GetTaskPriority(&id, &priority)))
@@ -77,7 +77,7 @@ int32_t Task::GetPriority() {
* @param priority The priority at which the internal thread should run.
* @return true on success.
*/
bool Task::SetPriority(int32_t priority) {
bool Task::SetPriority(int priority) {
auto id = m_thread.native_handle();
return HandleError(HAL_SetTaskPriority(&id, priority));
}

View File

@@ -22,7 +22,7 @@
// To call it, just give the name of the function and the arguments
#define SAFE_IMAQ_CALL(funName, ...) \
{ \
unsigned int error = funName(__VA_ARGS__); \
int error = funName(__VA_ARGS__); \
if (error != IMAQdxErrorSuccess) \
wpi_setImaqErrorWithContext(error, #funName); \
}
@@ -33,15 +33,15 @@
* http://stackoverflow.com/a/1602428. Be sure to also read the comments for
* the SOS flag explanation.
*/
unsigned int USBCamera::GetJpegSize(void* buffer, unsigned int buffSize) {
int USBCamera::GetJpegSize(void* buffer, int buffSize) {
uint8_t* data = static_cast<uint8_t*>(buffer);
if (!wpi_assert(data[0] == 0xff && data[1] == 0xd8)) return 0;
unsigned int pos = 2;
int pos = 2;
while (pos < buffSize) {
// All control markers start with 0xff, so if this isn't present,
// the JPEG is not valid
if (!wpi_assert(data[pos] == 0xff)) return 0;
unsigned char t = data[pos + 1];
int t = data[pos + 1];
// These are RST markers. We just skip them and move onto the next marker
if (t == 0x01 || (t >= 0xd0 && t <= 0xd7)) {
pos += 2;
@@ -54,7 +54,8 @@ unsigned int USBCamera::GetJpegSize(void* buffer, unsigned int buffSize) {
} else if (t == 0xda) {
// SOS marker. The next two bytes are a 16-bit big-endian int that is
// the length of the SOS header, skip that
unsigned int len = (data[pos + 2] & 0xffu) << 8 | (data[pos + 3] & 0xffu);
int len = (static_cast<int>(data[pos + 2]) & 0xff) << 8 |
(static_cast<int>(data[pos + 3]) & 0xff);
pos += len + 2;
// The next marker is the first marker that is 0xff followed by a non-RST
// element. 0xff followed by 0x00 is an escaped 0xff. 0xd0-0xd7 are RST
@@ -69,7 +70,8 @@ unsigned int USBCamera::GetJpegSize(void* buffer, unsigned int buffSize) {
// 16-bit
// big-endian int with the length of the marker header, skip that then
// continue searching
unsigned int len = (data[pos + 2] & 0xffu) << 8 | (data[pos + 3] & 0xffu);
int len = (static_cast<int>(data[pos + 2]) & 0xff) << 8 |
(static_cast<int>(data[pos + 3]) & 0xff);
pos += len + 2;
}
}
@@ -82,7 +84,7 @@ USBCamera::USBCamera(std::string name, bool useJpeg)
void USBCamera::OpenCamera() {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
for (unsigned int i = 0; i < 3; i++) {
for (int i = 0; i < 3; i++) {
uInt32 id = 0;
// Can't use SAFE_IMAQ_CALL here because we only error on the third time
IMAQdxError error = IMAQdxOpenCamera(
@@ -151,11 +153,11 @@ void USBCamera::UpdateSettings() {
double foundFps = 1000.0;
// Loop through the modes, and find the match with the lowest fps
for (unsigned int i = 0; i < count; i++) {
for (uint32_t i = 0; i < count; i++) {
std::cmatch m;
if (!std::regex_match(modes[i].Name, m, reMode)) continue;
unsigned int width = static_cast<unsigned int>(std::stoul(m[1].str()));
unsigned int height = static_cast<unsigned int>(std::stoul(m[2].str()));
int width = static_cast<int>(std::stoul(m[1].str()));
int height = static_cast<int>(std::stoul(m[2].str()));
if (width != m_width) continue;
if (height != m_height) continue;
double fps = atof(m[4].str().c_str());
@@ -230,7 +232,7 @@ void USBCamera::SetFPS(double fps) {
}
}
void USBCamera::SetSize(unsigned int width, unsigned int height) {
void USBCamera::SetSize(int width, int height) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
if (m_width != width || m_height != height) {
m_needSettingsUpdate = true;
@@ -239,7 +241,7 @@ void USBCamera::SetSize(unsigned int width, unsigned int height) {
}
}
void USBCamera::SetBrightness(unsigned int brightness) {
void USBCamera::SetBrightness(int brightness) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
if (m_brightness != brightness) {
m_needSettingsUpdate = true;
@@ -247,7 +249,7 @@ void USBCamera::SetBrightness(unsigned int brightness) {
}
}
unsigned int USBCamera::GetBrightness() {
int USBCamera::GetBrightness() {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
return m_brightness;
}
@@ -268,7 +270,7 @@ void USBCamera::SetWhiteBalanceHoldCurrent() {
m_needSettingsUpdate = true;
}
void USBCamera::SetWhiteBalanceManual(unsigned int whiteBalance) {
void USBCamera::SetWhiteBalanceManual(int whiteBalance) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
m_whiteBalance = MANUAL;
m_whiteBalanceValue = whiteBalance;
@@ -292,7 +294,7 @@ void USBCamera::SetExposureHoldCurrent() {
m_needSettingsUpdate = true;
}
void USBCamera::SetExposureManual(unsigned int level) {
void USBCamera::SetExposureManual(int level) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
m_exposure = MANUAL;
if (level > 100)
@@ -316,7 +318,7 @@ void USBCamera::GetImage(Image* image) {
SAFE_IMAQ_CALL(IMAQdxGrab, m_id, image, 1, &bufNum);
}
unsigned int USBCamera::GetImageData(void* buffer, unsigned int bufferSize) {
int USBCamera::GetImageData(void* buffer, int bufferSize) {
std::lock_guard<priority_recursive_mutex> lock(m_mutex);
if (m_needSettingsUpdate || !m_useJpeg) {
m_needSettingsUpdate = false;

View File

@@ -18,7 +18,7 @@
// Time (sec) for the ping trigger pulse.
constexpr double Ultrasonic::kPingTime;
// Priority that the ultrasonic round robin task runs.
const uint32_t Ultrasonic::kPriority;
const int Ultrasonic::kPriority;
// Max time (ms) between readings.
constexpr double Ultrasonic::kMaxUltrasonicTime;
constexpr double Ultrasonic::kSpeedOfSoundInchesPerSec;
@@ -91,8 +91,7 @@ void Ultrasonic::Initialize() {
* round trip time of the ping, and the distance.
* @param units The units returned in either kInches or kMilliMeters
*/
Ultrasonic::Ultrasonic(uint32_t pingChannel, uint32_t echoChannel,
DistanceUnit units)
Ultrasonic::Ultrasonic(int pingChannel, int echoChannel, DistanceUnit units)
: m_pingChannel(std::make_shared<DigitalOutput>(pingChannel)),
m_echoChannel(std::make_shared<DigitalInput>(echoChannel)),
m_counter(m_echoChannel) {

View File

@@ -23,8 +23,8 @@
* Utility.h.
*/
bool wpi_assert_impl(bool conditionValue, const char* conditionText,
const char* message, const char* fileName,
uint32_t lineNumber, const char* funcName) {
const char* message, const char* fileName, int lineNumber,
const char* funcName) {
if (!conditionValue) {
std::stringstream locStream;
locStream << funcName << " [";
@@ -58,7 +58,7 @@ bool wpi_assert_impl(bool conditionValue, const char* conditionText,
*/
void wpi_assertEqual_common_impl(const char* valueA, const char* valueB,
const char* equalityType, const char* message,
const char* fileName, uint32_t lineNumber,
const char* fileName, int lineNumber,
const char* funcName) {
std::stringstream locStream;
locStream << funcName << " [";
@@ -92,7 +92,7 @@ void wpi_assertEqual_common_impl(const char* valueA, const char* valueB,
*/
bool wpi_assertEqual_impl(int valueA, int valueB, const char* valueAString,
const char* valueBString, const char* message,
const char* fileName, uint32_t lineNumber,
const char* fileName, int lineNumber,
const char* funcName) {
if (!(valueA == valueB)) {
wpi_assertEqual_common_impl(valueAString, valueBString, "==", message,
@@ -110,7 +110,7 @@ bool wpi_assertEqual_impl(int valueA, int valueB, const char* valueAString,
*/
bool wpi_assertNotEqual_impl(int valueA, int valueB, const char* valueAString,
const char* valueBString, const char* message,
const char* fileName, uint32_t lineNumber,
const char* fileName, int lineNumber,
const char* funcName) {
if (!(valueA != valueB)) {
wpi_assertEqual_common_impl(valueAString, valueBString, "!=", message,
@@ -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.
*/
int32_t GetFPGAVersion() {
int GetFPGAVersion() {
int32_t status = 0;
int32_t version = HAL_GetFPGAVersion(&status);
int version = HAL_GetFPGAVersion(&status);
wpi_setGlobalErrorWithContext(status, HAL_GetErrorMessage(status));
return version;
}
@@ -180,7 +180,7 @@ bool GetUserButton() {
static std::string demangle(char const* mangledSymbol) {
char buffer[256];
size_t length;
int status;
int32_t status;
if (sscanf(mangledSymbol, "%*[^(]%*[(]%255[^)+]", buffer)) {
char* symbol = abi::__cxa_demangle(buffer, nullptr, &length, &status);
@@ -201,7 +201,7 @@ static std::string demangle(char const* mangledSymbol) {
* Get a stack trace, ignoring the first "offset" symbols.
* @param offset The number of symbols at the top of the stack to ignore
*/
std::string GetStackTrace(uint32_t offset) {
std::string GetStackTrace(int offset) {
void* stackTrace[128];
int stackSize = backtrace(stackTrace, 128);
char** mangledSymbols = backtrace_symbols(stackTrace, stackSize);

View File

@@ -16,7 +16,7 @@
* @param channel The PWM channel number that the Victor is attached to. 0-9
* are on-board, 10-19 are on the MXP port
*/
Victor::Victor(uint32_t channel) : PWMSpeedController(channel) {
Victor::Victor(int channel) : PWMSpeedController(channel) {
/* Note that the Victor uses the following bounds for PWM values. These
* values were determined empirically and optimized for the Victor 888. These
* values should work reasonably well for Victor 884 controllers as well but

View File

@@ -16,7 +16,7 @@
* @param channel The PWM channel that the VictorSP is attached to. 0-9 are
* on-board, 10-19 are on the MXP port
*/
VictorSP::VictorSP(uint32_t channel) : PWMSpeedController(channel) {
VictorSP::VictorSP(int channel) : PWMSpeedController(channel) {
/**
* Note that the VictorSP uses the following bounds for PWM values. These
* values should work reasonably well for most controllers, but if users

View File

@@ -20,8 +20,8 @@
#include "Timer.h"
#include "WPIErrors.h"
static const unsigned int kMaxPacketSize = 1536;
static const unsigned int kImageBufferAllocationIncrement = 1000;
static const int kMaxPacketSize = 1536;
static const int kImageBufferAllocationIncrement = 1000;
static const std::string kWhiteBalanceStrings[] = {
"auto", "hold", "fixed_outdoor1", "fixed_outdoor2",
@@ -123,8 +123,8 @@ HSLImage* AxisCamera::GetImage() {
* @param numBytes The size of the destination image.
* @return 0 if failed (no source image or no memory), 1 if success.
*/
int AxisCamera::CopyJPEG(char** destImage, unsigned int& destImageSize,
unsigned int& destImageBufferSize) {
int AxisCamera::CopyJPEG(char** destImage, int& destImageSize,
int& destImageBufferSize) {
std::lock_guard<priority_mutex> lock(m_imageDataMutex);
if (destImage == nullptr) {
wpi_setWPIErrorWithContext(NullParameter, "destImage must not be nullptr");
@@ -134,7 +134,7 @@ int AxisCamera::CopyJPEG(char** destImage, unsigned int& destImageSize,
if (m_imageData.size() == 0) return 0; // if no source image
// if current destination buffer too small
if (destImageBufferSize < m_imageData.size()) {
if (static_cast<uint32_t>(destImageBufferSize) < m_imageData.size()) {
if (*destImage != nullptr) delete[] * destImage;
destImageBufferSize = m_imageData.size() + kImageBufferAllocationIncrement;
*destImage = new char[destImageBufferSize];

View File

@@ -622,19 +622,18 @@ int frcColorEqualize(Image* dest, const Image* source, int colorEqualization) {
* @return On success: 1. On failure: 0. To get extended error information, call
* GetLastError().
*/
int frcSmartThreshold(Image* dest, const Image* source,
unsigned int windowWidth, unsigned int windowHeight,
LocalThresholdMethod method, double deviationWeight,
ObjectType type) {
int frcSmartThreshold(Image* dest, const Image* source, int windowWidth,
int windowHeight, LocalThresholdMethod method,
double deviationWeight, ObjectType type) {
float replaceValue = 1.0;
return imaqLocalThreshold(dest, source, windowWidth, windowHeight, method,
deviationWeight, type, replaceValue);
}
int frcSmartThreshold(Image* dest, const Image* source,
unsigned int windowWidth, unsigned int windowHeight,
LocalThresholdMethod method, double deviationWeight,
ObjectType type, float replaceValue) {
int frcSmartThreshold(Image* dest, const Image* source, int windowWidth,
int windowHeight, LocalThresholdMethod method,
double deviationWeight, ObjectType type,
float replaceValue) {
return imaqLocalThreshold(dest, source, windowWidth, windowHeight, method,
deviationWeight, type, replaceValue);
}