001/*
002 * Copyright (C) Cross The Road Electronics.  All rights reserved.
003 * License information can be found in CTRE_LICENSE.txt
004 * For support and suggestions contact support@ctr-electronics.com or file
005 * an issue tracker at https://github.com/CrossTheRoadElec/Phoenix-Releases
006 */
007package com.ctre.phoenix6.swerve;
008
009import com.ctre.phoenix6.configs.Pigeon2Configuration;
010import com.ctre.phoenix6.swerve.jni.SwerveJNI;
011
012/**
013 * Common constants for a swerve drivetrain.
014 */
015public class SwerveDrivetrainConstants {
016    /**
017     * Name of the CAN bus the swerve drive is on. Possible CAN bus strings are:
018     * 
019     * <ul>
020     *   <li> "rio" for the native roboRIO CAN bus
021     *   <li> CANivore name or serial number
022     *   <li> SocketCAN interface (non-FRC Linux only)
023     *   <li> "*" for any CANivore seen by the program
024     *   <li> empty string (default) to select the default for the system:
025     *   <ul>
026     *     <li> "rio" on roboRIO
027     *     <li> "can0" on Linux
028     *     <li> "*" on Windows
029     *   </ul>
030     * </ul>
031     * 
032     * Note that all devices must be on the same CAN bus.
033     */
034    public String CANBusName = "";
035    /**
036     * CAN ID of the Pigeon2 on the drivetrain.
037     */
038    public int Pigeon2Id = 0;
039    /**
040     * The configuration object to apply to the Pigeon2. This defaults to null. If
041     * this remains null, then the Pigeon2 will not be configured (and whatever
042     * configs are on it remain on it). If this is not null, the Pigeon2 will be
043     * overwritten with these configs.
044     */
045    public Pigeon2Configuration Pigeon2Configs = null;
046    
047    /**
048     * Modifies the CANBusName parameter and returns itself.
049     * <p>
050     * Name of the CAN bus the swerve drive is on. Possible CAN bus strings are:
051     * 
052     * <ul>
053     *   <li> "rio" for the native roboRIO CAN bus
054     *   <li> CANivore name or serial number
055     *   <li> SocketCAN interface (non-FRC Linux only)
056     *   <li> "*" for any CANivore seen by the program
057     *   <li> empty string (default) to select the default for the system:
058     *   <ul>
059     *     <li> "rio" on roboRIO
060     *     <li> "can0" on Linux
061     *     <li> "*" on Windows
062     *   </ul>
063     * </ul>
064     * 
065     * Note that all devices must be on the same CAN bus.
066     *
067     * @param newCANBusName Parameter to modify
068     * @return this object
069     */
070    public SwerveDrivetrainConstants withCANBusName(String newCANBusName) {
071        this.CANBusName = newCANBusName;
072        return this;
073    }
074    
075    /**
076     * Modifies the Pigeon2Id parameter and returns itself.
077     * <p>
078     * CAN ID of the Pigeon2 on the drivetrain.
079     *
080     * @param newPigeon2Id Parameter to modify
081     * @return this object
082     */
083    public SwerveDrivetrainConstants withPigeon2Id(int newPigeon2Id) {
084        this.Pigeon2Id = newPigeon2Id;
085        return this;
086    }
087    
088    /**
089     * Modifies the Pigeon2Configs parameter and returns itself.
090     * <p>
091     * The configuration object to apply to the Pigeon2. This defaults to null. If
092     * this remains null, then the Pigeon2 will not be configured (and whatever
093     * configs are on it remain on it). If this is not null, the Pigeon2 will be
094     * overwritten with these configs.
095     *
096     * @param newPigeon2Configs Parameter to modify
097     * @return this object
098     */
099    public SwerveDrivetrainConstants withPigeon2Configs(Pigeon2Configuration newPigeon2Configs) {
100        this.Pigeon2Configs = newPigeon2Configs;
101        return this;
102    }
103    
104    final long createNativeInstance() {
105        return SwerveJNI.JNI_CreateDrivetrainConstants(
106            CANBusName,
107            Pigeon2Id
108        );
109    }
110}