1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

OP-334 Linux start of implementation and Windows stub to enable compilation.

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2949 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2011-03-03 13:41:13 +00:00 committed by edouard
parent 28d4bbbcfb
commit c01329810a
3 changed files with 109 additions and 17 deletions

View File

@ -9,7 +9,8 @@ HEADERS += rawhid_global.h \
rawhid_const.h \
usbmonitor.h
SOURCES += rawhidplugin.cpp \
rawhid.cpp
rawhid.cpp \
usbmonitor_win.cpp
FORMS +=
RESOURCES +=
DEFINES += RAWHID_LIBRARY
@ -17,8 +18,9 @@ OTHER_FILES += RawHID.pluginspec
# Platform Specific USB HID Stuff
win32 {
SOURCES += pjrc_rawhid_win.cpp
LIBS += -lhid \
SOURCES += pjrc_rawhid_win.cpp \
usbmonitor_win.cpp
LIBS += -lhid \
-lsetupapi
}
macx {
@ -37,10 +39,12 @@ macx {
CoreFoundation
}
linux-g++ {
SOURCES += pjrc_rawhid_unix.cpp
LIBS += -lusb
SOURCES += pjrc_rawhid_unix.cpp \
usbmonitor_linux.cpp
LIBS += -lusb -ludev
}
linux-g++-64 {
SOURCES += pjrc_rawhid_unix.cpp
LIBS += -lusb
SOURCES += pjrc_rawhid_unix.cpp \
usbmonitor_linux.cpp
LIBS += -lusb -ludev
}

View File

@ -1,17 +1,58 @@
/**
* This snippet monitors devices using libudev.
******************************************************************************
*
* @file usbmonitor_linux.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup RawHIDPlugin Raw HID Plugin
* @{
* @brief Implements the USB monitor on Linux using libudev
*****************************************************************************/
/*
* 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 3 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
*/
/*
Need help wihth udev ?
There is a great tuturial at: http://www.signal11.us/oss/udev/
*/
#include "usbmonitor.h"
#include <QDebug>
#include <QTimer>
#define printf qDebug
void USBMonitor::deviceEventReceived() {
qDebug() << "Device event";
struct udev_device *dev;
dev = udev_monitor_receive_device(this->monitor);
if (dev) {
printf("Got Device");
printf(" Node: %s", udev_device_get_devnode(dev));
printf(" Subsystem: %s", udev_device_get_subsystem(dev));
printf(" Devtype: %s", udev_device_get_devtype(dev));
printf(" Action: %s", udev_device_get_action(dev));
udev_device_unref(dev);
}
else {
printf("No Device from receive_device(). An error occured.");
}
}
@ -28,14 +69,11 @@ USBMonitor::USBMonitor(QObject *parent): QThread(parent) {
connect(this->monitorNotifier, SIGNAL(activated(int)),
this, SLOT(deviceEventReceived()));
qDebug() << "Starting the Udev client";
/*
connect(&pollingTimer, SIGNAL(timeout()), this, SLOT(udevDataAvailable()));
pollingTimer.start(100);
*/
start();
start(); // Start the thread event loop so that the socketnotifier works
}
USBMonitor::~USBMonitor()
{
quit();
}

View File

@ -0,0 +1,50 @@
/**
******************************************************************************
*
* @file usbmonitor_win.cpp
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
* @addtogroup GCSPlugins GCS Plugins
* @{
* @addtogroup RawHIDPlugin Raw HID Plugin
* @{
* @brief Implements the USB monitor on Windows using system API
*****************************************************************************/
/*
* 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 3 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 "usbmonitor.h"
#include <QDebug>
#define printf qDebug
void USBMonitor::deviceEventReceived() {
qDebug() << "Device event";
// Dispatch and emit the signals here...
}
USBMonitor::USBMonitor(QObject *parent): QThread(parent) {
}
USBMonitor::~USBMonitor()
{
quit();
}