001/*----------------------------------------------------------------------------*/
002/* Copyright (c) FIRST 2016-2017. All Rights Reserved.                        */
003/* Open Source Software - may be modified and shared by FRC teams. The code   */
004/* must be accompanied by the FIRST BSD license file in the root directory of */
005/* the project.                                                               */
006/*----------------------------------------------------------------------------*/
007
008package edu.wpi.first.wpilibj.hal;
009
010import java.nio.ByteBuffer;
011
012/**
013 * JNI Wrapper for HAL<br>.
014 */
015@SuppressWarnings({"AbbreviationAsWordInName", "MethodName"})
016public class HAL extends JNIWrapper {
017  public static native void waitForDSData();
018
019  public static native int initialize(int mode);
020
021  public static native void observeUserProgramStarting();
022
023  public static native void observeUserProgramDisabled();
024
025  public static native void observeUserProgramAutonomous();
026
027  public static native void observeUserProgramTeleop();
028
029  public static native void observeUserProgramTest();
030
031  public static void report(int resource, int instanceNumber) {
032    report(resource, instanceNumber, 0, "");
033  }
034
035  public static void report(int resource, int instanceNumber, int context) {
036    report(resource, instanceNumber, context, "");
037  }
038
039  /**
040   * Report the usage of a resource of interest. <br>
041   *
042   * <p>Original signature: <code>uint32_t report(tResourceType, uint8_t, uint8_t, const
043   * char*)</code>
044   *
045   * @param resource       one of the values in the tResourceType above (max value 51). <br>
046   * @param instanceNumber an index that identifies the resource instance. <br>
047   * @param context        an optional additional context number for some cases (such as module
048   *                       number). Set to 0 to omit. <br>
049   * @param feature        a string to be included describing features in use on a specific
050   *                       resource. Setting the same resource more than once allows you to change
051   *                       the feature string.
052   */
053  public static native int report(int resource, int instanceNumber, int context, String feature);
054
055  private static native int nativeGetControlWord();
056
057  @SuppressWarnings("JavadocMethod")
058  public static void getControlWord(ControlWord controlWord) {
059    int word = nativeGetControlWord();
060    controlWord.update((word & 1) != 0, ((word >> 1) & 1) != 0, ((word >> 2) & 1) != 0,
061        ((word >> 3) & 1) != 0, ((word >> 4) & 1) != 0, ((word >> 5) & 1) != 0);
062  }
063
064  private static native int nativeGetAllianceStation();
065
066  @SuppressWarnings("JavadocMethod")
067  public static AllianceStationID getAllianceStation() {
068    switch (nativeGetAllianceStation()) {
069      case 0:
070        return AllianceStationID.Red1;
071      case 1:
072        return AllianceStationID.Red2;
073      case 2:
074        return AllianceStationID.Red3;
075      case 3:
076        return AllianceStationID.Blue1;
077      case 4:
078        return AllianceStationID.Blue2;
079      case 5:
080        return AllianceStationID.Blue3;
081      default:
082        return null;
083    }
084  }
085
086  public static int kMaxJoystickAxes = 12;
087  public static int kMaxJoystickPOVs = 12;
088
089  public static native short getJoystickAxes(byte joystickNum, float[] axesArray);
090
091  public static native short getJoystickPOVs(byte joystickNum, short[] povsArray);
092
093  public static native int getJoystickButtons(byte joystickNum, ByteBuffer count);
094
095  public static native int setJoystickOutputs(byte joystickNum, int outputs, short leftRumble,
096                                              short rightRumble);
097
098  public static native int getJoystickIsXbox(byte joystickNum);
099
100  public static native int getJoystickType(byte joystickNum);
101
102  public static native String getJoystickName(byte joystickNum);
103
104  public static native int getJoystickAxisType(byte joystickNum, byte axis);
105
106  public static native double getMatchTime();
107
108  public static native boolean getSystemActive();
109
110  public static native boolean getBrownedOut();
111
112  public static native int setErrorData(String error);
113
114  public static native int sendError(boolean isError, int errorCode, boolean isLVCode,
115                                     String details, String location, String callStack,
116                                     boolean printMsg);
117}