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