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 * Addressable LED HAL JNI Methods.
009 *
010 * @see "hal/AdressableLED.h"
011 */
012public class AddressableLEDJNI extends JNIWrapper {
013  /**
014   * Initialize Addressable LED using a PWM Digital handle.
015   *
016   * @param pwmHandle handle of the digital port for PWM
017   * @return Addressable LED handle
018   * @see "HAL_InitializeAddressableLED"
019   */
020  public static native int initialize(int pwmHandle);
021
022  /**
023   * Free the Addressable LED Handle.
024   *
025   * @param handle the Addressable LED handle to free
026   * @see "HAL_FreeAddressableLED"
027   */
028  public static native void free(int handle);
029
030  /**
031   * Sets the length of the LED strip.
032   *
033   * <p>The max length is 5460 LEDs.
034   *
035   * @param handle the Addressable LED handle
036   * @param length the strip length
037   * @see "HAL_SetAddressableLEDLength"
038   */
039  public static native void setLength(int handle, int length);
040
041  /**
042   * Sets the led output data.
043   *
044   * <p>If the output is enabled, this will start writing the next data cycle. It is safe to call,
045   * even while output is enabled.
046   *
047   * @param handle the Addressable LED handle
048   * @param data the buffer to write
049   * @see "HAL_WriteAddressableLEDData"
050   */
051  public static native void setData(int handle, byte[] data);
052
053  /**
054   * Sets the bit timing.
055   *
056   * <p>By default, the driver is set up to drive WS2812Bs, so nothing needs to be set for those.
057   *
058   * @param handle the Addressable LED handle
059   * @param highTime0NanoSeconds high time for 0 bit (default 400ns)
060   * @param lowTime0NanoSeconds low time for 0 bit (default 900ns)
061   * @param highTime1NanoSeconds high time for 1 bit (default 900ns)
062   * @param lowTime1NanoSeconds low time for 1 bit (default 600ns)
063   * @see "HAL_SetAddressableLEDBitTiming"
064   */
065  public static native void setBitTiming(
066      int handle,
067      int highTime0NanoSeconds,
068      int lowTime0NanoSeconds,
069      int highTime1NanoSeconds,
070      int lowTime1NanoSeconds);
071
072  /**
073   * Sets the sync time.
074   *
075   * <p>The sync time is the time to hold output so LEDs enable. Default set for WS2812B.
076   *
077   * @param handle the Addressable LED handle
078   * @param syncTimeMicroSeconds the sync time (default 280us)
079   * @see "HAL_SetAddressableLEDSyncTime"
080   */
081  public static native void setSyncTime(int handle, int syncTimeMicroSeconds);
082
083  /**
084   * Starts the output.
085   *
086   * <p>The output writes continuously.
087   *
088   * @param handle the Addressable LED handle
089   * @see "HAL_StartAddressableLEDOutput"
090   */
091  public static native void start(int handle);
092
093  /**
094   * Stops the output.
095   *
096   * @param handle the Addressable LED handle
097   * @see "HAL_StopAddressableLEDOutput"
098   */
099  public static native void stop(int handle);
100
101  /** Utility class. */
102  private AddressableLEDJNI() {}
103}