diff options
author | endolf <[email protected]> | 2005-08-27 22:21:52 +0000 |
---|---|---|
committer | endolf <[email protected]> | 2005-08-27 22:21:52 +0000 |
commit | 69b47e65b8ee4851d13d3589bc2a31f4c1c32d2e (patch) | |
tree | 2dfaace9b8a0d1f2332a01cfc435405617e81a72 /plugins/linux/src/native/JoystickDevice.cpp | |
parent | 88ae7c1e09086907eb749a6b9bddce4dc5406799 (diff) |
Changes to the interface between java and native code.
git-svn-id: file:///home/sven/projects/JOGL/git-svn/svn-server-sync/jinput/branches/forcefeedback@113 e343933a-64c8-49c5-92b1-88f2ce3e89e8
Diffstat (limited to 'plugins/linux/src/native/JoystickDevice.cpp')
-rw-r--r-- | plugins/linux/src/native/JoystickDevice.cpp | 200 |
1 files changed, 0 insertions, 200 deletions
diff --git a/plugins/linux/src/native/JoystickDevice.cpp b/plugins/linux/src/native/JoystickDevice.cpp deleted file mode 100644 index 59d69eb..0000000 --- a/plugins/linux/src/native/JoystickDevice.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Copyright (C) 2003 Jeremy Booth ([email protected]) - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. Redistributions in binary - * form must reproduce the above copyright notice, this list of conditions and - * the following disclaimer in the documentation and/or other materials provided - * with the distribution. - * The name of the author may not be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO - * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE - */ - -#include "eventInterfaceTypes.h" -#include "JoystickDevice.h" -#include <stdio.h> -#include <linux/input.h> -#include <linux/joystick.h> -#include <fcntl.h> -#include <unistd.h> -#include <string.h> -#include <malloc.h> -#include <errno.h> - -#include "logger.h" - -JoystickDevice::JoystickDevice(char *deviceFileName) { - char tempName[Device::MAX_NAME_LENGTH-1] = "Unknown"; - int i; - - LOG_TRACE("Trying to open %s\n", deviceFileName); - fd = open(deviceFileName, O_RDWR | O_NONBLOCK); - /*if(fd<0) { - char errorMessage[512]; - sprintf(errorMessage, "Error opening device %s\n", deviceFileName); - perror(errorMessage); - }*/ - - if(fd>0){ - LOG_TRACE("Opened %s, trying to get device name\n", deviceFileName); - if(ioctl(fd, JSIOCGNAME(sizeof(tempName)), tempName) < 0) { - LOG_TRACE("Failed to get device name for %s\n", deviceFileName); - char errorMessage[512]; - sprintf(errorMessage, "Error reading device %s\n", deviceFileName); - perror(errorMessage); - } - - int namelength=strlen(tempName); - name = (char *)malloc(namelength+1); - strncpy(name,tempName, namelength+1); - - char tempNumButtons; - char tempNumAxes; - LOG_TRACE("Getting button and axes information for %s\n", deviceFileName); - ioctl (fd, JSIOCGBUTTONS, &tempNumButtons); - ioctl (fd, JSIOCGAXES, &tempNumAxes); - - numButtons = tempNumButtons; - numAbsAxes = tempNumAxes; - - //fprintf(stderr, "Got joystick %s with %d buttons and %d axes\n", tempName, numButtons, numAbsAxes); - - //buttonData = (uint8_t *)malloc(numButtons * sizeof(uint8_t)); - buttonData = new uint8_t[numButtons]; - //absAxesData = (int *)malloc(numAbsAxes * sizeof(int)); - absAxesData = new int[numAbsAxes]; - - LOG_TRACE("Initialisation of %s completed\n", deviceFileName); - inited = 1; - } else { - LOG_TRACE("Failed to open device %s\n", deviceFileName); - inited = 0; - } -} - -int JoystickDevice::isValidDevice() { - return inited; -} - -int JoystickDevice::getNumberRelAxes(){ - if(inited!=1) return -1; - return 0; -} - -int JoystickDevice::getNumberAbsAxes(){ - if(inited!=1) return -1; - return numAbsAxes; -} - -int JoystickDevice::getNumberButtons(){ - if(inited!=1) return -1; - return numButtons; -} - -const char *JoystickDevice::getName(){ - return name; -} - -int JoystickDevice::getBusType(){ - if(inited!=1) return -1; - return 0; -} - -int JoystickDevice::getVendorID(){ - if(inited!=1) return -1; - return 0; -} - -int JoystickDevice::getProductID(){ - if(inited!=1) return -1; - return 0; -} - -int JoystickDevice::getVersion(){ - if(inited!=1) return -1; - return 0; -} - -void JoystickDevice::getSupportedRelAxes(int supportedAxis[]){ -} - -void JoystickDevice::getSupportedAbsAxes(int supportedAxis[]){ -} - -void JoystickDevice::getSupportedButtons(int supportedButtons[]){ -} - -/** - * A return value of -1 means error, 0 means ok, but no change - * a return of >0 means the data for this device has changed - */ -int JoystickDevice::poll(){ - struct js_event event; - int numEvents = 0; - while(read(fd, &event, sizeof event) > 0) { - numEvents++; - event.type &= ~JS_EVENT_INIT; - if(event.type == JS_EVENT_BUTTON) { - buttonData[event.number] = event.value; - } else if(event.type == JS_EVENT_AXIS) { - absAxesData[event.number] = event.value; - } - - } - // EAGAIN is returned when the queue is empty - if(errno != EAGAIN) { - printf("Something went wrong getting an event\n"); - } - - return numEvents; -} - -void JoystickDevice::getPolledData(int relAxesData[], int absAxesData[], int buttonData[]){ - int i; - - if(inited!=1) return; - for(i=0;i<numAbsAxes;i++) { - (absAxesData)[i] = this->absAxesData[i]; - } - for(i=0;i<numButtons;i++) { - (buttonData)[i] = this->buttonData[i]; - } -} - -int JoystickDevice::getAbsAxisMinimum(int axisNumber) { - return -32767; -} - -int JoystickDevice::getAbsAxisMaximum(int axisNumber) { - return 32767; -} - -int JoystickDevice::getAbsAxisFuzz(int axisNumber) { - return 0; -} - -bool JoystickDevice::getFFEnabled() { - return false; -} - -void JoystickDevice::rumble(float force) { - return; -} - -void JoystickDevice::cleanup() { - close(fd); -} |