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;
006
007/**
008 * Analog Input / Output / Trigger JNI Functions.
009 *
010 * @see "wpi/hal/AnalogInput.h"
011 */
012public class AnalogInputJNI extends JNIWrapper {
013  /**
014   * Initializes the analog input port using the given port object.
015   *
016   * @param channel The smartio channel.
017   * @return the created analog input handle
018   * @see "HAL_InitializeAnalogInputPort"
019   */
020  public static native int initializeAnalogInputPort(int channel);
021
022  /**
023   * Frees an analog input port.
024   *
025   * @param analogPortHandle Handle to the analog port.
026   * @see "HAL_FreeAnalogInputPort"
027   */
028  public static native void freeAnalogInputPort(int analogPortHandle);
029
030  /**
031   * Checks that the analog module number is valid.
032   *
033   * @param module The analog module number.
034   * @return Analog module is valid and present
035   * @see "HAL_CheckAnalogModule"
036   */
037  public static native boolean checkAnalogModule(byte module);
038
039  /**
040   * Checks that the analog output channel number is valid. Verifies that the analog channel number
041   * is one of the legal channel numbers. Channel numbers are 0-based.
042   *
043   * @param channel The analog output channel number.
044   * @return Analog channel is valid
045   * @see "HAL_CheckAnalogInputChannel"
046   */
047  public static native boolean checkAnalogInputChannel(int channel);
048
049  /**
050   * Indicates the analog input is used by a simulated device.
051   *
052   * @param handle the analog input handle
053   * @param device simulated device handle
054   * @see "HAL_SetAnalogInputSimDevice"
055   */
056  public static native void setAnalogInputSimDevice(int handle, int device);
057
058  /**
059   * Gets a sample straight from the channel on this module.
060   *
061   * <p>The sample is a 12-bit value representing the 0V to 3.3V range of the A/D converter in the
062   * module. The units are in A/D converter codes. Use GetVoltage() to get the analog value in
063   * calibrated units.
064   *
065   * @param analogPortHandle Handle to the analog port to use.
066   * @return A sample straight from the channel on this module.
067   * @see "HAL_GetAnalogValue"
068   */
069  public static native short getAnalogValue(int analogPortHandle);
070
071  /**
072   * Converts a voltage to a raw value for a specified channel.
073   *
074   * <p>This process depends on the calibration of each channel, so the channel must be specified.
075   *
076   * <p>todo This assumes raw values. Oversampling not supported as is.
077   *
078   * @param analogPortHandle Handle to the analog port to use.
079   * @param voltage The voltage to convert.
080   * @return The raw value for the channel.
081   * @see "HAL_GetAnalogVoltsToValue"
082   */
083  public static native int getAnalogVoltsToValue(int analogPortHandle, double voltage);
084
085  /**
086   * Get the analog voltage from a raw value.
087   *
088   * @param analogPortHandle Handle to the analog port the values were read from.
089   * @param value The raw analog value
090   * @return The voltage relating to the value
091   * @see "HAL_GetAnalogValueToVolts"
092   */
093  public static native double getAnalogValueToVolts(int analogPortHandle, int value);
094
095  /**
096   * Gets a scaled sample straight from the channel on this module.
097   *
098   * <p>The value is scaled to units of Volts.
099   *
100   * @param analogPortHandle Handle to the analog port to use.
101   * @return A scaled sample straight from the channel on this module.
102   * @see "HAL_GetAnalogVoltage"
103   */
104  public static native double getAnalogVoltage(int analogPortHandle);
105
106  /** Utility class. */
107  private AnalogInputJNI() {}
108}