mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
Changes HAL to return -1 to 1 for joysticks (#35)
First part of the HAL changes. Returns -1 to 1 for joysticks instead of -128 to 127. Implemented by replacing the old structure with a new structure that uses floats instead of shorts.
This commit is contained in:
committed by
Peter Johnson
parent
a4f0c4fbe0
commit
54092378e9
@@ -4,6 +4,11 @@
|
||||
#include <cstring>
|
||||
#include "FRC_NetworkCommunication/FRCComm.h"
|
||||
|
||||
struct HALJoystickAxesInt {
|
||||
uint16_t count;
|
||||
int16_t axes[kMaxJoystickAxes];
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
|
||||
int HALGetControlWord(HALControlWord* data) {
|
||||
@@ -17,9 +22,26 @@ int HALGetAllianceStation(enum HALAllianceStationID* allianceStation) {
|
||||
(AllianceStationID_t*)allianceStation);
|
||||
}
|
||||
|
||||
int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes* axes) {
|
||||
return FRC_NetworkCommunication_getJoystickAxes(
|
||||
joystickNum, (JoystickAxes_t*)axes, kMaxJoystickAxes);
|
||||
int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes *axes) {
|
||||
HALJoystickAxesInt axesInt;
|
||||
|
||||
int retVal = FRC_NetworkCommunication_getJoystickAxes(
|
||||
joystickNum, (JoystickAxes_t*) &axesInt, kMaxJoystickAxes);
|
||||
|
||||
// copy int values to float values
|
||||
axes->count = axesInt.count;
|
||||
// current scaling is -128 to 127, can easily be patched in the future by
|
||||
// changing this function.
|
||||
for (unsigned int i = 0; i < axesInt.count; i++) {
|
||||
int8_t value = axesInt.axes[i];
|
||||
if (value < 0) {
|
||||
axes->axes[i] = value / 128.0f;
|
||||
} else {
|
||||
axes->axes[i] = value / 127.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
int HALGetJoystickPOVs(uint8_t joystickNum, HALJoystickPOVs* povs) {
|
||||
|
||||
Reference in New Issue
Block a user