diff --git a/src/kits/device/Jamfile b/src/kits/device/Jamfile index 743911d519..94e8c8fc27 100644 --- a/src/kits/device/Jamfile +++ b/src/kits/device/Jamfile @@ -2,6 +2,8 @@ SubDir HAIKU_TOP src kits device ; SetSubDirSupportedPlatformsBeOSCompatible ; +UsePrivateHeaders device ; + # for usb_raw.h that defines the ioctl protocol used by the USB classes UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel drivers bus usb ] : true ; @@ -10,6 +12,7 @@ SharedLibrary libdevice.so : D2A.cpp DigitalPort.cpp Joystick.cpp + JoystickTweaker.cpp SerialPort.cpp USBConfiguration.cpp USBDevice.cpp diff --git a/src/kits/device/Joystick.cpp b/src/kits/device/Joystick.cpp index badb00294c..fe3fbf6cd4 100644 --- a/src/kits/device/Joystick.cpp +++ b/src/kits/device/Joystick.cpp @@ -3,10 +3,14 @@ * All rights reserved. * Distributed under the terms of the MIT License. */ + +/* +joystick preference app + JoyCalib::JoyCalib(BRect, BJoystick &, BWindow *): +__8JoyCalibG5BRectR9BJoystickP7BWindow: +*/ -#include #include -#include #include #include @@ -17,112 +21,74 @@ #include #include -#define DEVICEPATH "/dev/joystick/" +#include "Joystick.h" -typedef struct _joystick_info { - char module_name[64]; - char device_name[64]; - int16 num_axes; - int16 num_buttons; - int16 num_hats; - uint16 num_sticks; -} joystick_info; +#ifdef DEBUG + inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \ + fputs(buf, BJoystick::sLogFile); fflush(BJoystick::sLogFile); } + #define LOG_ERR(text...) LOG(text) +FILE *BJoystick::sLogFile = NULL; +#else + #define LOG(text...) + #define LOG_ERR(text...) fprintf(stderr, text) +#endif -//Scans a directory and adds the entries it founds as strings to the given list -static status_t -scan_directory(const char* rootPath, BList *list, BEntry *rootEntry = NULL) -{ - BDirectory root; - - if (rootEntry != NULL) - root.SetTo( rootEntry); - else if (rootPath != NULL) - root.SetTo(rootPath); - else - return B_ERROR; - - BEntry entry; - - ASSERT(list != NULL); - while ((root.GetNextEntry(&entry)) > B_ERROR ) { - if (entry.IsDirectory()) { - scan_directory(rootPath, list, &entry); - } else { - BPath path; - entry.GetPath(&path); - BString str(path.Path()); - str.RemoveFirst(rootPath); - list->AddItem(strdup(str.String())); - } - } - return B_OK; -} - -class _BJoystickTweaker { - -public: - _BJoystickTweaker(); - _BJoystickTweaker(BJoystick &stick); -virtual ~_BJoystickTweaker(); - -protected: -private: - status_t scan_including_disabled(); - status_t save_config(const entry_ref * ref = NULL); - status_t get_info(); - BJoystick* fJoystick; -}; -//-------------------------------------------------------------------// +#define CALLED() LOG("%s\n", __PRETTY_FUNCTION__) +#include "JoystickTweaker.h" BJoystick::BJoystick() : _mBeBoxMode(false) , _fDevices(new BList) -{ - ScanDevices(); + , m_info(new _joystick_info()) +{ +#ifdef DEBUG + sLogFile = fopen("/var/log/libdevice.log", "a"); +#endif + //ScanDevices(); } BJoystick::~BJoystick() -{ +{ if (ffd >= 0) close(ffd); - for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) + for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) { free(_fDevices->RemoveItem(count)); + } delete _fDevices; + delete m_info; } status_t BJoystick::Open(const char *portName) { + CALLED(); return Open(portName, true); } status_t -BJoystick::Open(const char *portName, - bool enter_enhanced) +BJoystick::Open(const char *portName, bool enter_enhanced) { + CALLED(); char buf[64]; - //We don't want to use enhanced mode but _mBeBoxMode sugest if we use - //BeBoxMode if(!enter_enhanced) _mBeBoxMode = !enter_enhanced; if (portName == NULL) - return B_BAD_VALUE; // Heheee, we won't crash + return B_BAD_VALUE; if (portName[0] != '/') snprintf(buf, 64, DEVICEPATH"/%s", portName); else - // A name like "/dev/joystick/usb/0" was passed snprintf(buf, 64, "%s", portName); - if (ffd >= 0) //If this port is already open, close it + if (ffd >= 0) close(ffd); // TODO: BeOS don't use O_EXCL, and this seems to lead to some issues. I @@ -141,13 +107,22 @@ BJoystick::Open(const char *portName, } // TODO: I wonder why the return type is a status_t, // since we (as BeOS does) return the descriptor number for the device... - return (ffd >= 0) ? ffd : errno; + + //Read the Joystick Description file for this port/joystick + _BJoystickTweaker jt(*this); + jt.get_info(m_info, portName); + + if (ffd >= 0) { + return ffd; + } else + return errno; } void BJoystick::Close(void) { + CALLED(); if (ffd >= 0) close(ffd); ffd = -1; @@ -157,26 +132,27 @@ BJoystick::Close(void) void BJoystick::ScanDevices(bool use_disabled) { - // First, we empty the list - for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) - free(_fDevices->RemoveItem(count)); - - // Add devices to the list - scan_directory(DEVICEPATH, _fDevices); + CALLED(); + if (use_disabled) { + _BJoystickTweaker temp(*this); + temp.scan_including_disabled(); + } } int32 BJoystick::CountDevices() { + CALLED(); int32 count = 0; // Refresh devices list - ScanDevices(); + ScanDevices(true); if (_fDevices != NULL) count = _fDevices->CountItems(); + LOG("Count = %d\n", count); return count; } @@ -184,37 +160,27 @@ BJoystick::CountDevices() status_t BJoystick::GetDeviceName(int32 n, char *name, size_t bufSize) { - status_t result = B_ERROR; - const char *dev = NULL; + CALLED(); + status_t result = B_ERROR; + BString *temp = new BString(); if (_fDevices != NULL) - dev = static_cast(_fDevices->ItemAt(n)); + temp = static_cast(_fDevices->ItemAt(n)); - if (dev != NULL && name != NULL) { - strncpy(name, dev, bufSize); + if (temp != NULL && name != NULL) { + strncpy(name, temp->String(), bufSize); name[bufSize - 1] = '\0'; result = B_OK; } + + LOG("Device Name = %s\n", name); return result; } -status_t -BJoystick::Update(void) -{ - return B_ERROR; -} - - -status_t -BJoystick::SetMaxLatency(bigtime_t max_latency) -{ - return B_ERROR; -} - - bool BJoystick::EnterEnhancedMode(const entry_ref *ref) { + CALLED(); _mBeBoxMode = false; return !_mBeBoxMode; } @@ -222,44 +188,122 @@ BJoystick::EnterEnhancedMode(const entry_ref *ref) int32 BJoystick::CountSticks() -{ - return 0; +{ + CALLED(); + return m_info->num_sticks; } int32 BJoystick::CountAxes() { - return 0; + CALLED(); + return m_info->num_axes; } int32 BJoystick::CountHats() { - return 0; + CALLED(); + return m_info->num_hats; } int32 BJoystick::CountButtons() { - return 0; + CALLED(); + return m_info->num_buttons; +} + +status_t +BJoystick::GetControllerModule(BString *out_name) +{ + CALLED(); + if (m_info != NULL && ffd >= 0) { + out_name->SetTo(m_info->module_name); + return B_OK; + } else + return B_ERROR; + } status_t -BJoystick::GetAxisValues(int16 *out_values, - int32 for_stick) +BJoystick::GetControllerName(BString *out_name) { + CALLED(); + if (m_info != NULL && ffd >= 0) { + out_name->SetTo(m_info->controller_name); + return B_OK; + } else + return B_ERROR; +} + + +bool +BJoystick::IsCalibrationEnabled() +{ + CALLED(); + return m_info->calibration_enable; +} + + +status_t +BJoystick::EnableCalibration(bool calibrates) +{ + CALLED(); + return m_info->calibration_enable = calibrates; +} + + +status_t +BJoystick::SetMaxLatency(bigtime_t max_latency) +{ + CALLED(); + m_info->max_latency = max_latency; + return B_OK; +} + +//--------- not done ------------------- + +status_t +BJoystick::GetAxisNameAt(int32 index, BString *out_name) +{ + CALLED(); return B_ERROR; } status_t -BJoystick::GetHatValues(uint8 *out_hats, - int32 for_stick) +BJoystick::GetHatNameAt(int32 index, BString *out_name) { + CALLED(); + return B_ERROR; +} + + +status_t +BJoystick::GetButtonNameAt(int32 index, BString *out_name) +{ + CALLED(); + return B_ERROR; +} + + +status_t +BJoystick::GetAxisValues(int16 *out_values, int32 for_stick) +{ + CALLED(); + return B_ERROR; +} + + +status_t +BJoystick::GetHatValues(uint8 *out_hats, int32 for_stick) +{ + CALLED(); return B_ERROR; } @@ -267,71 +311,30 @@ BJoystick::GetHatValues(uint8 *out_hats, uint32 BJoystick::ButtonValues(int32 for_stick) { + CALLED(); return 0; } status_t -BJoystick::GetAxisNameAt(int32 index, - BString *out_name) +BJoystick::Update(void) { + CALLED(); return B_ERROR; } -status_t -BJoystick::GetHatNameAt(int32 index, - BString *out_name) -{ - return B_ERROR; -} - - -status_t -BJoystick::GetButtonNameAt(int32 index, - BString *out_name) -{ - return B_ERROR; -} - - -status_t -BJoystick::GetControllerModule(BString *out_name) -{ - return B_ERROR; -} - - -status_t -BJoystick::GetControllerName(BString *out_name) -{ - return B_ERROR; -} - - -bool -BJoystick::IsCalibrationEnabled() -{ - return false; -} - - -status_t -BJoystick::EnableCalibration(bool calibrates) -{ - return false; -} - - void BJoystick::Calibrate(struct _extended_joystick *reading) { + CALLED(); } status_t BJoystick::gather_enhanced_info(const entry_ref *ref) { + CALLED(); return B_ERROR; } @@ -339,54 +342,15 @@ BJoystick::gather_enhanced_info(const entry_ref *ref) status_t BJoystick::save_config(const entry_ref *ref) { + CALLED(); return B_ERROR; } /* These functions are here to maintain Binary Compatibility */ -void BJoystick::_ReservedJoystick1() {} -void BJoystick::_ReservedJoystick2() {} -void BJoystick::_ReservedJoystick3() {} -status_t BJoystick::_Reserved_Joystick_4(void *, ...) {return B_ERROR;} -status_t BJoystick::_Reserved_Joystick_5(void *, ...) {return B_ERROR;} -status_t BJoystick::_Reserved_Joystick_6(void *, ...) {return B_ERROR;} - - -//-------------------------------------------------------------------// - - -_BJoystickTweaker::_BJoystickTweaker() -{ -} - - -_BJoystickTweaker::_BJoystickTweaker(BJoystick &stick) -{ - fJoystick = &stick; -} - - -_BJoystickTweaker::~_BJoystickTweaker() -{ -} - - -status_t -_BJoystickTweaker::save_config(const entry_ref *ref) -{ - return B_ERROR; -} - - -status_t -_BJoystickTweaker::scan_including_disabled() -{ - return B_ERROR; -} - - -status_t -_BJoystickTweaker::get_info() -{ - return B_ERROR; -} +void BJoystick::_ReservedJoystick1() {CALLED();} +void BJoystick::_ReservedJoystick2() {CALLED();} +void BJoystick::_ReservedJoystick3() {CALLED();} +status_t BJoystick::_Reserved_Joystick_4(void *, ...) {CALLED();return B_ERROR;} +status_t BJoystick::_Reserved_Joystick_5(void *, ...) {CALLED();return B_ERROR;} +status_t BJoystick::_Reserved_Joystick_6(void *, ...) {CALLED();return B_ERROR;}