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.phoenixpro.wpiutils;
008
009import com.ctre.phoenixpro.unmanaged.Unmanaged;
010
011import edu.wpi.first.hal.HAL;
012import edu.wpi.first.hal.HAL.SimPeriodicBeforeCallback;
013import edu.wpi.first.wpilibj.DriverStation;
014
015/**
016 * @deprecated Classes in the phoenixpro package will be removed in 2024.
017 *             Users should instead use classes from the phoenix6 package.
018 */
019@Deprecated(forRemoval = true)
020public class AutoFeedEnable implements AutoCloseable {
021    private static final AutoFeedEnable autoFeedEnable = new AutoFeedEnable();
022    private SimPeriodicBeforeCallback simPeriodicCallback = null;
023
024    public static AutoFeedEnable getInstance() {
025        return autoFeedEnable;
026    }
027
028    private AutoFeedEnable() {
029        simPeriodicCallback = HAL.registerSimPeriodicBeforeCallback(() -> {
030            if (DriverStation.isEnabled()) {
031                Unmanaged.feedEnable(100);
032            }
033        });
034    }
035
036    @Override
037    public void close() {
038        if (simPeriodicCallback != null) {
039            simPeriodicCallback.close();
040            simPeriodicCallback = null;
041        }
042    }
043}