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:
parent
bce469c184
commit
28d4bbbcfb
@ -28,10 +28,28 @@
|
||||
#ifndef USBMONITOR_H
|
||||
#define USBMONITOR_H
|
||||
|
||||
#include "rawhid_global.h"
|
||||
//#include "rawhid_global.h"
|
||||
|
||||
#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 {
|
||||
QString friendName; ///< Friendly name.
|
||||
QString physName;
|
||||
@ -39,6 +57,7 @@ struct USBPortInfo {
|
||||
int vendorID; ///< Vendor ID.
|
||||
int productID; ///< Product ID
|
||||
};
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
@ -50,8 +69,8 @@ class USBMonitor : public QThread
|
||||
|
||||
|
||||
public:
|
||||
USBMonitor();
|
||||
USBMonitor(int vid, int pid);
|
||||
USBMonitor(QObject *parent = 0);
|
||||
// USBMonitor(int vid, int pid);
|
||||
~USBMonitor();
|
||||
|
||||
signals:
|
||||
@ -72,9 +91,27 @@ signals:
|
||||
*/
|
||||
void deviceRemoved( const USBPortInfo & info );
|
||||
|
||||
private slots:
|
||||
/**
|
||||
Callback available for whenever the system that is put in place gets
|
||||
an event
|
||||
*/
|
||||
void deviceEventReceived();
|
||||
|
||||
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
|
||||
|
||||
};
|
||||
|
||||
|
41
ground/openpilotgcs/src/plugins/rawhid/usbmonitor_linux.cpp
Normal file
41
ground/openpilotgcs/src/plugins/rawhid/usbmonitor_linux.cpp
Normal 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()
|
||||
{
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user