Refactored everything.
This commit is contained in:
		
							
								
								
									
										46
									
								
								include/okapi/api/device/button/abstractButton.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								include/okapi/api/device/button/abstractButton.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,46 @@ | ||||
| /* | ||||
|  * This Source Code Form is subject to the terms of the Mozilla Public | ||||
|  * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||
|  */ | ||||
| #pragma once | ||||
|  | ||||
| #include "okapi/api/control/controllerInput.hpp" | ||||
|  | ||||
| namespace okapi { | ||||
| class AbstractButton : public ControllerInput<bool> { | ||||
|   public: | ||||
|   virtual ~AbstractButton(); | ||||
|  | ||||
|   /** | ||||
|    * Return whether the button is currently pressed. | ||||
|    **/ | ||||
|   virtual bool isPressed() = 0; | ||||
|  | ||||
|   /** | ||||
|    * Return whether the state of the button changed since the last time this method was | ||||
|    * called. | ||||
|    **/ | ||||
|   virtual bool changed() = 0; | ||||
|  | ||||
|   /** | ||||
|    * Return whether the state of the button changed to being pressed since the last time this method | ||||
|    * was called. | ||||
|    **/ | ||||
|   virtual bool changedToPressed() = 0; | ||||
|  | ||||
|   /** | ||||
|    * Return whether the state of the button to being not pressed changed since the last time this | ||||
|    * method was called. | ||||
|    **/ | ||||
|   virtual bool changedToReleased() = 0; | ||||
|  | ||||
|   /** | ||||
|    * Get the sensor value for use in a control loop. This method might be automatically called in | ||||
|    * another thread by the controller. | ||||
|    * | ||||
|    * @return the current sensor value. This is the same as the output of the pressed() method. | ||||
|    */ | ||||
|   virtual bool controllerGet() override; | ||||
| }; | ||||
| } // namespace okapi | ||||
							
								
								
									
										52
									
								
								include/okapi/api/device/button/buttonBase.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								include/okapi/api/device/button/buttonBase.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | ||||
| /* | ||||
|  * This Source Code Form is subject to the terms of the Mozilla Public | ||||
|  * License, v. 2.0. If a copy of the MPL was not distributed with this | ||||
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||||
|  */ | ||||
| #pragma once | ||||
|  | ||||
| #include "okapi/api/device/button/abstractButton.hpp" | ||||
|  | ||||
| namespace okapi { | ||||
| class ButtonBase : public AbstractButton { | ||||
|   public: | ||||
|   /** | ||||
|    * @param iinverted Whether the button is inverted (`true` meaning default pressed and `false` | ||||
|    * meaning default not pressed). | ||||
|    */ | ||||
|   explicit ButtonBase(bool iinverted = false); | ||||
|  | ||||
|   /** | ||||
|    * Return whether the button is currently pressed. | ||||
|    **/ | ||||
|   bool isPressed() override; | ||||
|  | ||||
|   /** | ||||
|    * Return whether the state of the button changed since the last time this method was called. | ||||
|    **/ | ||||
|   bool changed() override; | ||||
|  | ||||
|   /** | ||||
|    * Return whether the state of the button changed to pressed since the last time this method was | ||||
|    *called. | ||||
|    **/ | ||||
|   bool changedToPressed() override; | ||||
|  | ||||
|   /** | ||||
|    * Return whether the state of the button to not pressed since the last time this method was | ||||
|    *called. | ||||
|    **/ | ||||
|   bool changedToReleased() override; | ||||
|  | ||||
|   protected: | ||||
|   bool inverted{false}; | ||||
|   bool wasPressedLast_c{false}; | ||||
|   bool wasPressedLast_ctp{false}; | ||||
|   bool wasPressedLast_ctr{false}; | ||||
|  | ||||
|   virtual bool currentlyPressed() = 0; | ||||
|  | ||||
|   private: | ||||
|   bool changedImpl(bool &prevState); | ||||
| }; | ||||
| } // namespace okapi | ||||
		Reference in New Issue
	
	Block a user
	 Jacob
					Jacob