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:
Thad House
2016-05-21 01:42:16 -07:00
committed by Peter Johnson
parent a4f0c4fbe0
commit 54092378e9
6 changed files with 34 additions and 18 deletions

View File

@@ -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) {