001/* Copyright (C) Cross The Road Electronics 2024 */
002/*
003 *  Software License Agreement
004 *
005 * Copyright (C) Cross The Road Electronics.  All rights
006 * reserved.
007 * 
008 * Cross The Road Electronics (CTRE) licenses to you the right to 
009 * use, publish, and distribute copies of CRF (Cross The Road) firmware files (*.crf) and Software
010 * API Libraries ONLY when in use with Cross The Road Electronics hardware products.
011 * 
012 * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT
013 * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT
014 * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A
015 * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
016 * CROSS THE ROAD ELECTRONICS BE LIABLE FOR ANY INCIDENTAL, SPECIAL, 
017 * INDIRECT OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF
018 * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS
019 * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE
020 * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER
021 * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT
022 * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE
023 */
024 package com.ctre.phoenix;
025 
026 public class CANifierJNI extends CTREJNIWrapper {
027         
028        public enum GeneralPin
029        {
030                QUAD_IDX(0),
031                QUAD_B (1),
032                QUAD_A (2),
033                LIMR (3),
034                LIMF (4),
035                SDA (5),
036                SCL (6),
037                SPI_CS (7),
038                SPI_MISO_PWM2P (8),
039                SPI_MOSI_PWM1P (9),
040                SPI_CLK_PWM0P (10);
041                
042                final public int value;
043
044                GeneralPin(int value) {
045                        this.value = value;
046                }
047        }
048        
049        public static native long JNI_new_CANifier(int deviceNumber);
050        
051        public static native int JNI_destroy_CANifier(long handle);
052        
053        //public static native int JNI_destroy_AllCANifiers(long handle);
054
055        public static native void JNI_SetLEDOutput(long handle, int dutyCycle, int ledChannel);
056
057        public static native void JNI_SetGeneralOutputs(long handle, int outputBits, int isOutputBits);
058
059        public static native void JNI_SetGeneralOutput(long handle, int outputPin, boolean outputValue,
060                        boolean outputEnable);
061
062        public static native void JNI_SetPWMOutput(long handle, int pwmChannel, int dutyCycle);
063
064        public static native void JNI_EnablePWMOutput(long handle, int pwmChannel, boolean bEnable);
065
066        public static native void JNI_GetGeneralInputs(long handle, boolean[] allPins);
067
068        public static native boolean JNI_GetGeneralInput(long handl, int inputPin);
069
070        public static native void JNI_GetPWMInput(long handle, int pwmChannel, double pulseWidthAndPeriod[]);
071
072        public static native int JNI_GetLastError(long handle);
073
074        public static native double JNI_GetBatteryVoltage(long handle);
075        
076        public static native int JNI_GetQuadraturePosition(long handle);
077        
078        public static native int JNI_SetQuadraturePosition(long handle, int newPosition, int timeoutMs);
079        
080        public static native int JNI_GetQuadratureVelocity(long handle);
081        
082        public static native int JNI_ConfigVelocityMeasurementPeriod(long handle, int period, int timeoutMs);
083        
084        public static native int JNI_ConfigVelocityMeasurementWindow(long handle, int windowSize, int timeoutMs);
085
086    public static native int JNI_ConfigClearPositionOnLimitF(long handle, boolean clearPositionOnLimitF, int timeoutMs);
087 
088    public static native int JNI_ConfigClearPositionOnLimitR(long handle, boolean clearPositionOnLimitR, int timeoutMs);
089 
090    public static native int JNI_ConfigClearPositionOnQuadIdx(long handle, boolean clearPositionOnQuadIdx, int timeoutMs);
091 
092    public static native int JNI_ConfigSetCustomParam(long handle, int newValue, int paramIndex, int timeoutMs);
093
094        public static native int JNI_ConfigGetCustomParam(long handle, int paramIndex, int timoutMs);
095
096        public static native int JNI_ConfigSetParameter(long handle, int param, double value, int subValue, int ordinal,
097                        int timeoutMs);
098
099        public static native double JNI_ConfigGetParameter(long handle, int param, int ordinal, int timeoutMs);
100        
101        public static native int JNI_ConfigFactoryDefault(long handle, int timeoutMs);
102
103        public static native int JNI_SetStatusFramePeriod(long handle, int statusFrame, int periodMs, int timeoutMs);
104
105        public static native int JNI_GetStatusFramePeriod(long handle, int frame, int timeoutMs);
106
107        public static native int JNI_SetControlFramePeriod(long handle, int frame, int periodMs);
108
109        public static native int JNI_GetFirmwareVersion(long handle);
110
111        public static native boolean JNI_HasResetOccurred(long handle);
112
113        public static native int JNI_GetFaults(long handle);
114
115        public static native int JNI_GetStickyFaults(long handle);
116
117        public static native int JNI_ClearStickyFaults(long handle, int timeoutMs);
118
119        public static native double JNI_GetBusVoltage(long handle);
120 }