| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | // Copyright 2015 Dolphin Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2+
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace ciface | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | namespace Pipes | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | // To create a piped controller input, create a named pipe in the
 | 
					
						
							|  |  |  | // Pipes directory and write commands out to it. Commands are separated
 | 
					
						
							|  |  |  | // by a newline character, with spaces separating command tokens.
 | 
					
						
							|  |  |  | // Command syntax is as follows, where curly brackets are one-of and square
 | 
					
						
							|  |  |  | // brackets are inclusive numeric ranges. Cases are sensitive. Numeric inputs
 | 
					
						
							|  |  |  | // are clamped to [0, 1] and otherwise invalid commands are discarded.
 | 
					
						
							|  |  |  | // {PRESS, RELEASE} {A, B, X, Y, Z, START, L, R, D_UP, D_DOWN, D_LEFT, D_RIGHT}
 | 
					
						
							|  |  |  | // SET {L, R} [0, 1]
 | 
					
						
							|  |  |  | // SET {MAIN, C} [0, 1] [0, 1]
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-16 13:39:05 -07:00
										 |  |  | void PopulateDevices(); | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | class PipeDevice : public Core::Device | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2016-07-14 10:25:52 +02:00
										 |  |  |   PipeDevice(int fd, const std::string& name); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   ~PipeDevice(); | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   void UpdateInput() override; | 
					
						
							|  |  |  |   std::string GetName() const override { return m_name; } | 
					
						
							|  |  |  |   std::string GetSource() const override { return "Pipe"; } | 
					
						
							| 
									
										
										
										
											2018-04-12 14:18:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   class PipeInput : public Input | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |   public: | 
					
						
							|  |  |  |     PipeInput(const std::string& name) : m_name(name), m_state(0.0) {} | 
					
						
							|  |  |  |     std::string GetName() const override { return m_name; } | 
					
						
							|  |  |  |     ControlState GetState() const override { return m_state; } | 
					
						
							|  |  |  |     void SetState(ControlState state) { m_state = state; } | 
					
						
							| 
									
										
										
										
											2018-04-12 14:18:04 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   private: | 
					
						
							|  |  |  |     const std::string m_name; | 
					
						
							|  |  |  |     ControlState m_state; | 
					
						
							|  |  |  |   }; | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   void AddAxis(const std::string& name, double value); | 
					
						
							|  |  |  |   void ParseCommand(const std::string& command); | 
					
						
							|  |  |  |   void SetAxis(const std::string& entry, double value); | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   const int m_fd; | 
					
						
							|  |  |  |   const std::string m_name; | 
					
						
							|  |  |  |   std::string m_buf; | 
					
						
							|  |  |  |   std::map<std::string, PipeInput*> m_buttons; | 
					
						
							|  |  |  |   std::map<std::string, PipeInput*> m_axes; | 
					
						
							| 
									
										
										
										
											2015-10-24 20:20:03 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | } |