11/* *
22 * @file Controller.h
33 * @author Gabriel Saberian
4- * @brief Controller header file for Vanier Robotics' RobotUtils library, controls the robot by pressing
5- * digital and analog buttons on a controller.
4+ * @brief Controller class used to manage all sorts of inputs
65 *
76 * @copyright Copyright (c) 2023 Vanier Robotics (MIT License)
87 */
9-
108#include < ArduinoExtra.h>
119#include < CrcLib.h>
1210
1614namespace rou
1715{
1816
17+ /* *
18+ * @brief Controller class, which can be used to manage the various inputs for a robot
19+ *
20+ */
1921class Controller
2022{
21- // Structure that contains the variables and fuctions for the digital binding
23+ /* *
24+ * @brief Structure that contains the variables and function for a digital binding
25+ *
26+ */
2227 struct DigitalBinding
2328 {
24- Crc::BUTTON buttonID; // variable of type BUTTON (from CRC lib ) that stores a specific button
25- aex::Function<void (bool )> callback; // pointer function used to do some action with a digital button
29+ Crc::BUTTON buttonID; // /< variable of type BUTTON (from CrcLib ) that stores a specific button
30+ aex::Function<void (bool )> callback; // /< pointer to the function called when the binding changes state
2631 };
2732
28- // Structure that contains the variables and fuctions for the toggle binding
33+ /* *
34+ * @brief Structure that contains the variables and function for a toggle binding
35+ *
36+ */
2937 struct ToggleBinding
3038 {
31- Crc::BUTTON buttonID; // variable of type BUTTON (from CRC lib ) that stores a specific button
32- aex::Function<void (bool )> callback; // pointer function used to do some action with a toggle action
39+ Crc::BUTTON buttonID; // /< variable of type BUTTON (from CrcLib ) that stores a specific button
40+ aex::Function<void (bool )> callback; // /< pointer to the function called when the binding changes state
3341
34- bool isToggled; // boolean variable that stores the state of the button (Toggled = true and not toggled = false)
35- // boolean variable that stores the last value of a button and used to defined the isToggled value
36- // (if lastValue = true, then the last button was pressed and if lastValue = false, then the last button wasn't pressed)
37- bool lastValue;
42+ bool isToggled; // /< stores the state of the button
43+ bool lastValue; // /< boolean variable that keeps track of the previous value of a button
3844 };
3945
40- // Structure that contains the variables and fuctions for the analog binding
46+ /* *
47+ * @brief Structure that contains the variables and function for an analog binding
48+ *
49+ */
4150 struct AnalogBinding
4251 {
43- Crc::ANALOG analogID; // variable of type ANALOG (from CRC lib ) that stores a specific button
44- aex::Function<void (int8_t )> callback; // pointer function used to do some action with an analog button
52+ Crc::ANALOG analogID; // /< variable of type ANALOG (from CrcLib ) that stores a specific button
53+ aex::Function<void (int8_t )> callback; // /< pointer to the function called when the binding changes state
4554 };
4655
47- // Structure that contains the variables and fuctions for the digital sensor binding
56+ /* *
57+ * @brief Structure that contains the variables and functions for a digital sensor binding
58+ *
59+ */
4860 struct DigitalSensorBinding
4961 {
50- uint8_t pin; // variable of type uint8_t that stores the number of the pin on the crcDuino board change type
51- aex::Function<void (bool )> callback;
62+ uint8_t pin; // /< the pin number from Crclib
63+ aex::Function<void (bool )> callback; // /< pointer to the function called when the binding changes state
5264 };
5365
54- // Structure that contains the variables and fuctions for the analog sensor binding
66+ /* *
67+ * @brief Structure that contains the variables and functions for an analog sensor binding
68+ *
69+ */
5570 struct AnalogSensorBinding
5671 {
57- uint8_t pin; // variable of type uint8_t that stores the number of the pin on the crcDuino board change type
58- aex::Function<void (unsigned int )> callback;
72+ uint8_t pin; // /< the pin number from Crclib
73+ aex::Function<void (unsigned int )> callback; // /< pointer to the function called when the binding changes state
5974 };
6075
6176public:
62- // callback functions (pointer functions) of the different structures
63- // callback function for digital bindings
77+ /* *
78+ * @brief Setup a callback function for a digital binding
79+ *
80+ * @param buttonID The BUTTON to which the binding is assigned
81+ * @param callback Pointer to the function that will be called when this binding is updated
82+ */
6483 void digitalBind (Crc::BUTTON buttonID, aex::Function<void (bool )> callback)
6584 {
6685 m_digitalBindings.pushBack ({buttonID, callback});
6786 }
6887
69- // callback function for toggle bindings
88+ /* *
89+ * @brief Setup a callback function for a toggle binding
90+ *
91+ * @param buttonID The BUTTON to which the binding is assigned
92+ * @param callback Pointer to the function that will be called when this binding is updated
93+ */
7094 void toggleBind (Crc::BUTTON buttonID, aex::Function<void (bool )> callback)
7195 {
7296 m_toggleBindings.pushBack ({buttonID, callback, false , false });
7397 }
7498
75- // callback function for analog bindings
99+ /* *
100+ * @brief Setup a callback function for an analog binding
101+ *
102+ * @param analogID The ANALOG input to which the binding is assigned
103+ * @param callback Pointer to the function that will be called when this binding is updated
104+ */
76105 void analogBind (Crc::ANALOG analogID, aex::Function<void (int8_t )> callback)
77106 {
78107 m_analogBindings.pushBack ({analogID, callback});
79108 }
80109
81- // callback function for digital sensor bindings
110+ /* *
111+ * @brief Setup a callback function for a digital sensor binding
112+ *
113+ * @param pin The CrcLib pin number to which the sensor is connected
114+ * @param callback Pointer to the function that will be called when this binding is updated
115+ */
82116 void digitalSensorBind (uint8_t pin, aex::Function<void (bool )> callback)
83117 {
84118 m_digitalSensorBindings.pushBack ({pin, callback});
85119 }
86120
87- // callback function for analog sensor binding
121+ /* *
122+ * @brief Setup a callback function for an analog sensor binding
123+ *
124+ * @param pin The CrcLib pin number to which the sensor is connected
125+ * @param callback Pointer to the function that will be called when this binding is updated
126+ */
88127 void analogSensorBind (uint8_t pin, aex::Function<void (unsigned int )> callback)
89128 {
90129 m_analogSensorBindings.pushBack ({pin, callback});
91130 }
92131
132+ /* *
133+ * @brief Update all the bindings and call the required callbacks
134+ *
135+ */
93136 void update ()
94137 {
95- // For each frame, verify which button are pressed and call the corresponding methods
96- // Digital Bindings verification
138+ // For each frame, verify which button are pressed and call the corresponding methods
139+
140+ // Digital Bindings verification
97141 for (int i = 0 ; i < m_digitalBindings.getSize (); i++)
98142 {
99143 m_digitalBindings[i].callback (
100144 Crc::CrcLib::ReadDigitalChannel (m_digitalBindings[i].buttonID ));
101145 }
102146
103- // Analog Bindings verification
147+ // Analog Bindings verification
104148 for (int i = 0 ; i < m_analogBindings.getSize (); i++)
105149 {
106150 m_analogBindings[i].callback (
107151 Crc::CrcLib::ReadAnalogChannel (m_analogBindings[i].analogID ));
108152 }
109153
110- // Toggle Bindings verification
154+ // Toggle Bindings verification
111155 for (int i = 0 ; i < m_toggleBindings.getSize (); i++)
112156 {
113157 bool status = Crc::CrcLib::ReadDigitalChannel (m_toggleBindings[i].buttonID );
@@ -120,14 +164,14 @@ class Controller
120164 m_toggleBindings[i].lastValue = status;
121165 }
122166
123- // Digital Sensor Bindings verification
167+ // Digital Sensor Bindings verification
124168 for (int i = 0 ; i < m_digitalSensorBindings.getSize (); i++)
125169 {
126170 m_digitalSensorBindings[i].callback (
127171 (Crc::CrcLib::GetDigitalInput (m_digitalSensorBindings[i].pin ) == HIGH));
128172 }
129173
130- // Analog Sensor Bindings verification
174+ // Analog Sensor Bindings verification
131175 for (int i = 0 ; i < m_analogSensorBindings.getSize (); i++)
132176 {
133177 m_analogSensorBindings[i].callback (
@@ -136,12 +180,11 @@ class Controller
136180 }
137181
138182private:
139- // Vector arrays
140- aex::Vector<DigitalBinding> m_digitalBindings; // Create a vector array of type DigitalBinding
141- aex::Vector<ToggleBinding> m_toggleBindings; // Create a vector array of type ToggleBinding
142- aex::Vector<AnalogBinding> m_analogBindings; // Create a vector array of type AnalogBinding
143- aex::Vector<DigitalSensorBinding> m_digitalSensorBindings; // Create a vector array of type DigitalSensorBinding
144- aex::Vector<AnalogSensorBinding> m_analogSensorBindings; // Create a vector array of type AnalogBinding
183+ aex::Vector<DigitalBinding> m_digitalBindings; // /< Vector of DigitalBinding's which were created
184+ aex::Vector<ToggleBinding> m_toggleBindings; // /< Vector of ToggleBinding's which were created
185+ aex::Vector<AnalogBinding> m_analogBindings; // /< Vector of AnalogBinding's which were created
186+ aex::Vector<DigitalSensorBinding> m_digitalSensorBindings; // /< Vector of DigitalSensorBinding's which were created
187+ aex::Vector<AnalogSensorBinding> m_analogSensorBindings; // /< Vector of AnalogSensorBinding's which were created
145188};
146189
147190} // rou
0 commit comments