inputs: buttons: split implementation into cpp
This commit is contained in:
		
							
								
								
									
										23
									
								
								firmware/inputs/Buttons.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								firmware/inputs/Buttons.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | |||||||
|  | #include "Particle.h" | ||||||
|  | #include "./Buttons.h" | ||||||
|  |  | ||||||
|  | void | ||||||
|  | Buttons::onStart() | ||||||
|  | { | ||||||
|  |     for(int i = 0; i < 3; i++) { | ||||||
|  |         m_buttons[i].attach(2 + i, INPUT_PULLDOWN); | ||||||
|  |         m_buttons[i].interval(15); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | InputEvent | ||||||
|  | Buttons::read() | ||||||
|  | { | ||||||
|  |     for(int i = 0; i < 3; i++) { | ||||||
|  |         m_buttons[i].update(); | ||||||
|  |         if (m_buttons[i].fell()) { | ||||||
|  |             return InputEvent{m_buttonMap[i]}; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     return InputEvent{}; | ||||||
|  | } | ||||||
| @@ -1,4 +1,5 @@ | |||||||
| #pragma once | #pragma once | ||||||
|  | #include "../Figments/Input.h" | ||||||
|  |  | ||||||
| class Bounce { | class Bounce { | ||||||
| public: | public: | ||||||
| @@ -43,6 +44,10 @@ public: | |||||||
|         return m_state == Confirmed; |         return m_state == Confirmed; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     bool held() const { | ||||||
|  |         return m_state == Held; | ||||||
|  |     } | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     enum State { |     enum State { | ||||||
|         Ready, |         Ready, | ||||||
| @@ -59,22 +64,8 @@ private: | |||||||
|  |  | ||||||
| class Buttons: public InputSource { | class Buttons: public InputSource { | ||||||
| public: | public: | ||||||
|     void onStart() override { |     void onStart() override; | ||||||
|         for(int i = 0; i < 3; i++) { |     InputEvent read() override; | ||||||
|             m_buttons[i].attach(2 + i, INPUT_PULLDOWN); |  | ||||||
|             m_buttons[i].interval(15); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     InputEvent read() override { |  | ||||||
|         for(int i = 0; i < 3; i++) { |  | ||||||
|             m_buttons[i].update(); |  | ||||||
|             if (m_buttons[i].fell()) { |  | ||||||
|                 return InputEvent{m_buttonMap[i]}; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|         return InputEvent{}; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| private: | private: | ||||||
|     Bounce m_buttons[3]; |     Bounce m_buttons[3]; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user