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>
|
2022-10-15 16:33:14 -07:00
|
|
|
#include <span>
|
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>
|
2019-09-04 22:54:49 -05:00
|
|
|
|
2023-07-14 01:12:01 -04:00
|
|
|
#include "frc2/command/Command.h"
|
2019-11-05 20:52:49 -08:00
|
|
|
#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
|
2022-02-04 01:14:52 -05:00
|
|
|
* Command::WithTimeout(double) or Command::Until(BooleanSupplier) to
|
2021-10-14 18:09:38 -07:00
|
|
|
* 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.
|
2022-01-08 11:11:34 -08:00
|
|
|
*
|
|
|
|
|
* This class is provided by the NewCommands VendorDep
|
2019-08-25 23:55:59 -04:00
|
|
|
*/
|
2023-07-14 01:12:01 -04:00
|
|
|
class NotifierCommand : public CommandHelper<Command, NotifierCommand> {
|
2019-08-25 23:55:59 -04:00
|
|
|
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,
|
2023-09-17 20:48:39 -07:00
|
|
|
Requirements 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
|