RobotCore 1.0
WPILib port to raspberry Pi
Loading...
Searching...
No Matches
DriverStationJNI.java
1// TODO - RobotCore - Modified file
2
3// Copyright (c) FIRST and other WPILib contributors.
4// Open Source Software; you can modify and/or share it under the terms of
5// the WPILib BSD license file in the root directory of this project.
6
7package org.wpilib.hardware.hal;
8
9import org.wpilib.driverstation.GenericHID.HIDType;
10
11import robotCore.JoystickBase;
12import robotCore.Logger;
13import robotCore.RobotCore;
14
20public class DriverStationJNI {
21
23 public static final int MAX_JOYSTICK_AXES = 12;
24
25 public static final int MAX_JOYSTICK_BUTTONS = 64;
26
28 public static final int MAX_JOYSTICK_POVS = 8;
29
31 public static final int MAX_JOYSTICKS = 6;
32
34 public static final int MAX_JOYSTICK_TOUCHPADS = 2;
35
37 public static final int MAX_JOYSTICK_TOUCHPAD_FINGERS = 2;
38
39 private static JoystickBase m_joystick = null;
40 private static JoystickBase joystick()
41 {
42 if (m_joystick == null)
43 {
44 m_joystick = JoystickBase.getInstance();
45 }
46
47 return m_joystick;
48 }
49
50 public static void observeUserProgram(long word) {
51 // System.out.println(String.format("DriverStationJNI.observeUserProgram(%d)", word));
52 // throw new UnsupportedOperationException("Unimplemented method 'DriverStationJNI.observeUserProgram'");
53 // TODO - Must verify
54 }
55
56 public static int setJoystickLeds(byte joystickNum, int leds) {
57 throw new UnsupportedOperationException("Unimplemented method 'DriverStationJNI.setJoystickLeds'");
58 // return 0; // TODO - Must fix
59 }
60
61 public static int setJoystickRumble(
62 byte joystickNum,
63 int leftRumble,
64 int rightRumble,
65 int leftTriggerRumble,
66 int rightTriggerRumble) {
67 throw new UnsupportedOperationException("Unimplemented method 'DriverStationJNI.setjoystickRumble'");
68 // return 0; // TODO - Must fix
69 }
70
71 public static AllianceStationID getAllianceStation() {
72 return AllianceStationID.BLUE_1;
73 };
74
75 public static long selectOpMode(RobotMode mode) {
76 for (OpModeOption o : s_opModes) {
77 if (o.getMode() == mode)
78 return o.id; // first opmode of that type
79 }
80 return 0;
81 }
82
83 public static void getControlWord(ControlWord controlWord) {
84 // controlWord.update(nativeGetControlWord());
85 RobotCore.getInstance().getControlWord(controlWord); // TODO - Must verify
86 }
87
88 public static int sendError(
89 boolean isError,
90 int errorCode,
91 String details,
92 String location,
93 String callStack,
94 boolean printMsg) {
95 if (isError) {
96 System.out.println(String.format("DriverStationJNI.sendError(%b,%d,%s,%s,%s,%b", isError, errorCode, details, location, callStack, printMsg));
97 }
98 // System.out.println((isError ? "Error: " : "Warning: ") + details);
99 return 0; // TODO - Must verify
100 }
101
102 public static int sendProgramCrash(String details, String location, String callStack) {
103 System.out.println(String.format("DriverStationJNI.sendProgramCrash(%s,%s,%s", details, location, callStack));
104 return 0; // TODO - Must verify
105 }
106
107 public static int getJoystickIsGamepad(byte joystickNum) {
108 return joystick().isGamepad() ? 1 : 0; // TODO - Must verify
109 }
110
111 public static int getJoystickGamepadType(byte joystickNum) {
112 // System.out.println("DriverStationJNI.getJoystickGamepadType");
113 return HIDType.UNKNOWN.value; // TODO - Must verify
114 }
115
116 public static int getJoystickSupportedOutputs(byte joystickNum) {
117 // System.out.println("DriverStationJNI.getJoystickSupportedOutputs");
118 return 0; // TODO - Must verify
119 }
120
121 public static String getJoystickName(byte joystickNum) {
122 // System.out.println("DriverStationJNI.getJoystickName");
123 return "Joystick"; // TODO - Must verify
124 }
125
126
127 private static volatile OpModeOption[] s_opModes = new OpModeOption[0];
128
129 public static void setOpModeOptions(OpModeOption[] options) {
130 // Logger.log("DriverStationJNI", 1, String.format("options.length=%d", options.length));
131 for (OpModeOption o : options) {
132 // Logger.log("DriverStation", 1, String.format("option %s mode=%s id=0x%x%n", o.name, o.getMode(), o.id));
133 }
134 s_opModes = options.clone();
135 }
136
137 public static void observeUserProgramStarting() {
138 // System.out.println("DriverStationJNI.observeUserProgramStarting");
139 // TODO - Must verify
140 }
141
142 public static void getAllJoystickData(
143 int stick,
144 float[] axesArray,
145 short[] rawAxesArray,
146 byte[] povsArray,
147 float[] touchpadFingersArray,
148 long[] buttonsAndMetadata) {
149 // Logger.log("DriverStationJNI", 1, "getAllJoystickData");
150 joystick().getAllJoystickData(stick, axesArray, rawAxesArray, povsArray, touchpadFingersArray, buttonsAndMetadata);
151 // if (buttonsAndMetadata[3] != 0)
152 // {
153 // Logger.log("DriverStationJNI", 1, String.format("b[3]=0x%x", buttonsAndMetadata[3]));
154 // }
155 }
156
157 public static boolean refreshDSData() {
158 // System.out.println("DriverStationJNI.refreshData");
159 return true; // TODO Must verify
160 }
161
162 public static int getMatchInfo(MatchInfoData info) {
163 // System.out.println("DriverStationJNI.getMatchInfo");
164 return 0; // TODO - Must verify
165 }
166
167 public static String getGameData(String gameData) {
168 // System.out.println("DeiverSationJNI.getGameData");
169 return gameData; // TODO - Must Verify
170 }
171
172 public static double getMatchTime() {
173 System.out.println("DriverStationJNI.getMatchTime");
174 return 0; // TODO - Must Verify
175 }
176
177
178 // /**
179 // * Sets the program starting flag in the DS.
180 // *
181 // * <p>This is what changes the DS to showing robot code ready.
182 // *
183 // * @see "HAL_ObserveUserProgramStarting"
184 // */
185 // public static native void observeUserProgramStarting();
186
187 // /**
188 // * Sets the control state returned to the DS.
189 // *
190 // * <p>This is used for the DS to ensure the robot is properly responding to its state request.
191 // * Ensure this gets called about every 50ms, or the robot will be disabled by the DS.
192 // *
193 // * @param word control word returned by nativeGetControlWord()
194 // */
195 // public static native void observeUserProgram(long word);
196
197 // /**
198 // * Gets the current control word of the driver station.
199 // *
200 // * <p>The control word contains the robot state.
201 // *
202 // * @return the control word
203 // * @see "HAL_GetControlWord"
204 // * @see getControlWord for a version easier to parse
205 // */
206 // public static native long nativeGetControlWord();
207
208 // /**
209 // * Gets the current control word of the driver station.
210 // *
211 // * <p>The control work contains the robot state.
212 // *
213 // * @param controlWord the ControlWord to update
214 // * @see "HAL_GetControlWord"
215 // */
216 // public static void getControlWord(ControlWord controlWord) {
217 // controlWord.update(nativeGetControlWord());
218 // }
219
220 // /**
221 // * Gets the current control word of the driver station. Unlike nativeGetControlWord, this function
222 // * gets the latest value rather than using the value cached by refreshDSData().
223 // *
224 // * <p>The control word contains the robot state.
225 // *
226 // * @return the control word
227 // * @see "HAL_GetUncachedControlWord"
228 // * @see getUncachedControlWord for a version easier to parse
229 // */
230 // public static native long nativeGetUncachedControlWord();
231
232 // /**
233 // * Gets the current control word of the driver station. Unlike getControlWord, this function gets
234 // * the latest value rather than using the value cached by refreshDSData().
235 // *
236 // * <p>The control work contains the robot state.
237 // *
238 // * @param controlWord the ControlWord to update
239 // * @see "HAL_GetControlWord"
240 // */
241 // public static void getUncachedControlWord(ControlWord controlWord) {
242 // controlWord.update(nativeGetUncachedControlWord());
243 // }
244
245 // /**
246 // * Sets operating mode options.
247 // *
248 // * @param options operating mode options
249 // */
250 // public static native void setOpModeOptions(OpModeOption[] options);
251
252 // /**
253 // * Gets the current alliance station ID.
254 // *
255 // * @return the alliance station ID int
256 // * @see "HAL_GetAllianceStation"
257 // */
258 // private static native int nativeGetAllianceStation();
259
260 // /** Unknown Alliance Station ID. */
261 // public static final int ALLIANCE_STATION_UNKNOWN = 0;
262
263 // /** Red Alliance Station 1 ID. */
264 // public static final int ALLIANCE_STATION_RED_1 = 1;
265
266 // /** Red Alliance Station 2 ID. */
267 // public static final int ALLIANCE_STATION_RED_2 = 2;
268
269 // /** Red Alliance Station 3 ID. */
270 // public static final int ALLIANCE_STATION_RED_3 = 3;
271
272 // /** Blue Alliance Station 1 ID. */
273 // public static final int ALLIANCE_STATION_BLUE_1 = 4;
274
275 // /** Blue Alliance Station 2 ID. */
276 // public static final int ALLIANCE_STATION_BLUE_2 = 5;
277
278 // /** Blue Alliance Station 3 ID. */
279 // public static final int ALLIANCE_STATION_BLUE_3 = 6;
280
281 // /**
282 // * Gets the current alliance station ID.
283 // *
284 // * @return the alliance station ID as AllianceStationID
285 // * @see "HAL_GetAllianceStation"
286 // */
287 // public static AllianceStationID getAllianceStation() {
288 // return switch (nativeGetAllianceStation()) {
289 // case ALLIANCE_STATION_UNKNOWN -> AllianceStationID.UNKNOWN;
290 // case ALLIANCE_STATION_RED_1 -> AllianceStationID.RED_1;
291 // case ALLIANCE_STATION_RED_2 -> AllianceStationID.RED_2;
292 // case ALLIANCE_STATION_RED_3 -> AllianceStationID.RED_3;
293 // case ALLIANCE_STATION_BLUE_1 -> AllianceStationID.BLUE_1;
294 // case ALLIANCE_STATION_BLUE_2 -> AllianceStationID.BLUE_2;
295 // case ALLIANCE_STATION_BLUE_3 -> AllianceStationID.BLUE_3;
296 // default -> null;
297 // };
298 // }
299
300 // /** The maximum number of axes. */
301 // public static final int MAX_JOYSTICK_AXES = 12;
302
303 // public static final int MAX_JOYSTICK_BUTTONS = 64;
304
305 // /** The maximum number of POVs. */
306 // public static final int MAX_JOYSTICK_POVS = 8;
307
308 // /** The maximum number of joysticks. */
309 // public static final int MAX_JOYSTICKS = 6;
310
311 // /** The maximum number of touchpads. */
312 // public static final int MAX_JOYSTICK_TOUCHPADS = 2;
313
314 // /** The maximum number of fingers per touchpad. */
315 // public static final int MAX_JOYSTICK_TOUCHPAD_FINGERS = 2;
316
317 // /**
318 // * Get all joystick data.
319 // *
320 // * @param stick the joystick to grab
321 // * @param axesArray all joystick axes
322 // * @param rawAxesArray all joystick axes as int
323 // * @param povsArray all povs
324 // * @param touchpadFingersArray all touchpad fingers
325 // * @param buttonsAndMetadata array of long joystick axes count, long joystick povs count, long
326 // * joystick buttons count, long joystick buttons values, long joystick touchpad count, long
327 // * pad 0 finger0 down 0x1, finger1 down 0x2, fingerCount 0xC, long pad 1 finger0 down 0x1,
328 // * finger1 down 0x2, fingerCount 0xC
329 // * @see "HAL_GetAllJoystickData"
330 // */
331 // public static native void getAllJoystickData(
332 // int stick,
333 // float[] axesArray,
334 // short[] rawAxesArray,
335 // byte[] povsArray,
336 // float[] touchpadFingersArray,
337 // long[] buttonsAndMetadata);
338
339 // /**
340 // * Set joystick rumbles.
341 // *
342 // * @param joystickNum the joystick number
343 // * @param leftRumble the left rumble value (0-FFFF)
344 // * @param rightRumble the right rumble value (0-FFFF)
345 // * @param leftTriggerRumble the left trigger rumble value (0-FFFF)
346 // * @param rightTriggerRumble the right trigger rumble value (0-FFFF)
347 // * @return the error code, or 0 for success
348 // * @see "HAL_SetJoystickRumble"
349 // */
350 // public static native int setJoystickRumble(
351 // byte joystickNum,
352 // int leftRumble,
353 // int rightRumble,
354 // int leftTriggerRumble,
355 // int rightTriggerRumble);
356
357 // /**
358 // * Sets the LEDs on a specific joystick.
359 // *
360 // * @param joystickNum the joystick number
361 // * @param leds the rgb led color value (0xRRGGBB)
362 // * @return the error code, or 0 for success
363 // * @see "HAL_SetJoystickLeds"
364 // */
365 // public static native int setJoystickLeds(byte joystickNum, int leds);
366
367 // /**
368 // * Gets whether a specific joystick is considered to be an Gamepad.
369 // *
370 // * @param joystickNum the joystick number
371 // * @return 1 if gamepad, 0 otherwise
372 // * @see "HAL_GetJoystickIsGamepad"
373 // */
374 // public static native int getJoystickIsGamepad(byte joystickNum);
375
376 // /**
377 // * Gets the type of joystick connected.
378 // *
379 // * <p>This is device specific, and different depending on what system input type the joystick
380 // * uses.
381 // *
382 // * @param joystickNum the joystick number
383 // * @return the enumerated joystick type
384 // * @see "HAL_GetJoystickGamepadType"
385 // */
386 // public static native int getJoystickGamepadType(byte joystickNum);
387
388 // /**
389 // * Gets the supported outputs of a specific joystick.
390 // *
391 // * @param joystickNum the joystick number
392 // * @return bitmask of supported outputs
393 // * @see "HAL_GetJoystickSupportedOutputs"
394 // */
395 // public static native int getJoystickSupportedOutputs(byte joystickNum);
396
397 // /**
398 // * Gets the name of a joystick.
399 // *
400 // * <p>The returned array must be freed with HAL_FreeJoystickName.
401 // *
402 // * @param joystickNum the joystick number
403 // * @return the joystick name
404 // * @see "HAL_GetJoystickName"
405 // */
406 // public static native String getJoystickName(byte joystickNum);
407
408 // /**
409 // * Return the approximate match time. The FMS does not send an official match time to the robots,
410 // * but does send an approximate match time. The value will count down the time remaining in the
411 // * current period (auto or teleop). Warning: This is not an official time (so it cannot be used to
412 // * dispute ref calls or guarantee that a function will trigger before the match ends).
413 // *
414 // * <p>When connected to the real field, this number only changes in full integer increments, and
415 // * always counts down.
416 // *
417 // * <p>When the DS is in practice mode, this number is a floating point number, and counts down.
418 // *
419 // * <p>When the DS is in teleop or autonomous mode, this number returns -1.0.
420 // *
421 // * <p>Simulation matches DS behavior without an FMS connected.
422 // *
423 // * @return time remaining in current match period (auto or teleop)
424 // * @see "HAL_GetMatchTime"
425 // */
426 // public static native double getMatchTime();
427
428 // /**
429 // * Gets info about a specific match.
430 // *
431 // * @param info the match info to populate
432 // * @return the error code, or 0 for success
433 // * @see "HAL_GetMatchInfo"
434 // */
435 // public static native int getMatchInfo(MatchInfoData info);
436
437 // /**
438 // * Gets the game-specific data for the current match.
439 // *
440 // * @param gameData The existing game data string.
441 // * @return the game-specific data
442 // * @see "HAL_GetGameData"
443 // */
444 // public static native String getGameData(String gameData);
445
446 // /**
447 // * Sends an error to the driver station.
448 // *
449 // * @param isError true for error, false for warning
450 // * @param errorCode the error code
451 // * @param details the details of the error
452 // * @param location the file location of the error
453 // * @param callStack the callstack of the error
454 // * @param printMsg true to print the error message to stdout as well as to the DS
455 // * @return the error code, or 0 for success
456 // * @see "HAL_SendError"
457 // */
458 // public static native int sendError(
459 // boolean isError,
460 // int errorCode,
461 // String details,
462 // String location,
463 // String callStack,
464 // boolean printMsg);
465
466 // /**
467 // * Sends a line to the driver station console.
468 // *
469 // * @param line the line to send
470 // * @return the error code, or 0 for success
471 // */
472 // public static native int sendConsoleLine(String line);
473
474 // /**
475 // * Sends a program crash to the driver station.
476 // *
477 // * @param details the details of the crash
478 // * @param location the file location of the crash
479 // * @param callStack the callstack of the crash
480 // * @return the error code, or 0 for success
481 // * @see "HAL_SendProgramCrash"
482 // */
483 // public static native int sendProgramCrash(String details, String location, String callStack);
484
485 // /**
486 // * Refresh the DS control word.
487 // *
488 // * @return true if updated
489 // * @see "HAL_RefreshDSData"
490 // */
491 // public static native boolean refreshDSData();
492
493 // /**
494 // * Adds an event handle to be signalled when new data arrives.
495 // *
496 // * @param handle the event handle to be signalled
497 // */
498 // public static native void provideNewDataEventHandle(int handle);
499
500 // /**
501 // * Removes the event handle from being signalled when new data arrives.
502 // *
503 // * @param handle the event handle to remove
504 // */
505 // public static native void removeNewDataEventHandle(int handle);
506
507 // /**
508 // * Gets if outputs are enabled by the control system.
509 // *
510 // * @return true if outputs are enabled
511 // */
512 // public static native boolean getOutputsActive();
513
514 // /**
515 // * Writes ANSI text to the display.
516 // *
517 // * @param data the ANSI text to write
518 // * @see "HAL_WriteDisplayAnsi"
519 // */
520 // public static native void writeDisplayAnsi(String data);
521
522 // /** Utility class. */
523 // private DriverStationJNI() {}
524}
The Joystick class read the joystick connected to the driver station.