001/* Copyright (C) Cross The Road Electronics 2024 */
002package com.ctre.phoenix.led;
003
004/**
005 * Animation that sends a pocket of light across the LED strip.
006 */
007public class LarsonAnimation extends BaseTwoSizeAnimation {
008    /**
009     * How the pocket of light behaves when it reaches the end of the strip
010     */
011    public enum BounceMode {
012        /**
013         * Bounce the pocket as soon as the first LED reaches the end of the strip
014         */
015        Front(0),
016        /**
017         * Bounce the pocket once it is midway through the end of the strip
018         */
019        Center(1),
020        /**
021         * Bounce the pocket once all the LEDs are off the strip
022         */
023        Back(2);
024
025        final public int value;
026
027        BounceMode(int value) {
028            this.value = value;
029        }
030    }
031    /**
032     * Constructor for a LarsonAnimation
033     * @param r How much red should the color have [0, 255]
034     * @param g How much green should the color have [0, 255]
035     * @param b How much blue should the color have [0, 255]
036     * @param w How much white should the color have [0, 255]
037     * @param speed How fast should the color travel the strip [0, 1]
038     * @param numLed The number of LEDs the CANdle will control
039     * @param mode How the pocket of LEDs will behave once it reaches the end of the strip
040     * @param size How large the pocket of LEDs are [0, 7]
041     * @param ledOffset Where to start the animation
042     */
043    public LarsonAnimation(int r, int g, int b, int w, double speed, int numLed, BounceMode mode, int size, int ledOffset) {
044        super(0x61, r, g, b, w, speed, numLed, mode.value, size, ledOffset);
045    }
046    /**
047     * Constructor for a LarsonAnimation
048     * @param r How much red should the color have [0, 255]
049     * @param g How much green should the color have [0, 255]
050     * @param b How much blue should the color have [0, 255]
051     * @param w How much white should the color have [0, 255]
052     * @param speed How fast should the color travel the strip [0, 1]
053     * @param numLed The number of LEDs the CANdle will control
054     * @param mode How the pocket of LEDs will behave once it reaches the end of the strip
055     * @param size How large the pocket of LEDs are [0, 7]
056     */
057    public LarsonAnimation(int r, int g, int b, int w, double speed, int numLed, BounceMode mode, int size) {
058        this(r, g, b, w, speed, numLed, mode, size, 0);
059    }
060    /**
061     * Constructor for a LarsonAnimation
062     * @param r How much red should the color have [0, 255]
063     * @param g How much green should the color have [0, 255]
064     * @param b How much blue should the color have [0, 255]
065     */
066    public LarsonAnimation(int r, int g, int b) {
067        this(r, g, b, 0, 1, -1, BounceMode.Front, 2, 0);
068    }
069
070    /**
071     * Sets the bounce mode of the animation.
072     * @param mode How the pocket of LEDs will behave once it reaches the end of the strip
073     */
074    public void setBounceMode(BounceMode mode) {
075        setDirection(mode.value);
076    }
077    
078    /**
079     * Sets the size of the pocket of LEDs
080     * @param size The size of the pocket [0, 7]
081     */
082    public void setSize(int size) {
083        super.setSize(size);
084    }
085}