001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package edu.wpi.first.hal;
006
007import java.nio.ByteBuffer;
008
009public class DriverStationJNI extends JNIWrapper {
010  public static native void observeUserProgramStarting();
011
012  public static native void observeUserProgramDisabled();
013
014  public static native void observeUserProgramAutonomous();
015
016  public static native void observeUserProgramTeleop();
017
018  public static native void observeUserProgramTest();
019
020  public static void report(int resource, int instanceNumber) {
021    report(resource, instanceNumber, 0, "");
022  }
023
024  public static void report(int resource, int instanceNumber, int context) {
025    report(resource, instanceNumber, context, "");
026  }
027
028  /**
029   * Report the usage of a resource of interest.
030   *
031   * <p>Original signature: <code>uint32_t report(tResourceType, uint8_t, uint8_t, const
032   * char*)</code>
033   *
034   * @param resource one of the values in the tResourceType above (max value 51).
035   * @param instanceNumber an index that identifies the resource instance.
036   * @param context an optional additional context number for some cases (such as module number).
037   *     Set to 0 to omit.
038   * @param feature a string to be included describing features in use on a specific resource.
039   *     Setting the same resource more than once allows you to change the feature string.
040   * @return TODO
041   */
042  public static native int report(int resource, int instanceNumber, int context, String feature);
043
044  public static native int nativeGetControlWord();
045
046  @SuppressWarnings("MissingJavadocMethod")
047  public static void getControlWord(ControlWord controlWord) {
048    int word = nativeGetControlWord();
049    controlWord.update(
050        (word & 1) != 0,
051        ((word >> 1) & 1) != 0,
052        ((word >> 2) & 1) != 0,
053        ((word >> 3) & 1) != 0,
054        ((word >> 4) & 1) != 0,
055        ((word >> 5) & 1) != 0);
056  }
057
058  private static native int nativeGetAllianceStation();
059
060  public static final int kRed1AllianceStation = 0;
061  public static final int kRed2AllianceStation = 1;
062  public static final int kRed3AllianceStation = 2;
063  public static final int kBlue1AllianceStation = 3;
064  public static final int kBlue2AllianceStation = 4;
065  public static final int kBlue3AllianceStation = 5;
066
067  @SuppressWarnings("MissingJavadocMethod")
068  public static AllianceStationID getAllianceStation() {
069    switch (nativeGetAllianceStation()) {
070      case kRed1AllianceStation:
071        return AllianceStationID.Red1;
072      case kRed2AllianceStation:
073        return AllianceStationID.Red2;
074      case kRed3AllianceStation:
075        return AllianceStationID.Red3;
076      case kBlue1AllianceStation:
077        return AllianceStationID.Blue1;
078      case kBlue2AllianceStation:
079        return AllianceStationID.Blue2;
080      case kBlue3AllianceStation:
081        return AllianceStationID.Blue3;
082      default:
083        return null;
084    }
085  }
086
087  public static final int kMaxJoystickAxes = 12;
088  public static final int kMaxJoystickPOVs = 12;
089  public static final int kMaxJoysticks = 6;
090
091  public static native int getJoystickAxes(byte joystickNum, float[] axesArray);
092
093  public static native int getJoystickAxesRaw(byte joystickNum, int[] rawAxesArray);
094
095  public static native int getJoystickPOVs(byte joystickNum, short[] povsArray);
096
097  public static native int getJoystickButtons(byte joystickNum, ByteBuffer count);
098
099  public static native void getAllJoystickData(
100      float[] axesArray, byte[] rawAxesArray, short[] povsArray, long[] buttonsAndMetadata);
101
102  public static native int setJoystickOutputs(
103      byte joystickNum, int outputs, short leftRumble, short rightRumble);
104
105  public static native int getJoystickIsXbox(byte joystickNum);
106
107  public static native int getJoystickType(byte joystickNum);
108
109  public static native String getJoystickName(byte joystickNum);
110
111  public static native int getJoystickAxisType(byte joystickNum, byte axis);
112
113  public static native double getMatchTime();
114
115  public static native int getMatchInfo(MatchInfoData info);
116
117  public static native int sendError(
118      boolean isError,
119      int errorCode,
120      boolean isLVCode,
121      String details,
122      String location,
123      String callStack,
124      boolean printMsg);
125
126  public static native int sendConsoleLine(String line);
127
128  public static native boolean refreshDSData();
129
130  public static native void provideNewDataEventHandle(int handle);
131
132  public static native void removeNewDataEventHandle(int handle);
133
134  public static native boolean getOutputsActive();
135
136  private DriverStationJNI() {}
137}