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 org.wpilib.simulation; 006 007import org.wpilib.hardware.hal.ControlWord; 008import org.wpilib.hardware.hal.simulation.SimulatorJNI; 009 010/** Simulation hooks. */ 011public final class SimHooks { 012 private SimHooks() {} 013 014 /** 015 * Override the HAL runtime type (simulated/real). 016 * 017 * @param type runtime type 018 */ 019 public static void setHALRuntimeType(int type) { 020 SimulatorJNI.setRuntimeType(type); 021 } 022 023 /** Waits until the user program has started. */ 024 public static void waitForProgramStart() { 025 SimulatorJNI.waitForProgramStart(); 026 } 027 028 /** 029 * Sets flag that indicates if the user program has started. 030 * 031 * @param started true if started 032 */ 033 public static void setProgramStarted(boolean started) { 034 SimulatorJNI.setProgramStarted(started); 035 } 036 037 /** 038 * Returns true if the user program has started. 039 * 040 * @return True if the user program has started. 041 */ 042 public static boolean getProgramStarted() { 043 return SimulatorJNI.getProgramStarted(); 044 } 045 046 /** 047 * Sets the user program state (control word). 048 * 049 * @param controlWord control word 050 */ 051 public static void setProgramState(ControlWord controlWord) { 052 SimulatorJNI.setProgramState(controlWord.getNative()); 053 } 054 055 /** 056 * Gets the user program state (control word). 057 * 058 * @param controlWord control word (output) 059 */ 060 public static void getProgramState(ControlWord controlWord) { 061 SimulatorJNI.getProgramState(controlWord); 062 } 063 064 /** Restart the simulator time. */ 065 public static void restartTiming() { 066 SimulatorJNI.restartTiming(); 067 } 068 069 /** Pause the simulator time. */ 070 public static void pauseTiming() { 071 SimulatorJNI.pauseTiming(); 072 } 073 074 /** Resume the simulator time. */ 075 public static void resumeTiming() { 076 SimulatorJNI.resumeTiming(); 077 } 078 079 /** 080 * Check if the simulator time is paused. 081 * 082 * @return true if paused 083 */ 084 public static boolean isTimingPaused() { 085 return SimulatorJNI.isTimingPaused(); 086 } 087 088 /** 089 * Advance the simulator time and wait for all notifiers to run. 090 * 091 * @param delta the amount to advance in seconds 092 */ 093 public static void stepTiming(double delta) { 094 SimulatorJNI.stepTiming((long) (delta * 1e6)); 095 } 096 097 /** 098 * Advance the simulator time and return immediately. 099 * 100 * @param delta the amount to advance in seconds 101 */ 102 public static void stepTimingAsync(double delta) { 103 SimulatorJNI.stepTimingAsync((long) (delta * 1e6)); 104 } 105}