Author: mmlr Date: 2011-06-03 14:45:35 +0200 (Fri, 03 Jun 2011) New Revision: 41878 Changeset: https://dev.haiku-os.org/changeset/41878 Modified: haiku/trunk/headers/os/device/Joystick.h haiku/trunk/src/kits/device/Joystick.cpp Log: Move function definitions to match their declaration order. Also move some declarations to group them more logically. No functional changes. Modified: haiku/trunk/headers/os/device/Joystick.h =================================================================== --- haiku/trunk/headers/os/device/Joystick.h 2011-06-03 12:39:51 UTC (rev 41877) +++ haiku/trunk/headers/os/device/Joystick.h 2011-06-03 12:45:35 UTC (rev 41878) @@ -51,12 +51,6 @@ int32 CountSticks(); - status_t GetControllerModule(BString* outName); - status_t GetControllerName(BString* outName); - - bool IsCalibrationEnabled(); - status_t EnableCalibration(bool calibrates = true); - int32 CountAxes(); status_t GetAxisValues(int16* outValues, int32 forStick = 0); @@ -69,11 +63,16 @@ status_t GetHatNameAt(int32 index, BString* outName); int32 CountButtons(); - uint32 ButtonValues(int32 forStick = 0); status_t GetButtonNameAt(int32 index, BString* outName); + status_t GetControllerModule(BString* outName); + status_t GetControllerName(BString* outName); + + bool IsCalibrationEnabled(); + status_t EnableCalibration(bool calibrates = true); + protected: virtual void Calibrate(struct _extended_joystick*); Modified: haiku/trunk/src/kits/device/Joystick.cpp =================================================================== --- haiku/trunk/src/kits/device/Joystick.cpp 2011-06-03 12:39:51 UTC (rev 41877) +++ haiku/trunk/src/kits/device/Joystick.cpp 2011-06-03 12:45:35 UTC (rev 41878) @@ -174,17 +174,58 @@ } -void -BJoystick::ScanDevices(bool useDisabled) +status_t +BJoystick::Update() { CALLED(); - if (useDisabled) { - _BJoystickTweaker joystickTweaker(*this); - joystickTweaker.scan_including_disabled(); + if (fJoystickInfo == NULL || fExtendedJoystick == NULL || fFD < 0) + return B_NO_INIT; + + for (uint16 i = 0; i < fJoystickInfo->module_info.num_sticks; i++) { + extended_joystick *extendedJoystick + = (extended_joystick *)fExtendedJoystick->ItemAt(i); + if (extendedJoystick == NULL) + return B_NO_INIT; + + ssize_t result = read_pos(fFD, i, extendedJoystick, + sizeof(extended_joystick)); + if (result < 0) + return result; + + if (result != sizeof(extended_joystick)) + return B_ERROR; + + if (i > 0) + continue; + + // fill in the legacy values for the first stick + timestamp = extendedJoystick->timestamp; + horizontal = extendedJoystick->axes[0]; + vertical = extendedJoystick->axes[1]; + button1 = (extendedJoystick->buttons & 1) == 0; + button2 = (extendedJoystick->buttons & 2) == 0; } + + return B_OK; } +status_t +BJoystick::SetMaxLatency(bigtime_t maxLatency) +{ + CALLED(); + if (fJoystickInfo == NULL || fFD < 0) + return B_NO_INIT; + + status_t result = ioctl(fFD, B_JOYSTICK_SET_MAX_LATENCY, &maxLatency, + sizeof(maxLatency)); + if (result == B_OK) + fJoystickInfo->max_latency = maxLatency; + + return result; +} + + int32 BJoystick::CountDevices() { @@ -267,134 +308,128 @@ } -int32 -BJoystick::CountHats() +status_t +BJoystick::GetAxisValues(int16 *outValues, int32 forStick) { CALLED(); - if (fJoystickInfo == NULL) - return 0; - return fJoystickInfo->module_info.num_hats; -} + if (fJoystickInfo == NULL || fExtendedJoystick == NULL) + return B_NO_INIT; + if (forStick < 0 + || forStick >= (int32)fJoystickInfo->module_info.num_sticks) + return B_BAD_INDEX; -int32 -BJoystick::CountButtons() -{ - CALLED(); - if (fJoystickInfo == NULL) - return 0; - - return fJoystickInfo->module_info.num_buttons; -} - - -status_t -BJoystick::GetControllerModule(BString *outName) -{ - CALLED(); - if (fJoystickInfo == NULL || fFD < 0) + extended_joystick *extendedJoystick + = (extended_joystick *)fExtendedJoystick->ItemAt(forStick); + if (extendedJoystick == NULL) return B_NO_INIT; - if (outName == NULL) - return B_BAD_VALUE; - - outName->SetTo(fJoystickInfo->module_info.module_name); + memcpy(outValues, extendedJoystick->axes, + fJoystickInfo->module_info.num_axes * sizeof(uint16)); return B_OK; } status_t -BJoystick::GetControllerName(BString *outName) +BJoystick::GetAxisNameAt(int32 index, BString *outName) { CALLED(); - if (fJoystickInfo == NULL || fFD < 0) - return B_NO_INIT; + if (index >= CountAxes()) + return B_BAD_INDEX; + if (outName == NULL) return B_BAD_VALUE; - outName->SetTo(fJoystickInfo->module_info.device_name); + // TODO: actually retrieve the name from the driver (via a new ioctl) + *outName = "Axis "; + *outName << index; return B_OK; } -bool -BJoystick::IsCalibrationEnabled() +int32 +BJoystick::CountHats() { CALLED(); if (fJoystickInfo == NULL) - return false; + return 0; - return fJoystickInfo->calibration_enable; + return fJoystickInfo->module_info.num_hats; } status_t -BJoystick::EnableCalibration(bool calibrates) +BJoystick::GetHatValues(uint8 *outHats, int32 forStick) { CALLED(); - if (fJoystickInfo == NULL || fFD < 0) + + if (fJoystickInfo == NULL || fExtendedJoystick == NULL) return B_NO_INIT; - status_t result = ioctl(fFD, B_JOYSTICK_SET_RAW_MODE, &calibrates, - sizeof(calibrates)); - if (result == B_OK) - fJoystickInfo->calibration_enable = calibrates; + if (forStick < 0 + || forStick >= (int32)fJoystickInfo->module_info.num_sticks) + return B_BAD_INDEX; - return result; -} - - -status_t -BJoystick::SetMaxLatency(bigtime_t maxLatency) -{ - CALLED(); - if (fJoystickInfo == NULL || fFD < 0) + extended_joystick *extendedJoystick + = (extended_joystick *)fExtendedJoystick->ItemAt(forStick); + if (extendedJoystick == NULL) return B_NO_INIT; - status_t result = ioctl(fFD, B_JOYSTICK_SET_MAX_LATENCY, &maxLatency, - sizeof(maxLatency)); - if (result == B_OK) - fJoystickInfo->max_latency = maxLatency; - - return result; + memcpy(outHats, extendedJoystick->hats, + fJoystickInfo->module_info.num_hats); + return B_OK; } status_t -BJoystick::GetAxisNameAt(int32 index, BString *outName) +BJoystick::GetHatNameAt(int32 index, BString *outName) { CALLED(); - if (index >= CountAxes()) + if (index >= CountHats()) return B_BAD_INDEX; if (outName == NULL) return B_BAD_VALUE; // TODO: actually retrieve the name from the driver (via a new ioctl) - *outName = "Axis "; + *outName = "Hat "; *outName << index; return B_OK; } -status_t -BJoystick::GetHatNameAt(int32 index, BString *outName) +int32 +BJoystick::CountButtons() { CALLED(); + if (fJoystickInfo == NULL) + return 0; - if (index >= CountHats()) - return B_BAD_INDEX; + return fJoystickInfo->module_info.num_buttons; +} - if (outName == NULL) - return B_BAD_VALUE; - // TODO: actually retrieve the name from the driver (via a new ioctl) - *outName = "Hat "; - *outName << index; - return B_OK; +uint32 +BJoystick::ButtonValues(int32 forStick) +{ + CALLED(); + + if (fJoystickInfo == NULL || fExtendedJoystick == NULL) + return 0; + + if (forStick < 0 + || forStick >= (int32)fJoystickInfo->module_info.num_sticks) + return 0; + + extended_joystick *extendedJoystick + = (extended_joystick *)fExtendedJoystick->ItemAt(forStick); + if (extendedJoystick == NULL) + return 0; + + return extendedJoystick->buttons; } @@ -417,112 +452,77 @@ status_t -BJoystick::GetAxisValues(int16 *outValues, int32 forStick) +BJoystick::GetControllerModule(BString *outName) { CALLED(); - - if (fJoystickInfo == NULL || fExtendedJoystick == NULL) + if (fJoystickInfo == NULL || fFD < 0) return B_NO_INIT; - if (forStick < 0 - || forStick >= (int32)fJoystickInfo->module_info.num_sticks) - return B_BAD_INDEX; + if (outName == NULL) + return B_BAD_VALUE; - extended_joystick *extendedJoystick - = (extended_joystick *)fExtendedJoystick->ItemAt(forStick); - if (extendedJoystick == NULL) - return B_NO_INIT; - - memcpy(outValues, extendedJoystick->axes, - fJoystickInfo->module_info.num_axes * sizeof(uint16)); + outName->SetTo(fJoystickInfo->module_info.module_name); return B_OK; } status_t -BJoystick::GetHatValues(uint8 *outHats, int32 forStick) +BJoystick::GetControllerName(BString *outName) { CALLED(); - - if (fJoystickInfo == NULL || fExtendedJoystick == NULL) + if (fJoystickInfo == NULL || fFD < 0) return B_NO_INIT; - if (forStick < 0 - || forStick >= (int32)fJoystickInfo->module_info.num_sticks) - return B_BAD_INDEX; + if (outName == NULL) + return B_BAD_VALUE; - extended_joystick *extendedJoystick - = (extended_joystick *)fExtendedJoystick->ItemAt(forStick); - if (extendedJoystick == NULL) - return B_NO_INIT; - - memcpy(outHats, extendedJoystick->hats, - fJoystickInfo->module_info.num_hats); + outName->SetTo(fJoystickInfo->module_info.device_name); return B_OK; } -uint32 -BJoystick::ButtonValues(int32 forStick) +bool +BJoystick::IsCalibrationEnabled() { CALLED(); + if (fJoystickInfo == NULL) + return false; - if (fJoystickInfo == NULL || fExtendedJoystick == NULL) - return 0; - - if (forStick < 0 - || forStick >= (int32)fJoystickInfo->module_info.num_sticks) - return 0; - - extended_joystick *extendedJoystick - = (extended_joystick *)fExtendedJoystick->ItemAt(forStick); - if (extendedJoystick == NULL) - return 0; - - return extendedJoystick->buttons; + return fJoystickInfo->calibration_enable; } status_t -BJoystick::Update() +BJoystick::EnableCalibration(bool calibrates) { CALLED(); - if (fJoystickInfo == NULL || fExtendedJoystick == NULL || fFD < 0) + if (fJoystickInfo == NULL || fFD < 0) return B_NO_INIT; - for (uint16 i = 0; i < fJoystickInfo->module_info.num_sticks; i++) { - extended_joystick *extendedJoystick - = (extended_joystick *)fExtendedJoystick->ItemAt(i); - if (extendedJoystick == NULL) - return B_NO_INIT; + status_t result = ioctl(fFD, B_JOYSTICK_SET_RAW_MODE, &calibrates, + sizeof(calibrates)); + if (result == B_OK) + fJoystickInfo->calibration_enable = calibrates; - ssize_t result = read_pos(fFD, i, extendedJoystick, - sizeof(extended_joystick)); - if (result < 0) - return result; + return result; +} - if (result != sizeof(extended_joystick)) - return B_ERROR; - if (i > 0) - continue; - - // fill in the legacy values for the first stick - timestamp = extendedJoystick->timestamp; - horizontal = extendedJoystick->axes[0]; - vertical = extendedJoystick->axes[1]; - button1 = (extendedJoystick->buttons & 1) == 0; - button2 = (extendedJoystick->buttons & 2) == 0; - } - - return B_OK; +void +BJoystick::Calibrate(struct _extended_joystick *reading) +{ + CALLED(); } void -BJoystick::Calibrate(struct _extended_joystick *reading) +BJoystick::ScanDevices(bool useDisabled) { CALLED(); + if (useDisabled) { + _BJoystickTweaker joystickTweaker(*this); + joystickTweaker.scan_including_disabled(); + } }