WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
NotifierCommand.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <functional>
8
13#include "wpi/units/time.hpp"
14
15namespace wpi::cmd {
16/**
17 * A command that starts a notifier to run the given runnable periodically in a
18 * separate thread. Has no end condition as-is; either subclass it or use
19 * Command::WithTimeout(double) or Command::Until(BooleanSupplier) to
20 * give it one.
21 *
22 * <p>WARNING: Do not use this class unless you are confident in your ability to
23 * make the executed code thread-safe. If you do not know what "thread-safe"
24 * means, that is a good sign that you should not use this class.
25 *
26 * This class is provided by the NewCommands VendorDep
27 */
28class NotifierCommand : public CommandHelper<Command, NotifierCommand> {
29 public:
30 /**
31 * Creates a new NotifierCommand.
32 *
33 * @param toRun the runnable for the notifier to run
34 * @param period the period at which the notifier should run
35 * @param requirements the subsystems required by this command
36 */
37 NotifierCommand(std::function<void()> toRun, wpi::units::second_t period,
38 Requirements requirements = {});
39
41
43
44 void Initialize() override;
45
46 void End(bool interrupted) override;
47
48 private:
49 std::function<void()> m_toRun;
50 wpi::Notifier m_notifier;
51 wpi::units::second_t m_period;
52};
53} // namespace wpi::cmd
Notifiers run a user-provided callback function on a separate thread.
Definition Notifier.hpp:30
NotifierCommand(NotifierCommand &&other)
void Initialize() override
void End(bool interrupted) override
NotifierCommand(std::function< void()> toRun, wpi::units::second_t period, Requirements requirements={})
Creates a new NotifierCommand.
NotifierCommand(const NotifierCommand &other)
Represents requirements for a command, which is a set of (pointers to) subsystems.
Definition Requirements.hpp:20
Definition CommandNiDsStadiaController.hpp:15