⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 joystickinputhandler.cc

📁 Linux下比较早的基于命令行的DVD播放器
💻 CC
字号:
//// Copyright (c) 2004 by Istv醤 V醨adi//// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA//------------------------------------------------------------------------------#include "JoystickInputHandler.h"#include "sched/Scheduler.h"#include "util/Config.h"#include <linux/joystick.h>//------------------------------------------------------------------------------using input::JoystickInputHandler;using sched::Scheduler;//------------------------------------------------------------------------------//------------------------------------------------------------------------------JoystickInputHandler::axisPosition_t JoystickInputHandler::getPosition(int value){    if (value<-16384) return LEFT;    else if (value>16384) return RIGHT;    else return CENTERED;}//------------------------------------------------------------------------------JoystickInputHandler::JoystickInputHandler(InputListener& listener) :    Schedulable("JoystickInputHandler", 16*1024),    CommandInputHandler(listener),    inputReadable("JoystickInputHandler", "inputReadable"),    axisPositions(0){    int fd = open(Config::get().js, O_RDONLY|O_NONBLOCK);    if (fd<0) {        Log::warning("Could not open joystick device '%s', ignoring\n",                     Config::get().js);        return;    }    char numberOfAxes;    POSIX::ioctl(fd, JSIOCGAXES, &numberOfAxes);    axisPositions = new axisPosition_t[numberOfAxes];    for(char i = 0; i<numberOfAxes; ++i) {        axisPositions[i] = CENTERED;    }    inputReadable.setFileDescriptor(fd);}//------------------------------------------------------------------------------JoystickInputHandler::~JoystickInputHandler(){    delete[] axisPositions;}//------------------------------------------------------------------------------void JoystickInputHandler::run(){    const Config& config = Config::get();    Log::debug("Joystick input handler started\n");    while(!shouldQuit() && inputReadable.getFileDescriptor()>=0) {        clearInterrupt();        if (Scheduler::waitInterruptible(inputReadable)) {            struct js_event e;                        ssize_t a = POSIX::read(inputReadable.getFileDescriptor(),                                    &e, sizeof(e), "Error reading from joystick");            if (a==sizeof(e)) {                const char* command = 0;                if (e.type==JS_EVENT_AXIS) {                    size_t axisNumber = e.number;                    axisPosition_t axisPosition = getPosition(e.value);                    if (axisPosition!=axisPositions[axisNumber]) {                        axisPositions[axisNumber] = axisPosition;                        if (axisPosition==LEFT)                           command = config.joystick.getLeftCommand(axisNumber);                        else if (axisPosition==RIGHT)                          command = config.joystick.getRightCommand(axisNumber);                    }                } else if (e.type==JS_EVENT_BUTTON) {                    if (e.value==1) {                        command = config.joystick.getButtonCommand(e.number);                    }                }                if (command!=0) {                    Log::debug("input::JoystickInputHandler::run: joystick command: %s\n", command);                    processCommand(command);                }            }        }            }    Log::debug("Joystick input handler exiting\n");}//------------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -