Fixes warnings thrown by cpplint.py (#154)

* Fixed cpplint.py [runtime/int] warnings

* Fixed cpplint.py [readability/casting] warnings

* Fixed cpplint.py [readability/namespace] warnings

* Fixed cpplint.py [readability/braces] warnings

* Fixed cpplint.py [whitespace/braces] warnings

* Fixed cpplint.py [runtime/explicit] warnings

* Fixed cpplint.py [runtime/printf] warnings

* Fixed cpplint.py [readability/inheritance] warnings

* Fixed cpplint.py [whitespace/tab] warnings

* Fixed cpplint.py [build/storage_class] warnings

* Fixed cpplint.py [readability/multiline_comment] warnings

* Fixed cpplint.py [whitespace/semicolon] warnings

* Fixed cpplint.py [readability/check] warnings

* Fixed cpplint.py [runtime/arrays] warnings

* Ran format.py
This commit is contained in:
Tyler Veness
2016-07-10 17:47:44 -07:00
committed by Peter Johnson
parent e44a6e227a
commit 0cb288ffba
141 changed files with 670 additions and 626 deletions

View File

@@ -24,7 +24,7 @@ void HAL_SetDigitalPWMDutyCycle(HAL_DigitalPWMHandle pwmGenerator,
void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
uint32_t pin, int32_t* status);
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, short value,
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, int16_t value,
int32_t* status);
bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status);
bool HAL_GetDIODirection(HAL_DigitalHandle dio_port_handle, int32_t* status);

View File

@@ -162,9 +162,11 @@ void HAL_CalibrateAnalogGyro(HAL_GyroHandle handle, int32_t* status) {
HAL_GetAccumulatorOutput(gyro->handle, &value, &count, status);
if (*status != 0) return;
gyro->center = (uint32_t)((float)value / (float)count + .5);
gyro->center = static_cast<uint32_t>(
static_cast<float>(value) / static_cast<float>(count) + .5);
gyro->offset = ((float)value / (float)count) - (float)gyro->center;
gyro->offset = static_cast<float>(value) / static_cast<float>(count) -
static_cast<float>(gyro->center);
HAL_SetAccumulatorCenter(gyro->handle, gyro->center, status);
if (*status != 0) return;
HAL_ResetAnalogGyro(handle, status);
@@ -194,14 +196,16 @@ float HAL_GetAnalogGyroAngle(HAL_GyroHandle handle, int32_t* status) {
uint32_t count = 0;
HAL_GetAccumulatorOutput(gyro->handle, &rawValue, &count, status);
int64_t value = rawValue - (int64_t)((float)count * gyro->offset);
int64_t value =
rawValue - static_cast<int64_t>(static_cast<float>(count) * gyro->offset);
double scaledValue =
value * 1e-9 * (double)HAL_GetAnalogLSBWeight(gyro->handle, status) *
(double)(1 << HAL_GetAnalogAverageBits(gyro->handle, status)) /
value * 1e-9 *
static_cast<double>(HAL_GetAnalogLSBWeight(gyro->handle, status)) *
static_cast<double>(1 << HAL_GetAnalogAverageBits(gyro->handle, status)) /
(HAL_GetAnalogSampleRate(status) * gyro->voltsPerDegreePerSecond);
return (float)scaledValue;
return static_cast<float>(scaledValue);
}
double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
@@ -212,7 +216,7 @@ double HAL_GetAnalogGyroRate(HAL_GyroHandle handle, int32_t* status) {
}
return (HAL_GetAnalogAverageValue(gyro->handle, status) -
((double)gyro->center + gyro->offset)) *
(static_cast<double>(gyro->center) + gyro->offset)) *
1e-9 * HAL_GetAnalogLSBWeight(gyro->handle, status) /
((1 << HAL_GetAnalogOversampleBits(gyro->handle, status)) *
gyro->voltsPerDegreePerSecond);

View File

@@ -51,8 +51,9 @@ HAL_AnalogInputHandle HAL_InitializeAnalogInputPort(HAL_PortHandle port_handle,
analog_port->pin = static_cast<uint8_t>(pin);
if (HAL_IsAccumulatorChannel(handle, status)) {
analog_port->accumulator = tAccumulator::create(pin, status);
} else
} else {
analog_port->accumulator = nullptr;
}
// Set default configuration
analogInputSystem->writeScanList(pin, pin, status);
@@ -102,7 +103,8 @@ void HAL_SetAnalogSampleRate(double samplesPerSecond, int32_t* status) {
analogSampleRateSet = true;
// Compute the convert rate
uint32_t ticksPerSample = (uint32_t)((float)kTimebase / samplesPerSecond);
uint32_t ticksPerSample =
static_cast<uint32_t>(static_cast<float>(kTimebase) / samplesPerSecond);
uint32_t ticksPerConversion =
ticksPerSample / getAnalogNumChannelsToActivate(status);
// ticksPerConversion must be at least 80
@@ -134,7 +136,7 @@ float HAL_GetAnalogSampleRate(int32_t* status) {
uint32_t ticksPerConversion = analogInputSystem->readLoopTiming(status);
uint32_t ticksPerSample =
ticksPerConversion * getAnalogNumActiveChannels(status);
return (float)kTimebase / (float)ticksPerSample;
return static_cast<float>(kTimebase) / static_cast<float>(ticksPerSample);
}
/**
@@ -317,7 +319,7 @@ float HAL_GetAnalogAverageVoltage(HAL_AnalogInputHandle analog_port_handle,
uint32_t oversampleBits =
HAL_GetAnalogOversampleBits(analog_port_handle, status);
float voltage =
((LSBWeight * 1.0e-9 * value) / (float)(1 << oversampleBits)) -
LSBWeight * 1.0e-9 * value / static_cast<float>(1 << oversampleBits) -
offset * 1.0e-9;
return voltage;
}

View File

@@ -78,4 +78,4 @@ uint32_t getAnalogNumChannelsToActivate(int32_t* status) {
void setAnalogNumChannelsToActivate(uint32_t channels) {
analogNumChannelsToActivate = channels;
}
}
} // namespace hal

View File

@@ -16,9 +16,9 @@
#include "handles/IndexedHandleResource.h"
namespace hal {
constexpr long kTimebase = 40000000; ///< 40 MHz clock
constexpr long kDefaultOversampleBits = 0;
constexpr long kDefaultAverageBits = 7;
constexpr int32_t kTimebase = 40000000; ///< 40 MHz clock
constexpr int32_t kDefaultOversampleBits = 0;
constexpr int32_t kDefaultAverageBits = 7;
constexpr float kDefaultSampleRate = 50000.0;
static const uint32_t kAccumulatorChannels[] = {0, 1};
@@ -41,4 +41,4 @@ void setAnalogNumChannelsToActivate(uint32_t channels);
void initializeAnalog(int32_t* status);
extern bool analogSystemInitialized;
}
} // namespace hal

View File

@@ -362,7 +362,8 @@ double HAL_GetCounterPeriod(HAL_CounterHandle counter_handle, int32_t* status) {
} else {
// output.Period is a fixed point number that counts by 2 (24 bits, 25
// integer bits)
period = (double)(output.Period << 1) / (double)output.Count;
period = static_cast<double>(output.Period << 1) /
static_cast<double>(output.Count);
}
return period * 2.5e-8; // result * timebase (currently 40ns)
}

View File

@@ -70,7 +70,7 @@ HAL_DigitalHandle HAL_InitializeDIOPort(HAL_PortHandle port_handle,
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
// Disable special functions on this pin
short specialFunctions =
int16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
status);
@@ -207,7 +207,7 @@ void HAL_SetDigitalPWMOutputChannel(HAL_DigitalPWMHandle pwmGenerator,
* @param value The state to set the digital channel (if it is configured as an
* output)
*/
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, short value,
void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, int16_t value,
int32_t* status) {
auto port = digitalPinHandles.Get(dio_port_handle, HAL_HandleEnum::DIO);
if (port == nullptr) {
@@ -235,7 +235,7 @@ void HAL_SetDIO(HAL_DigitalHandle dio_port_handle, short value,
}
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
short specialFunctions =
int16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
status);
@@ -268,7 +268,7 @@ bool HAL_GetDIO(HAL_DigitalHandle dio_port_handle, int32_t* status) {
} else {
// Disable special functions
uint32_t bitToSet = 1 << remapMXPChannel(port->pin);
short specialFunctions =
int16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToSet,
status);

View File

@@ -134,4 +134,4 @@ bool remapDigitalSource(HAL_Handle digitalSourceHandle,
return false;
}
}
}
} // namespace hal

View File

@@ -82,4 +82,4 @@ bool remapDigitalSource(HAL_Handle digitalSourceHandle,
uint8_t& module, bool& analogTrigger);
uint32_t remapMXPPWMChannel(uint32_t pin);
uint32_t remapMXPChannel(uint32_t pin);
}
} // namespace hal

View File

@@ -73,4 +73,4 @@ class Encoder {
int32_t m_encodingScale;
};
}
} // namespace hal

View File

@@ -148,7 +148,8 @@ double HAL_GetFPGAEncoderPeriod(HAL_FPGAEncoderHandle fpga_encoder_handle,
} else {
// output.Period is a fixed point number that counts by 2 (24 bits, 25
// integer bits)
value = (double)(output.Period << 1) / (double)output.Count;
value = static_cast<double>(output.Period << 1) /
static_cast<double>(output.Count);
}
double measuredPeriod = value * 2.5e-8;
return measuredPeriod / DECODING_SCALING_FACTOR;

View File

@@ -342,10 +342,10 @@ int HAL_Initialize(int mode) {
if (mode == 0) {
std::cout << "FRC pid " << pid
<< " did not die within 110ms. Aborting" << std::endl;
return 0; // just fail
} else if (mode == 1) // kill -9 it
return 0; // just fail
} else if (mode == 1) { // kill -9 it
kill(pid, SIGKILL);
else {
} else {
std::cout << "WARNING: FRC pid " << pid
<< " did not die within 110ms." << std::endl;
}

View File

@@ -94,9 +94,10 @@ int32_t HAL_TransactionI2C(uint8_t port, uint8_t deviceAddress,
{
std::lock_guard<priority_recursive_mutex> sync(lock);
return i2clib_writeread(handle, deviceAddress, (const char*)dataToSend,
(int32_t)sendSize, (char*)dataReceived,
(int32_t)receiveSize);
return i2clib_writeread(
handle, deviceAddress, reinterpret_cast<const char*>(dataToSend),
static_cast<int32_t>(sendSize), reinterpret_cast<char*>(dataReceived),
static_cast<int32_t>(receiveSize));
}
}
@@ -153,7 +154,8 @@ int32_t HAL_ReadI2C(uint8_t port, uint8_t deviceAddress, uint8_t* buffer,
port == 0 ? digitalI2COnBoardMutex : digitalI2CMXPMutex;
{
std::lock_guard<priority_recursive_mutex> sync(lock);
return i2clib_read(handle, deviceAddress, (char*)buffer, (int32_t)count);
return i2clib_read(handle, deviceAddress, reinterpret_cast<char*>(buffer),
static_cast<int32_t>(count));
}
}

View File

@@ -20,8 +20,8 @@
using namespace hal;
namespace {
struct Interrupt // FIXME: why is this internal?
{
// FIXME: why is this internal?
struct Interrupt {
tInterrupt* anInterrupt;
tInterruptManager* manager;
};

View File

@@ -75,7 +75,8 @@ HAL_DigitalHandle HAL_InitializePWMPort(HAL_PortHandle port_handle,
port->pin = origPin;
uint32_t bitToSet = 1 << remapMXPPWMChannel(port->pin);
short specialFunctions = digitalSystem->readEnableMXPSpecialFunction(status);
int16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions | bitToSet,
status);
@@ -90,7 +91,7 @@ void HAL_FreePWMPort(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
if (port->pin > tPWM::kNumHdrRegisters - 1) {
uint32_t bitToUnset = 1 << remapMXPPWMChannel(port->pin);
short specialFunctions =
int16_t specialFunctions =
digitalSystem->readEnableMXPSpecialFunction(status);
digitalSystem->writeEnableMXPSpecialFunction(specialFunctions & ~bitToUnset,
status);
@@ -244,11 +245,13 @@ void HAL_SetPWMSpeed(HAL_DigitalHandle pwm_port_handle, float speed,
if (speed == 0.0) {
rawValue = GetCenterPwm(dPort);
} else if (speed > 0.0) {
rawValue = (int32_t)(speed * ((float)GetPositiveScaleFactor(dPort)) +
((float)GetMinPositivePwm(dPort)) + 0.5);
rawValue = static_cast<int32_t>(
speed * static_cast<float>(GetPositiveScaleFactor(dPort)) +
static_cast<float>(GetMinPositivePwm(dPort)) + 0.5);
} else {
rawValue = (int32_t)(speed * ((float)GetNegativeScaleFactor(dPort)) +
((float)GetMaxNegativePwm(dPort)) + 0.5);
rawValue = static_cast<int32_t>(
speed * static_cast<float>(GetNegativeScaleFactor(dPort)) +
static_cast<float>(GetMaxNegativePwm(dPort)) + 0.5);
}
if (!((rawValue >= GetMinNegativePwm(dPort)) &&
@@ -291,8 +294,9 @@ void HAL_SetPWMPosition(HAL_DigitalHandle pwm_port_handle, float pos,
// note, need to perform the multiplication below as floating point before
// converting to int
uint16_t rawValue = (int32_t)((pos * (float)GetFullRangeScaleFactor(dPort)) +
GetMinNegativePwm(dPort));
uint16_t rawValue = static_cast<int32_t>(
(pos * static_cast<float>(GetFullRangeScaleFactor(dPort))) +
GetMinNegativePwm(dPort));
if (rawValue == kPwmDisabled) {
*status = HAL_PWM_SCALE_ERROR;
@@ -354,11 +358,11 @@ float HAL_GetPWMSpeed(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
} else if (value < GetMinNegativePwm(dPort)) {
return -1.0;
} else if (value > GetMinPositivePwm(dPort)) {
return (float)(value - GetMinPositivePwm(dPort)) /
(float)GetPositiveScaleFactor(dPort);
return static_cast<float>(value - GetMinPositivePwm(dPort)) /
static_cast<float>(GetPositiveScaleFactor(dPort));
} else if (value < GetMaxNegativePwm(dPort)) {
return (float)(value - GetMaxNegativePwm(dPort)) /
(float)GetNegativeScaleFactor(dPort);
return static_cast<float>(value - GetMaxNegativePwm(dPort)) /
static_cast<float>(GetNegativeScaleFactor(dPort));
} else {
return 0.0;
}
@@ -390,8 +394,8 @@ float HAL_GetPWMPosition(HAL_DigitalHandle pwm_port_handle, int32_t* status) {
} else if (value > GetMaxPositivePwm(dPort)) {
return 1.0;
} else {
return (float)(value - GetMinNegativePwm(dPort)) /
(float)GetFullRangeScaleFactor(dPort);
return static_cast<float>(value - GetMinNegativePwm(dPort)) /
static_cast<float>(GetFullRangeScaleFactor(dPort));
}
}

View File

@@ -32,4 +32,4 @@ constexpr int32_t kNumSolenoidPins = 8;
constexpr int32_t kNumPDPModules = 63;
constexpr int32_t kNumPDPChannels = 16;
constexpr int32_t kNumCanTalons = 63;
}
} // namespace hal

View File

@@ -64,7 +64,8 @@ bool HAL_GetUserActive6V(int32_t* status) {
*/
int HAL_GetUserCurrentFaults6V(int32_t* status) {
initializePower(status);
return (int)power->readFaultCounts_OverCurrentFaultCount6V(status);
return static_cast<int>(
power->readFaultCounts_OverCurrentFaultCount6V(status));
}
/**
@@ -96,7 +97,8 @@ bool HAL_GetUserActive5V(int32_t* status) {
*/
int HAL_GetUserCurrentFaults5V(int32_t* status) {
initializePower(status);
return (int)power->readFaultCounts_OverCurrentFaultCount5V(status);
return static_cast<int>(
power->readFaultCounts_OverCurrentFaultCount5V(status));
}
unsigned char HAL_GetUserStatus5V(int32_t* status) {
@@ -133,7 +135,8 @@ bool HAL_GetUserActive3V3(int32_t* status) {
*/
int HAL_GetUserCurrentFaults3V3(int32_t* status) {
initializePower(status);
return (int)power->readFaultCounts_OverCurrentFaultCount3V3(status);
return static_cast<int>(
power->readFaultCounts_OverCurrentFaultCount3V3(status));
}
} // extern "C"

View File

@@ -152,8 +152,9 @@ void HAL_InitializeSPI(uint8_t port, int32_t* status) {
int32_t HAL_TransactionSPI(uint8_t port, uint8_t* dataToSend,
uint8_t* dataReceived, uint8_t size) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
return spilib_writeread(HAL_GetSPIHandle(port), (const char*)dataToSend,
(char*)dataReceived, (int32_t)size);
return spilib_writeread(
HAL_GetSPIHandle(port), reinterpret_cast<const char*>(dataToSend),
reinterpret_cast<char*>(dataReceived), static_cast<int32_t>(size));
}
/**
@@ -168,8 +169,9 @@ int32_t HAL_TransactionSPI(uint8_t port, uint8_t* dataToSend,
*/
int32_t HAL_WriteSPI(uint8_t port, uint8_t* dataToSend, uint8_t sendSize) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
return spilib_write(HAL_GetSPIHandle(port), (const char*)dataToSend,
(int32_t)sendSize);
return spilib_write(HAL_GetSPIHandle(port),
reinterpret_cast<const char*>(dataToSend),
static_cast<int32_t>(sendSize));
}
/**
@@ -187,7 +189,8 @@ int32_t HAL_WriteSPI(uint8_t port, uint8_t* dataToSend, uint8_t sendSize) {
*/
int32_t HAL_ReadSPI(uint8_t port, uint8_t* buffer, uint8_t count) {
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(port));
return spilib_read(HAL_GetSPIHandle(port), (char*)buffer, (int32_t)count);
return spilib_read(HAL_GetSPIHandle(port), reinterpret_cast<char*>(buffer),
static_cast<int32_t>(count));
}
/**
@@ -325,13 +328,14 @@ void HAL_SetSPIHandle(uint8_t port, int32_t handle) {
}
static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
SPIAccumulator* accum = (SPIAccumulator*)param;
SPIAccumulator* accum = static_cast<SPIAccumulator*>(param);
// perform SPI transaction
uint8_t resp_b[4];
std::lock_guard<priority_recursive_mutex> sync(spiGetSemaphore(accum->port));
spilib_writeread(HAL_GetSPIHandle(accum->port), (const char*)accum->cmd,
(char*)resp_b, (int32_t)accum->xfer_size);
spilib_writeread(
HAL_GetSPIHandle(accum->port), reinterpret_cast<const char*>(accum->cmd),
reinterpret_cast<char*>(resp_b), static_cast<int32_t>(accum->xfer_size));
// convert from bytes
uint32_t resp = 0;
@@ -350,7 +354,7 @@ static void spiAccumulatorProcess(uint64_t currentTime, void* param) {
// process response
if ((resp & accum->valid_mask) == accum->valid_value) {
// valid sensor data; extract data field
int32_t data = (int32_t)(resp >> accum->data_shift);
int32_t data = static_cast<int32_t>(resp >> accum->data_shift);
data &= accum->data_max - 1;
// 2s complement conversion if signed MSB is set
if (accum->is_signed && (data & accum->data_msb_mask) != 0)
@@ -553,7 +557,7 @@ double HAL_GetSPIAccumulatorAverage(uint8_t port, int32_t* status) {
uint32_t count;
HAL_GetAccumulatorOutput(port, &value, &count, status);
if (count == 0) return 0.0;
return ((double)value) / count;
return static_cast<double>(value) / count;
}
/**

View File

@@ -18,7 +18,7 @@ void HAL_InitializeSerialPort(uint8_t port, int32_t* status) {
char const* portName;
if (m_resourceManagerHandle == 0)
viOpenDefaultRM((ViSession*)&m_resourceManagerHandle);
viOpenDefaultRM(reinterpret_cast<ViSession*>(&m_resourceManagerHandle));
if (port == 0)
portName = "ASRL1::INSTR";
@@ -27,8 +27,9 @@ void HAL_InitializeSerialPort(uint8_t port, int32_t* status) {
else
portName = "ASRL3::INSTR";
*status = viOpen(m_resourceManagerHandle, const_cast<char*>(portName),
VI_NULL, VI_NULL, (ViSession*)&m_portHandle[port]);
*status =
viOpen(m_resourceManagerHandle, const_cast<char*>(portName), VI_NULL,
VI_NULL, reinterpret_cast<ViSession*>(&m_portHandle[port]));
if (*status > 0) *status = 0;
}

View File

@@ -104,4 +104,4 @@ void DigitalHandleResource<THandle, TStruct, size>::Free(
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
}
} // namespace hal

View File

@@ -35,4 +35,4 @@ HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType) {
handle += index;
return handle;
}
}
} // namespace hal

View File

@@ -86,4 +86,4 @@ static inline int16_t getPortHandleModule(HAL_PortHandle handle) {
HAL_PortHandle createPortHandle(uint8_t pin, uint8_t module);
HAL_Handle createHandle(int16_t index, HAL_HandleEnum handleType);
}
} // namespace hal

View File

@@ -112,4 +112,4 @@ void IndexedHandleResource<THandle, TStruct, size, enumValue>::Free(
std::lock_guard<priority_mutex> sync(m_handleMutexes[index]);
m_structures[index].reset();
}
}
} // namespace hal

View File

@@ -114,4 +114,4 @@ void LimitedClassedHandleResource<THandle, TStruct, size, enumValue>::Free(
std::lock_guard<priority_mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
}
} // namespace hal

View File

@@ -110,4 +110,4 @@ void LimitedHandleResource<THandle, TStruct, size, enumValue>::Free(
std::lock_guard<priority_mutex> lock(m_handleMutexes[index]);
m_structures[index].reset();
}
}
} // namespace hal

View File

@@ -84,4 +84,4 @@ void UnlimitedHandleResource<THandle, TStruct, enumValue>::Free(
if (index < 0 || index >= static_cast<int16_t>(m_structures.size())) return;
m_structures[index].reset();
}
}
} // namespace hal

View File

@@ -39,7 +39,8 @@ int HAL_GetJoystickAxes(uint8_t joystickNum, HAL_JoystickAxes* axes) {
HAL_JoystickAxesInt axesInt;
int retVal = FRC_NetworkCommunication_getJoystickAxes(
joystickNum, (JoystickAxes_t*)&axesInt, HAL_kMaxJoystickAxes);
joystickNum, reinterpret_cast<JoystickAxes_t*>(&axesInt),
HAL_kMaxJoystickAxes);
// copy int values to float values
axes->count = axesInt.count;
@@ -59,7 +60,8 @@ int HAL_GetJoystickAxes(uint8_t joystickNum, HAL_JoystickAxes* axes) {
int HAL_GetJoystickPOVs(uint8_t joystickNum, HAL_JoystickPOVs* povs) {
return FRC_NetworkCommunication_getJoystickPOVs(
joystickNum, (JoystickPOV_t*)povs, HAL_kMaxJoystickPOVs);
joystickNum, reinterpret_cast<JoystickPOV_t*>(povs),
HAL_kMaxJoystickPOVs);
}
int HAL_GetJoystickButtons(uint8_t joystickNum, HAL_JoystickButtons* buttons) {
@@ -87,8 +89,9 @@ int HAL_GetJoystickDescriptor(uint8_t joystickNum,
desc->buttonCount = 0;
desc->povCount = 0;
int retval = FRC_NetworkCommunication_getJoystickDesc(
joystickNum, &desc->isXbox, &desc->type, (char*)(&desc->name),
&desc->axisCount, (uint8_t*)&desc->axisTypes, &desc->buttonCount,
joystickNum, &desc->isXbox, &desc->type,
reinterpret_cast<char*>(&desc->name), &desc->axisCount,
reinterpret_cast<uint8_t*>(&desc->axisTypes), &desc->buttonCount,
&desc->povCount);
/* check the return, if there is an error and the RIOimage predates FRC2017,
* then axisCount needs to be cleared */
@@ -120,13 +123,14 @@ int HAL_GetJoystickType(uint8_t joystickNum) {
char* HAL_GetJoystickName(uint8_t joystickNum) {
HAL_JoystickDescriptor joystickDesc;
if (HAL_GetJoystickDescriptor(joystickNum, &joystickDesc) < 0) {
char* name = (char*)std::malloc(1);
char* name = static_cast<char*>(std::malloc(1));
name[0] = '\0';
return name;
} else {
size_t len = std::strlen(joystickDesc.name);
char* name = (char*)std::malloc(len + 1);
std::strcpy(name, joystickDesc.name);
char* name = static_cast<char*>(std::malloc(len + 1));
std::strncpy(name, joystickDesc.name, len);
name[len] = '\0';
return name;
}
}