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 @SuppressWarnings("MemberName") 032 public static class SimDeviceInfo { 033 public String name; 034 public int handle; 035 036 /** 037 * SimDeviceInfo constructor. 038 * 039 * @param name SimDevice name. 040 * @param handle SimDevice handle. 041 */ 042 public SimDeviceInfo(String name, int handle) { 043 this.name = name; 044 this.handle = handle; 045 } 046 } 047 048 public static native SimDeviceInfo[] enumerateSimDevices(String prefix); 049 050 public static native int registerSimValueCreatedCallback( 051 int device, SimValueCallback callback, boolean initialNotify); 052 053 public static native void cancelSimValueCreatedCallback(int uid); 054 055 public static native int registerSimValueChangedCallback( 056 int handle, SimValueCallback callback, boolean initialNotify); 057 058 public static native void cancelSimValueChangedCallback(int uid); 059 060 /** 061 * Register a callback for SimDeviceJNI.resetSimValue(). The callback is called with the old 062 * value. 063 * 064 * @param handle simulated value handle 065 * @param callback callback 066 * @param initialNotify ignored (present for consistency) 067 * @return TODO 068 */ 069 public static native int registerSimValueResetCallback( 070 int handle, SimValueCallback callback, boolean initialNotify); 071 072 public static native void cancelSimValueResetCallback(int uid); 073 074 public static native int getSimValueHandle(int device, String name); 075 076 @SuppressWarnings("MemberName") 077 public static class SimValueInfo { 078 public String name; 079 public int handle; 080 public int direction; 081 public HALValue value; 082 083 /** 084 * SimValueInfo constructor. 085 * 086 * @param name SimValue name. 087 * @param handle SimValue handle. 088 * @param direction SimValue direction. 089 * @param type SimValue type. 090 * @param value1 Value 1. 091 * @param value2 Value 2. 092 */ 093 public SimValueInfo( 094 String name, int handle, int direction, int type, long value1, double value2) { 095 this.name = name; 096 this.handle = handle; 097 this.direction = direction; 098 this.value = HALValue.fromNative(type, value1, value2); 099 } 100 } 101 102 public static native SimValueInfo[] enumerateSimValues(int device); 103 104 public static native String[] getSimValueEnumOptions(int handle); 105 106 public static native double[] getSimValueEnumDoubleValues(int handle); 107 108 public static native void resetSimDeviceData(); 109}