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
4
#include "
ctre/phoenix/tasking/ILoopable.h
"
5
#include "
ctre/phoenix/tasking/IProcessable.h
"
6
#include <functional>
7
8
/* forward proto's */
9
namespace
frc
{
10
class
GenericHID;
11
}
12
13
namespace
ctre
{
14
namespace
phoenix {
15
namespace
tasking {
16
17
/**
18
* Class to handle button events
19
*/
20
class
ButtonMonitor
:
public
IProcessable
,
public
ILoopable
{
21
public
:
22
23
/**
24
* Interface for classes that handle button events
25
*/
26
class
IButtonPressEventHandler
{
27
public
:
28
virtual
~IButtonPressEventHandler
(){}
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
*/
47
ButtonMonitor
(
const
ButtonMonitor
& rhs);
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
74
private
:
75
frc::GenericHID * _gameCntrlr;
76
int
_btnIdx;
77
IButtonPressEventHandler
* _handler;
78
bool
_isDown =
false
;
79
};
80
}
81
}
82
}
ILoopable.h
IProcessable.h
ctre::phoenix::tasking::ButtonMonitor::IButtonPressEventHandler
Interface for classes that handle button events.
Definition:
ButtonMonitor.h:26
ctre::phoenix::tasking::ButtonMonitor::IButtonPressEventHandler::OnButtonPress
virtual void OnButtonPress(int idx, bool isDown)=0
Method to execute when a button is pressed.
ctre::phoenix::tasking::ButtonMonitor::IButtonPressEventHandler::~IButtonPressEventHandler
virtual ~IButtonPressEventHandler()
Definition:
ButtonMonitor.h:28
ctre::phoenix::tasking::ButtonMonitor
Class to handle button events.
Definition:
ButtonMonitor.h:20
ctre::phoenix::tasking::ButtonMonitor::Process
virtual void Process()
Call this every loop, it monitors for button presses.
ctre::phoenix::tasking::ButtonMonitor::~ButtonMonitor
virtual ~ButtonMonitor()
Definition:
ButtonMonitor.h:48
ctre::phoenix::tasking::ButtonMonitor::IsDone
virtual bool IsDone()
ctre::phoenix::tasking::ButtonMonitor::ButtonMonitor
ButtonMonitor(frc::GenericHID *controller, int buttonIndex, IButtonPressEventHandler *ButtonPressEventHandler)
Constructor for ButtonMonitor.
ctre::phoenix::tasking::ButtonMonitor::OnLoop
virtual void OnLoop()
Process every loop.
ctre::phoenix::tasking::ButtonMonitor::ButtonMonitor
ButtonMonitor(const ButtonMonitor &rhs)
This is able to copy another ButtonMonitor class.
ctre::phoenix::tasking::ButtonMonitor::OnStop
virtual void OnStop()
Do nothing on stop.
ctre::phoenix::tasking::ButtonMonitor::OnStart
virtual void OnStart()
Do nothing on start.
ctre::phoenix::tasking::ILoopable
Interface for loopable objects.
Definition:
ILoopable.h:9
ctre::phoenix::tasking::IProcessable
Interface for processable objects.
Definition:
IProcessable.h:8
ctre
namespace ctre
Definition:
paramEnum.h:5
frc
Definition:
ButtonMonitor.h:9
ctre
phoenix
tasking
ButtonMonitor.h
Generated on Fri Feb 16 2024 22:57:39 for CTRE Phoenix C++ by
1.9.4