2020-12-26 14:12:05 -08:00
|
|
|
// Copyright (c) FIRST and other WPILib contributors.
|
|
|
|
|
// Open Source Software; you can modify and/or share it under the terms of
|
|
|
|
|
// the WPILib BSD license file in the root directory of this project.
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include <functional>
|
|
|
|
|
#include <initializer_list>
|
2019-08-25 23:55:59 -04:00
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include <frc/Notifier.h>
|
2020-06-29 22:25:09 -07:00
|
|
|
#include <units/time.h>
|
2021-06-06 19:51:14 -07:00
|
|
|
#include <wpi/span.h>
|
2019-09-04 22:54:49 -05:00
|
|
|
|
2019-11-05 20:52:49 -08:00
|
|
|
#include "frc2/command/CommandBase.h"
|
|
|
|
|
#include "frc2/command/CommandHelper.h"
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
namespace frc2 {
|
|
|
|
|
/**
|
|
|
|
|
* A command that starts a notifier to run the given runnable periodically in a
|
2021-10-14 18:09:38 -07:00
|
|
|
* separate thread. Has no end condition as-is; either subclass it or use
|
|
|
|
|
* Command::WithTimeout(double) or Command::WithInterrupt(BooleanSupplier) to
|
|
|
|
|
* give it one.
|
2019-08-25 23:55:59 -04:00
|
|
|
*
|
|
|
|
|
* <p>WARNING: Do not use this class unless you are confident in your ability to
|
|
|
|
|
* make the executed code thread-safe. If you do not know what "thread-safe"
|
|
|
|
|
* means, that is a good sign that you should not use this class.
|
|
|
|
|
*/
|
|
|
|
|
class NotifierCommand : public CommandHelper<CommandBase, NotifierCommand> {
|
|
|
|
|
public:
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new NotifierCommand.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the runnable for the notifier to run
|
2019-09-04 22:54:49 -05:00
|
|
|
* @param period the period at which the notifier should run
|
2019-08-25 23:55:59 -04:00
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
2019-09-04 22:54:49 -05:00
|
|
|
NotifierCommand(std::function<void()> toRun, units::second_t period,
|
2020-01-01 20:09:17 -08:00
|
|
|
std::initializer_list<Subsystem*> requirements);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a new NotifierCommand.
|
|
|
|
|
*
|
|
|
|
|
* @param toRun the runnable for the notifier to run
|
|
|
|
|
* @param period the period at which the notifier should run
|
|
|
|
|
* @param requirements the subsystems required by this command
|
|
|
|
|
*/
|
|
|
|
|
NotifierCommand(std::function<void()> toRun, units::second_t period,
|
2021-06-06 19:51:14 -07:00
|
|
|
wpi::span<Subsystem* const> requirements = {});
|
2019-08-25 23:55:59 -04:00
|
|
|
|
|
|
|
|
NotifierCommand(NotifierCommand&& other);
|
|
|
|
|
|
|
|
|
|
NotifierCommand(const NotifierCommand& other);
|
|
|
|
|
|
|
|
|
|
void Initialize() override;
|
|
|
|
|
|
|
|
|
|
void End(bool interrupted) override;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::function<void()> m_toRun;
|
|
|
|
|
frc::Notifier m_notifier;
|
2019-09-04 22:54:49 -05:00
|
|
|
units::second_t m_period;
|
2019-08-25 23:55:59 -04:00
|
|
|
};
|
|
|
|
|
} // namespace frc2
|