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 status_t RescanDevices(); 45 // Haiku extension. Updates the list of devices 46 // as enumerated by CountDevices() and 47 // GetDeviceName() with possibly newly plugged 48 // in devices. 49 50 bool EnterEnhancedMode(const entry_ref* ref = NULL); 51 52 int32 CountSticks(); 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 uint32 ButtonValues(int32 forStick = 0); 67 // Allows access to the first 32 buttons where 68 // each set bit indicates a pressed button. 69 status_t GetButtonValues(bool* outButtons, 70 int32 forStick = 0); 71 // Haiku extension. Allows to retrieve the state 72 // of an arbitrary count of buttons. The 73 // outButtons argument is an array of boolean 74 // values with at least CountButtons() elements. 75 // True means the button is pressed and false 76 // means it is released. 77 status_t GetButtonNameAt(int32 index, 78 BString* outName); 79 80 status_t GetControllerModule(BString* outName); 81 status_t GetControllerName(BString* outName); 82 83 bool IsCalibrationEnabled(); 84 status_t EnableCalibration(bool calibrates = true); 85 86 protected: 87 virtual void Calibrate(struct _extended_joystick*); 88 89 private: 90 friend class _BJoystickTweaker; 91 92 void ScanDevices(bool useDisabled = false); 93 94 void _ReservedJoystick1(); 95 virtual void _ReservedJoystick2(); 96 virtual void _ReservedJoystick3(); 97 virtual status_t _Reserved_Joystick_4(void *, ...); 98 virtual status_t _Reserved_Joystick_5(void *, ...); 99 virtual status_t _Reserved_Joystick_6(void *, ...); 100 101 bool fBeBoxMode; 102 bool fReservedBool; 103 int fFD; 104 BList* fDevices; 105 _joystick_info* fJoystickInfo; 106 BList* fJoystickData; 107 108 uint32 _reserved_Joystick_[10]; 109 }; 110 111 #endif // _JOYSTICK_H 112