1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-18 03:52:11 +01:00

OP-332 Linux work in progress implementation (not compiled right now)

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@2948 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
edouard 2011-03-03 11:37:09 +00:00 committed by edouard
parent bce469c184
commit 28d4bbbcfb
2 changed files with 82 additions and 4 deletions

View File

@ -28,10 +28,28 @@
#ifndef USBMONITOR_H #ifndef USBMONITOR_H
#define USBMONITOR_H #define USBMONITOR_H
#include "rawhid_global.h" //#include "rawhid_global.h"
#include <QThread> #include <QThread>
//TODO: temporary, will have to remove
#include "pjrc_rawhid.h"
// Depending on the OS, we'll need different things:
#if defined( Q_OS_MAC)
// TODO
#elif defined(Q_OS_UNIX)
#include <libudev.h>
#include <QSocketNotifier>
#elif defined (Q_OS_WIN32)
//TODO
#endif
/*
struct USBPortInfo { struct USBPortInfo {
QString friendName; ///< Friendly name. QString friendName; ///< Friendly name.
QString physName; QString physName;
@ -39,6 +57,7 @@ struct USBPortInfo {
int vendorID; ///< Vendor ID. int vendorID; ///< Vendor ID.
int productID; ///< Product ID int productID; ///< Product ID
}; };
*/
/** /**
@ -50,8 +69,8 @@ class USBMonitor : public QThread
public: public:
USBMonitor(); USBMonitor(QObject *parent = 0);
USBMonitor(int vid, int pid); // USBMonitor(int vid, int pid);
~USBMonitor(); ~USBMonitor();
signals: signals:
@ -72,9 +91,27 @@ signals:
*/ */
void deviceRemoved( const USBPortInfo & info ); void deviceRemoved( const USBPortInfo & info );
private slots:
/**
Callback available for whenever the system that is put in place gets
an event
*/
void deviceEventReceived();
private: private:
QString serialNumber; // Depending on the OS, we'll need different things:
#if defined( Q_OS_MAC)
// TODO
#elif defined(Q_OS_UNIX)
struct udev *context;
struct udev_monitor *monitor;
QSocketNotifier *monitorNotifier;
#elif defined (Q_OS_WIN32)
//TODO
#endif
}; };

View File

@ -0,0 +1,41 @@
/**
* This snippet monitors devices using libudev.
*/
#include "usbmonitor.h"
#include <QDebug>
#include <QTimer>
void USBMonitor::deviceEventReceived() {
qDebug() << "Device event";
}
USBMonitor::USBMonitor(QObject *parent): QThread(parent) {
this->context = udev_new();
this->monitor = udev_monitor_new_from_netlink(this->context, "udev");
// udev_monitor_filter_add_match_subsystem_devtype(
// this->monitor, "hidraw", NULL);
udev_monitor_enable_receiving(this->monitor);
this->monitorNotifier = new QSocketNotifier(
udev_monitor_get_fd(this->monitor), QSocketNotifier::Read, this);
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();
}
USBMonitor::~USBMonitor()
{
}