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.SimulatorJNI;
008
009/** Simulation hooks. */
010public final class SimHooks {
011  private SimHooks() {}
012
013  /**
014   * Override the HAL runtime type (simulated/real).
015   *
016   * @param type runtime type
017   */
018  public static void setHALRuntimeType(int type) {
019    SimulatorJNI.setRuntimeType(type);
020  }
021
022  /** Waits until the user program has started. */
023  public static void waitForProgramStart() {
024    SimulatorJNI.waitForProgramStart();
025  }
026
027  /** Sets that the user program has started. */
028  public static void setProgramStarted() {
029    SimulatorJNI.setProgramStarted();
030  }
031
032  /**
033   * Returns true if the user program has started.
034   *
035   * @return True if the user program has started.
036   */
037  public static boolean getProgramStarted() {
038    return SimulatorJNI.getProgramStarted();
039  }
040
041  /** Restart the simulator time. */
042  public static void restartTiming() {
043    SimulatorJNI.restartTiming();
044  }
045
046  /** Pause the simulator time. */
047  public static void pauseTiming() {
048    SimulatorJNI.pauseTiming();
049  }
050
051  /** Resume the simulator time. */
052  public static void resumeTiming() {
053    SimulatorJNI.resumeTiming();
054  }
055
056  /**
057   * Check if the simulator time is paused.
058   *
059   * @return true if paused
060   */
061  public static boolean isTimingPaused() {
062    return SimulatorJNI.isTimingPaused();
063  }
064
065  /**
066   * Advance the simulator time and wait for all notifiers to run.
067   *
068   * @param deltaSeconds the amount to advance (in seconds)
069   */
070  public static void stepTiming(double deltaSeconds) {
071    SimulatorJNI.stepTiming((long) (deltaSeconds * 1e6));
072  }
073
074  /**
075   * Advance the simulator time and return immediately.
076   *
077   * @param deltaSeconds the amount to advance (in seconds)
078   */
079  public static void stepTimingAsync(double deltaSeconds) {
080    SimulatorJNI.stepTimingAsync((long) (deltaSeconds * 1e6));
081  }
082}