CTRE Phoenix C++ 5.33.1
ButtonMonitor.h
Go to the documentation of this file.
1/* Copyright (C) Cross The Road Electronics 2024 */
2#pragma once
3
6#include <functional>
7
8/* forward proto's */
9namespace frc {
10 class GenericHID;
11}
12
13namespace ctre {
14namespace phoenix {
15namespace tasking {
16
17/**
18 * Class to handle button events
19 */
20class ButtonMonitor: public IProcessable, public ILoopable {
21public:
22
23 /**
24 * Interface for classes that handle button events
25 */
27 public:
29 /**
30 * Method to execute when a button is pressed
31 * @param idx Index of button pressed
32 * @param isDown Whether the button is down or not
33 */
34 virtual void OnButtonPress(int idx, bool isDown) = 0;
35 };
36
37 /**
38 * Constructor for ButtonMonitor
39 * @param controller Controller to monitor
40 * @param buttonIndex Button to monitor
41 * @param ButtonPressEventHandler Class that will handle buttonPresses
42 */
43 ButtonMonitor(frc::GenericHID * controller, int buttonIndex, IButtonPressEventHandler * ButtonPressEventHandler);
44 /**
45 * This is able to copy another ButtonMonitor class
46 */
48 virtual ~ButtonMonitor() { }
49
50 /* IProcessable */
51 /**
52 * Call this every loop, it monitors for button presses
53 */
54 virtual void Process();
55
56 /* ILoopable */
57 /**
58 * Do nothing on start
59 */
60 virtual void OnStart();
61 /**
62 * Process every loop
63 */
64 virtual void OnLoop();
65 /**
66 * @return false, this is never done
67 */
68 virtual bool IsDone();
69 /**
70 * Do nothing on stop
71 */
72 virtual void OnStop();
73
74private:
75 frc::GenericHID * _gameCntrlr;
76 int _btnIdx;
77 IButtonPressEventHandler * _handler;
78 bool _isDown = false;
79};
80}
81}
82}
Interface for classes that handle button events.
Definition: ButtonMonitor.h:26
virtual void OnButtonPress(int idx, bool isDown)=0
Method to execute when a button is pressed.
virtual ~IButtonPressEventHandler()
Definition: ButtonMonitor.h:28
Class to handle button events.
Definition: ButtonMonitor.h:20
virtual void Process()
Call this every loop, it monitors for button presses.
virtual ~ButtonMonitor()
Definition: ButtonMonitor.h:48
ButtonMonitor(frc::GenericHID *controller, int buttonIndex, IButtonPressEventHandler *ButtonPressEventHandler)
Constructor for ButtonMonitor.
virtual void OnLoop()
Process every loop.
ButtonMonitor(const ButtonMonitor &rhs)
This is able to copy another ButtonMonitor class.
virtual void OnStop()
Do nothing on stop.
virtual void OnStart()
Do nothing on start.
Interface for loopable objects.
Definition: ILoopable.h:9
Interface for processable objects.
Definition: IProcessable.h:8
namespace ctre
Definition: paramEnum.h:5
Definition: ButtonMonitor.h:9