Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame^] | 1 | //This file must compile on ALL PLATFORMS. Be very careful what you put in here. |
| 2 | #include "HAL/HAL.hpp" |
| 3 | #include "FRC_NetworkCommunication/FRCComm.h" |
| 4 | #include <cstring> |
| 5 | |
| 6 | int HALGetControlWord(HALControlWord *data) |
| 7 | { |
| 8 | return FRC_NetworkCommunication_getControlWord((ControlWord_t*) data); |
| 9 | } |
| 10 | |
| 11 | void HALSetNewDataSem(MULTIWAIT_ID sem) |
| 12 | { |
| 13 | setNewDataSem(sem->native_handle()); |
| 14 | } |
| 15 | |
| 16 | int HALGetAllianceStation(enum HALAllianceStationID *allianceStation) |
| 17 | { |
| 18 | return FRC_NetworkCommunication_getAllianceStation((AllianceStationID_t*) allianceStation); |
| 19 | } |
| 20 | |
| 21 | int HALGetJoystickAxes(uint8_t joystickNum, HALJoystickAxes *axes) |
| 22 | { |
| 23 | return FRC_NetworkCommunication_getJoystickAxes(joystickNum, (JoystickAxes_t*) axes, kMaxJoystickAxes); |
| 24 | } |
| 25 | |
| 26 | int HALGetJoystickPOVs(uint8_t joystickNum, HALJoystickPOVs *povs) |
| 27 | { |
| 28 | return FRC_NetworkCommunication_getJoystickPOVs(joystickNum, (JoystickPOV_t*) povs, kMaxJoystickPOVs); |
| 29 | } |
| 30 | |
| 31 | int HALGetJoystickButtons(uint8_t joystickNum, HALJoystickButtons *buttons) |
| 32 | { |
| 33 | return FRC_NetworkCommunication_getJoystickButtons(joystickNum, &buttons->buttons, &buttons->count); |
| 34 | } |
| 35 | |
| 36 | int HALGetJoystickDescriptor(uint8_t joystickNum, HALJoystickDescriptor *desc) |
| 37 | { |
| 38 | return FRC_NetworkCommunication_getJoystickDesc(joystickNum, &desc->isXbox, &desc->type, (char *)(&desc->name), |
| 39 | &desc->axisCount, (uint8_t *)&desc->axisTypes, &desc->buttonCount, &desc->povCount); |
| 40 | } |
| 41 | |
| 42 | int HALGetJoystickIsXbox(uint8_t joystickNum) |
| 43 | { |
| 44 | HALJoystickDescriptor joystickDesc; |
| 45 | if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0) |
| 46 | { |
| 47 | return 0; |
| 48 | }else |
| 49 | { |
| 50 | return joystickDesc.isXbox; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | int HALGetJoystickType(uint8_t joystickNum) |
| 55 | { |
| 56 | HALJoystickDescriptor joystickDesc; |
| 57 | if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0) |
| 58 | { |
| 59 | return -1; |
| 60 | } else |
| 61 | { |
| 62 | return joystickDesc.type; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | char* HALGetJoystickName(uint8_t joystickNum) |
| 67 | { |
| 68 | HALJoystickDescriptor joystickDesc; |
| 69 | if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0) |
| 70 | { |
| 71 | char* name = (char*)std::malloc(1); |
| 72 | name[0] = '\0'; |
| 73 | return name; |
| 74 | } else |
| 75 | { |
| 76 | size_t len = std::strlen(joystickDesc.name); |
| 77 | char* name = (char*)std::malloc(len+1); |
| 78 | std::strcpy(name, joystickDesc.name); |
| 79 | return name; |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | int HALGetJoystickAxisType(uint8_t joystickNum, uint8_t axis) |
| 84 | { |
| 85 | HALJoystickDescriptor joystickDesc; |
| 86 | if(HALGetJoystickDescriptor(joystickNum, &joystickDesc)<0) |
| 87 | { |
| 88 | return -1; |
| 89 | } else |
| 90 | { |
| 91 | return joystickDesc.axisTypes[axis]; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | int HALSetJoystickOutputs(uint8_t joystickNum, uint32_t outputs, uint16_t leftRumble, uint16_t rightRumble) |
| 96 | { |
| 97 | return FRC_NetworkCommunication_setJoystickOutputs(joystickNum, outputs, leftRumble, rightRumble); |
| 98 | } |
| 99 | |
| 100 | int HALGetMatchTime(float *matchTime) |
| 101 | { |
| 102 | return FRC_NetworkCommunication_getMatchTime(matchTime); |
| 103 | } |
| 104 | |
| 105 | void HALNetworkCommunicationObserveUserProgramStarting(void) |
| 106 | { |
| 107 | FRC_NetworkCommunication_observeUserProgramStarting(); |
| 108 | } |
| 109 | |
| 110 | void HALNetworkCommunicationObserveUserProgramDisabled(void) |
| 111 | { |
| 112 | FRC_NetworkCommunication_observeUserProgramDisabled(); |
| 113 | } |
| 114 | |
| 115 | void HALNetworkCommunicationObserveUserProgramAutonomous(void) |
| 116 | { |
| 117 | FRC_NetworkCommunication_observeUserProgramAutonomous(); |
| 118 | } |
| 119 | |
| 120 | void HALNetworkCommunicationObserveUserProgramTeleop(void) |
| 121 | { |
| 122 | FRC_NetworkCommunication_observeUserProgramTeleop(); |
| 123 | } |
| 124 | |
| 125 | void HALNetworkCommunicationObserveUserProgramTest(void) |
| 126 | { |
| 127 | FRC_NetworkCommunication_observeUserProgramTest(); |
| 128 | } |