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 whenever the Vin voltage changes. 018 * 019 * @param callback the callback 020 * @param initialNotify whether to call the callback with the initial state 021 * @return the {@link CallbackStore} object associated with this callback. 022 */ 023 public static CallbackStore registerVInVoltageCallback( 024 NotifyCallback callback, boolean initialNotify) { 025 int uid = RoboRioDataJNI.registerVInVoltageCallback(callback, initialNotify); 026 return new CallbackStore(uid, RoboRioDataJNI::cancelVInVoltageCallback); 027 } 028 029 /** 030 * Measure the Vin voltage. 031 * 032 * @return the Vin voltage 033 */ 034 public static double getVInVoltage() { 035 return RoboRioDataJNI.getVInVoltage(); 036 } 037 038 /** 039 * Define the Vin voltage. 040 * 041 * @param vInVoltage the new voltage 042 */ 043 public static void setVInVoltage(double vInVoltage) { 044 RoboRioDataJNI.setVInVoltage(vInVoltage); 045 } 046 047 /** 048 * Register a callback to be run whenever the 3.3V rail voltage changes. 049 * 050 * @param callback the callback 051 * @param initialNotify whether the callback should be called with the initial value 052 * @return the {@link CallbackStore} object associated with this callback. 053 */ 054 public static CallbackStore registerUserVoltage3V3Callback( 055 NotifyCallback callback, boolean initialNotify) { 056 int uid = RoboRioDataJNI.registerUserVoltage3V3Callback(callback, initialNotify); 057 return new CallbackStore(uid, RoboRioDataJNI::cancelUserVoltage3V3Callback); 058 } 059 060 /** 061 * Measure the 3.3V rail voltage. 062 * 063 * @return the 3.3V rail voltage 064 */ 065 public static double getUserVoltage3V3() { 066 return RoboRioDataJNI.getUserVoltage3V3(); 067 } 068 069 /** 070 * Define the 3.3V rail voltage. 071 * 072 * @param userVoltage3V3 the new voltage 073 */ 074 public static void setUserVoltage3V3(double userVoltage3V3) { 075 RoboRioDataJNI.setUserVoltage3V3(userVoltage3V3); 076 } 077 078 /** 079 * Register a callback to be run whenever the 3.3V rail current changes. 080 * 081 * @param callback the callback 082 * @param initialNotify whether the callback should be called with the initial value 083 * @return the {@link CallbackStore} object associated with this callback. 084 */ 085 public static CallbackStore registerUserCurrent3V3Callback( 086 NotifyCallback callback, boolean initialNotify) { 087 int uid = RoboRioDataJNI.registerUserCurrent3V3Callback(callback, initialNotify); 088 return new CallbackStore(uid, RoboRioDataJNI::cancelUserCurrent3V3Callback); 089 } 090 091 /** 092 * Measure the 3.3V rail current. 093 * 094 * @return the 3.3V rail current 095 */ 096 public static double getUserCurrent3V3() { 097 return RoboRioDataJNI.getUserCurrent3V3(); 098 } 099 100 /** 101 * Define the 3.3V rail current. 102 * 103 * @param userCurrent3V3 the new current 104 */ 105 public static void setUserCurrent3V3(double userCurrent3V3) { 106 RoboRioDataJNI.setUserCurrent3V3(userCurrent3V3); 107 } 108 109 /** 110 * Register a callback to be run whenever the 3.3V rail active state changes. 111 * 112 * @param callback the callback 113 * @param initialNotify whether the callback should be called with the initial state 114 * @return the {@link CallbackStore} object associated with this callback. 115 */ 116 public static CallbackStore registerUserActive3V3Callback( 117 NotifyCallback callback, boolean initialNotify) { 118 int uid = RoboRioDataJNI.registerUserActive3V3Callback(callback, initialNotify); 119 return new CallbackStore(uid, RoboRioDataJNI::cancelUserActive3V3Callback); 120 } 121 122 /** 123 * Get the 3.3V rail active state. 124 * 125 * @return true if the 3.3V rail is active 126 */ 127 public static boolean getUserActive3V3() { 128 return RoboRioDataJNI.getUserActive3V3(); 129 } 130 131 /** 132 * Set the 3.3V rail active state. 133 * 134 * @param userActive3V3 true to make rail active 135 */ 136 public static void setUserActive3V3(boolean userActive3V3) { 137 RoboRioDataJNI.setUserActive3V3(userActive3V3); 138 } 139 140 /** 141 * Register a callback to be run whenever the 3.3V rail number of faults changes. 142 * 143 * @param callback the callback 144 * @param initialNotify whether the callback should be called with the initial value 145 * @return the {@link CallbackStore} object associated with this callback. 146 */ 147 public static CallbackStore registerUserFaults3V3Callback( 148 NotifyCallback callback, boolean initialNotify) { 149 int uid = RoboRioDataJNI.registerUserFaults3V3Callback(callback, initialNotify); 150 return new CallbackStore(uid, RoboRioDataJNI::cancelUserFaults3V3Callback); 151 } 152 153 /** 154 * Get the 3.3V rail number of faults. 155 * 156 * @return number of faults 157 */ 158 public static int getUserFaults3V3() { 159 return RoboRioDataJNI.getUserFaults3V3(); 160 } 161 162 /** 163 * Set the 3.3V rail number of faults. 164 * 165 * @param userFaults3V3 number of faults 166 */ 167 public static void setUserFaults3V3(int userFaults3V3) { 168 RoboRioDataJNI.setUserFaults3V3(userFaults3V3); 169 } 170 171 /** 172 * Register a callback to be run whenever the Brownout voltage changes. 173 * 174 * @param callback the callback 175 * @param initialNotify whether to call the callback with the initial state 176 * @return the {@link CallbackStore} object associated with this callback. 177 */ 178 public static CallbackStore registerBrownoutVoltageCallback( 179 NotifyCallback callback, boolean initialNotify) { 180 int uid = RoboRioDataJNI.registerBrownoutVoltageCallback(callback, initialNotify); 181 return new CallbackStore(uid, RoboRioDataJNI::cancelBrownoutVoltageCallback); 182 } 183 184 /** 185 * Measure the Brownout voltage. 186 * 187 * @return the Brownout voltage 188 */ 189 public static double getBrownoutVoltage() { 190 return RoboRioDataJNI.getBrownoutVoltage(); 191 } 192 193 /** 194 * Define the Brownout voltage. 195 * 196 * @param vInVoltage the new voltage 197 */ 198 public static void setBrownoutVoltage(double vInVoltage) { 199 RoboRioDataJNI.setBrownoutVoltage(vInVoltage); 200 } 201 202 /** 203 * Register a callback to be run whenever the cpu temp changes. 204 * 205 * @param callback the callback 206 * @param initialNotify whether to call the callback with the initial state 207 * @return the {@link CallbackStore} object associated with this callback. 208 */ 209 public static CallbackStore registerCPUTempCallback( 210 NotifyCallback callback, boolean initialNotify) { 211 int uid = RoboRioDataJNI.registerCPUTempCallback(callback, initialNotify); 212 return new CallbackStore(uid, RoboRioDataJNI::cancelCPUTempCallback); 213 } 214 215 /** 216 * Get the cpu temp. 217 * 218 * @return the cpu temp. 219 */ 220 public static double getCPUTemp() { 221 return RoboRioDataJNI.getCPUTemp(); 222 } 223 224 /** 225 * Set the cpu temp. 226 * 227 * @param cpuTemp the new cpu temp. 228 */ 229 public static void setCPUTemp(double cpuTemp) { 230 RoboRioDataJNI.setCPUTemp(cpuTemp); 231 } 232 233 /** 234 * Register a callback to be run whenever the team number changes. 235 * 236 * @param callback the callback 237 * @param initialNotify whether to call the callback with the initial state 238 * @return the {@link CallbackStore} object associated with this callback. 239 */ 240 public static CallbackStore registerTeamNumberCallback( 241 NotifyCallback callback, boolean initialNotify) { 242 int uid = RoboRioDataJNI.registerTeamNumberCallback(callback, initialNotify); 243 return new CallbackStore(uid, RoboRioDataJNI::cancelTeamNumberCallback); 244 } 245 246 /** 247 * Get the team number. 248 * 249 * @return the team number. 250 */ 251 public static int getTeamNumber() { 252 return RoboRioDataJNI.getTeamNumber(); 253 } 254 255 /** 256 * Set the team number. 257 * 258 * @param teamNumber the new team number. 259 */ 260 public static void setTeamNumber(int teamNumber) { 261 RoboRioDataJNI.setTeamNumber(teamNumber); 262 } 263 264 /** 265 * Get the serial number. 266 * 267 * @return The serial number. 268 */ 269 public static String getSerialNumber() { 270 return RoboRioDataJNI.getSerialNumber(); 271 } 272 273 /** 274 * Set the serial number. 275 * 276 * @param serialNumber The serial number. 277 */ 278 public static void setSerialNumber(String serialNumber) { 279 RoboRioDataJNI.setSerialNumber(serialNumber); 280 } 281 282 /** 283 * Get the comments string. 284 * 285 * @return The comments string. 286 */ 287 public static String getComments() { 288 return RoboRioDataJNI.getComments(); 289 } 290 291 /** 292 * Set the comments string. 293 * 294 * @param comments The comments string. 295 */ 296 public static void setComments(String comments) { 297 RoboRioDataJNI.setComments(comments); 298 } 299 300 /** Reset all simulation data. */ 301 public static void resetData() { 302 RoboRioDataJNI.resetData(); 303 } 304}