xref: /haiku/headers/os/device/Joystick.h (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
1 /*
2  * Copyright 2009, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_JOYSTICK_H
6 #define	_JOYSTICK_H
7 
8 
9 #include <OS.h>
10 #include <SupportDefs.h>
11 
12 
13 class BList;
14 class BString;
15 class _BJoystickTweaker;
16 struct entry_ref;
17 struct _extended_joystick;
18 struct _joystick_info;
19 
20 
21 class BJoystick {
22 public:
23 							BJoystick();
24 	virtual					~BJoystick();
25 
26 			status_t		Open(const char* portName);
27 			status_t		Open(const char* portName, bool enhanced);
28 			void			Close();
29 
30 			status_t		Update();
31 			status_t		SetMaxLatency(bigtime_t maxLatency);
32 
33 			bigtime_t		timestamp;
34 			int16			horizontal;
35 			int16			vertical;
36 
37 			bool			button1;
38 			bool			button2;
39 
40 			int32			CountDevices();
41 			status_t		GetDeviceName(int32 index, char* name,
42 								size_t bufSize = B_OS_NAME_LENGTH);
43 
44 			bool			EnterEnhancedMode(const entry_ref* ref = NULL);
45 
46 			int32			CountSticks();
47 
48 			status_t		GetControllerModule(BString* outName);
49 			status_t		GetControllerName(BString* outName);
50 
51 			bool			IsCalibrationEnabled();
52 			status_t		EnableCalibration(bool calibrates = true);
53 
54 			int32			CountAxes();
55 			status_t		GetAxisValues(int16* outValues,
56 								int32 forStick = 0);
57 			status_t		GetAxisNameAt(int32 index,
58 								BString* outName);
59 
60 			int32			CountHats();
61 			status_t		GetHatValues(uint8* outHats,
62 								int32 forStick = 0);
63 			status_t		GetHatNameAt(int32 index, BString* outName);
64 
65 			int32			CountButtons();
66 
67 			uint32			ButtonValues(int32 forStick = 0);
68 			status_t		GetButtonNameAt(int32 index,
69 								BString* outName);
70 
71 protected:
72 	virtual	void			Calibrate(struct _extended_joystick*);
73 
74 private:
75 friend class _BJoystickTweaker;
76 
77 			void			ScanDevices(bool useDisabled = false);
78 			status_t		GatherEnhanced_info(const entry_ref* ref = NULL);
79 			status_t		SaveConfig(const entry_ref* ref = NULL);
80 
81 			void            _ReservedJoystick1();
82 	virtual void            _ReservedJoystick2();
83 	virtual void            _ReservedJoystick3();
84 	virtual status_t        _Reserved_Joystick_4(void *, ...);
85 	virtual status_t        _Reserved_Joystick_5(void *, ...);
86 	virtual status_t        _Reserved_Joystick_6(void *, ...);
87 
88 			bool			fBeBoxMode;
89 			bool			fReservedBool;
90 			int				ffd;
91 			BList*			fDevices;
92 			_joystick_info*	fJoystickInfo;
93 			char*			fDevName;
94 			uint32          _reserved_Joystick_[10];
95 };
96 
97 #endif // _JOYSTICK_H
98