PathPlannerLib
Loading...
Searching...
No Matches
EventTrigger.h
1#pragma once
2
3#include <frc2/command/button/Trigger.h>
4#include <string>
5#include <unordered_map>
6#include "pathplanner/lib/events/EventScheduler.h"
7
8namespace pathplanner {
9class EventTrigger: public frc2::Trigger {
10public:
16 EventTrigger(std::string name) : frc2::Trigger(
17 EventScheduler::getEventLoop(), pollCondition(name)) {
18 }
19
27 EventTrigger(frc::EventLoop *eventLoop, std::string name) : frc2::Trigger(
28 eventLoop, pollCondition(name)) {
29 }
30
31 static inline void setCondition(std::string name, bool value) {
32 getEventConditions()[name] = value;
33 }
34
35private:
36
37 static inline std::unordered_map<std::string, bool>& getEventConditions() {
38 static std::unordered_map<std::string, bool> *eventConditions =
39 new std::unordered_map<std::string, bool>();
40 return *eventConditions;
41 }
42
49 static inline std::function<bool()> pollCondition(std::string name) {
50 // Ensure there is a condition in the map for this name
51 if (!getEventConditions().contains(name)) {
52 getEventConditions().emplace(name, false);
53 }
54
55 return [name]() {
56 return getEventConditions()[name];
57 };
58 }
59};
60}
Definition: EventScheduler.h:15
Definition: EventTrigger.h:9
EventTrigger(frc::EventLoop *eventLoop, std::string name)
Definition: EventTrigger.h:27
EventTrigger(std::string name)
Definition: EventTrigger.h:16