xref: /haiku/headers/os/device/Joystick.h (revision 959ff00ddee8411dabb09211f3bfbd52d87229da)
1 /********************************************************************************
2 /
3 /	File:		Joystick.h
4 /
5 /	Description:	Joystick port class header.
6 /
7 /	Copyright 1996-98, Be Incorporated, All Rights Reserved.
8 /
9 ********************************************************************************/
10 
11 
12 #ifndef	_JOYSTICK_H
13 #define	_JOYSTICK_H
14 
15 #include <BeBuild.h>
16 #include <SupportDefs.h>
17 #include <OS.h>
18 
19 class BList;
20 class BString;
21 struct entry_ref;
22 struct _extended_joystick;
23 class _BJoystickTweaker;
24 
25 typedef struct _joystick_info {
26 	char		module_name[64];
27 	char		controller_name[64];
28 	int16		num_axes;
29 	int16		num_buttons;
30 	int16		num_hats;
31 	uint32		num_sticks;
32 	bool		calibration_enable;
33 	bigtime_t	max_latency;
34 	BList		name_axis;
35 	BList		name_hat;
36 	BList		name_button;
37 //	BList		name_
38 } joystick_info;
39 
40 /* -----------------------------------------------------------------------*/
41 class BJoystick {
42 public:
43 					BJoystick();
44 virtual				~BJoystick();
45 
46 		status_t	Open(const char *portName);
47 		status_t	Open(const char *portName, bool enter_enhanced = true);
48 		void		Close(void);
49 
50 		status_t	Update(void);
51 		status_t	SetMaxLatency(bigtime_t max_latency);
52 
53 		bigtime_t	timestamp;
54 		int16		horizontal;
55 		int16		vertical;
56 
57 		/* NOTE: true == off */
58 		bool		button1;
59 		bool		button2;
60 
61 		int32		CountDevices();
62 		status_t	GetDeviceName(int32 n, char * name,
63 						size_t bufSize = B_OS_NAME_LENGTH);
64 
65 		bool		EnterEnhancedMode(const entry_ref * ref = NULL);
66 
67 		int32		CountSticks();
68 
69 		status_t	GetControllerModule(BString * out_name);
70 		status_t	GetControllerName(BString * out_name);
71 
72 		bool		IsCalibrationEnabled();
73 		status_t	EnableCalibration(bool calibrates = true);
74 
75 		int32		CountAxes();
76 		status_t	GetAxisValues(int16 * out_values, int32 for_stick = 0);
77 		status_t	GetAxisNameAt(int32 index, BString * out_name);
78 
79 		int32		CountHats();
80 		status_t	GetHatValues(uint8 * out_hats, int32 for_stick = 0);
81 		status_t	GetHatNameAt(int32 index, BString * out_name);
82 
83 		int32		CountButtons();
84 		/* NOTE: Buttons() are 1 == on */
85 		uint32		ButtonValues(int32 for_stick = 0);
86 		status_t	GetButtonNameAt(int32 index, BString * out_name);
87 /* -----------------------------------------------------------------------*/
88 
89 protected:
90 
91 virtual	void		Calibrate(struct _extended_joystick * reading);
92 
93 private:
94 friend class _BJoystickTweaker;
95 
96 		void		ScanDevices(bool use_disabled = false);
97 		status_t	GatherEnhanced_info(const entry_ref * ref = NULL);
98 		status_t	SaveConfig(const entry_ref * ref = NULL);
99 
100 		bool			fBeBoxMode;
101 		bool			fReservedBool;
102 		int				ffd;
103 		BList*			fDevices;
104 		_joystick_info* fJoystickInfo;
105 		char* 			fDevName;
106 #if DEBUG
107 public:
108 	static FILE *sLogFile;
109 #endif
110 };
111 
112 #endif
113