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.wpilibj.simulation;
006
007import edu.wpi.first.hal.simulation.NotifyCallback;
008import edu.wpi.first.hal.simulation.RoboRioDataJNI;
009
010/** A utility class to control a simulated RoboRIO. */
011public final class RoboRioSim {
012  private RoboRioSim() {
013    // Utility class
014  }
015
016  /**
017   * Register a callback to be run when the FPGA button state changes.
018   *
019   * @param callback the callback
020   * @param initialNotify whether to run the callback with the initial state
021   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
022   *     this object so GC doesn't cancel the callback.
023   */
024  public static CallbackStore registerFPGAButtonCallback(
025      NotifyCallback callback, boolean initialNotify) {
026    int uid = RoboRioDataJNI.registerFPGAButtonCallback(callback, initialNotify);
027    return new CallbackStore(uid, RoboRioDataJNI::cancelFPGAButtonCallback);
028  }
029
030  /**
031   * Query the state of the FPGA button.
032   *
033   * @return the FPGA button state
034   */
035  public static boolean getFPGAButton() {
036    return RoboRioDataJNI.getFPGAButton();
037  }
038
039  /**
040   * Define the state of the FPGA button.
041   *
042   * @param fpgaButton the new state
043   */
044  public static void setFPGAButton(boolean fpgaButton) {
045    RoboRioDataJNI.setFPGAButton(fpgaButton);
046  }
047
048  /**
049   * Register a callback to be run whenever the Vin voltage changes.
050   *
051   * @param callback the callback
052   * @param initialNotify whether to call the callback with the initial state
053   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
054   *     this object so GC doesn't cancel the callback.
055   */
056  public static CallbackStore registerVInVoltageCallback(
057      NotifyCallback callback, boolean initialNotify) {
058    int uid = RoboRioDataJNI.registerVInVoltageCallback(callback, initialNotify);
059    return new CallbackStore(uid, RoboRioDataJNI::cancelVInVoltageCallback);
060  }
061
062  /**
063   * Measure the Vin voltage.
064   *
065   * @return the Vin voltage
066   */
067  public static double getVInVoltage() {
068    return RoboRioDataJNI.getVInVoltage();
069  }
070
071  /**
072   * Define the Vin voltage.
073   *
074   * @param vInVoltage the new voltage
075   */
076  public static void setVInVoltage(double vInVoltage) {
077    RoboRioDataJNI.setVInVoltage(vInVoltage);
078  }
079
080  /**
081   * Register a callback to be run whenever the Vin current changes.
082   *
083   * @param callback the callback
084   * @param initialNotify whether the callback should be called with the initial value
085   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
086   *     this object so GC doesn't cancel the callback.
087   */
088  public static CallbackStore registerVInCurrentCallback(
089      NotifyCallback callback, boolean initialNotify) {
090    int uid = RoboRioDataJNI.registerVInCurrentCallback(callback, initialNotify);
091    return new CallbackStore(uid, RoboRioDataJNI::cancelVInCurrentCallback);
092  }
093
094  /**
095   * Measure the Vin current.
096   *
097   * @return the Vin current
098   */
099  public static double getVInCurrent() {
100    return RoboRioDataJNI.getVInCurrent();
101  }
102
103  /**
104   * Define the Vin current.
105   *
106   * @param vInCurrent the new current
107   */
108  public static void setVInCurrent(double vInCurrent) {
109    RoboRioDataJNI.setVInCurrent(vInCurrent);
110  }
111
112  /**
113   * Register a callback to be run whenever the 6V rail voltage changes.
114   *
115   * @param callback the callback
116   * @param initialNotify whether the callback should be called with the initial value
117   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
118   *     this object so GC doesn't cancel the callback.
119   */
120  public static CallbackStore registerUserVoltage6VCallback(
121      NotifyCallback callback, boolean initialNotify) {
122    int uid = RoboRioDataJNI.registerUserVoltage6VCallback(callback, initialNotify);
123    return new CallbackStore(uid, RoboRioDataJNI::cancelUserVoltage6VCallback);
124  }
125
126  /**
127   * Measure the 6V rail voltage.
128   *
129   * @return the 6V rail voltage
130   */
131  public static double getUserVoltage6V() {
132    return RoboRioDataJNI.getUserVoltage6V();
133  }
134
135  /**
136   * Define the 6V rail voltage.
137   *
138   * @param userVoltage6V the new voltage
139   */
140  public static void setUserVoltage6V(double userVoltage6V) {
141    RoboRioDataJNI.setUserVoltage6V(userVoltage6V);
142  }
143
144  /**
145   * Register a callback to be run whenever the 6V rail current changes.
146   *
147   * @param callback the callback
148   * @param initialNotify whether the callback should be called with the initial value
149   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
150   *     this object so GC doesn't cancel the callback.
151   */
152  public static CallbackStore registerUserCurrent6VCallback(
153      NotifyCallback callback, boolean initialNotify) {
154    int uid = RoboRioDataJNI.registerUserCurrent6VCallback(callback, initialNotify);
155    return new CallbackStore(uid, RoboRioDataJNI::cancelUserCurrent6VCallback);
156  }
157
158  /**
159   * Measure the 6V rail current.
160   *
161   * @return the 6V rail current
162   */
163  public static double getUserCurrent6V() {
164    return RoboRioDataJNI.getUserCurrent6V();
165  }
166
167  /**
168   * Define the 6V rail current.
169   *
170   * @param userCurrent6V the new current
171   */
172  public static void setUserCurrent6V(double userCurrent6V) {
173    RoboRioDataJNI.setUserCurrent6V(userCurrent6V);
174  }
175
176  /**
177   * Register a callback to be run whenever the 6V rail active state changes.
178   *
179   * @param callback the callback
180   * @param initialNotify whether the callback should be called with the initial state
181   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
182   *     this object so GC doesn't cancel the callback.
183   */
184  public static CallbackStore registerUserActive6VCallback(
185      NotifyCallback callback, boolean initialNotify) {
186    int uid = RoboRioDataJNI.registerUserActive6VCallback(callback, initialNotify);
187    return new CallbackStore(uid, RoboRioDataJNI::cancelUserActive6VCallback);
188  }
189
190  /**
191   * Get the 6V rail active state.
192   *
193   * @return true if the 6V rail is active
194   */
195  public static boolean getUserActive6V() {
196    return RoboRioDataJNI.getUserActive6V();
197  }
198
199  /**
200   * Set the 6V rail active state.
201   *
202   * @param userActive6V true to make rail active
203   */
204  public static void setUserActive6V(boolean userActive6V) {
205    RoboRioDataJNI.setUserActive6V(userActive6V);
206  }
207
208  /**
209   * Register a callback to be run whenever the 5V rail voltage changes.
210   *
211   * @param callback the callback
212   * @param initialNotify whether the callback should be called with the initial value
213   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
214   *     this object so GC doesn't cancel the callback.
215   */
216  public static CallbackStore registerUserVoltage5VCallback(
217      NotifyCallback callback, boolean initialNotify) {
218    int uid = RoboRioDataJNI.registerUserVoltage5VCallback(callback, initialNotify);
219    return new CallbackStore(uid, RoboRioDataJNI::cancelUserVoltage5VCallback);
220  }
221
222  /**
223   * Measure the 5V rail voltage.
224   *
225   * @return the 5V rail voltage
226   */
227  public static double getUserVoltage5V() {
228    return RoboRioDataJNI.getUserVoltage5V();
229  }
230
231  /**
232   * Define the 5V rail voltage.
233   *
234   * @param userVoltage5V the new voltage
235   */
236  public static void setUserVoltage5V(double userVoltage5V) {
237    RoboRioDataJNI.setUserVoltage5V(userVoltage5V);
238  }
239
240  /**
241   * Register a callback to be run whenever the 5V rail current changes.
242   *
243   * @param callback the callback
244   * @param initialNotify whether the callback should be called with the initial value
245   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
246   *     this object so GC doesn't cancel the callback.
247   */
248  public static CallbackStore registerUserCurrent5VCallback(
249      NotifyCallback callback, boolean initialNotify) {
250    int uid = RoboRioDataJNI.registerUserCurrent5VCallback(callback, initialNotify);
251    return new CallbackStore(uid, RoboRioDataJNI::cancelUserCurrent5VCallback);
252  }
253
254  /**
255   * Measure the 5V rail current.
256   *
257   * @return the 5V rail current
258   */
259  public static double getUserCurrent5V() {
260    return RoboRioDataJNI.getUserCurrent5V();
261  }
262
263  /**
264   * Define the 5V rail current.
265   *
266   * @param userCurrent5V the new current
267   */
268  public static void setUserCurrent5V(double userCurrent5V) {
269    RoboRioDataJNI.setUserCurrent5V(userCurrent5V);
270  }
271
272  /**
273   * Register a callback to be run whenever the 5V rail active state changes.
274   *
275   * @param callback the callback
276   * @param initialNotify whether the callback should be called with the initial state
277   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
278   *     this object so GC doesn't cancel the callback.
279   */
280  public static CallbackStore registerUserActive5VCallback(
281      NotifyCallback callback, boolean initialNotify) {
282    int uid = RoboRioDataJNI.registerUserActive5VCallback(callback, initialNotify);
283    return new CallbackStore(uid, RoboRioDataJNI::cancelUserActive5VCallback);
284  }
285
286  /**
287   * Get the 5V rail active state.
288   *
289   * @return true if the 5V rail is active
290   */
291  public static boolean getUserActive5V() {
292    return RoboRioDataJNI.getUserActive5V();
293  }
294
295  /**
296   * Set the 5V rail active state.
297   *
298   * @param userActive5V true to make rail active
299   */
300  public static void setUserActive5V(boolean userActive5V) {
301    RoboRioDataJNI.setUserActive5V(userActive5V);
302  }
303
304  /**
305   * Register a callback to be run whenever the 3.3V rail voltage changes.
306   *
307   * @param callback the callback
308   * @param initialNotify whether the callback should be called with the initial value
309   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
310   *     this object so GC doesn't cancel the callback.
311   */
312  public static CallbackStore registerUserVoltage3V3Callback(
313      NotifyCallback callback, boolean initialNotify) {
314    int uid = RoboRioDataJNI.registerUserVoltage3V3Callback(callback, initialNotify);
315    return new CallbackStore(uid, RoboRioDataJNI::cancelUserVoltage3V3Callback);
316  }
317
318  /**
319   * Measure the 3.3V rail voltage.
320   *
321   * @return the 3.3V rail voltage
322   */
323  public static double getUserVoltage3V3() {
324    return RoboRioDataJNI.getUserVoltage3V3();
325  }
326
327  /**
328   * Define the 3.3V rail voltage.
329   *
330   * @param userVoltage3V3 the new voltage
331   */
332  public static void setUserVoltage3V3(double userVoltage3V3) {
333    RoboRioDataJNI.setUserVoltage3V3(userVoltage3V3);
334  }
335
336  /**
337   * Register a callback to be run whenever the 3.3V rail current changes.
338   *
339   * @param callback the callback
340   * @param initialNotify whether the callback should be called with the initial value
341   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
342   *     this object so GC doesn't cancel the callback.
343   */
344  public static CallbackStore registerUserCurrent3V3Callback(
345      NotifyCallback callback, boolean initialNotify) {
346    int uid = RoboRioDataJNI.registerUserCurrent3V3Callback(callback, initialNotify);
347    return new CallbackStore(uid, RoboRioDataJNI::cancelUserCurrent3V3Callback);
348  }
349
350  /**
351   * Measure the 3.3V rail current.
352   *
353   * @return the 3.3V rail current
354   */
355  public static double getUserCurrent3V3() {
356    return RoboRioDataJNI.getUserCurrent3V3();
357  }
358
359  /**
360   * Define the 3.3V rail current.
361   *
362   * @param userCurrent3V3 the new current
363   */
364  public static void setUserCurrent3V3(double userCurrent3V3) {
365    RoboRioDataJNI.setUserCurrent3V3(userCurrent3V3);
366  }
367
368  /**
369   * Register a callback to be run whenever the 3.3V rail active state changes.
370   *
371   * @param callback the callback
372   * @param initialNotify whether the callback should be called with the initial state
373   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
374   *     this object so GC doesn't cancel the callback.
375   */
376  public static CallbackStore registerUserActive3V3Callback(
377      NotifyCallback callback, boolean initialNotify) {
378    int uid = RoboRioDataJNI.registerUserActive3V3Callback(callback, initialNotify);
379    return new CallbackStore(uid, RoboRioDataJNI::cancelUserActive3V3Callback);
380  }
381
382  /**
383   * Get the 3.3V rail active state.
384   *
385   * @return true if the 3.3V rail is active
386   */
387  public static boolean getUserActive3V3() {
388    return RoboRioDataJNI.getUserActive3V3();
389  }
390
391  /**
392   * Set the 3.3V rail active state.
393   *
394   * @param userActive3V3 true to make rail active
395   */
396  public static void setUserActive3V3(boolean userActive3V3) {
397    RoboRioDataJNI.setUserActive3V3(userActive3V3);
398  }
399
400  /**
401   * Register a callback to be run whenever the 6V rail number of faults changes.
402   *
403   * @param callback the callback
404   * @param initialNotify whether the callback should be called with the initial value
405   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
406   *     this object so GC doesn't cancel the callback.
407   */
408  public static CallbackStore registerUserFaults6VCallback(
409      NotifyCallback callback, boolean initialNotify) {
410    int uid = RoboRioDataJNI.registerUserFaults6VCallback(callback, initialNotify);
411    return new CallbackStore(uid, RoboRioDataJNI::cancelUserFaults6VCallback);
412  }
413
414  /**
415   * Get the 6V rail number of faults.
416   *
417   * @return number of faults
418   */
419  public static int getUserFaults6V() {
420    return RoboRioDataJNI.getUserFaults6V();
421  }
422
423  /**
424   * Set the 6V rail number of faults.
425   *
426   * @param userFaults6V number of faults
427   */
428  public static void setUserFaults6V(int userFaults6V) {
429    RoboRioDataJNI.setUserFaults6V(userFaults6V);
430  }
431
432  /**
433   * Register a callback to be run whenever the 5V rail number of faults changes.
434   *
435   * @param callback the callback
436   * @param initialNotify whether the callback should be called with the initial value
437   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
438   *     this object so GC doesn't cancel the callback.
439   */
440  public static CallbackStore registerUserFaults5VCallback(
441      NotifyCallback callback, boolean initialNotify) {
442    int uid = RoboRioDataJNI.registerUserFaults5VCallback(callback, initialNotify);
443    return new CallbackStore(uid, RoboRioDataJNI::cancelUserFaults5VCallback);
444  }
445
446  /**
447   * Get the 5V rail number of faults.
448   *
449   * @return number of faults
450   */
451  public static int getUserFaults5V() {
452    return RoboRioDataJNI.getUserFaults5V();
453  }
454
455  /**
456   * Set the 5V rail number of faults.
457   *
458   * @param userFaults5V number of faults
459   */
460  public static void setUserFaults5V(int userFaults5V) {
461    RoboRioDataJNI.setUserFaults5V(userFaults5V);
462  }
463
464  /**
465   * Register a callback to be run whenever the 3.3V rail number of faults changes.
466   *
467   * @param callback the callback
468   * @param initialNotify whether the callback should be called with the initial value
469   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
470   *     this object so GC doesn't cancel the callback.
471   */
472  public static CallbackStore registerUserFaults3V3Callback(
473      NotifyCallback callback, boolean initialNotify) {
474    int uid = RoboRioDataJNI.registerUserFaults3V3Callback(callback, initialNotify);
475    return new CallbackStore(uid, RoboRioDataJNI::cancelUserFaults3V3Callback);
476  }
477
478  /**
479   * Get the 3.3V rail number of faults.
480   *
481   * @return number of faults
482   */
483  public static int getUserFaults3V3() {
484    return RoboRioDataJNI.getUserFaults3V3();
485  }
486
487  /**
488   * Set the 3.3V rail number of faults.
489   *
490   * @param userFaults3V3 number of faults
491   */
492  public static void setUserFaults3V3(int userFaults3V3) {
493    RoboRioDataJNI.setUserFaults3V3(userFaults3V3);
494  }
495
496  /**
497   * Register a callback to be run whenever the Brownout voltage changes.
498   *
499   * @param callback the callback
500   * @param initialNotify whether to call the callback with the initial state
501   * @return the {@link CallbackStore} object associated with this callback. Save a reference to
502   *     this object so GC doesn't cancel the callback.
503   */
504  public static CallbackStore registerBrownoutVoltageCallback(
505      NotifyCallback callback, boolean initialNotify) {
506    int uid = RoboRioDataJNI.registerBrownoutVoltageCallback(callback, initialNotify);
507    return new CallbackStore(uid, RoboRioDataJNI::cancelBrownoutVoltageCallback);
508  }
509
510  /**
511   * Measure the Brownout voltage.
512   *
513   * @return the Brownout voltage
514   */
515  public static double getBrownoutVoltage() {
516    return RoboRioDataJNI.getBrownoutVoltage();
517  }
518
519  /**
520   * Define the Brownout voltage.
521   *
522   * @param vInVoltage the new voltage
523   */
524  public static void setBrownoutVoltage(double vInVoltage) {
525    RoboRioDataJNI.setBrownoutVoltage(vInVoltage);
526  }
527
528  /**
529   * Get the serial number.
530   *
531   * @return The serial number.
532   */
533  public static String getSerialNumber() {
534    return RoboRioDataJNI.getSerialNumber();
535  }
536
537  /**
538   * Set the serial number.
539   *
540   * @param serialNumber The serial number.
541   */
542  public static void setSerialNumber(String serialNumber) {
543    RoboRioDataJNI.setSerialNumber(serialNumber);
544  }
545
546  /**
547   * Get the comments string.
548   *
549   * @return The comments string.
550   */
551  public static String getComments() {
552    return RoboRioDataJNI.getComments();
553  }
554
555  /**
556   * Set the comments string.
557   *
558   * @param comments The comments string.
559   */
560  public static void setComments(String comments) {
561    RoboRioDataJNI.setComments(comments);
562  }
563
564  /** Reset all simulation data. */
565  public static void resetData() {
566    RoboRioDataJNI.resetData();
567  }
568}