QList<QStringList> WebcamDetectElement::webcams(QString dir)
{
    Sleep::msleep(250);
    QDir devicesDir(dir);

    QStringList devices = devicesDir.entryList(QStringList("video*"),
                                               QDir::System |
                                               QDir::Readable |
                                               QDir::Writable |
                                               QDir::NoSymLinks |
                                               QDir::NoDotAndDotDot |
                                               QDir::CaseSensitive,
                                               QDir::Name);

    QList<QStringList> webcams;
    struct v4l2_capability capability;

    foreach (QString device, devices)
    {
        QFile devicePath(devicesDir.absoluteFilePath(device));

        if (!devicePath.open(QIODevice::ReadWrite))
            continue;

        ioctl(devicePath.handle(), VIDIOC_QUERYCAP, &capability);

        if (capability.capabilities & V4L2_CAP_VIDEO_CAPTURE)
            webcams << (QStringList() << devicePath.fileName() << QString((const char *)capability.card));

        devicePath.close();
    }
示例#2
0
void BbAccelerometer::applyAccelerationMode()
{
    const QAccelerometer * const accelerometer = qobject_cast<QAccelerometer *>(sensor());
    if (accelerometer) {
        QString fileName;
        sensor_type_e sensorType;
        switch (accelerometer->accelerationMode()) {
        case QAccelerometer::Gravity:
            fileName = QLatin1String("/dev/sensor/gravity");
            sensorType = SENSOR_TYPE_GRAVITY;
            break;
        case QAccelerometer::User:
            fileName = QLatin1String("/dev/sensor/linAccel");
            sensorType = SENSOR_TYPE_LINEAR_ACCEL;
            break;
        default:
        case QAccelerometer::Combined:
            fileName = devicePath();
            sensorType = SENSOR_TYPE_ACCELEROMETER;
            break;
        }

        setDevice(fileName, sensorType);
    }
}
BbOrientationSensor::BbOrientationSensor(QSensor *sensor)
    : BbSensorBackend<QOrientationReading>(devicePath(), SENSOR_TYPE_ORIENTATION, sensor)
{
    setDescription(QLatin1String("Device orientation"));

    // Orientation rarely changes, so enable skipping of duplicates by default
    sensor->setSkipDuplicates(true);
}
示例#4
0
BbAccelerometer::BbAccelerometer(QSensor *sensor)
    : BbSensorBackend<QAccelerometerReading>(devicePath(), SENSOR_TYPE_ACCELEROMETER, sensor)
{
    setDescription(QLatin1String("X, Y, and Z axes accelerations in m/s^2"));

    QAccelerometer * const accelerometer = qobject_cast<QAccelerometer *>(sensor);
    if (accelerometer) {
        connect(accelerometer, SIGNAL(accelerationModeChanged(AccelerationMode)),
                this, SLOT(applyAccelerationMode()));
    }
}
示例#5
0
bool QEglFSKmsEglDevice::open()
{
    Q_ASSERT(fd() == -1);

    int fd = drmOpen(devicePath().toLocal8Bit().constData(), Q_NULLPTR);
    if (Q_UNLIKELY(fd < 0))
        qFatal("Could not open DRM (NV) device");

    setFd(fd);

    return true;
}
nsString
GetObjectPathFromAddress(const nsAString& aAdapterPath,
                         const nsAString& aDeviceAddress)
{
  // The object path would be like /org/bluez/2906/hci0/dev_00_23_7F_CB_B4_F1,
  // and the adapter path would be the first part of the object path, according
  // to the example above, it's /org/bluez/2906/hci0.
  nsString devicePath(aAdapterPath);
  devicePath.AppendLiteral("/dev_");
  devicePath.Append(aDeviceAddress);
  devicePath.ReplaceChar(':', '_');
  return devicePath;
}
BbAmbientLightSensor::BbAmbientLightSensor(QSensor *sensor)
    : BbSensorBackend<QAmbientLightReading>(devicePath(), SENSOR_TYPE_LIGHT, sensor)
{
    setDescription(QLatin1String("Ambient light brightness"));
}
示例#8
0
void NetworkManager::setDeviceEnabled(const QUuid &uuid, const bool enable)
{
    m_networkInter->EnableDevice(QDBusObjectPath(devicePath(uuid)), enable);
}
示例#9
0
bool NetworkManager::deviceEnabled(const QUuid &uuid) const
{
    return m_networkInter->IsDeviceEnabled(QDBusObjectPath(devicePath(uuid)));
}
示例#10
0
BbPressureSensor::BbPressureSensor(QSensor *sensor)
    : BbSensorBackend<QPressureReading>(devicePath(), SENSOR_TYPE_PRESSURE, sensor)
{
    setDescription(QLatin1String("Pressure in Pascals"));
}
示例#11
0
BbAltimeter::BbAltimeter(QSensor *sensor)
    : BbSensorBackend<BbAltimeterReading>(devicePath(), SENSOR_TYPE_ALTIMETER, sensor)
{
    setDescription(QLatin1String("Altitude in meters relative to mean sea level"));
}
示例#12
0
BbMagnetometer::BbMagnetometer(QSensor *sensor)
    : BbSensorBackend<QMagnetometerReading>(devicePath(), SENSOR_TYPE_MAGNETOMETER, sensor)
{
    setDescription(QLatin1String("Magnetic flux density in Teslas (T)"));
}
示例#13
0
BbHolsterSensor::BbHolsterSensor(QSensor *sensor)
    : BbSensorBackend<QHolsterReading>(devicePath(), SENSOR_TYPE_HOLSTER, sensor)
{
    setDescription(QLatin1String("Whether the device is holstered or not"));
}
LRESULT CALLBACK DeviceStatus::WindowsMessageCallback(  HWND hwnd, 
                                                        UINT message, 
                                                        WPARAM wParam, 
                                                        LPARAM lParam)
{
	switch (message)
	{
	case WM_CREATE:
		{
			// Setup window user data with device status object pointer.
			LPCREATESTRUCT create_struct = reinterpret_cast<LPCREATESTRUCT>(lParam);
			void *lpCreateParam = create_struct->lpCreateParams;
			DeviceStatus *pDeviceStatus = reinterpret_cast<DeviceStatus*>(lpCreateParam);

			SetWindowLongPtr(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(pDeviceStatus));
		}
		return 0;	// Return 0 for successfully handled WM_CREATE.

	case WM_DEVICECHANGE:
		{
			WORD loword = LOWORD(wParam);

			if (loword != DBT_DEVICEARRIVAL &&
				loword != DBT_DEVICEREMOVECOMPLETE) 
			{
				// Ignore messages other than device arrive and remove complete 
                // (we're not handling intermediate ones).
				return TRUE;	// Grant WM_DEVICECHANGE request.
			}

			DEV_BROADCAST_DEVICEINTERFACE* hdr;
			hdr = (DEV_BROADCAST_DEVICEINTERFACE*) lParam;

			if (hdr->dbcc_devicetype != DBT_DEVTYP_DEVICEINTERFACE) 
			{
				// Ignore non interface device messages.
				return TRUE;	// Grant WM_DEVICECHANGE request.
			}

			LONG_PTR userData = GetWindowLongPtr(hwnd, GWLP_USERDATA);
			OVR_ASSERT(userData != NULL);

			// Call callback on device messages object with the device path.
			DeviceStatus* pDeviceStatus = (DeviceStatus*) userData;
			String devicePath(hdr->dbcc_name);

            // check if HID device caused the event...
            if (pDeviceStatus->HidGuid == hdr->dbcc_classguid)
            {
                // check if recovery timer is already running; stop it and 
                // remove it, if so.
                pDeviceStatus->FindAndCleanupRecoveryTimer(devicePath);

                if (!pDeviceStatus->MessageCallback(loword, devicePath))
                {
                    // hmmm.... unsuccessful
                    if (loword == DBT_DEVICEARRIVAL)
                    {
                        // Windows sometimes may return errors ERROR_SHARING_VIOLATION and
                        // ERROR_FILE_NOT_FOUND when trying to open an USB device via
                        // CreateFile. Need to start a recovery timer that will try to 
                        // re-open the device again.
                        OVR_DEBUG_LOG(("Adding failed, recovering through a timer..."));
                        UINT_PTR tid = ::SetTimer(hwnd, ++pDeviceStatus->LastTimerId, 
                            USBRecoveryTimeInterval, NULL);
                        RecoveryTimerDesc rtDesc;
                        rtDesc.TimerId = tid;
                        rtDesc.DevicePath = devicePath;
                        rtDesc.NumAttempts= 0;
                        pDeviceStatus->RecoveryTimers.PushBack(rtDesc);
                        // wrap around the timer counter, avoid timerId == 0...
                        if (pDeviceStatus->LastTimerId + 1 == 0)
                            pDeviceStatus->LastTimerId = 0;
                    }
                }
            }
            // Check if Oculus HDMI device was plugged/unplugged, preliminary
            // filtering. (is there any way to get GUID? !AB)
            //else if (strstr(devicePath.ToCStr(), "DISPLAY#"))
            else if (strstr(devicePath.ToCStr(), "#OVR00"))
            {
                pDeviceStatus->MessageCallback(loword, devicePath);
            }
		}
		return TRUE;	// Grant WM_DEVICECHANGE request.

	case WM_TIMER:
		{
			if (wParam != 0)
			{
				LONG_PTR userData = GetWindowLongPtr(hwnd, GWLP_USERDATA);
				OVR_ASSERT(userData != NULL);

				// Call callback on device messages object with the device path.
				DeviceStatus* pDeviceStatus = (DeviceStatus*) userData;

                // Check if we have recovery timer running (actually, we must be!)
                UPInt rtIndex;
                RecoveryTimerDesc* prtDesc = pDeviceStatus->FindRecoveryTimer(wParam, &rtIndex);
				if (prtDesc)
				{
					if (pDeviceStatus->MessageCallback(DBT_DEVICEARRIVAL, prtDesc->DevicePath))
					{
                        OVR_DEBUG_LOG(("Recovered, adding is successful, cleaning up the timer..."));
                        // now it is successful, kill the timer and cleanup
                        pDeviceStatus->CleanupRecoveryTimer(rtIndex);
					}
                    else
                    {
                        if (++prtDesc->NumAttempts >= MaxUSBRecoveryAttempts)
                        {
                            OVR_DEBUG_LOG(("Failed to recover USB after %d attempts, path = '%s', aborting...",
                                prtDesc->NumAttempts, prtDesc->DevicePath.ToCStr()));
                            pDeviceStatus->CleanupRecoveryTimer(rtIndex);
                        }
                        else
                        {
                            OVR_DEBUG_LOG(("Failed to recover USB, %d attempts, path = '%s'",
                                prtDesc->NumAttempts, prtDesc->DevicePath.ToCStr()));
                        }
                    }
				}
			}
		}
		return 0;

	case WM_CLOSE:
		{
			LONG_PTR userData = GetWindowLongPtr(hwnd, GWLP_USERDATA);
			OVR_ASSERT(userData != NULL);
			DeviceStatus* pDeviceStatus = (DeviceStatus*) userData;
			pDeviceStatus->hMessageWindow = NULL;

			DestroyWindow(hwnd);
		}
		return 0;	// We processed the WM_CLOSE message.

	case WM_DESTROY:
		PostQuitMessage(0);
		return 0;	// We processed the WM_DESTROY message.
	}

	return DefWindowProc(hwnd, message, wParam, lParam);
}
示例#15
0
BbIRProximitySensor::BbIRProximitySensor(QSensor *sensor)
    : BbSensorBackend<QIRProximityReading>(devicePath(), SENSOR_TYPE_PROXIMITY, sensor)
{
    setDescription(QLatin1String("IR Proximity"));
}
示例#16
0
BbLightSensor::BbLightSensor(QSensor *sensor)
    : BbSensorBackend<QLightReading>(devicePath(), SENSOR_TYPE_LIGHT, sensor)
{
    setDescription(QLatin1String("Light intensity in lux"));
}
示例#17
0
文件: io_osx.cpp 项目: bmillham/osmc
   QList<DiskDevice *> enumerateDevice()
   {
       QList<DiskDevice *> devices;
       utils::writeLog("Enumerating imageable devices for OSX");
       QProcess process;
       QStringList lines;
       process.setEnvironment(QStringList() << "LANG=C");
       process.start("/usr/sbin/diskutil", QStringList() << "list", QIODevice::ReadWrite | QIODevice::Text);
       if (! process.waitForFinished())
           utils::writeLog("Could not execute diskutil to enumerate devices");
       else
       {
           QTextStream stdoutStream(process.readAllStandardOutput());
           while (true)
           {
               QString line = stdoutStream.readLine().simplified(); /* Remove trailing and leading ws */
               if (line.isNull())
                   break;
               /* The line holding the device is the only line always starting with 0: */
               else if (line.startsWith("0:"))
               {
                   lines << line;
               }
           }
           for (int i = 0; i < lines.count(); i++)
           {
               QString line = lines.at(i);
               QStringList deviceAttr = line.split(" ");

               /*
                * THE FOLLOWING LIST CHANGES IF THE DISK WAS NOT INITIALISED
                * In that case, <partition schema name> is missing and the
                * index for the following elements has to be adressed by n-1
                * content is now:
                * [0] 0:
                * [1] <partition scheme name>
                * [2] <total_size>
                * [3] <size_unit>
                * [4] device name (disk0, disk1, etc)
                */
               QString deviceSpace;
               QString devicePath("/dev/");
               if (deviceAttr.at(1).startsWith("*"))
               {
                   /* partition schema name was missing - uninitialised disk */
                   deviceSpace = deviceAttr.at(1) + " " + deviceAttr.at(2);
                   devicePath += (new QString(deviceAttr.at(3)))->replace(0, 1, "rd");
               } else
               {
                   deviceSpace = deviceAttr.at(2) + " " + deviceAttr.at(3);
                   QString deviceName(deviceAttr.at(4));
                   /* make the disk become a rdisk */
                   devicePath += deviceName.replace(0, 1, "rd");
               }

               deviceSpace.remove("*");
               DiskDevice *nd = new DiskDevice(i, devicePath, deviceSpace);
               utils::writeLog("=================================================");
               utils::writeLog("Starting to parse " + devicePath + " for additional info\n");
               nd = addAdditionalInfo(nd);

               if (nd->getIsWritable())
               {
                   utils::writeLog("Parsed device as writable. Appending.");
                   devices.append(nd);
               }
               else
               {
                   utils::writeLog("Parsed device as NON-writable. NOT Appending.");
               }
               utils::writeLog("\n");
               utils::writeLog("Finished parsing additional info for " + devicePath);
               utils::writeLog("=================================================\n");
           }
       }
       return devices;
   }
示例#18
0
BbDistanceSensor::BbDistanceSensor(QSensor *sensor)
    : BbSensorBackend<QDistanceReading>(devicePath(), SENSOR_TYPE_PROXIMITY, sensor)
{
    setDescription(QLatin1String("Distance"));
}