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; 006 007/** 008 * Digital Input/Output (IO) JNI Functions. 009 * 010 * @see "hal/DIO.h" 011 */ 012public class DIOJNI extends JNIWrapper { 013 /** 014 * Creates a new instance of a digital port. 015 * 016 * @param channel the smartio channel 017 * @param input true for input, false for output 018 * @return the created digital handle 019 * @see "HAL_InitializeDIOPort" 020 */ 021 public static native int initializeDIOPort(int channel, boolean input); 022 023 /** 024 * Checks if a DIO channel is valid. 025 * 026 * @param channel the channel number to check 027 * @return true if the channel is valid, otherwise false 028 * @see "HAL_CheckDIOChannel" 029 */ 030 public static native boolean checkDIOChannel(int channel); 031 032 /** 033 * Frees a DIO port. 034 * 035 * @param dioPortHandle the DIO channel handle 036 * @see "HAL_FreeDIOPort" 037 */ 038 public static native void freeDIOPort(int dioPortHandle); 039 040 /** 041 * Indicates the DIO channel is used by a simulated device. 042 * 043 * @param handle the DIO channel handle 044 * @param device simulated device handle 045 * @see "HAL_SetDIOSimDevice" 046 */ 047 public static native void setDIOSimDevice(int handle, int device); 048 049 /** 050 * Writes a digital value to a DIO channel. 051 * 052 * @param dioPortHandle the digital port handle 053 * @param value the state to set the digital channel (if it is configured as an output) 054 * @see "HAL_SetDIO" 055 */ 056 public static native void setDIO(int dioPortHandle, boolean value); 057 058 /** 059 * Sets the direction of a DIO channel. 060 * 061 * @param dioPortHandle the digital port handle 062 * @param input true to set input, false for output 063 * @see "HAL_SetDIODirection" 064 */ 065 public static native void setDIODirection(int dioPortHandle, boolean input); 066 067 /** 068 * Reads a digital value from a DIO channel. 069 * 070 * @param dioPortHandle the digital port handle 071 * @return the state of the specified channel 072 * @see "HAL_GetDIO" 073 */ 074 public static native boolean getDIO(int dioPortHandle); 075 076 /** 077 * Reads the direction of a DIO channel. 078 * 079 * @param dioPortHandle the digital port handle 080 * @return true for input, false for output 081 * @see "HAL_GetDIODirection" 082 */ 083 public static native boolean getDIODirection(int dioPortHandle); 084 085 /** 086 * Generates a single digital pulse. 087 * 088 * <p>Write a pulse to the specified digital output channel. There can only be a single pulse 089 * going at any time. 090 * 091 * @param dioPortHandle the digital port handle 092 * @param pulseLength the active length of the pulse in seconds 093 * @see "HAL_Pulse" 094 */ 095 public static native void pulse(int dioPortHandle, double pulseLength); 096 097 /** 098 * Generates a single digital pulse on multiple channels. 099 * 100 * <p>Write a pulse to the channels enabled by the mask. There can only be a single pulse going at 101 * any time. 102 * 103 * @param channelMask the channel mask 104 * @param pulseLength the active length of the pulse in seconds 105 * @see "HAL_PulseMultiple" 106 */ 107 public static native void pulseMultiple(long channelMask, double pulseLength); 108 109 /** 110 * Checks a DIO line to see if it is currently generating a pulse. 111 * 112 * @param dioPortHandle the digital port handle 113 * @return true if a pulse is in progress, otherwise false 114 * @see "HAL_IsPulsing" 115 */ 116 public static native boolean isPulsing(int dioPortHandle); 117 118 /** 119 * Checks if any DIO line is currently generating a pulse. 120 * 121 * @return true if a pulse on some line is in progress 122 * @see "HAL_IsAnyPulsing" 123 */ 124 public static native boolean isAnyPulsing(); 125 126 /** 127 * Allocates a DO PWM Generator. 128 * 129 * @return the allocated digital PWM handle 130 */ 131 public static native int allocateDigitalPWM(); 132 133 /** 134 * Frees the resource associated with a DO PWM generator. 135 * 136 * @param pwmGenerator the digital PWM handle 137 * @see "HAL_FreeDigitalPWM" 138 */ 139 public static native void freeDigitalPWM(int pwmGenerator); 140 141 /** 142 * Changes the frequency of the DO PWM generator. 143 * 144 * <p>The valid range is from 0.6 Hz to 19 kHz. 145 * 146 * <p>The frequency resolution is logarithmic. 147 * 148 * @param rate the frequency to output all digital output PWM signals 149 * @see "HAL_SetDigitalPWMRate" 150 */ 151 public static native void setDigitalPWMRate(double rate); 152 153 /** 154 * Configures the duty-cycle of the PWM generator. 155 * 156 * @param pwmGenerator the digital PWM handle 157 * @param dutyCycle the percent duty cycle to output [0..1] 158 * @see "HAL_SetDigitalPWMDutyCycle" 159 */ 160 public static native void setDigitalPWMDutyCycle(int pwmGenerator, double dutyCycle); 161 162 /** 163 * Configures the digital PWM to be a PPS signal with specified duty cycle. 164 * 165 * @param pwmGenerator the digital PWM handle 166 * @param dutyCycle the percent duty cycle to output [0..1] 167 * @see "HAL_SetDigitalPWMPPS" 168 */ 169 public static native void setDigitalPWMPPS(int pwmGenerator, double dutyCycle); 170 171 /** 172 * Configures which DO channel the PWM signal is output on. 173 * 174 * @param pwmGenerator the digital PWM handle 175 * @param channel the channel to output on 176 * @see "HAL_SetDigitalPWMOutputChannel" 177 */ 178 public static native void setDigitalPWMOutputChannel(int pwmGenerator, int channel); 179 180 /** Utility class. */ 181 DIOJNI() {} 182}