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.hal.simulation;
006
007import edu.wpi.first.hal.HALValue;
008import edu.wpi.first.hal.JNIWrapper;
009
010public class SimDeviceDataJNI extends JNIWrapper {
011  public static native void setSimDeviceEnabled(String prefix, boolean enabled);
012
013  public static native boolean isSimDeviceEnabled(String name);
014
015  public static native int registerSimDeviceCreatedCallback(
016      String prefix, SimDeviceCallback callback, boolean initialNotify);
017
018  public static native void cancelSimDeviceCreatedCallback(int uid);
019
020  public static native int registerSimDeviceFreedCallback(
021      String prefix, SimDeviceCallback callback, boolean initialNotify);
022
023  public static native void cancelSimDeviceFreedCallback(int uid);
024
025  public static native int getSimDeviceHandle(String name);
026
027  public static native String getSimDeviceName(int handle);
028
029  public static native int getSimValueDeviceHandle(int handle);
030
031  public static class SimDeviceInfo {
032    @SuppressWarnings("JavadocMethod")
033    public SimDeviceInfo(String name, int handle) {
034      this.name = name;
035      this.handle = handle;
036    }
037
038    @SuppressWarnings("MemberName")
039    public String name;
040
041    @SuppressWarnings("MemberName")
042    public int handle;
043  }
044
045  public static native SimDeviceInfo[] enumerateSimDevices(String prefix);
046
047  public static native int registerSimValueCreatedCallback(
048      int device, SimValueCallback callback, boolean initialNotify);
049
050  public static native void cancelSimValueCreatedCallback(int uid);
051
052  public static native int registerSimValueChangedCallback(
053      int handle, SimValueCallback callback, boolean initialNotify);
054
055  public static native void cancelSimValueChangedCallback(int uid);
056
057  /**
058   * Register a callback for SimDeviceJNI.resetSimValue(). The callback is called with the old
059   * value.
060   *
061   * @param handle simulated value handle
062   * @param callback callback
063   * @param initialNotify ignored (present for consistency)
064   * @return TODO
065   */
066  public static native int registerSimValueResetCallback(
067      int handle, SimValueCallback callback, boolean initialNotify);
068
069  public static native void cancelSimValueResetCallback(int uid);
070
071  public static native int getSimValueHandle(int device, String name);
072
073  public static class SimValueInfo {
074    @SuppressWarnings("JavadocMethod")
075    public SimValueInfo(
076        String name, int handle, int direction, int type, long value1, double value2) {
077      this.name = name;
078      this.handle = handle;
079      this.readonly = direction == 1;
080      this.direction = direction;
081      this.value = HALValue.fromNative(type, value1, value2);
082    }
083
084    @SuppressWarnings("MemberName")
085    public String name;
086
087    @SuppressWarnings("MemberName")
088    public int handle;
089
090    @SuppressWarnings("MemberName")
091    @Deprecated
092    public boolean readonly;
093
094    @SuppressWarnings("MemberName")
095    public int direction;
096
097    @SuppressWarnings("MemberName")
098    public HALValue value;
099  }
100
101  public static native SimValueInfo[] enumerateSimValues(int device);
102
103  public static native String[] getSimValueEnumOptions(int handle);
104
105  public static native double[] getSimValueEnumDoubleValues(int handle);
106
107  public static native void resetSimDeviceData();
108}