Read's the joystick description file

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26764 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Fredrik Modeen
2008-08-03 18:22:21 +00:00
parent cf859cccf6
commit a14895cc90
2 changed files with 162 additions and 195 deletions
+3
View File
@@ -2,6 +2,8 @@ SubDir HAIKU_TOP src kits device ;
SetSubDirSupportedPlatformsBeOSCompatible ; SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders device ;
# for usb_raw.h that defines the ioctl protocol used by the USB classes # 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 ; UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel drivers bus usb ] : true ;
@@ -10,6 +12,7 @@ SharedLibrary libdevice.so :
D2A.cpp D2A.cpp
DigitalPort.cpp DigitalPort.cpp
Joystick.cpp Joystick.cpp
JoystickTweaker.cpp
SerialPort.cpp SerialPort.cpp
USBConfiguration.cpp USBConfiguration.cpp
USBDevice.cpp USBDevice.cpp
+159 -195
View File
@@ -3,10 +3,14 @@
* All rights reserved. * All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
/*
joystick preference app
JoyCalib::JoyCalib(BRect, BJoystick &, BWindow *):
__8JoyCalibG5BRectR9BJoystickP7BWindow:
*/
#include <Joystick.h>
#include <List.h> #include <List.h>
#include <Entry.h>
#include <Path.h> #include <Path.h>
#include <Directory.h> #include <Directory.h>
@@ -17,112 +21,74 @@
#include <fcntl.h> #include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#define DEVICEPATH "/dev/joystick/" #include "Joystick.h"
typedef struct _joystick_info { #ifdef DEBUG
char module_name[64]; inline void LOG(const char *fmt, ...) { char buf[1024]; va_list ap; va_start(ap, fmt); vsprintf(buf, fmt, ap); va_end(ap); \
char device_name[64]; fputs(buf, BJoystick::sLogFile); fflush(BJoystick::sLogFile); }
int16 num_axes; #define LOG_ERR(text...) LOG(text)
int16 num_buttons; FILE *BJoystick::sLogFile = NULL;
int16 num_hats; #else
uint16 num_sticks; #define LOG(text...)
} joystick_info; #define LOG_ERR(text...) fprintf(stderr, text)
#endif
//Scans a directory and adds the entries it founds as strings to the given list #define CALLED() LOG("%s\n", __PRETTY_FUNCTION__)
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;
};
//-------------------------------------------------------------------//
#include "JoystickTweaker.h"
BJoystick::BJoystick() BJoystick::BJoystick()
: _mBeBoxMode(false) : _mBeBoxMode(false)
, _fDevices(new BList) , _fDevices(new BList)
{ , m_info(new _joystick_info())
ScanDevices(); {
#ifdef DEBUG
sLogFile = fopen("/var/log/libdevice.log", "a");
#endif
//ScanDevices();
} }
BJoystick::~BJoystick() BJoystick::~BJoystick()
{ {
if (ffd >= 0) if (ffd >= 0)
close(ffd); close(ffd);
for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) {
free(_fDevices->RemoveItem(count)); free(_fDevices->RemoveItem(count));
}
delete _fDevices; delete _fDevices;
delete m_info;
} }
status_t status_t
BJoystick::Open(const char *portName) BJoystick::Open(const char *portName)
{ {
CALLED();
return Open(portName, true); return Open(portName, true);
} }
status_t status_t
BJoystick::Open(const char *portName, BJoystick::Open(const char *portName, bool enter_enhanced)
bool enter_enhanced)
{ {
CALLED();
char buf[64]; char buf[64];
//We don't want to use enhanced mode but _mBeBoxMode sugest if we use
//BeBoxMode
if(!enter_enhanced) if(!enter_enhanced)
_mBeBoxMode = !enter_enhanced; _mBeBoxMode = !enter_enhanced;
if (portName == NULL) if (portName == NULL)
return B_BAD_VALUE; // Heheee, we won't crash return B_BAD_VALUE;
if (portName[0] != '/') if (portName[0] != '/')
snprintf(buf, 64, DEVICEPATH"/%s", portName); snprintf(buf, 64, DEVICEPATH"/%s", portName);
else else
// A name like "/dev/joystick/usb/0" was passed
snprintf(buf, 64, "%s", portName); snprintf(buf, 64, "%s", portName);
if (ffd >= 0) //If this port is already open, close it if (ffd >= 0)
close(ffd); close(ffd);
// TODO: BeOS don't use O_EXCL, and this seems to lead to some issues. I // 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, // TODO: I wonder why the return type is a status_t,
// since we (as BeOS does) return the descriptor number for the device... // 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 void
BJoystick::Close(void) BJoystick::Close(void)
{ {
CALLED();
if (ffd >= 0) if (ffd >= 0)
close(ffd); close(ffd);
ffd = -1; ffd = -1;
@@ -157,26 +132,27 @@ BJoystick::Close(void)
void void
BJoystick::ScanDevices(bool use_disabled) BJoystick::ScanDevices(bool use_disabled)
{ {
// First, we empty the list CALLED();
for (int32 count = _fDevices->CountItems() - 1; count >= 0; count--) if (use_disabled) {
free(_fDevices->RemoveItem(count)); _BJoystickTweaker temp(*this);
temp.scan_including_disabled();
// Add devices to the list }
scan_directory(DEVICEPATH, _fDevices);
} }
int32 int32
BJoystick::CountDevices() BJoystick::CountDevices()
{ {
CALLED();
int32 count = 0; int32 count = 0;
// Refresh devices list // Refresh devices list
ScanDevices(); ScanDevices(true);
if (_fDevices != NULL) if (_fDevices != NULL)
count = _fDevices->CountItems(); count = _fDevices->CountItems();
LOG("Count = %d\n", count);
return count; return count;
} }
@@ -184,37 +160,27 @@ BJoystick::CountDevices()
status_t status_t
BJoystick::GetDeviceName(int32 n, char *name, size_t bufSize) BJoystick::GetDeviceName(int32 n, char *name, size_t bufSize)
{ {
status_t result = B_ERROR; CALLED();
const char *dev = NULL; status_t result = B_ERROR;
BString *temp = new BString();
if (_fDevices != NULL) if (_fDevices != NULL)
dev = static_cast<char*>(_fDevices->ItemAt(n)); temp = static_cast<BString*>(_fDevices->ItemAt(n));
if (dev != NULL && name != NULL) { if (temp != NULL && name != NULL) {
strncpy(name, dev, bufSize); strncpy(name, temp->String(), bufSize);
name[bufSize - 1] = '\0'; name[bufSize - 1] = '\0';
result = B_OK; result = B_OK;
} }
LOG("Device Name = %s\n", name);
return result; return result;
} }
status_t
BJoystick::Update(void)
{
return B_ERROR;
}
status_t
BJoystick::SetMaxLatency(bigtime_t max_latency)
{
return B_ERROR;
}
bool bool
BJoystick::EnterEnhancedMode(const entry_ref *ref) BJoystick::EnterEnhancedMode(const entry_ref *ref)
{ {
CALLED();
_mBeBoxMode = false; _mBeBoxMode = false;
return !_mBeBoxMode; return !_mBeBoxMode;
} }
@@ -222,44 +188,122 @@ BJoystick::EnterEnhancedMode(const entry_ref *ref)
int32 int32
BJoystick::CountSticks() BJoystick::CountSticks()
{ {
return 0; CALLED();
return m_info->num_sticks;
} }
int32 int32
BJoystick::CountAxes() BJoystick::CountAxes()
{ {
return 0; CALLED();
return m_info->num_axes;
} }
int32 int32
BJoystick::CountHats() BJoystick::CountHats()
{ {
return 0; CALLED();
return m_info->num_hats;
} }
int32 int32
BJoystick::CountButtons() 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 status_t
BJoystick::GetAxisValues(int16 *out_values, BJoystick::GetControllerName(BString *out_name)
int32 for_stick)
{ {
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; return B_ERROR;
} }
status_t status_t
BJoystick::GetHatValues(uint8 *out_hats, BJoystick::GetHatNameAt(int32 index, BString *out_name)
int32 for_stick)
{ {
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; return B_ERROR;
} }
@@ -267,71 +311,30 @@ BJoystick::GetHatValues(uint8 *out_hats,
uint32 uint32
BJoystick::ButtonValues(int32 for_stick) BJoystick::ButtonValues(int32 for_stick)
{ {
CALLED();
return 0; return 0;
} }
status_t status_t
BJoystick::GetAxisNameAt(int32 index, BJoystick::Update(void)
BString *out_name)
{ {
CALLED();
return B_ERROR; 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 void
BJoystick::Calibrate(struct _extended_joystick *reading) BJoystick::Calibrate(struct _extended_joystick *reading)
{ {
CALLED();
} }
status_t status_t
BJoystick::gather_enhanced_info(const entry_ref *ref) BJoystick::gather_enhanced_info(const entry_ref *ref)
{ {
CALLED();
return B_ERROR; return B_ERROR;
} }
@@ -339,54 +342,15 @@ BJoystick::gather_enhanced_info(const entry_ref *ref)
status_t status_t
BJoystick::save_config(const entry_ref *ref) BJoystick::save_config(const entry_ref *ref)
{ {
CALLED();
return B_ERROR; return B_ERROR;
} }
/* These functions are here to maintain Binary Compatibility */ /* These functions are here to maintain Binary Compatibility */
void BJoystick::_ReservedJoystick1() {} void BJoystick::_ReservedJoystick1() {CALLED();}
void BJoystick::_ReservedJoystick2() {} void BJoystick::_ReservedJoystick2() {CALLED();}
void BJoystick::_ReservedJoystick3() {} void BJoystick::_ReservedJoystick3() {CALLED();}
status_t BJoystick::_Reserved_Joystick_4(void *, ...) {return B_ERROR;} status_t BJoystick::_Reserved_Joystick_4(void *, ...) {CALLED();return B_ERROR;}
status_t BJoystick::_Reserved_Joystick_5(void *, ...) {return B_ERROR;} status_t BJoystick::_Reserved_Joystick_5(void *, ...) {CALLED();return B_ERROR;}
status_t BJoystick::_Reserved_Joystick_6(void *, ...) {return B_ERROR;} status_t BJoystick::_Reserved_Joystick_6(void *, ...) {CALLED();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;
}