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.hardware.hal.simulation; 006 007import org.wpilib.hardware.hal.HALValue; 008import org.wpilib.hardware.hal.JNIWrapper; 009 010/** JNI for sim device data. */ 011public class SimDeviceDataJNI extends JNIWrapper { 012 public static native void setSimDeviceEnabled(String prefix, boolean enabled); 013 014 public static native boolean isSimDeviceEnabled(String name); 015 016 public static native int registerSimDeviceCreatedCallback( 017 String prefix, SimDeviceCallback callback, boolean initialNotify); 018 019 public static native void cancelSimDeviceCreatedCallback(int uid); 020 021 public static native int registerSimDeviceFreedCallback( 022 String prefix, SimDeviceCallback callback, boolean initialNotify); 023 024 public static native void cancelSimDeviceFreedCallback(int uid); 025 026 public static native int getSimDeviceHandle(String name); 027 028 public static native String getSimDeviceName(int handle); 029 030 public static native int getSimValueDeviceHandle(int handle); 031 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 public static class SimValueInfo { 077 public String name; 078 public int handle; 079 public int direction; 080 public HALValue value; 081 082 /** 083 * SimValueInfo constructor. 084 * 085 * @param name SimValue name. 086 * @param handle SimValue handle. 087 * @param direction SimValue direction. 088 * @param type SimValue type. 089 * @param value1 Value 1. 090 * @param value2 Value 2. 091 */ 092 public SimValueInfo( 093 String name, int handle, int direction, int type, long value1, double value2) { 094 this.name = name; 095 this.handle = handle; 096 this.direction = direction; 097 this.value = HALValue.fromNative(type, value1, value2); 098 } 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 109 /** Utility class. */ 110 private SimDeviceDataJNI() {} 111}